部分文档参阅友盟 记得在友盟后台添加你的 ip ,否则无法推送成功
public function index()
{
$body = array(
'ticker'=>'测试',
'title'=>'您有一条新的消息', //主标题
'text'=>'测试消息', //副标题
'after_open'=>'go_custom', //采用 自定义行为
'custom'=>'message' //自定义参数
);
$payload = array(
'display_type'=>'notification', //通知
'body'=>$body
);
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>//下面代码为 单播(针对个人 对应 <span style="font-family: Arial, Helvetica, sans-serif;">broadcast </span>) 和 广播(针对所有设备 对应 <span style="font-family: Arial, Helvetica, sans-serif;">customizedcast</span>)
$para = array(
'appkey'=>'', //android appkey
'timestamp'=>date('U'),
'type'=>'broadcast', //广播 broadcast //别名推送 填写 customizedcast
// 'alias_type'=>'digixxx',
// 'alias'=>'',
'payload'=>$payload
);
$paraJson = json_encode($para);
$original_str = 'POST'.'http://msg.umeng.com/api/send'.$paraJson.''; //App Master Secret
$md5Str = strtolower(md5($original_str));
$url = 'http://msg.umeng.com/api/send'.'?sign='.$md5Str;
$result = $this->post($url,$paraJson);
echo $result;
}
//post 请求
function post($url,$data) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data)));
$data = curl_exec($ch);
return $data;
}
本文介绍如何使用友盟推送服务实现消息推送,包括设置推送参数、构造推送内容及发送请求等关键步骤。

479

被折叠的 条评论
为什么被折叠?



