微信小程序企业微信兼容— wx.qy.login(Object object)

微信小程序企业微信兼容— wx.qy.login(Object object)

# wx.qy.login(Object object)

获取企业微信派发的临时登录凭证

# 参数

# Object object
参数名 类型 必填 说明
timeout Number 超时时间,单位 ms
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)
# object.success 回调函数

参数

Object res

参数名 类型 说明
errMsg String 调用结果
code String 用户登录凭证(有效期五分钟)。开发者需要在开发者服务器后台调用 api,使用 code 换取 userid 和 session_key 等信息

# 示例代码

//app.js
App({
  onLaunch: function() {
    wx.qy.login({
      success: function(res) {
        if (res.code) {
          //发起网络请求
          wx.request({
            url: 'https://test.com/onLogin',
            data: {
              code: res.code
            }
          })
        } else {
          console.log('登录失败!' + res.errMsg)
        }
      }
    });
  }
})