当前位置:网站首页>微信公众号第三方平台开发,零基础入门。想学我教你啊
微信公众号第三方平台开发,零基础入门。想学我教你啊
2022-06-30 08:06:00 【无名之辈之码谷娃】
在学习微信第三方平台开发之前你应该会的:
1,常用接口测试工具的使用:postman
2,学会看第三方平台文档。(这个很关键,不过很多还是喜欢百度,白嫖别人的操作文档)
3,学习排查问题,分析问题。
4,第三方平台的限制,和公众号,订阅号这些关系要了解。测试订阅号没有认证,没有认证的订阅号区别都是很大的。
5,善于使用缓存解决项目当中业务性能瓶颈。
微信开放文档:微信公众平台开发概述 | 微信开放文档
开盘:
上一个流程图:
第三方平台相当于代理我们微信公众号的配置,通过第三方平台的配置发起事件监听,包含回调信息处理,我们通过:授权事件接收配置--》开启推送Ticket--》授权后实现业务--》消息校验Token--》消息与事件接收配置--》微信公众号业务
流程就是这么简单,但是接口比较多,操作起来比较麻烦,还得管理token实效。我们最终要获取微信公众号的权限token才能实现业务扭转,要不然其他都是扯淡。
我们来看看第三方平台的页面配置和权限:
我这是自己的映射域名,正式上线后换成正式域名。
权限配置:
需要调试的接口:
接口比较多我们nacos配置:
wechat:
config:
#appid
component_appid: *************
#aeskey
component_encodingaeskey: ****************
#验证token
component_token: ****************
#加密正式
component_appsecret: ***********
#授权域名
redirect_url: http://d1989091s1.51mypc.cn/wechat/preauth/callback
#获取component_token url地址
api_component_url: https://api.weixin.qq.com/cgi-bin/component/api_component_token
#创建预授权 url地址
api_create_preauth_url: https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=
#权限查询api 授权平台地址
api_query_auth_url: https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=
#验证token 刷新地址
api_authorizer_token_url: https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=
#媒体文件下载地址
api_media_download_url: https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID
#客服回复用户文本信息
api_message_custom_send_url: https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=
#获取刷新token接口地址
api_refresh_url: https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=
#openid获取 unionid地址
api_unionid_batchget_url: https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=
#获取用户信息
api_unionid_get_url: https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
代码:
1,获取第三方平台授权component_token
2,获取预授权api_create_preauthcode
3,微信授权平台后获取权限接口根据预授权token+扫码授权code (api_query_auth)
4,扫码成功获取queryauthcode
5,通过queryauthcode获取公众号authorizer_token
6,通过authorizer_token操作公众号业务。
一,获取component_token
请求地址:https://api.weixin.qq.com/cgi-bin/component/api_component_token
请求参数:
{
"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"
需要配置ip白名单:
二,获取微信预授权pre_auth_code
请求参数:
{
"component_appid":"wx6ec5488b62c"
}
三,需要把预授权的token 和 component_appid 和重定向回调地址返回到html页面进行授权处理
<!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">点击授权</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>
授权的页面:这里是需要管理员,谁认证的订阅号,就谁扫码,如果你没有公众号订阅号没有绑定,那就授权不了。
这里的权限是我们第三方平台开启的权限集需要什么功能就开放什么权限功能。
四 更新授权回调。
<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">点击授权</a>
## 回调地址
redirect_uri=http://d1989091s1.51mypc.cn/wechat/preauth/callback
回调地址会返回一个auth_code默认一个小时过期,为了防止重复扫码,你必须获取到刷新token,定时刷缓存,保证token不用过期。
http://d1989091s1.51mypc.cn/wechat/preauth/[email protected]@@*****&expires_in=3600
五,第三方平台获取公众号权限token
参数:
{
"component_appid":"********" ,
"authorization_code": "[email protected]@@KEm1qXN8KFuVWO05a3FhXhMtAGQp8RFA4dAEaldQ_ffdvsKIUtDWpVXtzu8dDH8D1DCMhAS61RmonKgPBjecUw"
}
响应:
{
"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
}
}
]
}
}
这个权限token默认2个小时过期,所以这里需要定时刷新获取权限token
authorizer_refresh_token 代表我们定时刷新权限token,这个可以帮我们解决重复扫码的问题,管理员只需要扫码一次就好了。
六。公众号权限token的刷新
请求地址:
请求参数:
authorizer_appid 需要授权的第三方订阅号appid
component_appid 第三方平台appid
{
"component_appid":"wx6ec5e8ceb4882c",
"authorizer_appid":"wx3605b881a5f30b22"
}
七,通过刷新token定时去更换权限缓存
请求参数:
{
"component_appid":"*******",
"authorizer_appid":"wxbe11fb37fd31d2cb",
"authorizer_refresh_token":"[email protected]@@UFuvwOxnZ0eXBGEghR9DVTQnaZEwIQYBBGc6Oh89npg"
}
authorizer_access_token 验证成功的token就是我们公众号需要获取的凭证。
到这里我们就可以根据公众号的业务进行接口直接的调用了。整体的流程和实现已经完成了。
边栏推荐
- Deep learning - goal orientation
- Sword finger offer II 075 Array relative sort (custom sort, count sort)
- 【花雕体验】13 搭建ESP32C3之PlatformIO IDE开发环境
- Development technology sharing of Jingtan NFT digital collection system
- [nvme2.0b 14 - 5] commande de téléchargement / commande du logiciel
- 1. Problems related to OpenGL window and environment configuration
- Implementation of remote monitoring by camera in Experiment 5
- Miracle Mu server rental selection is real and easy to use, stable and intrusion proof
- Tue Jun 28 2022 15:30:29 gmt+0800 (China standard time) date formatting
- End-to-end 3D Point Cloud Instance Segmentation without Detection
猜你喜欢
【NVMe2.0b 14-5】Firmware Download/Commit command
Combinatorial mathematics Chapter 1 Notes
Hit the industry directly | the flying propeller launched the industry's first model selection tool
Construction of energy conservation supervision system for campus buildings of ankery University
CRM&PM如何帮助企业创造最优销售绩效
Wsl2 using GPU for deep learning
Sword finger offer II 076 The kth largest number in the array (use heap to solve TOPK problem)
Development technology sharing of Jingtan NFT digital collection system
Applet uses QR code plug-in
Halcon12+vs2013 C # configuration
随机推荐
Dlib database face
【NVMe2.0b 14-6】Format NVM、Keep Alive、Lockdown command
【NVMe2.0b 14-4】Directive Send/Receive command
2022.01.20 [bug note] | qiime2: an error was encoded while running dada2 in R (return code 1)
November 22, 2021 [reading notes] - bioinformatics and functional genomics (Section 5 of Chapter 5 uses a comparison tool similar to blast to quickly search genomic DNA)
Applet uses QR code plug-in
Development technology sharing of Jingtan NFT digital collection system
【NVMe2.0b 14-7】Set Features(上篇)
JS code case
【NVMe2.0b 14-1】Abort、Asynchronous Event Request、Capacity Management command
Getordefault method of map class
At the end of June, you can start to make preparations, otherwise you won't have a share in such a profitable industry
Combinatorial mathematics Chapter 2 Notes
AcrelEMS能效管理平台为高层小区用电安全保驾护航
1. Problems related to OpenGL window and environment configuration
Do you know the IP protocol?
多快好省,低门槛AI部署工具FastDeploy测试版来了!
Implementation of remote monitoring by camera in Experiment 5
CRM能为企业带来哪些管理提升
深度学习——卷积的滑动窗口实现