Home > WeChat Applet > WeChat Development > Force.com WeChat development series customer service interface

Force.com WeChat development series customer service interface

高洛峰
Release: 2017-02-25 16:41:24
Original
1814 people have browsed it

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

Customer service interface call request description

The interface description for customer service interface call is as follows (http request method is POST). If you want to obtain the Access Token, please refer to the previous description:

https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=[ACCESS_TOKEN]

The customer service interface provides a huge space for imagination, and we can use this For example, develop enterprise customer service solutions. When users send support requests to WeChat public accounts, customer service staff can receive the information through web pages, mobile applications, WeChat, etc. and perform further processing. Customer service staff can also queue up, or Set the user's VIP level to provide different levels of service response speed, etc., and build a very intelligent customer service support system.

Send a text message to the user

When sending a text message to the user, the data format sent is as follows:

 { "touser":"OPENID", "msgtype":"text", "text": { "content":"Hello World" } }
Copy after login

Among them, the specific parameters of each parameter The description is as follows:

Force.com WeChat development series customer service interface

The code for sending text messages to users in Force.com is implemented as follows:

Http h = new Http(); 
HttpRequest req = new HttpRequest(); 
req.setMethod('POST'); 
req.setHeader('Accept-Encoding','gzip,deflate'); 
req.setHeader('Content-Type','text/xml;charset=UTF-8'); 
req.setHeader('User-Agent','Jakarta Commons-HttpClient/3.1');

String sendMsg = '{ "touser":"ou-37t936RNZEcW0mI75RN2pdxkc", "msgtype":"text", "text": { "content":"测试客服消息" } }';

req.setBody(sendMsg); 
req.setEndpoint('https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=bW3aubvd1GVgDZbrO6zv1WGVYIU0QlEhI1J5x_NpbiouxyBc8eufzQQHHyy8cMoZmuQknz-_iEgSB76CggVTgQ’);

String bodyRes = ''; 
        
        try{ 
            HttpResponse res = h.send(req); 
            bodyRes = res.getBody(); 
        } 
        catch(System.CalloutException e) { 
            System.debug('Callout error: '+ e); 
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, e.getMessage())); 
        }

);
Copy after login

After executing the above code, the effect is as shown in the figure:

Force.com WeChat development series customer service interface

Send picture messages to users

When sending picture and text messages to users, the format of the data sent is as follows:

{
    "touser":"OPENID",
    "msgtype":"image",
    "image":
    {
      "media_id":"MEDIA_ID"
    }
}
Copy after login

Among them, each The specific description of each parameter is as follows:

Force.com WeChat development series customer service interface

The media ID of the image needs to be obtained after uploading the image through Tencent's multimedia file upload interface. We will give a specific example of this example later. The "Upload and download multimedia files" example is specifically explained.

Send voice messages to users

When sending music to users, the data format is as follows:

{
    "touser":"OPENID",
    "msgtype":"voice",
    "voice":
    {
      "media_id":"MEDIA_ID"
    }
}
Copy after login

The specific description of each parameter is as follows:

Force.com WeChat development series customer service interface

The media ID of the image needs to be obtained after uploading the image through Tencent's multimedia file upload interface. The other codes are no different from sending text messages, so I will not go into details here.

Send a voice message to the user

The message format for sending a video to the user is as follows:

{
    "touser":"OPENID",
    "msgtype":"video",
    "video":
    {
      "media_id":"MEDIA_ID",
      "thumb_media_id":"MEDIA_ID",
      "title":"TITLE",
      "description":"DESCRIPTION"
    }
}
Copy after login

The specific description of each parameter is as follows:

Force.com WeChat development series customer service interface

The media ID of the video needs to be obtained after uploading the image through Tencent's multimedia file upload interface. The other codes are no different from sending text messages, so I will not go into details here.

Send music messages to users

The message format for sending music to users is as follows:

{
    "touser":"OPENID",
    "msgtype":"music",
    "music":
    {
      "title":"MUSIC_TITLE",
      "description":"MUSIC_DESCRIPTION",
      "musicurl":"MUSIC_URL",
      "hqmusicurl":"HQ_MUSIC_URL",
      "thumb_media_id":"THUMB_MEDIA_ID" 
    }
}
Copy after login

The specific description of each parameter is as follows:

Force.com WeChat development series customer service interface

Send graphic messages to users

Post a code to send graphic messages as follows:

Http h = new Http(); 
 HttpRequest req = new HttpRequest(); 
 req.setMethod('POST'); 
 req.setHeader('Accept-Encoding','gzip,deflate'); 
 req.setHeader('Content-Type','text/xml;charset=UTF-8'); 
 req.setHeader('User-Agent','Jakarta Commons-HttpClient/3.1');
 
 String sendMsg = '{"touser":"ou-37t936RNZEcW0mI75RN2pdxkc","msgtype":"news","news":{"articles":[{"title":"HappyDay","description":"IsReallyAHappyDay","url":"http://www.36kr.com/p/212479.html","picurl":"http://a.36krcnd.com/photo/2014/4e3ae0dac4884bb91934a689b72f8f8b.png"}]}}';
 
 req.setBody(sendMsg); 
 req.setEndpoint('https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=bW3aubvd1GVgDZbrO6zv1WGVYIU0QlEhI1J5x_NpbiouxyBc8eufzQQHHyy8cMoZmuQknz-_iEgSB76CggVTgQ’);
 
 String bodyRes = ''; 
         
         try{ 
             HttpResponse res = h.send(req); 
             bodyRes = res.getBody(); 
         } 
         catch(System.CalloutException e) { 
             System.debug('Callout error: '+ e); 
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, e.getMessage())); 
        }

);
Copy after login

More Force.com WeChat development For articles related to the series of customer service interfaces, please pay attention to the PHP Chinese website!

Related labels:
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