1.在小程序中获得UserCode:
wx.login({
success: function (res) {
thisApp.setData({
userCode: res.code
})
}
})
2.在小程序中获得UserInfo:
wx.getUserInfo({
success: function (res) {
thisApp.setData({
userInfo: res.userInfo
})
}
})
3.调用远程开放接口(Elvania.cn)注册更新用户数据:
wx.request({
url: "https://www.elvania.cn/WeChat-interface/httpController/checkUser.WeChat",
method: "GET",
data: {
userCode: thisApp.data.userCode,
userName: thisApp.data.userInfo.nickName,
userGender: thisApp.data.userInfo.gender,
userIcon: thisApp.data.userInfo.avatarUrl,
appId: "位于开发设置中",
appSercet: "位于开发设置中"
},
success: function (res) {
var result = res.data.result; //用户主键(OpenId)
}
})
注意:
Elvania.cn是本人为了方便大家获取用户信息提供的一个开放的接口服务。
API:http://www.elvania.cn/WeChat-interface