Home > Backend Development > PHP Tutorial > WeChat public platform development (73) Sending customer service messages_PHP tutorial

WeChat public platform development (73) Sending customer service messages_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:16:55
Original
958 people have browsed it

WeChat public platform develops customer service interface to send customer service messages
Author: Fangbei Studio
Address: http://www.cnblogs.com/txw1958/p/weixin73-custom-send.html

When a user actively sends a message to an official account (including sending a message, clicking a custom menu clike event, subscribing event, scanning QR code event, payment success event, user rights protection), WeChat will The message data will be pushed to developers. Developers can call the customer service message interface within a period of time (currently 24 hours) and send messages to ordinary users by POSTing a JSON data packet. There is no limit on the number of sending times within 24 hours. This interface is mainly used for functions such as customer service that require manual message processing, so that developers can provide users with better services.

1. Obtain ACCESS_TOKEN

http request method: GET
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

参数 是否必须 说明
grant_type 获取access_token填写client_credential
appid 第三方用户唯一凭证
secret 第三方用户唯一凭证密钥,既appsecret

Under normal circumstances, WeChat will return the following JSON data packet to the public account:
{"access_token":"ACCESS_TOKEN","expires_in":7200}

2. Send message

Send text message

<span $txt</span> = '<span {
    "touser":"oLVPpjqs9BhvzwPj5A-vTYAX3GLc",
    "msgtype":"text",
    "text":
    {
         "content":"Hello World"
    }
}</span>'<span ;
</span><span $access_token</span> = "NU7Kr6v9L9TQaqm5NE3OTPctTZx797Wxw4Snd2WL2HHBqLCiXlDVOw2l-Se0I-WmOLLniAYLAwzhbYhXNjbLc_KAA092cxkmpj5FpuqNO0IL7bB0Exz5s5qC9Umypy-rz2y441W9qgfnmNtIZWSjSQ"<span ;
</span><span $url</span> = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".<span $access_token</span><span ;
</span><span $result</span> = https_post(<span $url</span>,<span $txt</span><span );
</span><span var_dump</span>(<span $result</span><span );

</span><span function</span> https_post(<span $url</span>,<span $data</span><span )
{
    </span><span $curl</span> =<span  curl_init();
    curl_setopt(</span><span $curl</span>, CURLOPT_URL, <span $url</span><span ); 
    curl_setopt(</span><span $curl</span>, CURLOPT_SSL_VERIFYPEER, <span FALSE</span><span );
    curl_setopt(</span><span $curl</span>, CURLOPT_SSL_VERIFYHOST, <span FALSE</span><span );
    curl_setopt(</span><span $curl</span>, CURLOPT_POST, 1<span );
    curl_setopt(</span><span $curl</span>, CURLOPT_POSTFIELDS, <span $data</span><span );
    curl_setopt(</span><span $curl</span>, CURLOPT_RETURNTRANSFER, 1<span );
    </span><span $result</span> = curl_exec(<span $curl</span><span );
    </span><span if</span> (curl_errno(<span $curl</span><span )) {
       </span><span return</span> 'Errno'.curl_error(<span $curl</span><span );
    }
    curl_close(</span><span $curl</span><span );
    </span><span return</span> <span $result</span><span ;
}</span>
Copy after login

Send pictures (media_id needs to be uploaded first to get the picture)

<span $img</span> = '<span {
    "touser":"oLVPpjqs9BhvzwPj5A-vTYAX3GLc",
    "msgtype":"image",
    "image":
    {
      "media_id":"jViS8sQUXIh6rTdkz2qUOD5pvChYpp50i9rsLR4YnCm-pqdpiHhz6xbN2KAboScV"
    }
}</span>';
Copy after login

==============================================

How to follow the Fangbei Studio WeChat public platform account:
1. WeChat address book-add friend-search public account-search for "Fangbei Studio"
2. WeChat address book-add friend-search Number - enter "pondbaystudio"
3. Use WeChat to scan the QR code below

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/626662.htmlTechArticleWeChat public platform develops customer service interface to send customer service messages Author: Fangbei Studio Address: http://www.cnblogs .com/txw1958/p/weixin73-custom-send.html When users actively send messages to the public...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template