Baidu PUSHPHP server

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.