该功能利用公众平台客服接口,文档地址:
http://mp.weixin.qq.com/wiki/1/70a29afed17f56d537c833f89be979c9.html
需要认证公众号方可实现,没有的口可以用测试平台使用。
https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=你的access_token
发送图片消息:
{ "touser":"ojM5us46feM315cpmfQ9hAWfX8rE", "msgtype":"image", "image": { "media_id":"RAcZpyMKyou8W94_q5WWTKzKvPHe9InakwZm66mVgXTeVH2zjRXK9ZVUoIOS8YdS" } }
该功能需要用户48小时内与公众号有互动行为方为有效。
文本消息:
{ "touser":"ojM5us46feM315cpmfQ9hAWfX8rE", "msgtype":"text", "text": { "content":"Hello World" } }
PHP实现:
$postdata =‘{"touser":"o5BkRs_vRwfPqAb1ceXHfJDzmQ5o","msgtype":"text","text":{"content":"Hello World"}}‘; $opts = array( ‘http‘ => array( ‘method‘ => ‘POST‘, ‘Content-Length‘ => strlen($postdata), ‘Host‘ => ‘api.weixin.qq.com‘, ‘Content-Type‘ => ‘application/json‘, ‘content‘ => $postdata ) ); $context = stream_context_create($opts); $result = file_get_contents(‘https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=58FbTdpcOVZzjlZt4oBbOVTed96abY1jeKSEJ_hCDkhPb5R-vW9v69z18qidN_nkRkyaUhdEkhE9M266VVO_ZqQoDvkD6BZdp04ucACnVS4‘, true, $context); echo $result;
不习惯此方式post的可以使用curl。
时间: 2024-10-08 00:04:31