本地-----------------------------------------------------------------------------------------------------
// wx.login({
// success: res => {
// var code = res.code; //返回code
// // console.log(code)
// // 小程序appid
// // wxd751fc845c90fbd8
// // 3df95e167161ab74e09ea54eda471c96
// var appId = 'wxd751fc845c90fbd8';
// // 小程序密钥
// var secret = '3df95e167161ab74e09ea54eda471c96';
// 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;
// // openid请求
// wx.request({
// url: 'http://192.168.1.15:8080/queryUsers',
// data:{
// openid: openid
// },
// success: function (res) {
// var result=res.data;
// if (result.length!=0){
// // app.globalData.user = result;
// // 同步缓存
// wx.setStorageSync('user', result[0]);
// var user = wx.getStorageSync('user');
// }else{
// wx.redirectTo({
// url: '/pages/userdata/userdata'
// })
// }
// }
// })
 
// }
// })
// }
// });
 
网络-----------------------------------------------------------------------------------------------------
 
wx.login({
success: res => {
if (res.code) {
// console.log(res.code)
var code1 = res.code;
wx.request({
url: 'https://www.didu86.com/Football-manager-web/Openid',
data: { code1: code1 },
success: function (res) {
// console.log(res)
var openid = res.data
// console.log(openid)
that.globalData.userId = openid
user请求---------------

wx.request({
url: 'https://www.didu86.com/Football-manager-web/queryUsers', //仅为示例,并非真实的接口地址
data: {
openid: openid,
},
success: function (res) {
var result = res.data;
wx.setStorageSync('user', result);
}
})
}
})
}
}
});
 
 
 
用户微信信息--------------------------------------------------------------------------------------------------------------------------------------------
wx.getSetting({
success: res => {
 
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo;
wx.setStorageSync('userInfo', res.userInfo)
// console.log(res.userInfo)
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}else{
}
}
});
 
 
请求登入-------------------------------------------------------------------------------------------------------------------------------------------
index
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo;
wx.setStorageSync('userInfo', res.userInfo)
// console.log(res.userInfo)
// this.setData({
// userInfo: res.userInfo,
// hasUserInfo: true
// })
}
})

微信小程序 功能函数 openid本地和网络请求的更多相关文章

  1. 微信小程序 功能函数 支付接口

    // 订单生成返回数据,弹出是否支付模态 wx.showModal({ title: '微信支付', content: '确定支付吗?', success: function (res) { if ( ...

  2. 微信小程序 功能函数 点击传参和页面

    // 商品详情页跳转函数 detailInto: function (e) { // console.log() var change = e.currentTarget.dataset.id; wx ...

  3. 微信小程序 功能函数 定时震动

    ffn: function () { let nnn = this.data.nnn nnn += 1; this.setData({ nnn: nnn }); if (nnn > 10) { ...

  4. 微信小程序 功能函数 客服

    <view> <view class='btn-img'> <image class='image-full' src='../../imgs/index/tab6.pn ...

  5. 微信小程序 功能函数 将对象的键添加到数组 (函数深入)

    // 将对象的键添加到数组 var arr = Object.keys(site); //英文 https://developer.mozilla.org/en-US/docs/Web/JavaScr ...

  6. 微信小程序 功能函数 购物车商品删除

    // 购物车删除 deleteList(e) { const index = e.currentTarget.dataset.index; let carts = this.data.carts; c ...

  7. 微信小程序 功能函数 替换字符串内的指定字符

    var str = 'abcadeacf'; var str1 = str.replace('a', 'o'); alert(str1);    // 打印结果: obcadeacf   var st ...

  8. 微信小程序 功能函数picker-view的弹出模态

    <view class="list"> <form bindsubmit="formSubmit"> <view class=&q ...

  9. 微信小程序 功能函数 获取验证码*

    yanZhengInput: function (e) { var that = this; var yanzheng = e.detail.value; var huozheng = this.da ...

随机推荐

  1. 【JLOI2013】卡牌游戏

    题面 题解 概率$dp$ 设$f[i][j]$表示还剩$i$个人时,第$j$个人获胜的概率. 边界$f[1][1] = 1$ 转移: 枚举庄家抽到的卡牌$k$,得到这一轮被淘汰的位置$c$. 可以知道 ...

  2. selenium select 选择下拉框

    实战百度首页设置,浏览偏好设置. 打开首页,在非登录的情况下,查看分析页面元素,我们可以看到,我们首先要点击的是设置, 接着点击,搜索设置, 然后select选择下拉框. select_by_inde ...

  3. Zigbee系列(路由机制)

    参考文档: ug103-02-fundamentals-zigbee.pdf section4 zigbe routing concepts docs-05-3474-21-0csg-zigbee-s ...

  4. Minor GC&Full GC&Major GC区别及触发条件

    Minor GC:从年轻代回收内存 触发条件 1.Eden区域满 ​ 2.新创建的对象大小 > Eden所剩空间 Full GC:清理整个堆空间,包括年轻代和老年代 触发条件 ​ 1.每次晋升到 ...

  5. Unity学习笔记(3):一些常用API和应用场景

    Mathf.Lerp(float a,float b,float t)插值函数,当a < b时往a中插入t,以此来实现颜色,声音等渐变效果. GameObject.FindWithTag(str ...

  6. 基于zookeeper实现分布式锁(续)

    测试代码: 效果图:

  7. gitlab+jenkins持续集成(三)

    构建: 需要将jenkins服务器上  jenkins用户的公钥发送给  目标服务器的gs用户,使得在jenkins上能用gs免密登录目标服务器 复制密钥到目标机器上(需要登录到的机器) ssh-co ...

  8. Kettle日常使用汇总整理

    Kettle日常使用汇总整理 Kettle源码下载地址: https://github.com/pentaho/pentaho-kettle Kettle软件下载地址: https://sourcef ...

  9. 用线性分类器实现预测鸢尾花的种类(python)

    这是个人学习时跑的代码,结果就不贴了,有需要的可以自己运行,仅供参考,有不知道的可以私下交流,有问题也可以联系我.当然了我也只能提供一点建议,毕竟我也只是初学者 第一个页面 # -*- coding: ...

  10. Mysql数据库的隔离级别

    Mysql数据库的隔离级别有四种 1.read umcommitted   读未提交(当前事务可以读取其他事务没提交的数据,会读取到脏数据) 2.read committed 读已提交(当前事务不能读 ...