I am trying to send push notification through push woosh such like this :
is anybody help me how to send push notification on device from this code
function pwCall(
'createMessage', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
"devices" => PW_DEVICETOKEN,
'notifications' => array(
'send_date' =>'now', //gmdate('d-m-Y H:i', strtotime('2014-04-07 20:35')),
'content' => 'my custom notification testing ',
'link' => 'http://pushwoosh.com/',
'content' => array("en" => "English","ru" =>"Русский","de"=>"Deutsch")
),
'page_id' => 16863,
'link' => 'http://google.com',
'data' => array( 'custom' => 'json data' ),
)
);
I am getting error such as
Array ( [status_code] => 210 [status_message] => Cannot parse date [response] => )
notifications should be array of objects in JSON notation. In PHP it will be array of arrays. This is because you can create multiple notifications in one request.
final JSON for notifications field:
"notifications":[{ ... notification properties... }, { ... second notification properties ... }, ...]
There are only 3 root parameters in request: application(OR applications_group), auth, and notifications. Other parameters are parameters of notification, not request.
Finally your PHP call should be like following:
pwCall("createMessage", array(
"auth" => PW_AUTH,
"application" => PW_APPLICATION,
"notifications" => array(
array(
"send_date" => "now",
"content" => array("en" => "English", "ru" =>"Русский", "de"=>"Deutsch"),
"link" => "http://pushwoosh.com/",
"page_id" => 16863,
"devices" => array( PW_DEVICETOKEN ),
"data" => array( "custom" => "json data" )
)
)
));
All notification's fields except of send_date and content are optional and can be omited
By the looks of it, your date is not formatted correctly. You're passing an ordinary string consisting of the word "now". What you'll want to do is something along the lines of the following:
function pwCall("createMessage", array(
"application" => PW_APPLICATION,
"auth" => PW_AUTH,
"devices" => PW_DEVICETOKEN,
"notifications" => array(
"send_date" => gmdate("Y-m-d H:i"),
"content" => "My custom notification",
"link" => "http://pushwoosh.com/",
"content" => array("en" => "English", "ru" =>"Русский", "de"=>"Deutsch")
),
"page_i" => 16863,
"link" => "http://google.com",
"data" => array("custom" => "json data"),
)
);
we've developped an API to easily call the Pushwoosh Web Services.
This API should be a good quality one and is fully tested (very high code coverage).
https://github.com/gomoob/php-pushwoosh
$push_auth = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$push_app_id = 'XXXXX-XXXXX';
$push_debug = false;
$title = ''; // pushwoosh title
$banner = ''; // pushwoosh banner
$send_date = 'now'; // pushwoosh date
$android_header = ''; // pushwoosh android header
$android_custom_icon = '' pushwoosh notification icon;
sendpush('createMessage', array(
'application' => $push_app_id,
'auth' => $push_auth,
'notifications' => array(
array(
'send_date' => $send_date,
'content' => $title,
'android_header'=>$android_header,
'android_custom_icon' =>$android_custom_icon,
'android_badges' => 2,
'android_vibration' => 1,
'android_priority' => 1,
'data' => array('custom' => 'json data'),
),
)
));
function sendpush($method, $data) {
$url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
$request = json_encode(['request' => $data]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if (defined('PW_DEBUG') && self::$push_de) {
print "[PW] request: $request\n";
print "[PW] response: $response\n";
print "[PW] info: " . print_r($info, true);
}
return $info;
}
}
Related
I want to send an email with the image as an attachment and also embed it in the body.
<?php
$email = "to#example.com";
$name = "some_name";
$img = file_get_contents('image.jpg');
$body = '<img src = "cid:image">';
$subject = "Test email";
$headers = array(
'Authorization: Bearer API_KEY',
'Content-Type: application/json'
);
$data = array(
"personalizations" => array(
array(
"to" => array(
array(
"email" => $email,
"name" => $name
)
)
)
),
"from" => array(
"email" => "from#example.com"
),
"subject" => $subject,
"content" => array(
array(
"type" => "text/html",
"value" => $body
)
),
"attachments" => array(
array(
"content" => base64_encode($img),
"type" => "image/jpeg",
"filename" => "image",
"disposition" => "inline",
"content_ID" => "image",
//"disposition" => "attachment"
)
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sendgrid.com/v3/mail/send");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
echo $response;?>
The problem is that it is either going as inline content or an attachment but not both. I don't know how to solve this.
I tried adding two separate attachments blocks for inline and attachment, but it's always considering the second block.
Nothing seems to work.
Twilio SendGrid developer evangelist here.
You don't want to set two of the same keys in an array (as you are doing for disposition) or set two attachments blocks. Instead, you should add two items to the attachments block, like this:
"attachments" => array(
array(
"content" => base64_encode($img),
"type" => "image/jpeg",
"filename" => "image-inline",
"disposition" => "inline",
"content_ID" => "image-inline",
),
array(
"content" => base64_encode($img),
"type" => "image/jpeg",
"filename" => "image-attachment",
"disposition" => "attachment",
"content_ID" => "image-attachment",
),
)
Notice I also provided different filenames and content IDs for the inline and attached files.
Someone could help me ? I'm trying to do a request by the code bellow, but anything happen, any message appears. I believe my code it's right:
public function subscribe(){
$json_url = 'https://apisandbox.cieloecommerce.cielo.com.br/1/sales/';
$json_string = json_encode(array(
"MerchantOrderId"=>"2014113245231706",
"Customer" => array(
"Name" => "Comprador rec programada"
),
"Payment" => array(
"Type" => "CreditCard",
"Amount" => 1500,
"Installments" => 1,
"SoftDescriptor" => "Assinatura Fraldas"
)
));
$ch = curl_init($json_url);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
CURLOPT_POSTFIELDS => $json_string
);
curl_setopt_array( $ch, $options );
$result = curl_exec($ch); // Getting jSON result string
print_r($result);
}
Find link with instructions of the site:
you will reiceive this:
[
{
"Code": 114,
"Message": "The provided MerchantId is not in correct format"
}
]
with this code:
function subscribe(){
$json_url = 'https://apisandbox.cieloecommerce.cielo.com.br/1/sales/';
$json_string = json_encode(
array(
"MerchantOrderId"=>"2014113245231706",
"Customer" => array(
"Name" => "Comprador rec programada"
),
"Payment" => array(
"Type" => "CreditCard",
"Amount" => 1500,
"Installments" => 1,
"SoftDescriptor" => "Assinatura Fraldas"
)
)
);
$headers = array(
'Content-Type: application/json',
'MerchantId: xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxx',
'MerchantKey: xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxx',
'RequestId: xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxx'
);
$ch = curl_init($json_url);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $json_string
);
curl_setopt_array( $ch, $options ); $result = curl_exec($ch);
print_r($result);
}
subscribe()
It would be interesting what HTTP status code you get:
print_r(curl_getinfo($ch, CURLINFO_HTTP_CODE));
Trying to send messages to slackchannels with incoming webhooks installed on them. Attachments needs to be sent along with the message and PHP variables holds these URLs. Similary, I want to send some ID's which are again hold in some PHP variables. Here is my server side PHP code:
<?php
$testplan_name = $_POST[plan]; //test plan name coming from the client
$url1 = $_POST[run_url]; //run url coming from the client
$url2 = $_POST[plan_url]; //plan url coming from the client
$room = "random";
$icon_url = ":ghost:";
$username = "Test";
$attachments = array([
'fallback' => 'Hey! See this message',
'pretext' => 'Here is the plan name ${testplan_name}',
'color' => '#ff6600',
'fields' => array(
[
'title' => 'Run URL',
'value' => 'url1',
'short' => true
],
[
'title' => 'Build URL',
'value' => 'url2',
'short' => true
]
)
]);
$data = "payload=" . json_encode(array(
"channel" => "#{$room}",
"icon_emoji" => $icon_url,
"username" => $username,
"attachments" => $attachments
));
$url = "https://hooks.slack.com/services/XXXX/XXX/XXXXXXXXXXXXX"; //got from slack as a webhook URL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
echo var_dump($result);
if($result === false)
{
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
If you see in the attachments variable above, there is variable inside of pretext which tries to print the value of ${testplan_name} declared at the top. However, it does not seem to work and the program is failed to post messages to slack channels. Similarly, I want to print values of url1 and url2 in the attachments -> fields values as can be seen above(the way I am trying to print). The program just works fine if I do not try to use any variables and get their values while posting messages. How do I print the values of these variables in messages?
(slack is a messaging platform for teams, if you don't know)
Try this instead>
$attachments = array([
'fallback' => 'Hey! See this message',
'pretext' => 'Here is the plan name '.$testplan_name,
'color' => '#ff6600',
'fields' => array(
[
'title' => 'Run URL',
'value' => $url1,
'short' => true
],
[
'title' => 'Build URL',
'value' => $url2,
'short' => true
]
)
]);
I'm working with paypal adaptive payments API and all things were okay till last month.
The problem is ipnNotificationUrl is not sending any notifications to URL i provided in code.
Here is the code of PayPal adaptive payment,
<?php
class Paypal{
private $api_user;
private $api_pass;
private $api_sig;
private $app_id;
private $apiUrl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/';
private $paypalUrl="https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=";
private $headers;
public function setDetails($api_u, $api_p, $api_s, $api_id){
$this->api_user = $api_u;
$this->api_pass = $api_p;
$this->api_sig = $api_s;
$this->app_id = $api_id;
$this->headers = array(
"X-PAYPAL-SECURITY-USERID: ".$this->api_user,
"X-PAYPAL-SECURITY-PASSWORD: ".$this->api_pass,
"X-PAYPAL-SECURITY-SIGNATURE: ".$this->api_sig,
"X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-APPLICATION-ID: ".$this->app_id,
);
}
public function getPaymentOptions($paykey){
$pack = array(
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll",
),
"payKey" => $paykey
);
return $this->_paypalSend($pack, "GetPaymentOptions");
}
public function setPaymentOptions(){
}
public function _paypalSend($data,$call){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->apiUrl.$call);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
$response = json_decode(curl_exec($ch),true);
return $response;
}
public function splitPay($currency, $r1_email, $r2_email, $r1_amount, $r2_amount, $returnUrl, $cancelUrl, $product_name, $indentifier){
$createPacket = array(
"actionType" =>"PAY",
"currencyCode" => $currency,
"receiverList" => array("receiver" =>
array(
array(
"amount"=> $r1_amount,
"email"=> $r1_email
),
array(
"amount"=> $r2_amount,
"email"=> $r2_email
)
)
),
"returnUrl" => $returnUrl,
"cancelUrl" => $cancelUrl,
"ipnNotificationUrl" => URL::to('/adaptive_payments'),
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll",
),
);
$response = $this->_paypalSend($createPacket,"Pay");
$paykey = $response['payKey'];
$detailsPack = array(
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll",
),
"payKey" => $paykey,
"receiverOptions" => array(
array(
"receiver" => array("email" => $r1_email),
"invoiceData" => array(
"item" => array(
array(
array(
"name" => $product_name,
"price" => $r1_amount,
"identifier" => $indentifier
)
)
)
)
),
array(
"receiver" => array("email" => $r2_email),
"invoiceData" => array(
"item" => array(
array(
array(
"name" => "product 2",
"price" => $r2_amount,
"identifier" => "p2"
)
)
)
)
)
)
);
$response = $this->_paypalSend($detailsPack, "SetPaymentOptions");
$dets = $this->getPaymentOptions($paykey);
return $this->paypalUrl.$paykey;
}
}
And here the response i get,
array(3) { ["responseEnvelope"]=> array(4) { ["timestamp"]=> string(29) "2015-06-04T14:04:07.395-07:00" ["ack"]=> string(7) "Success" ["correlationId"]=> string(13) "6c472863c4053" ["build"]=> string(8) "15743565" } ["payKey"]=> string(20) "AP-5LN44020A0587750B" ["paymentExecStatus"]=> string(7) "CREATED" }
Which is perfectly fine and i can use paykey, but ipnNotificationUrl not working as it should. it doesn't send anything at all at URL.
What t tried to solve the issue,
1) did change URL of ipnNotificationUrl even made hard coded
2) tested with IPN simulator (the listener), worked for test
3) changed return URL and cancel URL to test if others working, also made sure that i'm working with correct file and code
Please HELP!
The code is working fine , it wasn't because paypal had put IPN as queued.
More details here https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNOperations/
Hope this answer will help others.
I am Trying to Tag a picture and posting it through graphs However, when I remove the 'tags' => $tags from below, it works. Otherwise I get this error:
Array ( [error] => Array ( [message] => (#100) param tags must be an array. [type] => OAuthException [code] => 100 ) )
Here is my code:
<?php
$tags = array(
'to' => $_SESSION['my_fb_id'],
'x' => 0,
'y' => 0
);
$tag[]= $tags ;
//
//upload photo
$file = 'imgtmp/save_as_this_name.jpg';
$args = array(
'message' => 'This is my Picture',
'tags' => $tag, // IF this line is removed ,It works!
);
$args[basename($file)] = '#' . realpath($file);
$ch = curl_init();
$url = 'https://graph.facebook.com/me/photos?access_token=' . $_SESSION['access_token'];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
print_r(json_decode($data, true));
?>
Tags must be array of tags as you can tag many people.
$tag1 = array(
'tag_text' => 'tag test1',
'tag_uid' => 'XXXXX1',
'x' => 0,
'y' => 0
);
$tag2 = array(
'tag_text' => 'tag test2',
'tag_uid' => 'XXXXX2',
'x' => 0,
'y' => 0
);
$tags = array($tag1, $tag2);
In your case
$args = array(
'message' => 'This is my Picture',
'tags' => array( $tags ) ,
);
EDIT 1:
To tag photos successfully you will require user_photos permission.
Using graph api
$file = 'test.jpg';
$tags = array(
'tag_text' => 'tag test',
'tag_uid' => 'XXXXX',
'x' => 10,
'y' => 10
);
$args['tags'] = array($tags);
$args[basename($file)] = '#' . realpath($file);
$data = $facebook->api("/me/photos", "post", $args);
print_r($data);
Edit 2:
Just use json_encode for tags parameter
$args['tags'] = json_encode(array($tags));
This will solve the issue while using cURL.
Alright I got it. From the Facebook API:
"tags": {
"data": [
{
"id": "11111111111111",
"name": "John Doe",
"x": 0,
"y": 0,
"created_time": "2012-09-03T03:08:44+0000"
}
]
},
The tags arg needs to contain an array with data as the key. Here:
$tags['data'] = array(
'to' => $_SESSION['my_fb_id'],
'x' => 0,
'y' => 0 );