Firebase Clooud Messaging Duplicate Push Notifivation - php

I am using Firebase for push notification in my ionic app. But unfortunately I am getting the same notification twice. I have searched through the net a lot and tried to apply all possible solutions found there but could not get it to work. My codes are as the following -
Web end (PHP)
$message_for_push = array(
"data" => array(
"title" => "New Notification",
"body" => "the message",
"icon" => "firebase-logo.png",
'sound' => 'mySound',
"type" => $message['type'],
"section_id" => $message['section_id'],
"isPush" => 1,
"subdomain" => $subdomain, //dynamiic
"id" => $message['id'],
"other_key" => true
),
/*"notification" => array(
"title" => "New Notification",
"body" => $message['title'],
"icon" => "firebase-logo.png",
'sound' => 'mySound',
"type" => $message['type'],
"section_id" => $message['section_id'],
"isPush" => 1,
"subdomain" => $subdomain, //dynamiic
"id" => $message['id'],
),*/
"registration_ids" => $registrationIds //array of device ids
);
$message_for_push = json_encode($message_for_push);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://fcm.googleapis.com/fcm/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_SSL_VERIFYHOST=>0,
CURLOPT_SSL_VERIFYPEER=>0,
CURLOPT_POSTFIELDS => $message_for_push,
CURLOPT_HTTPHEADER => array(
"authorization: key=THE_KEY_GIVEN_HERE",
"cache-control: no-cache",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
On the App End
I have saved the device id on my web end at the time of first login. The token is saved only once. It does not change until or unless the app is re-installed.
this.firebase.getToken().then(token => {
this.devicInfo.uuid = token;
console.log( 'device_id>>>>>', token ); ///saved on web end
}).catch(error => console.error('Error getting token', error));
When the notification is received (Do not think any problem here)-
this.firebase.onNotificationOpen().subscribe((pushed_data) => {
let alert = this.alert.create({
title: 'Notification Received!',
message: pushed_data,
buttons: ['OK']
});
alert.present();
});
The list of plugins used -
com-sarriaroman-photoviewer
cordova-plugin-console
cordova-plugin-device
cordova-plugin-file
cordova-plugin-file-opener2
cordova-plugin-file-transfer
cordova-plugin-firebase
cordova-plugin-network-information
cordova-plugin-splashscreen
cordova-plugin-statusbar
cordova-plugin-whitelist
cordova-plugin-youtube-video-player
cordova-sqlite-storage
ionic-plugin-keyboard
Any help is highly appreciable. Thanks.

Related

How to make redirecte to link, which return response from API php?

Situation - i got form on site, which action on api.php of partner system, data send success, partner system receive it, than it response on request with success and data - url, which user should be redirected.
{"status":true,"data":"https://client.domain.com/en-US/Account/autologin?Email=mail#yahoo.com&Password=password", etc.}
Code of API.php
<?php
$apidata = array(
"firstname" => $_POST['firstname'],
"lastname" => $_POST['lastname'],
"email" => $_POST['email'],
"password" => $_POST['password'],
"phone" => $_POST['phone'],
"userip" => $_SERVER['REMOTE_ADDR'],
"sub" => "sub1",
"so" => "sub2",
"ai" => "ID",
"ci" => "ID",
"gi" => "ID"
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://partner.media/api/signup/procform',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($apidata),
CURLOPT_HTTPHEADER => array(
'x-trackbox-username: username',
'x-trackbox-password: password',
'x-api-key: apikey',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
This code works well - it send data once, but i don't understand, how to get "data":"https://client.domain.com/en-US/Account/autologin?Email=mail#yahoo.com&Password=password" from response, send apidata there too and So user can be redirected there automatically?
I hope I understand you correctly. I think the only part your missing is, that the client side must call your api with the needed parameters. The echo $response sends the client (which is waiting for a response) the data back and you have to do the redirect on the client side.

Got 415 error "Unsupported Media Type" when use wp_remote_post

I tried to send a POST request from WordPress to an external API (assign a tag to an user in a CRM system). When I used cURL, everything was OK. Here is the cURL code:
function my_function () {
$body = array ( 'tags' => array ( array (
'email' => 'xxx#gmail.com',
'tag' => 'Customer5'
))
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "$api_url",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($body, true),
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"User-Agent: Your App Name (www.yourapp.com)",
"Authorization: Basic xxxxxx"
),
));
$response = curl_exec($curl);
curl_close($curl);
var_dump($response);
}
add_action( 'init', 'my_function');
But then I switched to use wp_remote_post, I got a "415 - Unsupported Media Type" response.
$body = array ( 'tags' => array (
array(
'email' => 'xxx#gmail.com',
'tag' => 'Customer5'
))
);
$headers = array (
'Content-Type' => 'application/json',
'User-Agent' => 'Your App Name (www.yourapp.com)',
'Authorization' => 'Basic xxxxxx',
);
$request = wp_remote_post('$api_url', $arg );
$arg = array (
'header' => $headers,
'body' => json_encode($body, true),
'method' => 'POST',
'sslverify' => false,
);
echo '<pre>';
print_r($request);
echo '</pre>';
I tried a lot of modifications (changed associative array format to key:value pair, add AddType to htaccess file...), but nothing worked. Please help, I'm stuck
Excerpt from KeyCDN:
A 415 Unsupported Media Type error occurs when the origin server
refuses a particular request since the resource is in a format that is not supported by the server for the HTTP
method
used. This unsupported format type issue can be caused by what is
defined in the resource's Content-Type or Content-Encoding
headers.
And in your case, the error happened most likely because your remote request sent the wrong Content-Type header — which defaults to application/x-www-form-urlencoded when the HTTP method is POST.
And yes, you did include the right Content-Type value in your $headers array. But unfortunately in your $arg array which you passed to wp_remote_post(), you used the wrong array key — header, which should actually be headers (note the "s").
So use headers and not header, just as you can see below:
$api_url = 'your API URL';
$body = array(
'tags' => array(
array(
'email' => 'xxx#gmail.com',
'tag' => 'Customer5',
),
),
);
$headers = array(
'Content-Type' => 'application/json',
'User-Agent' => 'Your App Name (www.yourapp.com)',
'Authorization' => 'Basic xxxxxx',
);
$arg = array(
'headers' => $headers, // good
// 'header' => $headers, // bad; i.e. wrong array key ('header')
'body' => json_encode( $body ),
// 'method' can be omitted since you're using wp_remote_post()
'method' => 'POST',
'sslverify' => false,
);
$request = wp_remote_post( $api_url, $arg );
// ..if the response still isn't good, what's the output of this:
var_dump( $request );

sms api integration with php - smsedge.com telnyx.com

Did anyone used https://smsedge.com/ or https://telnyx.com
I am trying to use the PHP api, but no luck with smsedge .
Telnyx works like a charm but I could not find a way to send like a bulk sms.
Tryed the help section, they just posted me a link, but it doesnt work :(
<?php
require_once __DIR__.'/vendor/autoload.php';
\Telnyx\Telnyx::setApiKey('myapikey');
\Telnyx\Message::Create([
"from" => "TShop",
"to" => "+4473836955xx",
"text" => "Hello, World! visit www.google.com",
"messaging_profile_id" => "40017370-b28d-425f-8785-92a64f52ea60"
]);
Is there any way to send to multiple number all at once ?
Also : I am new to php and still reading trying to figure it out .
Thanks in advance .
I struggled many hours to find a service and found one service that does bulk sms :
https://www.infobip.com/
Here is an example(just replace the <api_key> with your key)
$curl = curl_init();
$fields = [
'messages' => [
array(
'from' => 'infoSMS',
'destinations' => ['to' => '1st_phone_number'],
'text' => 'This is first message.',
),
array(
'from' => 'infoSMS',
'destinations' => ['to' => '2nd_phone_number'],
'text' => 'This is second message.',
),
array(
'from' => 'infoSMS',
'destinations' => ['to' => '3rd_phone_number'],
'text' => 'This is third message.',
),
]
];
curl_setopt_array($curl, array(
CURLOPT_URL => "https://qgdg2q.api.infobip.com/sms/2/text/advanced",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fields),
CURLOPT_HTTPHEADER => array(
"Authorization: App <api_key>",
"Content-Type: application/json",
"Accept: application/json",
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
There is also another service which is https://smsedge.com/

paypal single payout blank response

I want to integrate paypal's single payout method in my system, as I want to send money to my sellers, when they request for withdrawal. I have generated an "Access token key" for this and making a curl call from PHP script. But the response is a blank string. I have tried curl_error($curl); but this also doesn`t do anything. Below is my code
// data to be sent
$data = [
'sender_batch_header' => [
'email_subject' => "You have a payment",
'sender_batch_id' => "125458268"
],
'items' => [
[
'recipient_type' => "EMAIL",
'amount' => [
'value' => "12.00",
'currency' => "USD"
],
'receiver' => 'myselle#gmail.com',
'note' => 'A trial for single payout',
'sender_item_id' => "2014031400456"
],
],
];
//curl link for single payout with sync off
$curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payouts?sync_mode=true");
$header = array(
"Content-Type: application/json",
"Authorization: Bearer ".$access_token ,
);
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_POSTFIELDS => json_encode($values),
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_TIMEOUT => 10
);
curl_setopt_array($curl, $options);
$rep = curl_exec($curl);
$response = json_decode($rep, true);
curl_close($curl);
But here my $rep is a blank string, tried getting single payout details as well, but this also returns blank string...please help..thanx in advance.
After 2 days of search I found an answer, which was very easy. I didn't use paypal's single payout, instead of that I used it's Implicit Payments operation of PAY API. Below is the code for it..
$receiver[] = array(
'amount' => '125.00',//amount to be transferred
'email' => 'seller#gmail.com',// paypal email id to which you want to send money
);
$result = $paypal->call(
array(
'actionType' => 'PAY',
'currencyCode' => 'USD',
'feesPayer' => 'EACHRECEIVER',
'memo' => 'Withdrawal request no. 356',
'cancelUrl' => '/cancel.php',
'returnUrl' => '/success.php',
'senderEmail' => 'admin.business#gmail.com', // email id of admin's business account, from which amount will be transferred.
'receiverList' => array(
'receiver'=>$receiver
)
), 'Pay'
);
function call($values,$type)
{
$header = array(
"X-PAYPAL-SECURITY-USERID: ".$config['userid'],
"X-PAYPAL-SECURITY-PASSWORD: ".$config['password'],
"X-PAYPAL-SECURITY-SIGNATURE: ".$config['signature'],
"X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-APPLICATION-ID: ".$config['appid'];
);
$curl = curl_init("https://svcs.sandbox.paypal.com/AdaptivePayments/");
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_POSTFIELDS => json_encode($values),
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_TIMEOUT => 10
);
curl_setopt_array($curl, $options);
$rep = curl_exec($curl);
$response = json_decode($rep, true);
curl_close($curl);
return $response;
}
If you are the API caller and you specify your email address in the senderEmail field, PayPal sets the payment to be implicitly approved, without redirection to PayPal. (Alternatively, you can use sender.accountId.)

curl_exec return an XMLFault from Paypal REST Api

I'm currently using the Paypal REST Api for a mobile app.
Here's my code :
$paymentDatas = array(
"intent" => "sale",
"redirect_urls" => array(
"return_url" => "http://example.com/your_redirect_url/",
"cancel_url" => "http://example.com/your_cancel_url/"
),
"payer" => array("payment_method" => "paypal"),
"transactions" => array(
"transactions" => array(
"total" => ".99",
"currency" => "USD"
)
)
);
$paymentUrl = 'https://api.sandbox.paypal.com/v1/payments/payment';
$initCurl = curl_init();
curl_setopt_array(
$initCurl, array(
CURLOPT_URL => $paymentUrl,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false, //todo: For testing purpose, need tp be removed
CURLOPT_POST =>true,
CURLOPT_HTTPHEADER => array(
'Accept-Language: en_US',
'Accept: application/json',
'Authorization: Bearer '.$data['access_token']
),
CURLOPT_POSTFIELDS => json_encode($paymentDatas),
)
);
$initRet = curl_exec($initCurl);
dd($initRet);
curl_close($initCurl);
And the dd gives me this :
string '<ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring xmlns:ns1="http://cxf.apache.org/bindings/xformat">java.lang.NullPointerException</ns1:faultstring></ns1:XMLFault>' (length=196)
I've already made others functions for authentication but I'm pretty new with REST and Paypal Api.
I had the same problem.
When changing the POST request to GET everything worked fine. Hope this will help you.

Categories