09- QR code generation and scanning
table of Contents
1. The generation of QR code
First, you need to read Tencent's official documents in detail
There are two types of QR code creation requests
- Temporary two-dimensional
https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN
POST数据格式:
json POST数据例子:{"expire_seconds": 604800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123}}}
jon POST数据创建字符串形式的二维码参数:{"expire_seconds": 604800, "action_name": "QR_STR_SCENE", "action_info": {"scene": {"scene_str": "test"}}}
- Permanent QR code
https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN
POST数据格式:
json POST数据例子:{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}}}
json POST数据创建字符串形式的二维码参数: {"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "test"}}}
Parameter Description:
Understanding: The understanding of action_name, when using the QR code for promotion, the parameter of this band is the id of the promoted person
The creation of the QR code is a public post request, so I will not write a test method here, I will call it directly with postman
The parameters used are:
{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "你好"}}}
{
"ticket": "gQHL8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyZlI5TDk2THBmN0QxMDAwMGcwN1EAAgQmQT5gAwQAAAAA",
"url": "http://weixin.qq.com/q/02fR9L96Lpf7D10000g07Q"
}
2. Obtaining the QR code
The interface address of the QR code acquisition call is as follows
https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET
Reminder: TICKET remember to perform UrlEncode (I call it directly through the web page)
Use the following url to access
The QR code is shown in the figure below:
3. Scanning of QR code
Every time a QR code is scanned, a request will be sent to the background. The request is divided into two types
For more information, please refer to
https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Receiving_event_pushes.html
Scanned by people who did not follow the WeChat official account, the request sent to the server is as follows
The following is processed by my object, in fact it is an xml
{Ticket=gQHL8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyZlI5TDk2THBmN0QxMDAwMGcwN1EAAgQmQT5gAwQAAAAA, CreateTime=1614693308, EventKey=qrscene_你好, Event=subscribe,
ToUserName=gh_7c94dc7e2130, FromUserName=orxnH5x5ctnmrdrWQ80DsDRqn2nM, MsgType=event}
Scanned by people who follow the WeChat official account, the information sent to the server is entered as follows
{Ticket=gQHL8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyZlI5TDk2THBmN0QxMDAwMGcwN1EAAgQmQT5gAwQAAAAA, CreateTime=1614693382, EventKey=你好,
Event=SCAN, ToUserName=gh_7c94dc7e2130, FromUserName=orxnH5wNRLvz2DfNTopTGcL4y9ic, MsgType=event}
After that is the process of receiving messages.