Baidu PUSHPHP server sharing is a virtue!
[Function]: Baidu push, php Server, version 3.0
First download the official Baidu demo, address: http://push.baidu.com/sdk/push_server_sdk_for_php
Api documentation address: http://push.baidu.com/doc/php/api
The following code example uses the tp framework
Import ("Vendor. baiduPushService. sdk "); // Create an SDK object. $ sdk = new \ PushSDK (); // set the message type to the notification type. $ opts = array ('MSG _ type' => 1); $ data = $ this-> getPushData (); show_bug ($ data); foreach ($ data as $ val) {$ message = array ('title' => $ val ['title'], // The message title 'description' => $ val ['content'], // message content 'custom_content' => array ('Member _ id' => $ val ['Member _ id'], 'member _ phone' => $ val ['Member _ phone'], // your mobile phone number); $ channelId = $ val ['Channel _ id']; // send a message to the target device $ rs = $ sdk-> pushMsgToSingleDevice ($ channelId, $ message, $ opts); if ($ rs = false) {$ map = array ("error_code" => $ sdk-> getLastErrorCode (), "error_msg" => $ sdk-> getLastErrorMsg (),); $ this-> Information-> where (array ("id" => $ val ['id'])-> save ($ map );} else {$ this-> updateInformation ($ val ['id'], $ rs); // prints the message id, sending time, and other information. // print_r ($ rs );}
[Note]
1. the apikey and secretkey must be obtained on the Baidu console. For more information, see Baidu api documentation;
2. the channelId must be obtained from the customer;
3. Custom fields can be passed through array using custom_content;
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.