php 友盟 推送 android代码

本文介绍如何使用友盟推送服务实现消息推送,包括设置推送参数、构造推送内容及发送请求等关键步骤。

部分文档参阅友盟   记得在友盟后台添加你的 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;
   }


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值