微信小程序授权绑定到第三方开放平台的过程,官方文档 写的不太清晰,在这里梳理罗列一下。
1 服务器准备,开通开放平台
域名填写:weixin.mydomain.cn
IP白名单:47.888.888.888
授权事件接收URL:http://weixin.mydomain.cn/api/weixin/platform/grant-msg
消息校验token:htqa****************
消息加密Key:NCVs00ht8gr***************************************
消息与事件接收:http://weixin.mydomain.cn/api/weixin/business/msg/$APPID$/callback
2 绑定开发小程序
(1)第三方平台的开发人员需先到微信公众平台(mp.weixin.qq.com)申请一个普通的小程序并完善小程序的头像、暱称、简介、服务类目等信息。
(2)进入微信开放平台,在第三方平台详情中,将该小程序添加为开发小程序。
注意: 绑定为开发小程序后,该小程序的在开发工具中上传,代码会直接上传到开放平台,不会上传到公众平台。
3 为租户上传小程序
获取微信后台推送的 ticket -> 用来获取 “第三方平台component_access_token”
https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/component_verify_ticket.html
获取第三方平台 component_access_token -> 用来获取 “第三方平台接口调用令牌”
https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/component_access_token.html
获取第三方平台接口调用令牌 authorizer_access_token -> 用来上传小程序
https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/api_authorizer_token.html
1)获取预授权码 pre_auth_code https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/pre_auth_code.html
2)生成授权网页链接
3)用户访问授权页面授权 后 返回回调页面
4)回调页面得到授权码, 授权流程完成后,授权页会自动跳转进入回调 URI,并在 URL 参数中返回授权码和过期时间(redirect_url?auth_code=xxx&expires_in=600)
5) 调用上传小程序接口
上传小程序代码
https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/code/commit.html