In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to implement the customer service interface of the Force.com Wechat development series, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
When users actively send messages to Wechat public accounts (including sending messages, clicking custom menu click events, subscription events, scanning QR code events, payment success events, user rights protection), Wechat will push the message data to developers. Developers can call the customer service message interface within a period of time (currently 48 hours) and send messages to ordinary users through a JSON packet. There is no limit on the number of times to send within 48 hours. This API is mainly used for customer service and other functions with manual message processing, making it convenient for developers to provide more quality services.
Description of call request for customer service API
The API called by the customer service API is described below (the http request method is POST). For more information on how to obtain Access Token, please see the previous description:
Https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=[ACCESS_TOKEN]
The customer service interface provides a huge imagination space, based on which we can develop enterprise customer service solutions. When users send support requests to Wechat public accounts, customer service personnel can receive these messages and do further processing through web pages, mobile apps, Wechat, etc., customer service personnel can also queue for children, or set users' VIP levels to provide different levels of service response speed, and so on. Build a quite intelligent customer service support system.
Send text messages to users
When you send a text message to the user, the data format is as follows:
{"touser": "OPENID", "msgtype": "text", "text": {"content": "Hello World"}}
The details of each parameter are as follows:
The code for sending a text message to a user in Force.com is 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": "Test customer Service message"}}'; 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 ());})
After executing the above code, the effect is as shown in the figure:
Send a picture message to the user
When sending a picture and text message to the user, the data format is as follows:
{"touser": "OPENID", "msgtype": "image", "image": {"media_id": "MEDIA_ID"}}
The details of each parameter are as follows:
The media ID of the image needs to be obtained after uploading the image through Tencent's upload multimedia file API. The specific example of this example will be explained in the "upload and download multimedia file" example later.
Send voice messages to users
When sending music to the user, the data format is as follows:
{"touser": "OPENID", "msgtype": "voice", "voice": {"media_id": "MEDIA_ID"}}
The details of each parameter are as follows:
The media ID of the image needs to be obtained after uploading the image through Tencent's multimedia file upload API. Other codes are no different from sending text messages, so I won't repeat them here.
Send voice messages to users
The message format for sending 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"}}
The details of each parameter are as follows:
The media ID of the video needs to be obtained after uploading pictures through Tencent's API for uploading multimedia files. Other codes are no different from sending text messages. I will not repeat them here.
Send music messages to users
The message format for sending music to the user 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"}}
The details of each parameter are as follows:
Send picture and text messages to users
The code for posting a message to send a picture and text is 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 ());}); these are all the contents of the article "how to implement the customer service interface in the Force.com Wechat development series". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.