第三方平台授权流程说明(全网最详细的微信第三方平台授权公众号/小程序开发说明)
ttps://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Authorization_Process_Technical_Description.html
小程序或者公众号授权给第三方平台的技术实现流程比较简单,如下图所示:
第三方服务商构建授权链接放置自己的网站,用户点击后,弹出授权页面。
步骤 1:第三方平台方获取预授权码(pre_auth_code)
点击https://blog.csdn.net/u011627598/article/details/103668844链接地址有第三方平台方获取预授权码(pre_auth_code)的说明和写法
步骤 2:引入用户进入授权页
第三方平台方可以在自己的网站中放置“微信公众号授权”或者“小程序授权”的入口,或生成授权链接放置在移动网页中,引导公众号和小程序管理员进入授权页。
方式一:授权注册页面扫码授权
- **如果第三方平台没有全网发布,请在(开发资料-授权测试公众号列表)中配置要授权的公众号/小程序
授权页网址为:
https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=xxxx&pre_auth_code=xxxxx&redirect_uri=xxxx&auth_type=xxx
- 配置的回调 URI(redirect_uri)代码如下:
@ApiOperation(value = "小程序或者公众号授权给第三方平台")
@RequestMapping(value = "/platform/authcode",
method = RequestMethod.GET)
public void wechatPlatformAauthcode(HttpServletResponse response,
@RequestParam("auth_code") String authCode,
@RequestParam("expires_in") String expiresIn) {
logger.debug("小程序或者公众号授权给第三方平台");
try {
logger.debug("小程序或者公众号授权给第三方平台【authCode】:" + authCode + "【expiresIn】:" + expiresIn);
dbyWechatExtService.wechatPlatformAauthcode(response, authCode, expiresIn);
logger.debug("小程序或者公众号授权给第三方平台,操作成功");
} catch (Exception e) {
logger.error("小程序或者公众号授权给第三方平台,操作异常", e.getMessage(), e);
}
}
- response.sendRedirect()进行重定向
@Override
public void wechatPlatformAauthcode(HttpServletResponse response, String authCode, String expiresIn) {
try {
// 获取令牌【component_access_token】
String accessToken = redisTemplate.opsForValue().get("component_access_token").toString();
logger.debug("====================令牌【accessToken】:" + accessToken);
// 使用授权码获取授权信息
JSONObject jsonObject = new JSONObject();
jsonObject.put("component_appid", PLATFORM_APP_ID);
jsonObject.put("authorization_code", authCode);
String post = OkHttpHelper.post(API_QUERY_AUTH_URL + accessToken, JSON.toJSONString(jsonObject));
logger.debug("====================返回post结果:" + post);
// 重定向地址
response.sendRedirect("/wechat/authcode");
} catch (IOException e) {
e.printStackTrace();
}
}
- 到这里第三方平台授权公众号/小程序就完成了,如有疑问请私信我
如果对您起到了帮助,麻烦你点个赞,你的小心心就是我继续更新博客的动力,谢谢。
- 下期分享Linux系统命令行安装达梦数据库(全网最全最可行的安装方式)