微信公众平台开放授权
    微信公众平台开放授权
    • 生成微信公众号的二维码
      GET
    • 构建授权 URL
      GET
    • 查询用户是否已关注公众号
      GET
    • 获取微信渠道的 JWT
      GET

      构建授权 URL

      GET
      /wechat/authorize
      接口只用于构建微信网页授权的地址,用户应该被引导访问此地址或被跳转至此地址完成授权。
      1.
      用户授权完成后,微信侧将用户重定向至 callback 页面 ,并在 callback url 中拼接 code 查询参数。
      2.
      应用的 callback 页面应该使用获取到的 code 请求 /wechat/jwt 接口换取应用 token
      构建出的微信授权地址会携带 state 参数,callback 页面也会获取到相同的 state 参数,在换取应用 token 时携带 state 参数即可拿到 redirectUri

      请求参数

      Authorization
      在 Header 添加参数
      Authorization
      ,其值为在 Bearer 之后拼接 Token
      示例:
      Authorization: Bearer ********************
      Query 参数
      redirectUri
      string 
      必需
      完成授权后的跳转地址,这个跳转是由前端完成的。redirectUri 不能与 callback 相同
      callback
      string 
      必需
      在微信侧完成授权后的跳转地址,通常是应用中的专用回调页面。redirectUri 不能与 callback 相同
      scope
      string 
      可选
      snsapi_base 或 snsapi_userinfo,默认值 snsapi_base

      示例代码

      Shell
      JavaScript
      Java
      Swift
      Go
      PHP
      Python
      HTTP
      C
      C#
      Objective-C
      Ruby
      OCaml
      Dart
      R
      请求示例请求示例
      Shell
      JavaScript
      Java
      Swift
      curl --location --request GET 'http://localhost:3000/wechat/authorize?redirectUri&callback&scope'

      返回响应

      🟠401创建成功,需要授权
      application/json
      Body
      id
      string 
      必需
      status
      integer 
      必需
      name
      string 
      必需
      message
      string 
      必需
      details
      object 
      必需
      field
      string 
      必需
      fieldValue
      string 
      必需
      示例
      {
        "id": "3e906768-3b67-45e6-8eb7-630911f642d2",
        "status": 401,
        "name": "UNAUTHORIZED",
        "message": "UNAUTHORIZED",
        "details": {
          "field": "authorization url",
          "fieldValue": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5484861b38fa530f&redirect_uri=http%3A%2F%2F192.168.1.165%3A5173%2F&response_type=code&scope=snsapi_base&state=1c630cd9-850e-453d-bc62-48ba60afb974&forcePopup=false#wechat_redirect"
        }
      }
      🟠400参数校验错误
      上一页
      生成微信公众号的二维码
      下一页
      查询用户是否已关注公众号
      Built with