WxPusher (微信推送服务)是一个使用微信公众号作为通道的,实时信息推送平台,你可以通过调用API的方式,把信息推送到微信上,无需安装额外的软件,即可做到信息实时通知。 你可以使用WxPusher来做服务器报警通知、抢课通知、抢票通知,信息更新提示等。
官方文档:WxPusher微信推送服务 (zjiecode.com)
朋友让帮忙写的,他是用来推送余额信息的,我改成了读取get参数来推送了。
参数说明:
zy=填写摘要内容,即不点进去查看的标题内容。
zw=填写用户点击这个推送后展现的内容,比如详细的通知呀..
代码内容我已放到下方,并已添加注释!需要的小伙伴可以评论回复直接拿去。
[hidecontent type=”reply”]
<?php
//* blgo:zai1.com
//* 在意博客
$notificationApiUrl = "https://wxpusher.zjiecode.com/api/send/message";
$appToken = "AT_grLbeDOEVg9cDJmXeuuyMbLrFk5a2oA7"; // 应用Token WxPusher后台获取
$userUid = "UID_7tYeDMpH5seB2kCCQSTvUcRFWeq9"; // 你的用户UID WxPusher关注公众号可获得,或扫码。具体看后台获取~
$summary = $_GET['zy']; // 从GET请求中获取"zy"参数的内容
$content = $_GET['zw']; // 从GET请求中获取"zw"参数的内容
try {
// 构建通知数据
$notificationData = array(
"appToken" => $appToken,
"content" => $content, // 使用GET请求中获取的"zw"参数内容作为提示内容
"summary" => $summary, // 使用GET请求中获取的"zy"参数内容作为消息摘要
"contentType" => 1,
"uids" => array($userUid)
);
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($notificationData)
)
);
$context = stream_context_create($options);
$notificationResponse = file_get_contents($notificationApiUrl, false, $context);
$notificationResult = json_decode($notificationResponse, true);
if ($notificationResult["success"]) {
echo "推送通知已发送\n";
} else {
echo "推送通知发送失败\n";
}
} catch (Exception $e) {
echo "发生错误:" . $e->getMessage() . "\n";
}
?>
[/hidecontent]