微信小程序获取openid小程序端及服务器端代码
发布:2018-02-10 11:27浏览:
次来源:网络 作者:cola
一:客户端
var that = this
wx.login({
success: function (res) {
var appId = ' ';//微信公众号平台申请的appid
var appSecret = ' ';//微信公众号平台申请的app secret
var js_code = res.code;//调用登录接口获得的用户的登录凭证code
wx.request({
url: 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appId + '&secret=' + appSecret + '&js_code=' + js_code + '&grant_type=authorization_code',
data: {},
method: 'GET',
success: function (res) {
var openid = res.data.openid //返回的用户唯一标识符openid
console.log(openid)
console.log("试试吧上面就是获得的openid")
}
})
}
})
//试验自己的服务器获取openId
//调用登录接口
wx.login({
success: function (res) {
//console.log(res);
that.globalData.loginCode = res.code
wx.getUserInfo({
success: function (res) {
that.globalData.userInfo = res.userInfo
that.globalData.iv = res.iv
that.globalData.encryptedData = res.encryptedData
typeof cb == "function" && cb(that.globalData.userInfo)
that.req(
'https://lifar网址.aspx?Action=ActionLogin',
{
encryptedData: that.globalData.encryptedData,
iv: that.globalData.iv,
code: that.globalData.loginCode
},
'GET',
function (res) {
console.log(res)
if (
|
免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。