Baidu Push PHP server side

Source: Internet
Author: User
Tags php server

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

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.