apns-collapse-id does not replace push notification - apple-push-notifications

I'm using libcurl on my server side PHP script to send PHP notifications via HTTP/2. In my headers I'm sending an apns-collapse-id, like so:
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'apns-topic: ' . BUNDLE_ID,
'Authorization: Bearer ' . generateAuthenticationHeader(),
'apns-collapse-id', 'qwer1235'
]);
$url = "https://api.development.push.apple.com/3/device/$token";
curl_setopt($ch, CURLOPT_URL, "{$url}");
When the notification comes in I don't acknowledge it on the phone, and then I send another message with a different alert title but the exact same apns-collapse-id. Both messages are then displayed on the phone. My understanding of the apns-collapse-id is that it should have removed the older message and replaced it with this new one.
Am I missing something?

Related

how do i send notification to all mobile devices when i post a new content in Drupal? also Laravel is my Authentication back-end

I am using Laravel for authentication and druapl for content management, and now using firebase for notification to mobile devices... how do i send notification to all mobile devices when i post a new content in druapl?
this is my send function in Laravel
public function sendNotification($device_token, $message)
{
$SERVER_API_KEY = 'myKey';
$data = [
"to" => $device_token, // for single device id
"notification" => $message
];
$dataString = json_encode($data);
$headers = [
'Authorization: key=' . $SERVER_API_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_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
You should get token id from each user device and send notification via their device token as an array.
Add a new table named devices has user_id and device_token as columns then each new user open your application his device token will be sent to your server then you should save received token as new record to devices table.

POST requests require a Content-length header in laravel

$output = Curl::httpGet("https://bhleh.com/emailstorage", "POST", $params);
return $output;
this is in my laravel but when ever i try to run this i get an error saying
411. That’s an error.
POST requests require a Content-length header. That’s all we know.
i tried adding header files in my middle ware folder but nothing seems to work.
i figured out that the Content-length header isn't included in laravel (i think so not so sure) so how would i add it
please note i am very new to laravel
this fix to this is that this i replaced the whole code with this
$data_string = json_encode($params);
$ch = curl_init('https://bhleh.com/emailstorage');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
return $result;
I was facing the same issue but I was not sending CURLOPT_POSTFIELDS as per the API endpoint. I don't need to send any variable but when I send CURLOPT_POSTFIELDS with a blank array it started working.
$data_string = array();
$ch = curl_init('https://bhleh.com/emailstorage');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data_string));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
);
$result = curl_exec($ch);
return $result;

How to Use Google My Business Api to get the reviews , and reply to that

If I have api key of Business API, i just want example of URL, like how to put the place id and api key.
If Google have authorized you to use Google Business API then you need to
Authenticate the user via OAuth.
After authentication which will give you the token, API will return you the users's account.
Now to get the reviews you have to make Http Get request to the endpoint below
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationid}/reviews
Your Http Get request must have Access Token
For Example: https://mybusiness.googleapis.com/.../reviews??access_token={tokenHere}
this will return you all the reviews.
Ref: https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews
Hope that answered your Question.
*Please note, support of v3 of the API ended on March 10, 2018; v3 will no longer be available on May 10th 2018. So we encourage you to migrate to v4.1 as soon as possible to prevent any interruption in functionality. In addition, the deprecation schedule can be found here
You can get Google My business (GMB) reviews in same ways
Please find the below working code for review reply with PHP HTTP request
$access_token = "<your_access_token_here>";
$query = array('comment' => 'Thank you for visiting our business!');
$request_uri = "https://mybusiness.googleapis.com/v4/accounts/111050869667910417441/locations/17405754705905257334/reviews/AIe9_BFu3rdicGrPrzdyu4PDXmqMAu-9BCJf9_HF0DxzGxsjAGw5KGl1XsdqSkbsAMdl_W2XBG4bwO3wCp0_l_8KLAV7mckl5cSyJItwPqSYGiH3ktK6nrI/reply?access_token=" . $access_token;
$curinit = curl_init($request_uri);
curl_setopt($curinit, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curinit, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curinit, CURLOPT_POSTFIELDS, json_encode($query));
curl_setopt($curinit, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curinit, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($query)))
);
$json = curl_exec($curinit);
$phpObj = json_decode($json, true);
var_dump($phpObj);
This code worked for me. I used the curl library to answer a review. I hope it serves you
$url = "https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply";
$access_token = {access token google}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$query = array('comment' => 'Thank You!');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$access_token.'',
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($query)))
);
$response = curl_exec($ch);
echo $response;
curl_close($ch);

500 Internal Server Error on Payza IPN Handler

I am migrating an app from PayPal to Payza (formerly AlertPay). When I run the code directly from the browser to test the token handling it shows up in the logs and I get a proper response: token=47TXhMVgdPrmV3n5aauIZ5CC0MrytYXWjID81pjVnQsEhkSUklPXT3clXZ4SFUFOL5WqepRUpBz5SKomoyPuDw==& INVALID TOKEN. When I run the full IPN response directly in the browser I get a fail but no visible errors.
But when I generate a transaction or resend an IPN from Payza it is not showing up in the log and I am getting a 500 Internal Server Error. I have turned on allow Query Strings in the CI config file.
class PayzaIPN {
function validate_ipn($payzaIPN ='',$logId = null) {
define("IPN_V2_HANDLER", "https://secure.payza.com/ipn2.ashx");
define("TOKEN_IDENTIFIER", "token=");
$_POST['token'] = '';
$token = urlencode($_POST['token']);
$token = TOKEN_IDENTIFIER.$payzaIPN;
$response = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, IPN_V2_HANDLER);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $token);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
if(strlen($response) > 0)

send post include text and image by xmlrpc to wordpress

Im looking for a way to send remotely content(text and image ) by xmlrpc to wordpress but i couldn't find yet, im going to sent remotely content (text and image) over 100 post per minute to wordpress, whats the best way to do it? thanks so much
Use XMLRPC. Something like this:
$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);

Resources