接口标识:member
接口url:https://你的网站/index.php?m=api&c=index&_ajax=1&a=member
接口参数:
(1)type:'baidu'用户来源,必填;例:baidu、weixin、douyin
(2)其他相关参数比如:code、data、iv等(具体请参考demo)
小程序代码:
注意:
- getUserInfo: function (e) {
- wx.getUserProfile({
- desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
- success: (e) => {
- console.log(e)
- wx.login({
- success: (res) => {
- var code = res.code; //返回code
- console.log(code)
- wx.request({
- url: app.globalData.api+"member",
- data: {
- 'type': 'weixin',
- "code": code,
- "encryptedData": e.encryptedData,
- "iv": e.iv,
- "signature": e.signature,
- "rawData": e.rawData,
- 'aid': app.globalData.aid
- },
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded', // 默认值
- },
- success: function (res2) {
- if(res2.data.code == 200){
- let data = res2.data.data;
- wx.setStorageSync('userInfo', data);
- wx.showToast({
- title: '授权成功!!',
- icon: 'success',
- duration: 1500,
- success: function () {
- wx.switchTab({
- url: '/pages/member/index/index',
- })
- }
- })
- }else{
- wx.showToast({
- title: '授权失败!!',
- icon: 'fail',
- duration: 1500,
- success: function () {
- }
- })
- }
- }
- })
- }
- })
- },
- fail:(e)=>{
- console.log(e)
- }
- })
- },
(1)由于官方接口权限收回,可能部分用户无法获取用户头像和昵称
(2)由于用户名不能重复,重复的用户名会自动添加随机数字