微信小程序獲取用戶OpenId

1.在小程序中得到UserCode:javascript

wx.login({
	success: function (res) {
		thisApp.setData({
			userCode: res.code
		})
	}
})

2.在小程序中得到UserInfo:java

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)
	}
})
相關文章
相關標籤/搜索