login

解释: 调用接口 swan.login 获取 Authorization Code,智能小程序可以使用swan.login()接口获取Authorization Code。

参数: Object

Object参数说明:

参数名类型必填说明
timeoutnumber超时时间,单位ms
successFunction接口调用成功的回调函数
failFunction接口调用失败的回调函数
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)

success 返回参数说明:

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

示例:在开发者工具中预览效果

  1. swan.login({
    success: function (res) {
    swan.request({
    url: 'https://xxx/xxx', // 开发者服务器地址
    data: {
    code: res.code
    }
    });
    },
    fail: function (err) {
    console.log('login fail', err);
    }
    });