首页 > Web开发 > 详细

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

时间:2015-10-13 16:36:08      阅读:243      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!