login
解释: 调用接口 swan.login 获取 Authorization Code,智能小程序可以使用swan.login()
接口获取Authorization Code。
参数: Object
Object参数说明:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
timeout | number | 否 | 超时时间,单位ms |
success | Function | 否 | 接口调用成功的回调函数 |
fail | Function | 否 | 接口调用失败的回调函数 |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
success 返回参数说明:
参数 | 类型 | 说明 |
---|---|---|
code | String | 用户登录凭证(有效期五分钟),开发者需要在开发者服务器后台调用 api,使用 code 换取 session_key 等信息。 |
示例:在开发者工具中预览效果
- swan.login({
success: function (res) {
swan.request({
url: 'https://xxx/xxx', // 开发者服务器地址
data: {
code: res.code
}
});
},
fail: function (err) {
console.log('login fail', err);
}
});