Hey I'm building an App on iOS and want to implement PushNotifications.
I am using the EasyAPNS code from https://github.com/manifestinteractive/easyapns
When configuring it, I have to obviously add my Mysql-Database information in the DB_Connect php file. I am not good with php, so I don't really have a clue here as to how exactly I have to enter my information in the file because in the tutorials I'va watched the file always looked different. Can you guys give me any guidance as to how to proceed? Thnaks, oengelha.
Here the code snippet:
/**
* Constructor. Initializes a database connection and selects our database.
* #param string $host The host to wchich to connect.
* #param string $username The name of the user used to login to the database.
* #param string $password The password of the user to login to the database.
* #param string $database The name of the database to which to connect.
*/
function __construct($host, $username, $password, $database)
{
$this->DB_HOST = $host;
$this->DB_USERNAME = $username;
$this->DB_PASSWORD = $password;
$this->DB_DATABASE = $database;
}
This should help
function __construct()
{
$this->DB_HOST = 'Your Host';
$this->DB_USERNAME = 'Your Username'; // !!! CHANGE ME
$this->DB_PASSWORD = 'Your Password'; // !!! CHANGE ME
$this->DB_DATABASE = 'Your Database'; // !!! CHANGE ME
}
Best of luck!
Related
I have successfully added rapidoreach ios app monetization SDK into my app. i am not very much aware about server to server callbacks..Any idea how it can be done with nodejs and express?
You can use request method which comes by default with node.js or by using axios library for server to server callback, but a quick check at rapidoreach site (https://www.rapidoreach.com/docs#/callbacks) leads to this doc for callback setup and looks like you want to receive callbacks, in that case you have to setup a api at your end to receive their server call, this is one example done in Nodejs
Example:
function rapidoreachPostback(req: Request, res: Response) {
var IP = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
var Input = req.query;
if (Input.status == 'C' || Input.status == "P" || Input.status == "F") {
if(Input.status === "C"){
//record your completion here
}
//if rapidoreach allows disaqualification points
if(Input.status === "P"){
//record your disqualification transaction over here
}
if(Input.status === "F"){
//record your survey offer failure transaction over here
}
}
} catch (error) {
// send "1" in response to server call from rapidoreach.
res.send("1");
return;
}
res.send("1");
return;
})
return;
}
res.send("1");
return;
}
Rapidoreach will send server to server callback using get request to the callback URL maintained in App setings.
Assuming Callback URL in app settings is set as
https://local.callback.com/callback.php
Below is an example of server to server callback. Details of parameters available in callback can be found in their official docs
https://www.rapidoreach.com/docs#/callbacks
https://local.callback.com/callback.php?cmd=P&userId=SYKUser-CvkBPlfibeV-aba04fe2fc72219fdbb9a9353a68713d&amt=0.01&offerInvitationId=trans0002&status=P&offerHash=4fdcc6461ec225ba8af3bc66ccf4017c¤cyAmt=0.80&transactionId=trans0002&endUserId=SYKUser&txnHash=d5fecc45d5be250ff757f8694a6d65a1&useragent=Rapidoreach¤cyName=Local Coins&offerType=1&deviceType=Desktop&intergrationMethod=IFRAME
Here is an example how you can handle callback using PHP.
File callback.php
<?php
/**
* ApplicationKey can be found in credentials tab of app created in Rapidoreach
*/
$ApplicationKey = "<Replace this>"; //<- replace this with real application key
/**
* $endUserId is unique endUserId in publisher's system.
*/
$EndUserId = $_REQUEST['endUserId'];
/**
* Unique offer Id
*/
$OfferInvitationId = $_REQUEST['offerInvitationId'];
/**
* TransactionId
*/
$TransactionId = $_REQUEST['transactionId'];
/**
* Status
* C: Completed - User has successfully completed an offer and should be rewarded with currencyAmt
* P: Attempted - User has attempted an offer and attempt is valid will be rewarded with currencyAmt
* currencyAmt will not be full in this case and will be equal to screenout reward maintained in App Setting of Rapidoreach Publisher portal
* F: Failed - User has failed to complete an offer and hence terminated. No rewards should be awarded
*/
$Status = $_REQUEST['status'];
/**
* Validate offerHash
* You should verify oidHash upon receipt of the callback by recomputing it with the callback offerInvitationId and your ApplicationKey.
* This will secure against users faking their own id and passing it in if by some chance they come across the script.
*/
$offerHash = $_REQUEST['offerHash'];
$CalculatedOfferHash = md5($OfferInvitationId . $ApplicationKey);
if ($offerHash != $CalculatedOfferHash) {
/**
* TODO: User is trying to manupulate offerId to get credits. Flag this user within this condition if required (optional).
* Do not credit this user and send success response to Rapidoreach
* Do not continue further
*/
echo "1";
die;
}
/**
* Validate txnHash
*/
$txnHash = $_REQUEST['txnHash'];
$CalculatedTxnHash = md5($TransactionId . $ApplicationKey);
if ($txnHash != $CalculatedTxnHash) {
/**
* TODO: User is trying to manupulate transaction id to get credits. Flag this user within this condition if required (optional).
* Do not credit this user and send success response to Rapidoreach
* Do not continue further
*/
echo "1";
die;
}
/**
* Credit the user based on offer status
*/
switch ($Status) {
case 'C':
# TODO: Credit the $EndUserId with $currencyAmt use $TransactionId to avoid duplicates
echo "1";
die;
break;
case 'P':
# TODO: Credit the $EndUserId with $currencyAmt use $TransactionId to avoid duplicates
echo "1";
die;
break;
case 'F':
# TODO: User has failed to complete an offer
echo "1";
die;
break;
default:
# code...
break;
}
First I apologize if this is a duplicate because I've looked everywhere and the answers are either for slightly different scenarios or I just can't get them to work.
My scenario:
Hosting a Drupal site on a platform that does not support files larger than 250mb. Client wants a zip file that is 500mb to be hosted on the site and the reasoning is so that the url to the file is the same as any other file on the site. They want the ability to easily remove the file and replace it with a new large file in the future.
UPDATE:
I was successful masking an s3 file url with CNAME for a subdomain, but that will not resolve the issue that it is a slightly different URL and would require it's own ssl cert.
I'm using the s3fs module to set the default file location for the site to the s3 bucket. Now while setting up a file manager module, elfinder, I can't get it to know the new location to manage the files. Elfinder assumes they are in the local default files location. Once I've resolved this, I can tackle the cname.
This is not a complete answer, just a bit of code i cannot put inside the comment.
This code generates temporary link to download private files, that stored on S3 bucket.
Use it like this:
$url = el_s3_getTemporaryLink('myaccesskey','mysecretkey','mybucket','linux.png', 1);// this link is alive for one minute.
Which will output something like: https://mybucket.s3.amazonaws.com/?sometoken
You can put that inside links like:
l('Download now', $url, ['external'=>true]);
<?php
if(!function_exists('el_crypto_hmacSHA1')){
/**
* Calculate the HMAC SHA1 hash of a string.
*
* #param string $key The key to hash against
* #param string $data The data to hash
* #param int $blocksize Optional blocksize
* #return string HMAC SHA1
*/
function el_crypto_hmacSHA1($key, $data, $blocksize = 64) {
if (strlen($key) > $blocksize) $key = pack('H*', sha1($key));
$key = str_pad($key, $blocksize, chr(0x00));
$ipad = str_repeat(chr(0x36), $blocksize);
$opad = str_repeat(chr(0x5c), $blocksize);
$hmac = pack( 'H*', sha1(
($key ^ $opad) . pack( 'H*', sha1(
($key ^ $ipad) . $data
))
));
return base64_encode($hmac);
}
}
if(!function_exists('el_s3_getTemporaryLink')){
/**
* Create temporary URLs to your protected Amazon S3 files.
*
* #param string $accessKey Your Amazon S3 access key
* #param string $secretKey Your Amazon S3 secret key
* #param string $bucket The bucket (bucket.s3.amazonaws.com)
* #param string $path The target file path
* #param int $expires In minutes
* #return string Temporary Amazon S3 URL
* #see http://awsdocs.s3.amazonaws.com/S3/20060301/s3-dg-20060301.pdf
*/
function el_s3_getTemporaryLink($accessKey, $secretKey, $bucket, $path, $expires = 5) {
// Calculate expiry time
$expires = time() + intval(floatval($expires) * 60);
// Fix the path; encode and sanitize
$path = str_replace('%2F', '/', rawurlencode($path = ltrim($path, '/')));
// Path for signature starts with the bucket
$signpath = '/'. $bucket .'/'. $path;
// S3 friendly string to sign
$signsz = implode("\n", $pieces = array('GET', null, null, $expires, $signpath));
// Calculate the hash
$signature = el_crypto_hmacSHA1($secretKey, $signsz);
// Glue the URL ...
$url = sprintf('http://%s.s3.amazonaws.com/%s', $bucket, $path);
// ... to the query string ...
$qs = http_build_query($pieces = array(
'AWSAccessKeyId' => $accessKey,
'Expires' => $expires,
'Signature' => $signature,
));
// ... and return the URL!
return $url.'?'.$qs;
}
}
I'm creating a Swift app using Backendless. The app automatically creates the user's username attribute, though this may be changed in the future. Either way, how can I get Backendless to prevent a user from registering if they have the same username as another?
I have added an event handler in Backendless (Business Logic section) to run before allowing a user to register:
/* global Backendless */
/**
* #param {Object} req The request object contains information about the request
* #param {Object} req.context The execution context contains an information about application, current user and event
* #param {Object} req.user
*/
Backendless.ServerCode.User.beforeRegister(function(req) {
//add your code here
}, true);
How can I set it up to check if a username value is the same as an existing one and, if so, throw an error?
Here is the query to know whether user exists or not
let query = BackendlessDataQuery()
let userEmail = "foo#foo.com"
query.whereClause = "email = '\(userEmail)'"
let users = backendless.data.of(BackendlessUser.ofClass()).find(query)
if( users.data.count > 0 )
{
// user exists
}
referenced from Here
You may set a UNIQUE constraint on the username column. This way you'll receive an error in your app, which you'll we able to handle as you wish.
1.I had read https://www.igniterealtime.org/builds/smack/docs/latest/documentation/extensions /filetransfer.html
snippet code from this guide, it not need resource part
// Create the file transfer manager
FileTransferManager manager = new FileTransferManager(connection);
// Create the outgoing file transfer
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer("romeo#montague.net");
// Send the file
transfer.sendFile(new File("shakespeare_complete_works.txt"), "You won't believe this!");
2.so I read spark source code org.jivesoftware.spark.PresenceManager find this method , so the documentation long time no to update;
/**
* Returns the fully qualified jid of a user.
*
* #param jid the users bare jid (ex. derek#jivesoftware.com)
* #return the fully qualified jid of a user (ex. derek#jivesoftware.com --> derek#jivesoftware.com/spark)
*/
public static String getFullyQualifiedJID(String jid) {
System.out.println("getFullyQualifiedJID : " + jid);
final Roster roster = SparkManager.getConnection().getRoster();
Presence presence = roster.getPresence(jid);
System.out.println("getFullyQualifiedJID : " + presence.getFrom());
return presence.getFrom();
}
I find this method not work for asmack , so google it found this
Smack's FileTransferManager.createOutgoingFileTransfer only accepts full JIDs. How can I determine the full JID of a user in Smack?
//snippet code from my project
Roster roster = connection.getRoster();
List presenceList = roster.getPresences(jid);
Log.d(TAG, "bareJid : " + jid);
for (Presence presence : presenceList) {
Log.d(TAG, "fullJID : " + presence.getFrom());
}
why the code can not get the fullJID.
the output:
12-23 06:55:35.840: D/MChat(1805): bareJid : test#tigereye-pc
12-23 06:55:35.840: D/MChat(1805): fullJID : test#tigereye-pc
4.the result is the same, so how can I get the fullJID
Thanks & Regards
You have to supply Full user id as : user#serveripaddress/Smack
For Example :
xyz#192.168.1.1/Smack
The need the full JID and the client resource.
You can do something like that:
String fullJID = xmppConnection.getRoster().getPresence(JID).getFrom();
My JID variable is the full JID without the resource.
We're using the new gmail api on iOS to send emails and everything works great for messages with single recipients. When we specify more than one in the "to" field, we get the following error:
Error Domain=com.google.GTLJSONRPCErrorDomain Code=400 "The operation couldn’t be completed. (Invalid to header)
I have verified the content we are sending is in fact a valid rfc822 message.
You should use a list in your to field.
E.g. :
[ "liz6beigle#hotmail.com",
"another.one#email.com" ]
Gmail has a limit of bounces and recipients you can send at the same time.
You cannot store multiple emails under a single string.
Placing a single email address on each line will give better readability and prevent parsing errors.
Here is a code sample in Java from google. I hope it will help others to understand :
/**
* Create a MimeMessage using the parameters provided.
*
* #param to Email address of the receiver.
* #param from Email address of the sender, the mailbox account.
* #param subject Subject of the email.
* #param bodyText Body text of the email.
* #return MimeMessage to be used to send email.
* #throws MessagingException
*/
public static MimeMessage createEmail(String to, String from, String subject,
String bodyText) throws MessagingException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session);
InternetAddress tAddress = new InternetAddress(to);
InternetAddress fAddress = new InternetAddress(from);
email.setFrom(new InternetAddress(from));
email.addRecipient(javax.mail.Message.RecipientType.TO,
new InternetAddress(to));
email.setSubject(subject);
email.setText(bodyText);
return email;
}
Gmail API : Sending Messages
Check the first code sample.
This was a regression but we finished deploying the fix on Monday, 2014-08-25.
I think you can do the following
get the 'To' fields as this
"test1#example.com, test2#example.com"
then split it with ','
String mail1 = "test1#example.com";
String mail2 = "test2#example.com";
then do this
email.addRecipient(javax.mail.Message.RecipientType.TO,
new InternetAddress(mail1));
email.addRecipient(javax.mail.Message.RecipientType.TO,
new InternetAddress(mail2));
I checked this
it worked
You can use comma separated emails and loop through those emails
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session);
Multipart multiPart = new MimeMultipart("alternative");
email.setFrom(new InternetAddress(from));
String to = "xyz#gmail.com,sjaksks#gmail.cm,hysrtt#gmail.com";
String[] split = to.split(",");
for(int i=0;i<split.length;i++) {
email.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(split[i]));
}
email.setSubject(subject);
MimeBodyPart textPart = new MimeBodyPart();
textPart.setText(text, "utf-8");
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(html, "text/html; charset=utf-8");
multiPart.addBodyPart(textPart);
multiPart.addBodyPart(htmlPart);
email.setContent(multiPart);
return email;
I had an exchange with the gmail team and they did confirm that this is actually a bug with their api. Not sure when it will be fixed as they didn't provide any more details but it's on their radar.