微信小程序获取用户OpenId

陌路散爱 提交于 2020-02-27 06:40:23

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)
	}
})

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!