Skip to content

微信设备

微信网页授权流程

  1. 微信客户端请求微信授权地址 https://open.weixin.qq.com/connect/oauth2/authorize
  2. 用户点击允许后跳转到前端设备列表地址(/wechat-auth?code=xxx&state=xxx)
  3. 前端从url中获取state和code调用微信登录接口
  4. [可选] 前端url变化时通过氦氪access_token签名微信js-sdk

微信公众号登录

POST /login?type=wechat-public-platform HTTP/1.1
Host: uaa-openapi.hekr.me
Content-Type: application/json

{
  "state": "Njtd...",
  "code": "aXjb..."
}
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8

{
  "access_token": "eyJhbGciO...",
  "refresh_token": "eyJhbGci...",
  "token_type": "bearer",
  "expires_in": 86399,
  "user": "12264113078"
}

请求体

参数 是否必须 含义
code 微信授权authorization_code(重定向url中的code参数)
state 氦氪定义state(重定向url中的state参数)

微信JS-SDK签名

如需使用JS-SDK中的接口,必须调用微信签名。

POST /api/v1/wechat-js-sign?url HTTP/1.1
Host: wechat-api.hekr.me
Authorization: Bearer {JWT_TOKEN}
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8

{
  "signature": "0f9de62fce790f9a083d5c99e95740ceb90c27ed",
  "noncestr": "Wm3WZYTPz0wzccnW",
  "timestamp": 1414587457,
  "brandUserName": "gh_xxx"
}

请求参数

参数 类型 是否必须 默认 含义
url String true 需要签名的页面地址,参考微信文档

返回体

参数 含义
signature 签名结果
noncestr 随机字符串
timestamp UNIX时间戳(秒)
brandUserName 公众号原始ID

获取设备分享二维码

二维码过期时间为1小时

POST /api/v1/device-auth?type=wechat HTTP/1.1
Host: wechat-openapi.hekr.me
Content-Type: application/json;charset=UTF-8
Authorization: Bearer {JWT_TOKEN}

{
  "ctrlKey": [
      "89f089..."
  ],
  "expireAt": 1503479651538,
}
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8

{
    "url": "http://weixin.qq.com/q/02K8sUUNJVbv_1cvZ3hqcH",
    "qrcode": "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQHQ7zwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAySzhzVVVOSlZidl8xY3ZaM2hxY0gAAgQP7wNaAwQQDgAA",
    "expireAt": 1511424307244
}

请求体

参数 是否必须 含义
ctrlKey true 授权设备的ctrlKey
expireAt false 设备授权关系过期时间(UNIX毫秒时间戳), 空表示永不过期

返回体

参数 含义
qrcode 微信授权二维码
url 二维码识别的内容(对应微信的网址)
expireAt 二维码过期时间(UNIX毫秒时间戳)