API教程

了解最新公司动态及行业资讯

当前位置:首页>新闻资讯>API教程
全部 24 小程序教程 7 API教程 13 常见问题 4

用户授权登录member

时间:2023-09-09   访问量:1008


接口名称:用户信息接口
接口标识:member
接口url:https://你的网站/api.php/index/member
接口参数:
(1)type:'baidu'用户来源,必填;目前只有:baidu、weixin两种
(2)其他相关参数比如:code、data、iv等(具体请参考demo)

小程序代码:

code腾石建站

  1. swan.login({ 

  2.             success: function (login) { 

  3.                 //获取code,换取session_key 

  4.                 swan.authorize({ 

  5.                     scope: 'scope.userInfo'

  6.                     success(a) { 

  7.                         swan.showLoading({ 

  8.                             title: '授权中...' 

  9.                         }); 

  10.                         swan.getUserInfo({ 

  11.                             success(userInfo) { 

  12.                                 console.log(userInfo.userInfo) 

  13.                                 swan.request({ 

  14.                                     url: that.globalData.api + "member"

  15.                                     data: { 

  16.                                         aid: that.globalData.aid, 

  17.                                         code: login.code, 

  18.                                         data: userInfo.data, 

  19.                                         iv: userInfo.iv, 

  20.                                         type: 'baidu' 

  21.                                     }, 

  22.                                     method: 'POST'

  23.                                     header: { 

  24.                                         'content-type''application/x-www-form-urlencoded'// 默认值 

  25.                                         'x-appsecret': that.globalData.appsecret 

  26.                                     }, 

  27.                                     success: function (res) { 

  28.                                         swan.hideLoading(); 

  29.                                         let data = res.data; 

  30.                                         if (res.statusCode === 200) { 

  31.                                             swan.setStorageSync('Token', data.token); 

  32.                                             swan.setStorageSync('userInfo', data.data); 

  33.                                             swan.navigateBack(); 

  34.                                             swan.showToast({ 

  35.                                                 title: '授权成功'

  36.                                                 icon: 'success'

  37.                                                 duration: 1000, 

  38.                                             }); 

  39.                                         } 

  40.                                     } 

  41.                                 }) 

  42.                             } 

  43.                         }) 

  44.                     }, 

  45.                     fail(err) { 

  46.                         swan.showToast({ 

  47.                             title: '授权失败' 

  48.                         }); 

  49.                     } 

  50.                 }); 

  51.             }, 

  52.             fail: function (err) { 

  53.                 console.log('登录失败', err); 

  54.             } 

  55.         }); 


说明:

(1)添加会员字段:openid,字段长度:50

(2)修改数据库ay_member中的headpic字段的长度改成:255;


上一篇:没有了!

下一篇:自定义表单form

在线咨询

点击这里给我发消息 售前咨询专员

点击这里给我发消息 售后服务专员

在线咨询

免费通话

24小时免费咨询

请输入您的联系电话,座机请加区号

免费通话

微信扫一扫

微信联系
返回顶部