当前位置:Gxlcms > PHP教程 > 消息推送,实时聊天

消息推送,实时聊天

时间:2021-07-01 10:21:17 帮助过:6人阅读

//消息推送
function notice_message_push($data){
//     $tag = '"all"';  发给所有用户//     $tag = '{"tag":["'.$uid.'"]}';   发给部分用户
//     $data = '{"platform": "all","audience" :'.$tag.',"notification":{"android" : {"alert" : "'.$content.'", "title":"'.$title.'","sound":"default", "badge":"+1","extras":{"newsid":321}},"ios":{"alert":"'.$content.'","title":"'.$title.'","sound":"default","badge":"+1","extras":{"newsid":321}}},"options":{"time_to_live":60,"apns_production":false}}';
    $url= "https://api.jpush.cn/v3/push";
// 启动一个CURL会话
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Authorization: Basic MWI0MTc3NTMxODAwMTE5MjJjMzU2MjAxOjkwMjBiZjNhNGUzNzkyNTM2YjNjYzJkNw=='
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// 执行操作
$response_body = curl_exec($curl);
//捕抓异常
$error_msg = "";
if (curl_errno($curl)) {
$error_msg = 'Errno' . curl_error($curl);
    }
// 关闭CURL会话
curl_close($curl);
// 返回结果
$response["response_body"] = $response_body;
$response["error_msg"] = $error_msg;
return $response;
}

以上就介绍了消息推送,实时聊天,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行