In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how Force.com Wechat developers generate QR codes with parameters. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
In order to meet the needs of user channel promotion and analysis, the public platform provides an interface to generate a QR code. Using this interface, multiple QR codes with different scene values can be obtained. After scanning, the official account can receive the event push. At present, there are two types of QR codes, temporary QR codes and permanent QR codes, the former has an expiration time of up to 1800 seconds, but can generate a larger number of QR codes, while the latter has no expiration time and has a small number of QR codes (the current parameters only support 1 to 100000). The two QR codes are suitable for scenarios such as account binding and user source statistics, respectively.
When a user scans a QR code with scene values, the following two events may be pushed:
1. If the user has not followed the official account, the user can follow the official account. After following, Wechat will push the event with scene value to the developer (such as the QR code prepared for a specific event, and the attendees can follow the Wechat account after scanning. At the same time, Wechat account can push information related to the event to users)
two。 If the user has followed the official account, the user will automatically enter the session after scanning, and Wechat will also push the scanning event with scene value to the developer (the above example also applies).
The process of obtaining the QR code with parameters consists of two steps, first creating the QR code ticket, and then exchanging the QR code from ticket to the specified URL.
Create a QR code ticket
Each time you create a QR code ticket, you need to provide a parameter (scene_id) set by the developer. The process of creating a temporary QR code and a permanent QR code ticket is introduced respectively.
Temporary QR code request description:
Http request method: POST URL: POST data format: json POST data example: {"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123}
Permanent QR code request description
Http request method: POST URL: POST data format: json POST data example: {"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}
The details of the request JSON data parameters are as follows:
An example of the correct Json returned result is as follows:
{"ticket": "gQH47joAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL2taZ2Z3TVRtNzJXV1Brb3ZhYmJJAAIEZ23sUwMEmm3sUw==", "expire_seconds": 60, "url": "http:\ /\ / weixin.qq.com\ / Q\ / kZgfwMTm72WWPkovabbI"}
The format of the returned Json data is as follows:
An example of an incorrect Json return is as follows:
{"errcode": 40013, "errmsg": "invalid appid"}
Let's construct a Visualforce Page to generate the ticket.
The Visualforce Page code is as follows:
The first step is to create the QR code Ticket, please enter the authorization AccessToken: {! msg}
Line 4 of the above code places an apex:inputText control, which is equivalent to the text box of HTML. The value of value specifies accessToken, which must be a public property with Getter Setter in the WeChatQRCodeGeneratorController class. If the attribute has a default value, the text box will display the default value. If the user modifies the content of the text box, the value of the accessToken property will also change automatically. Line 5 places an apex:commandButton control, the equivalent of a HTML button, which will trigger the method send specified at action. Finally, line 8 shows the msg variable directly, which will be used to display the Json returned by the Wechat API. The display effect is as follows:
The code for the WeChatQRCodeGeneratorController class is as follows:
Public class WeChatQRCodeGeneratorController {public String msg {get; set;} public String accessToken {get; set;} public void send () {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 json =' {"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 12345}'; req.setBody (json) Req.setEndpoint ('https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' + accessToken); 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 ());} msg = bodyRes;}}
When you are finished, save the code, enter the correct and valid Access Token, and click the "generate create QR Code Ticket" button to get the ticket shown below in exchange for the QR code. In fact, the value of the last parameter url in the returned json is the value of the QR code, which can be used to generate the QR code through the online QR code generator:
Exchange for QR code through ticket
After obtaining the QR code ticket, developers can exchange ticket for QR code images. This API can be called without login. The API request is described as follows:
HTTP GET request (please use https protocol) https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET returned instructions: if ticket is correct, the http error code is 200. it is an image that can be displayed or downloaded directly. The HTTP header (example) is as follows: Accept-Ranges:bytesCache-control:max-age=604800Connection:keep-aliveContent-Length:28026Content-Type:image/jpgDate:Wed, 16 Oct 2013 06:37:10 GMTExpires:Wed, 23 Oct 2013 14:37:10 + 0800Server:nginx/1.4.1
HTTP error code 404 is returned in error cases (such as illegal ticket).
An example of calling this API with the ticket returned earlier is as follows:
Https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQH97zoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL2YweHpqY1hrX255RGdnckl0V0otAAIENIwAVAMECAcAAA==, thank you for your reading! This is the end of this article on "how to generate a QR code with parameters in the development of Force.com Wechat". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.