先看腾讯文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/uniform-message/uniformMessage.send.html
通过文档可以看出,需要携带ACCESS_TOKEN,相关参考在https://blog.csdn.net/mushui0633/article/details/89469209
'ox客户的openid', //发给谁
'template_id' => 'UU你的小程序统一服务消息ID——hBE',
'page' => 'pages/my/li你的小程序前端页面地址和参数?id=ggf&shareId=ghf',
'data' => array(
'thing1' => array(
'value' => '$goodTitle',
),
'thing2' => array(
'value' => '$orderPrice'.'元',
),
'thing5' => array(
'value' => '$orderTime',
),
'time3' => array(
'value' => '2019-12-11 18:36',
),
// 这里如果日期时间格式不对就报错,比如:{"errcode":47003,"errmsg":"argument invalid! hint: [I1D5la06238630] data.time3.value invalid"}
)
);
$data = json_encode($data);
$result = curl_post($url, $data);
$result = json_decode($result);
if ($result->errcode == '0' && $result->errmsg == 'ok') {
echo $result;
return 'success';
} else {
return '发送失败';
}
function curl_post($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
return $response;
}