OneSignal notification redirect to invalid URL - php

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'] ),

Related

Firebase push notifications php curl returning null

I am making a flutter app and I am using Firebase to do push notifications.
I am not sure what is going wrong here. It looks like it should work I think but I get no response back. Am I missing something?
Here is my code:
$fcmUrl = 'https://fcm.googleapis.com/fcm/send';
$token = $_POST['token'];
$notification = [
'title' => 'title',
'body' => 'body of message.',
'icon' => 'myIcon',
'sound' => 'mySound'
];
$extraNotificationData = ["message" => $notification, "moredata" => 'dd'];
$fcmNotification = [
//'registration_ids' => $tokenList, //multple token array
'to' => $token, //single token
'notification' => $notification,
'data' => $extraNotificationData
];
$headers = [
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $fcmUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
$result = curl_exec($ch);
curl_close($ch);
echo $result;

Only samsung mobile is not getting notification from fcm

I am getting notification to all android device except samsung mobile.
This problem started after I updated url from "https://android.googleapis.com/gcm/send" to
"https://fcm.googleapis.com/fcm/send" because gcm suddenly stopped sending notification to all devices..
After updating url,notification is not going to samsung devices
I am not getting wheee is the problem.Please help me with solution
Thank you
here is my fcm code in php
$msg = array(
'message' => json_encode($parsedMsg),
'title' => '',
'subtitle' => '',
'tickerText' => '',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
if(count($registrationIds) == 0){
return json_encode(array('success' => 0, 'failure'=>0));
}
$fields = array(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}

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);

Can't add user to a group using MailChimp API 3.0

I'm trying to update my code for subscribing new users to my MailChimp newsletter.
I would like it to add the user to a group, so that I can distinguish between users when sending out newsletters. This code, however, subscribes the user but does not add it to any group. What am I doing wrong? I am using the MailChimp API 3.0.
My code:
$apiKey = 'XXXX';
$list_id = 'XXXX';
$memberId = md5(strtolower($data['email']));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/' . $memberId;
$json = json_encode(array(
'email_address' => $data['email'],
'status' => $data['status'], // "subscribed","unsubscribed","cleaned","pending"
'merge_fields' => array(
'FNAME' => $data['firstname'],
'LNAME' => $data['lastname'],
'GROUPINGS' => array(
0 => array(
'name' => 'Interests',
'groups' => array( $data['tag'] ),
),
),
),
));
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
You are passing Interest grouping in the wrong array.
you need to pass the interest group id in interests array with value as true.
$json = json_encode(array(
'email_address' => 'test#example.com',
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => 'FirstName',
'LNAME' => 'LastName',
),
'interests' => array(
'9143cf3bd1' => true,
'789cf3bds1' => true
),
));
You will get the id of interest groups [9143cf3bd1,789cf3bds1 in above example] of the list by requesting to this URL
/lists/{list_id}/interest-categories
see doc here
If you want to remove the subscriber from the group, you need to set its value to false in your update request.

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'
));

Categories