Sharing is a virtue!
"Features": Baidu push Push, PHP server side, version 3.0
First download Baidu's official demo, Address: http://push.baidu.com/sdk/push_server_sdk_for_php
API Document 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 Message type to notification type. $opts=Array(' Msg_type '=1);$data=$this->getpushdata (); Show_bug ($data);foreach($data as $val) {$message=Array(' title '=$val[' title '],//title of message ' description '=$val[' content '],//message content ' Custom_content '=Array(' member_id '=$val[' member_id '],' Member_phone '=$val[' Member_phone '],//user 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);//will print out the message ID, send time and other related information. //Print_r ($RS);}
Note
1. Apikey and Secretkey need to be in the Baidu console to obtain, specific operation to see Baidu API documentation;
2. Channelid needs to be acquired by customers;
3. Custom fields can be passed through an array with custom_content;
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Baidu Push PHP server side