php 调用微信公众号消息订阅功能接口报错,无法实现推广通知消息?,返回结果 如下,要如何解决?是哪里错了?wx8ca0b9f968f63e8a
[{"errcode":40037,"errmsg":"invalid template_id rid: 672d2687-4d6ae76d-47b2cc1e"}]
调用代码如下
//发送订阅消息
function push_msg($access_token,$openid,$template_id,$content){
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token;
$data = array(
"touser" => $openid,
"template_id" => $template_id,
"data" => array(
"content" => array(
"value" =>$content
)
)
);
$data_json = json_encode($data);
// Log::record('订阅参数信息',$data_json);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_json))
);
$response = curl_exec($ch);
Log::record('订阅信息结果',$response);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
Log::record('订阅信息结果','Curl error: ' . curl_error($ch));
}
curl_close($ch);
// echo $response;
}
用错接口,你当前调用的是【发送模板消息】接口,【发送订阅通知】是另外一个接口,可参考文档:https://developers.weixin.qq.com/doc/offiaccount/Subscription_Messages/api.html#send%E5%8F%91%E9%80%81%E8%AE%A2%E9%98%85%E9%80%9A%E7%9F%A5
其次,data字段的内容没有按照当前模板上来填写。