当前位置:网站首页>Wechat official account third-party platform development, zero foundation entry. I want to teach you
Wechat official account third-party platform development, zero foundation entry. I want to teach you
2022-06-30 08:13:00 【Code GuWa of nobody】
You should know before you learn the development of wechat third-party platform :
1, Use of common interface testing tools :postman
2, Learn to read third-party platform documents .( This is the key , But many still like Baidu , White whoring others' operation documents )
3, Learn to troubleshoot problems , To analyze problems .
4, Limitations of third-party platforms , And the official account , The relationship between subscription numbers should be understood . The test subscription number is not authenticated , Subscription numbers without authentication are very different .
5, Be good at using cache to solve business performance bottlenecks in projects .
Wechat open documents : Overview of wechat public platform development | Wechat open documents
The opening quotation :
Previous flowchart :

The third-party platform is equivalent to the configuration of our wechat official account , Initiate event listening through the configuration of the third-party platform , Contains callback information processing , We go through : Authorization event receiving configuration --》 Start push Ticket--》 Realize business after authorization --》 Message verification Token--》 Message and event receiving configuration --》 Wechat official account business
The process is so simple , But there are many interfaces , It's more difficult to operate , Still have to manage token Effectiveness . We finally need to get the permission of wechat official account token To achieve business turnaround , Otherwise everything else is bullshit .
Let's take a look at the page configuration and permissions of the third-party platform :

This is my own mapped domain name , After the official launch, change to the official domain name .
Access configuration :

Interfaces to be debugged :
There are many interfaces nacos To configure :
wechat:
config:
#appid
component_appid: *************
#aeskey
component_encodingaeskey: ****************
# verification token
component_token: ****************
# Encryption is formal
component_appsecret: ***********
# Authorized domain name
redirect_url: http://d1989091s1.51mypc.cn/wechat/preauth/callback
# obtain component_token url Address
api_component_url: https://api.weixin.qq.com/cgi-bin/component/api_component_token
# Create pre authorization url Address
api_create_preauth_url: https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=
# Permission query api Authorized platform address
api_query_auth_url: https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=
# verification token Refresh address
api_authorizer_token_url: https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=
# Media file download address
api_media_download_url: https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID
# The customer service replies to the user's text message
api_message_custom_send_url: https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=
# Get refresh token Address of the interface
api_refresh_url: https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=
#openid obtain unionid Address
api_unionid_batchget_url: https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=
# Get user information
api_unionid_get_url: https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
Code :
1, Obtain third-party platform authorization component_token
2, Obtain pre authorization api_create_preauthcode
3, After the wechat authorization platform obtains the permission interface according to the pre authorization token+ Scan Authorization code (api_query_auth)
4, Scan code to get queryauthcode
5, adopt queryauthcode Official account authorizer_token
6, adopt authorizer_token Operate official account business .
One , obtain component_token
Request address :https://api.weixin.qq.com/cgi-bin/component/api_component_token
Request parameters :
{
"component_appid":"********",
"component_appsecret":"****",
"component_verify_ticket":"[email protected]@@lKkaZ1rc4AL43879Kq7g4vmz8DrLdjWNtpnBoUl5tEJtcLhuSGTdayh4rZHxmRv12YB7CU_s7yQ"
}

"errmsg": "access clientip is not registered requestIP: 58.246.190.94 rid: 62b67820-316cbaee-50f9473e"
Need configuration ip White list :


Two , Obtain wechat pre authorization pre_auth_code
Request parameters :
{
"component_appid":"wx6ec5488b62c"
}
3、 ... and , The pre authorized token and component_appid And redirect the callback address back to html Page for authorization processing
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="" style="text-align:center;padding-top:10%;font-size:10em;">
<a href=https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=wx6ec5e8cec&[email protected]@@YWPYsD65xHdHMkKkSoXTx8W5sXhg3j0l_QfGx_r5lADHryjDH9nEn80ILQb-TBp0pq8Gn5&redirect_uri=http://d1989091s1.51mypc.cn/wechat/preauth/callback id="url"> Click to authorize </a>
</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" >
$(function () {
$.ajax({
url: "/wechat/auth/cache",
type: "post",
success: function (r) {
if (r.code == 0) {
var component_access_token = r.data.component_access_token;
var component_appid = r.data.component_appid;
var pre_auth_code = r.data.pre_auth_code;
var redirect_uri = r.data.redirect_uri;
var url = 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid='+component_appid
+'&pre_auth_code='+pre_auth_code+'&redirect_uri='+redirect_uri;
$('#url').attr('href',url);
} else {
alert(r.msg)
}
}
});
})
</script>
</body>
</html>
Authorized pages : Here is the administrator , Who certifies the subscription number , Just scan the code , If you do not have a official account, the subscription number is not bound , Then you can't authorize .



The permission here is the permission set opened by our third-party platform. You can open any permission function you need .
Four Update authorization callback .
<a href=https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=wx6ec5e8cec&[email protected]@@YWPYsD65xHdHMkKkSoXTx8W5sXhg3j0l_QfGx_r5lADHryjDH9nEn80ILQb-TBp0pq8Gn5&redirect_uri=http://d1989091s1.51mypc.cn/wechat/preauth/callback id="url"> Click to authorize </a>
## token url
redirect_uri=http://d1989091s1.51mypc.cn/wechat/preauth/callback
The callback address will return a auth_code Default one hour expiration , To prevent repeated scanning , You must get a refresh token, Timed brush cache , Guarantee token Don't expire .
http://d1989091s1.51mypc.cn/wechat/preauth/[email protected]@@*****&expires_in=3600
5、 ... and , The third-party platform obtains the authority of official account token
Parameters :
{
"component_appid":"********" ,
"authorization_code": "[email protected]@@KEm1qXN8KFuVWO05a3FhXhMtAGQp8RFA4dAEaldQ_ffdvsKIUtDWpVXtzu8dDH8D1DCMhAS61RmonKgPBjecUw"
}
Respond to :
{
"authorization_info": {
"authorizer_appid": "*********",
"authorizer_access_token": "58_PZeVA66EDTONWgd-8X9Miuu2dqFQ9FzFar4JTLahB5QmCIdSE1gY9BCYQVnJ8peVGm-1231L3oyIDZ92xlbpSbESN0aIlGW-6XfJXvDIWP6b_b-WW2yEM20AZkkHnECQHDMPiD0Uzqh6sCoHrVDjRPCcAFDVTG",
"expires_in": 7200,
"authorizer_refresh_token": "[email protected]@@UFuvwOxnZ0eXBGEghR9CD12DVTQnaZEwIQYBBGc6Oh89npg",
"func_info": [
{
"funcscope_category": {
"id": 1
},
"confirm_info": {
"need_confirm": 1,
"already_confirm": 0,
"can_confirm": 1
}
},
{
"funcscope_category": {
"id": 2
},
"confirm_info": {
"need_confirm": 1,
"already_confirm": 0,
"can_confirm": 1
}
},
{
"funcscope_category": {
"id": 4
}
},
{
"funcscope_category": {
"id": 6
}
},
{
"funcscope_category": {
"id": 7
}
},
{
"funcscope_category": {
"id": 9
}
},
{
"funcscope_category": {
"id": 15
}
}
]
}
}This authority token Default 2 Hours expired , So you need to refresh regularly to obtain permissions token
authorizer_refresh_token On behalf of us, we regularly refresh permissions token, This can help us solve the problem of repeated scanning , The administrator only needs to scan the code once .
6、 ... and . Official account authority token Refresh of
Request address :
Request parameters :
authorizer_appid Third party subscription number that requires authorization appid
component_appid Third-party platform appid
{
"component_appid":"wx6ec5e8ceb4882c",
"authorizer_appid":"wx3605b881a5f30b22"
} 
7、 ... and , By refreshing token Change the permission cache regularly
Request parameters :
{
"component_appid":"*******",
"authorizer_appid":"wxbe11fb37fd31d2cb",
"authorizer_refresh_token":"[email protected]@@UFuvwOxnZ0eXBGEghR9DVTQnaZEwIQYBBGc6Oh89npg"
}

authorizer_access_token Verify successful token This is the certificate we need to obtain for our official account .
Here we can call the interface directly according to the business of the official account . The overall process and implementation have been completed .
边栏推荐
猜你喜欢

【NVMe2.0b 14-5】Firmware Download/Commit command
![[JUC series] overview of fork/join framework](/img/49/2cadac7818b0c1100539fd32ec0d37.png)
[JUC series] overview of fork/join framework

亚马逊测评术语有哪些?

Deep learning -- sequence model and mathematical symbols

Wsl2 using GPU for deep learning

【NVMe2.0b 14-7】Set Features(上篇)

Deep learning - bounding box prediction

【NVMe2.0b 14-2】Create/Delete Queue

多快好省,低门槛AI部署工具FastDeploy测试版来了!

Deep learning - goal orientation
随机推荐
min_ max_ Gray operator understanding
C. Fishingprince Plays With Array
Bingbing learning notes: quick sorting
牛客小白月賽52
【Tensorflow-gpu】window11下深度学习环境搭建
全栈最全性能测试理论-总结
[nvme2.0b 14 - 5] commande de téléchargement / commande du logiciel
Hit the industry directly | the flying propeller launched the industry's first model selection tool
[flower carving experience] 12 build the Arduino development environment of esp32c3
MySQL cannot connect to the intranet database
QT event cycle
1. Problems related to OpenGL window and environment configuration
vulfocus入门靶机
Wechat applet reports errors using vant web app
ACM. HJ48 从单向链表中删除指定值的节点 ●●
Opencv video
在浏览器输入url到页面展示出来
Getordefault method of map class
CRM&PM如何帮助企业创造最优销售绩效
Opencv image