How to send one signal push notification with large image using PHP - php

Code sends only a title and message but icon not getting received. I am new to one signal API. Here is my code:
<?php
$fields = array(
'app_id' => 'my app id',
'include_player_ids' => ['player_id'],
'contents' => array("en" =>"test message"),
'headings' => array("en"=>"test heading"),
'largeIcon' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png',
);
$fields = json_encode($fields);
//print("\nJSON sent:\n");
//print($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Authorization: Basic M2ZNDYtMjA4ZGM2ZmE5ZGFj'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
?>

You just simply add:
"chrome_web_image" => "image url";
$fields = array(
'app_id' => 'my app id',
'include_player_ids' => ['player_id'],
'contents' => array("en" =>"test message"),
'headings' => array("en"=>"test heading"),
'chrome_web_image' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png',
);
To further reading please go to: doc appearance of onesignal
Result:

They key for the icon should be large_icon not largeIcon
Check the API for more details

You can use ios_attachments parameter and it must be in array.
This is how I did it:
$iCon = array(
"ios_attachments" => 'https://Your.Image.png'
);
$fields = array(
// OneSignal - Personal ID
'app_id' => "Your_OneSignal_ID",
'included_segments' => array('All'),'data' => array("foo" => "bar"),
// Submitting Title && Message && iCon
'headings' => $headings,
'contents' => $content,
'ios_attachments' => $iCon,
);

$fields = array(
'app_id' => $app_id,
'headings' => array("en"=>$data['title']),
'contents' => ["en" => $data['description']] ,
'big_picture' => $data['file'],
'large_icon' => $data['file'],
'url' => $data['launch_url']
);

Related

OneSignal notification redirect to invalid URL

I have a OneSignal setup for sending notification to specific users via external user id as follows
$fields = [
'app_id' => env( 'app.onesignalAppKey' ),
'priority' => 10, // High priority.
'include_external_user_ids' => [ md5( $contact['email'] ) ],
'channel_for_external_user_ids' => 'push',
'headings' => [ 'en' => $this->subject ],
'contents' => [ 'en' => $this->message ],
'url' => [ 'en' => base_url( $this->args['log_extra']['url'] ) ]
];
$fields = json_encode($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, env( 'app.Onesignalurl'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
'Authorization: Basic '. env( 'app.onesignalAPI' )));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
While testing I'm receiving notification, but clocking the notification redirect to wrong url.
https://example.com/onesignal/{"en"=>"https://example.com/correct-path"}
OneSignal service worker installed with scope set to /onesignal/
Am I don't something wrong here..?
Just put the URL as string in $fields array, not an array.
like:
'url' => base_url( $this->args['log_extra']['url'] ),

Integrate Coinbase Commerce in PHP

I want to integrate Coinbase Commerce API in one of my web application. I have refer this link https://commerce.coinbase.com/docs/ and create a demo in local server. I successfully get the below output
and below screen
Now i want to know After getting the last screen which give me address what to do with that code. does i need to open it in any specific application or I have to use it in my code. If i need to use in code provide me example code.
Also I have try to make curl request of "Create Charge" with following code but I didn't get any response.
$metadata = array(
'customer_id' => '123456',
'customer_name' => 'adarsh bhatt'
);
$request_body = array(
'X-CC-Api-Key' => 'd59xxxxxxxxxxxxxxb8',
'X-CC-Version' => '2018-03-22',
'pricing_type' => 'fixed_price',
'name' => 'Adarsh',
'description' => ' This is test donation',
'local_price' => array(
'amount' => '100.00',
'currency' => 'USD'
),
'metadata' => $metadata
);
$req = curl_init('https://api.commerce.coinbase.com/charges');
curl_setopt($req, CURLOPT_RETURNTRANSFER, false);
curl_setopt($req, CURLOPT_POST, true);
curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($req, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen(json_encode($request_body))));
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($request_body));
$respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
$resp = json_decode(curl_exec($req), true);
curl_close($req);
echo '<pre>';
print_r($output);
exit;
The following should be a valid request to create a charge and return the hosted URL:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.commerce.coinbase.com/charges/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$post = array(
"name" => "E currency exchange",
"description" => "Exchange for Whatever",
"local_price" => array(
'amount' => 'AMOUNT',
'currency' => 'USD'
),
"pricing_type" => "fixed_price",
"metadata" => array(
'customer_id' => 'customerID',
'name' => 'ANY NAME'
)
);
$post = json_encode($post);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "X-Cc-Api-Key: YOUR-API-KEY";
$headers[] = "X-Cc-Version: 2018-03-22";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
curl_close ($ch);
$response = json_decode($result);
return $response->data->hosted_url;
You can try this way. It's work for me
$curl = curl_init();
$postFilds=array(
'pricing_type'=>'no_price',
'metadata'=>array('customer_id'=>10)
);
$postFilds=urldecode(http_build_query($postFilds));
curl_setopt_array($curl,
array(
CURLOPT_URL => "https://api.commerce.coinbase.com/charges",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $postFilds,
CURLOPT_HTTPHEADER => array(
"X-CC-Api-Key: APIKEY",
"X-CC-Version: 2018-03-22",
"content-type: multipart/form-data"
),
)
);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
Hello you can use php sdk for coinbase commerce.
https://github.com/coinbase/coinbase-commerce-php
composer require coinbase/coinbase-commerce
use CoinbaseCommerce\Resources\Charge;
use CoinbaseCommerce\ApiClient;
ApiClient::init('PUT_YOUR_API_KEY');
$chargeData = [
'name' => 'The Sovereign Individual',
'description' => 'Mastering the Transition to the Information Age',
'local_price' => [
'amount' => '100.00',
'currency' => 'USD'
],
'pricing_type' => 'fixed_price'
];
$chargeObj = Charge::create($chargeData);
var_dump($chargeObj);
var_dump($chargeObj->hosted_url);

