微信开放平台获取授权公众号的流程

官方流程如下


实际上这个流程图并不完整

实际流程

  1. 获取推送的component_verify_ticket,开放平台会每10分钟推送到授权事件接收URL里
  2. 获取component_access_token,使用上一步获取到的ticket,向开放平台请求https://api.weixin.qq.com/cgi-bin/component/api_component_token,这个token有效期两小时
  3. 获取预授权码pre_auth_code,使用component_access_token,向开放平台请求https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=%s
  4. 拼接授权回调url https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=xxxx&pre_auth_code=xxxxx&redirect_uri=xxxx&auth_type=xxx
  5. 在回调里向开放平台请求https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=%s,获取公众号授权,取得公众号id,这里还会返回公众的access_token,和refresh_token
  6. 在回调里向开放平台请求https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=%s,使用上一步的公众号id,获取公众号信息

常见错误

  • 请确认授权入口页所在域名,与授权后回调页面所在域名相同
    授权回调页要在服务器所在的那台机器上,可以简单的做个网页,在网页里跳转到授权页

猜你喜欢

转载自www.cnblogs.com/xdao/p/wechat_openpartform.html
今日推荐