【声明】关于六久阁私自出售我公司dedecms小程序插件声明
发布时间:2019-07-03 22:56:30查看:0用户信息接口member 
接口名称:用户信息接口
接口标识:member
接口url:https://你的网站/api/index.php?action=member&type=baidu
接口参数:
(1)type:'baidu'用户来源,必填;目前只有:baidu、weixin两种
(2)其他相关参数比如:code、data、iv等(具体请参考demo)

小程序代码:
  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 + "action=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)小程序用户首次访问,授权成功后用户信息会同步到后台“会员中心”,并通过form字段区分来源
(2)如果用户是登录用户,会同步更新会员中心登录状态,
(3)token验证正在开发中



版权声明:本文为原创文章,未经允许不得转载。https://doc.tengcee.com/dedecms/apis/67.html

服务热线

15137100750

我知道你不会打


但是我还是要写


你懂得!

微信二维码

QQ群二维码