Push notification with pusher beam, unable to send data/payload - php

I am using following php sdk for generating pusher beam push notification. but there is not information provided in the sdk docs on how to send data/payload along with it. the notification is bean sent correctly but I am unable to send data: please guide me how we can send the data: it is showing hasData as false in beam console, please check:
php sdk i am using : https://github.com/pusher/push-notifications-php
my code look like this:
$pushNotification = new PushNotifications([
'instanceId' => env('BEAM_INSTANCE_ID'),
'secretKey' => env('BEAM_PRIMARY_KEY')
]);
$pushNotification->publishToInterests(
['message-notification'],
[
"apns" => [
"aps" => [
"alert" => "Message Received",
],
],
"fcm" => [
"notification" => [
'title' => 'some title',
'body' => 'some body',
'data' => 'some data', //passing data here but not working
],
],
]
);

I got it working, we can pass data in following way:
$publishResponse = $pushNotifications->publishToInterests(
["donuts"],
[
"apns" => [
"aps" => [
"alert" => "Hello!",
],
],
"fcm" => [
"notification" => [
"title" => "Hello!",
"body" => "Hello, world!",
],
"data" => [ // <==== pass data here
"name" => "adam",
"type" => "user",
],
],
]
);

Related

Apple Wallet Store card expired before Expiry Date

In the application, we have a feature to download the wallet card into the Apple wallet as a contact card.
We have created this wallet contact card from the PHP code - below.
$data = [
'description' => 'MyApp',
'formatVersion' => 1,
'organizationName' => 'My app',
'passTypeIdentifier' => 'pass.test.test',
'serialNumber' => '12345678',
'teamIdentifier' => '*********',
'storeCard' => [
"headerFields" => [
[
"key" => "header-text",
"label" => "Let's connect",
"value" => "Together"
]
],
"auxiliaryFields" => [
[
"key" => "aux-text-two",
"label" => "",
"value" => ""
],
[
"key" => "aux-text-one",
"label" => "www.abc.com",
"value" => ""
]
],
"primaryFields" => [],
'secondaryFields' => [],
'backFields' => [],
],
'barcode' => [
'format' => 'PKBarcodeFormatQR',
'message' => 'https://abc.1-2-3-4-5.xyz/public/myapp/?id='.$userData->token.'',
'messageEncoding' => 'iso-8859-1',
],
"backgroundColor" => "rgb(255,255,255)",
'logoText' => '',
'relevantDate' => date('Y-m-d\TH:i:sP'),
"expirationDate" => "2030-01-01T23:00:00Z",
];
We are requesting an apple wallet card to be generated from the iOS code calling API for this - below.
if PKPassLibrary.isPassLibraryAvailable(){
if let data = try? Data(contentsOf: url){
if let pass = try? PKPass(data: data){
let passLibrary = PKPassLibrary()
if !passLibrary.containsPass(pass),
let passController = PKAddPassesViewController(pass: pass){
passController.delegate = self
self.present(passController, animated: true)
}else{
ShowAlert(message: "contact_card_already_exist".localize(), theme: .error)
}
}
}
}
As screenshots say - it’s valid till 1/1/30, PHP code we have given the expiry date as well, but still, the wallet card is gone to Expired in 2 days.
Any help is appreciated.

Attributes not visible when sending message to Amazon SQS using PHP SDK

I am trying to send a message to an SQS queue, in PHP with a message body and message attributes. This is how my message looks:
$message = [
'MessageAttributes' => [
"Title" => [
'DataType' => "String",
'StringValue' => "The Hitchhiker's Guide to the Galaxy"
],
"Author" => [
'DataType' => "String",
'StringValue' => "Douglas Adams."
],
"WeeksOn" => [
'DataType' => "Number",
'StringValue' => "6"
]
],
'QueueUrl' => $this->queueUrl,
'MessageBody' => 'Hello SQS testing'
];
I found this example on Github: Sending and Receiving Messages in Amazon SQS.
When I open the console and look for my message in the queue, I can see the message body but I don't see any attributes. I am using Amazon SDK for PHP 3.x.

FCM link not working in desktop notification

