php 怎么让极光推送消息不重复
答案:2 悬赏:30 手机版
解决时间 2021-03-24 15:57
- 提问者网友:藍了天白赴美
- 2021-03-23 19:34
php 怎么让极光推送消息不重复
最佳答案
- 五星知识达人网友:等灯
- 2021-03-23 20:35
class jpush {
private $_masterSecret = '';
private $_appkeys = '';
function __construct($masterSecret = '',$appkeys = '') {
$this->_masterSecret = $masterSecret;
$this->_appkeys = $appkeys;
}
function request_post($url="",$param="",$header="") {
if (empty($url) || empty($param)) {
return false;
}
$postUrl = $url;
$curlPost = $param;
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
// 增加 HTTP Header(头)里的字段
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// 终止从服务端进行验证
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$data = curl_exec($ch);//运行curl
curl_close($ch);
return $data;
}
//$content 推送的内容。
//$extras 附加字段
//$m_time 保存离线时间的秒数默认为一天(可不传)单位为秒
//$message_type消息类型,0消息,1通知
public function pushMessage($title='',$message='',$receiver='all',$message_type=0,$extras=array(),$m_time='86400',$platform='all'){
$url = 'https://api.jpush.cn/v3/push';
$base64=base64_encode("$this->_appkeys:$this->_masterSecret");
$header=array("Authorization:Basic $base64","Content-Type:application/json");
$data = array();
$data['platform'] = $platform; //目标用户终端手机的平台类型android,ios,winphone
$data['audience'] = $receiver; //目标用户
if($message_type == 1){
$data['notification'] = array(
//统一的模式--标准模式
"alert"=>$message,
//安卓自定义
"android"=>array(
"alert"=>$message,
"title"=>$title,
"builder_id"=>1,
"extras"=> $extras
),
//ios的自定义
"ios"=>array(
// "alert"=>$content,
"badge"=>"1",
"sound"=>"default",
// "extras"=>array("type"=>$m_type, "txt"=>$m_txt)
),
);
}else{
//苹果自定义---为了弹出值方便调测
$data['message'] = array(
"title"=> $title,
"msg_content" =>$message,
"extras"=>$extras
);
}
//附加选项
$data['options'] = array(
"sendno"=>time(),
"time_to_live"=>$m_time, //保存离线时间的秒数默认为一天
"apns_production"=>1, //指定 APNS 通知发送环境:0开发环境,1生产环境。
);
$param = json_encode($data);
$res = $this->request_post($url, $param,$header);
if ($res === false) {
return false;
}
$res_arr = json_decode($res, true);
return $res_arr;
}
}
$appkeys='';
$masterSecret='';
$jpush = new jpush($masterSecret,$appkeys);
$title = '标题';
$message = '消息内容';
$message_type = 0;
$receiver = 'all';//接收者
$extras = array();
$jpush->pushMessage($title,$message,$receiver,$message_type,$extras);
全部回答
- 1楼网友:一袍清酒付
- 2021-03-23 20:53
不是有个别名和标签?可以给某一类的用户单独发送消息的楼主可以研究一下
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