码迷,mamicode.com
首页 > Web开发 > 详细

php通过curl调用jpush接口实现消息的推送

时间:2015-10-13 16:37:05      阅读:1036      评论:0      收藏:0      [点我收藏+]

标签:

public function actionNotifyto() {
//$regid = $_REQUEST[‘regid‘];
$url = ‘https://api.jpush.cn/v3/push‘; //调用接口的平台服务地址
//$post_string = array(‘platform‘=>‘all‘,‘audience‘=>array());
$str = ‘{"platform":"all","audience":{
"registration_id" : [ "010157bbeb5" ]
},"notification":{"alert":" 您有新的消息!"}}‘;

$header = array(
‘Content-Type: application/json‘,
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERPWD, "1fe46801b7e1bc98bc65a964:c85db6c8c5180a4b5b563dd0");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch);
curl_close($ch);
return json_encode([‘e‘=>0, ‘r‘=>$result]);
}


php通过curl调用jpush接口实现消息的推送

标签:

原文地址:http://www.cnblogs.com/yuanxiaoping_21cn_com/p/4874748.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!