We are trying to send a desktop notification calling the FCM rest api via a php service.
We call the https://fcm.googleapis.com/fcm/send service, passing the following payload:
"data" => [
"notification" => [
"title" => $content->title,
"body" => "notification body",
"icon" => url('assets/images/logo_3.png'),
],
"webpush" => [
"headers" => [
"Urgency" => "high",
],
"fcm_options" => [
"link" => url($content->url)
]
],
],
The notification is received in desktop (tested on windows 10) but when we click on the popup the link is not opened in the browser.
What are we doing wrong?
It turns out that we must use click_action field, like this:
"notification" => [
"title" => $content->title,
"body" => "body",
"icon" => "assets/icon.png",
"click_action" => "https://www.example.com",
]
Docs here:https://firebase.google.com/docs/cloud-messaging/http-server-ref

using php guzzle for PUT with stream and parameters

I'm trying to figure out how to implement the following REST PUT using Guzzle. I've tried using multipart and json, but I'm not sure what the syntax should be for having the parameters with a streamed xml file.
Can anyone help me translate this into a proper query? Below is what I tried so far, but it returns an error because it says the ProjectXML must be included.
$newUri = sprintf('%s/projects/%s/storage', $api_base, $testPid);
$newResp = $client->put($newUri,
[
'headers' => [
'Authorization' => sprintf("HubApi %s", $api_key),
],
'multipart' => [
[
'name' => 'ProjectXml',
'contents' => file_get_contents("xml/$testPid.xml")
],
[
'name' => 'ProjectId',
'contents' => $testPid
],
[
'name' => 'HubUserId',
'contents' => "xxxxxxx-xxxxx-xxxx-xxxxx-xxxxxxxx"
],
[
'name' => 'ProductId',
'contents' => "$(package:ourcompany/ourproducttype)/products/ProductABC123"
],
[
'name' => 'ThemeUrl',
'contents' => "$(package:ourcompany/ourproducttype)/themes/themename-white-Classic"
],
]
]
);
Response:
`400 Bad Request - Validation Error` response:
{"code":"RequestValidationError","message":"'Project Xml' should not be empty."}

Sendgrid sending mail with attachment using web api v3

I'm new to using sendgrid web api v3. link here
Right now. It was easy to send a plain html using there api 'POST https://api.sendgrid.com/v3/mail/send' but I have this instance where we will attach a file (csv/xls,pdf) and I can't seem to get it right.
Here is my code below:
My function postSendMail
public function postSendMail($data = [])
{
if ( ! arrayHasValue($data) ) $this->error(__METHOD__, "Data is empty.");
$request = Curl::to( $this->apiUrl.'mail/send' )
->withHeader('Authorization: Bearer '. $this->apiKey)
->withData( $data )
->asJson(true)
->enableDebug(storage_path('logs/laravel-'.php_sapi_name().'.log'))
->post();
return $request;
}
//my instance
$sendgrid = new Sendgrid;
$data = [
'personalizations' => [
[
'to' => [
[ 'email' => 'myemail#gmail.com' ]
],
'subject' => 'Hello, World!'
]
],
'from' => [
'email' => 'myemail#gmail.com',
'name' => 'my_site'
],
'content' => [
[
'type' => 'text',
'value' => 'Hello, World!'
]
],
'track_settings' => [
[
'click_tracking' => true,
'open_tracking' => true
]
],
'attachments' => [
[
'content' => base64_encode(config('global.UPLOAD_PATH') . '/my_file.pdf'),
'type' => 'application/pdf',
'filename' => 'my_file.pdf',
'disposition' => 'attachment'
]
]
];
$lists = $sendgrid->postSendMail($data);
Mail was successfully sent but when I view the attached file, it was corrupted/unable to view. Can anyone help me? :(
Please help.
The problem is that you are not reading the file into an object and then encoding that object; you're encoding a string containing the file path.
'content' => base64_encode(config('global.UPLOAD_PATH') . '/my_file.pdf')
All of your attachments in the tests are probably the same size, and smaller than the actual file as a result.
Try something like:
$imagedata = file_get_contents(config('global.UPLOAD_PATH') . '/my_file.pdf');
$base64 = base64_encode($imagedata);
Coming to main point you need to get file content either by curl request or by file_get_content then encode the that content into attachments->content parameter, Please check following code which works for me:
'attachments' => [
[
'content' => base64_encode(file_get_contents(config('global.UPLOAD_PATH') . '/my_file.pdf')),
'type' => 'application/pdf',
'filename' => 'my_file.pdf',
'disposition' => 'attachment'
]
]

Categories