当前位置:网站首页>微信公众号第三方平台开发,零基础入门。想学我教你啊
微信公众号第三方平台开发,零基础入门。想学我教你啊
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就是我们公众号需要获取的凭证。
到这里我们就可以根据公众号的业务进行接口直接的调用了。整体的流程和实现已经完成了。
边栏推荐
- 跳槽字节跳动很难嘛?掌握这些技巧,你也能轻松通过
- Combinatorial mathematics Chapter 1 Notes
- November 9, 2020 [wgs/gwas] - whole genome analysis (association analysis) process (Part 2)
- min_ max_ Gray operator understanding
- Cesium learning notes (III) creating instances
- [notes] polygon mesh processing learning notes (10)
- 奇迹MU服务器租用选择 真实好用 稳定不卡 还能防入侵
- MySQL cannot connect to the intranet database
- Deep learning - residual networks resnets
- Deep learning vocabulary representation
猜你喜欢

Deep learning - LSTM

Environment configuration of ROS Aubo manipulator

深度学习——BRNN和DRNN

深度学习——残差网络ResNets

回文子串、回文子序列
![[JUC series] overview of fork/join framework](/img/49/2cadac7818b0c1100539fd32ec0d37.png)
[JUC series] overview of fork/join framework

深度学习——网络中的网络以及1x1卷积

Hit the industry directly | the flying propeller launched the industry's first model selection tool

Deep learning -- language model and sequence generation

1162 Postfix Expression
随机推荐
ACM. HJ48 从单向链表中删除指定值的节点 ●●
Vulfocus entry target
Fishingprince Plays with Array
Introduction to opencv (I): image reading and display
深度学习——目标定位
Qqquickpainteditem implements graffiti program drawing board
The counting tool of combinatorial mathematics -- generating function
牛客小白月赛52
ACM. Hj48 delete the node with the specified value from the one-way linked list ●●
min_ max_ Gray operator understanding
Go 数据类型篇之基本数据类型之间的转化
深度学习——语言模型和序列生成
More, faster, better and cheaper. Here comes the fastdeploy beta of the low threshold AI deployment tool!
Want to ask, how to choose securities companies for stock speculation? Is it safe to open an account online?
1162 Postfix Expression
Opencv video
【花雕体验】13 搭建ESP32C3之PlatformIO IDE开发环境
Wsl2 using GPU for deep learning
回文子串、回文子序列
微信小程序使用vant weapp报错