Subsrcibe a user in MailChimp API V3 give bad response

When I try to subscribe a user on mailchimp, it gives an error response pasted below:
‹<»nÃ0E…Вű2tòèt+ŠB‘[€.I¹0‚ü{i»è(Þ‹ÃC=Œ¬3šÁL"ómÀS‘úìbòSÌsïk¶¡ú–±ˆ“X‹ýÏìØb#¶HTé<¦Êìhµ¦3%mÜ·²¸\‘k#±R›áåréL#Q˜ß'ú+·[Ž"À×–”pCØQNÇ=¼V‚{ÄÎ<£÷èá#qŒ¢¸Ó®Å'pDníuu,º¼øML_Gl†‡ÙQÇ4£1n•+~·H±§?H¸«ÌT½;€ÛW|¹TÍóóùÿÿI*¯Q`
Here is the PHP code:
$apiKey = 'YOUR API KEY';
$listId = 'YOUR LIST ID';
$url2 = 'https://us12.api.mailchimp.com/3.0/lists/'.$listId.'/members/';
$args = array(
'email' => 'abc#xyz.com',
'status' => 'subscribed',
'merge_fields' => array(
'first_name' => 'WOW',
'last_name' => 'WOW',
'mobile'=>'',
'message'=>'',
'ID'=>'000'
));
function syncMailchimp($url,$apiKey,$args) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_USERPWD, "user apikey:" . $apiKey);
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/3.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
Is the server sending bad data or is client side using a wrong encoding and how do I fix it?
Changing the key called email to email_address appears to have fixed it. Perhaps that bad key caused the server to puke.
$args = array(
'email' => 'abc#xyz.com',
'status' => 'subscribed',
'merge_fields' => array(
'first_name' => 'WOW',
'last_name' => 'WOW',
'mobile'=>'',
'message'=>'',
'ID'=>'000'
));
to
$args = array(
'email_address' => 'abc#xyz.com',
'status' => 'subscribed',
'merge_fields' => array(
'first_name' => 'WOW',
'last_name' => 'WOW',
'mobile'=>'',
'message'=>'',
'ID'=>'000'
));

Bugzilla report bug using PHP

I was trying to post a bug to my bugzilla account using this code
set_time_limit(0);
$URI = 'http://site.com/bugzilla/xmlrpc.cgi';
$xml_data = array(
'login' => 'email',
'password' => 'password',
'remember' => 0
);
$bug_ids = array(50, 100); // bugs list
//$file_cookie = tempnam('', 'bugzilla-cookie');
$ch = curl_init();
$options = array(
//CURLOPT_VERBOSE => true,
CURLOPT_URL => $URI,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array( 'Content-Type: text/xml', 'charset=utf-8' )
);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt_array($ch, $options);
$request = xmlrpc_encode_request("User.login", $xml_data);
var_dump($request);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
//curl_setopt($ch, CURLOPT_COOKIEJAR, $file_cookie);
$server_output = curl_exec($ch); // Array( [id] => 1 ) for example
print_r ($server_output);
$response = xmlrpc_decode($server_output);
But it keep requesting and i get no response
Also I read the Documentation of the BugZilla and I got nothing from it
Also I found a code for Zend framework
$oClient = new Zend_XmlRpc_Client('http://my.zilla.url/xmlrpc.cgi');
$oHttpClient = new Zend_Http_Client();
$oHttpClient->setCookieJar();
$oClient->setHttpClient($oHttpClient);
$aResponse = $oClient->call('User.login', array(array(
'login' => 'peterh#mydomain.com',
'password' => 'mypassword',
'remember' => 1
)));
$aResponse = $oClient->call('Bug.create', array(array(
'product' => "My Product",
'component' => "My Component",
'summary' => "This is the summary of the bug I'm creating",
'version' => "unspecified",
'description' => "This is a description of the bug",
'op_sys' => "All",
'platform' => "---",
'priority' => "P5",
'severity' => "Trivial"
)));
$iBugId = $aResponse['id'];
$aResponse = $oClient->call('User.logout');
But I am not using Zend framework
And there is also some perl files as I read but I don't know how to deal with them
After three days of searching and reading I came here
Please Help me to accomplish it
i create bug in bugzilla using this code ...i hope this is helpful to someone
set_time_limit(0);
$URI = 'your bugzilla url/xmlrpc.cgi';
$xml_data = array(
'login' => 'username',
'password' => 'password',
'remember' => 0
);
$ch = curl_init();
$file_cookie = tempnam('', 'bugzilla-cookie');
$options = array(
//CURLOPT_VERBOSE => true,
CURLOPT_URL => $URI,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array( 'Content-Type: text/xml', 'charset=utf-8' )
);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt_array($ch, $options);
$request = xmlrpc_encode_request("User.login", $xml_data);
// var_dump($request);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_COOKIEJAR, $file_cookie);
$server_output = curl_exec($ch); // Array( [id] => 1 ) for example
print_r ($server_output);
echo "<br />";
$response = xmlrpc_decode($server_output);
print_r ($response);
$xml_data1 = array(
'product' => "Magento",
'component' => "Menu",
'summary' => "this is third testing bug",
'assigned_to' => "assigneename",
'version' => "1.6.2.0",
'description' => "This is a description of the bug",
'op_sys' => "All",
'platform' => "All",
'priority' => "Normal",
'severity' => "Trivial"
);
$request = xmlrpc_encode_request("Bug.create", $xml_data1); // create a request for filing bugs
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = xmlrpc_decode(curl_exec($ch));
print_r ($response);
This following documentation focus on how to create a XML-RPC Server, but at the end shows a sample for consuming the generated XML-RPC service.
the Bakery - How to create an XML-RPC server with CakePHP
The class may be helpful, since you need someway to connect to a XML-RPC server (bugzilla)

Facebook PHP Api cUrl auto post to page's wall (not profile wall)

I need to be able to post to the wall of my page, i have given offline_permissions and I got it to post to my profile wall but I need it to post to my pages wall.
Anyone know how to do this, where does my code need changing? thanks
<?php session_start();
$fb_page_id = xxxxxxxxxxxxxxxx;
$fb_access_token = 'xxxxxxxxx|xxxxxxxxxxxxxxxxxx-xxxxxxxx|xxxxxxxxxxxxxxxxxxxxxxx';
$url = 'https://graph.facebook.com/'.$fb_page_id.'/feed';
$attachment = array(
'access_token' => $fb_access_token,
'message' => 'message text',
'name' => 'name text',
'link' => 'http://domain.com/',
'description' => 'Description Text',
'picture'=>'http://domain.com/logo.jpg',
);
// set the target url
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$go = curl_exec($ch);
curl_close ($ch);
?>
$config = array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
'allowSignedRequest' => false //optional but should be set to false for non-canvas apps
);
$facebook->api('/me/feed', 'POST',
array(
'link' => 'www.example.com',
'message' => 'Posting with the PHP SDK!'
));
https://developers.facebook.com/docs/php/howto/postwithgraphapi/

Categories