小程序 openid 的原始请求和网络请求

// 登录
wx.login({
success: res => {
var code = res.code; //返回code
// console.log(code)
// 小程序appid
// wxd751fc845c90fbd8
// 3df95e167161ab74e09ea54eda471c96

var appId = 'wx2bd115231a8d3eb4';
// 小程序密钥
var secret = '4318963731f224658258d1c3cc851052';
wx.request({
url: 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appId + '&secret=' + secret + '&js_code=' + code + '&grant_type=authorization_code',
data: {},
header: {
'content-type': 'json'
},
success: function (res) {
// console.log(res)
var openid = res.data.openid
console.log(openid)
that.globalData.userId = openid;
// wx.request({
// url: 'https://www.didu86.com/Cloth-manager-web/queryUsers',
// data: {
// openid: openid,
// },
// success: function (res) {
// var result = res.data;
// // console.log(result)
// if (result.length != 0) {
// wx.setStorageSync('user', result[0]);
// } else {
// }

// }
// })

}
})
}
});
 
 
 
 
// 展示本地存储能力
wx.login({
success: res => {
var that = this
if (res.code) {
console.log(res.code)
var code1 = res.code;
wx.request({
url: 'http://192.168.1.15:8080/getOpenid',
data: { code1: code1 },
success: function (res) {
console.log(res)
// var openid = res.data
// console.log(openid)
// that.globalData.userId = openid

// wx.request({
// url: 'https://www.didu86.com/Cloth-manager-web/queryUsers', //仅为示例,并非真实的接口地址
// data: {
// openid: openid,
// },
// success: function (res) {
// var result = res.data;
// // console.log(result)
// if (result.length != 0) {
// wx.setStorageSync('user', result[0]);
// } else {
// }

// }
// })
}
})
}
}
});

转载于:https://www.cnblogs.com/dianzan/p/8124058.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值