本地-----------------------------------------------------------------------------------------------------
// 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. 4-[多进程]-互斥锁、Queue队列、生产者消费者

    1.互斥锁 (1)为什么需要互斥锁 进程之间数据不共享,但是共享同一套文件系统,所以访问同一个文件,或同一个打印终端,是没有问题的, 而共享带来的是竞争,竞争带来的结果就是错乱,如下 #并发运行,效率 ...

  2. HDU - 3874 Necklace (树状数组、离线处理)

    题目链接:Necklace 题意: 给出一串珠子,每个珠子有它的value,现在给出n(n<=5e4)个珠子的value(1<=value<=1e6),现在给出m(1<=m&l ...

  3. cogs468 [NOI2010]超级钢琴

    http://cogs.pro:8080/cogs/problem/problem.php?pid=468 emmmmmm 今天考试爆炸顺便切了这题 这题我肯定不会啦然后看一sol.. 固定一个右端点 ...

  4. Jenkins部署资料

    http://www.cnblogs.com/gaohongchen01/p/5058928.html https://www.javacodegeeks.com/2015/04/jenkins-ho ...

  5. Spring学习----- Spring配置文件xml文档的schema约束

    1.配置文件示例. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...

  6. frp+TeamViewer 完美解决TeamViewer5分钟商业提醒

    必要条件:必须有一个公网服务器 frp是一个开源的端口转发工具,中文使用说明及下载地址在这里  https://github.com/fatedier/frp/blob/master/README_z ...

  7. Unity 实现一个简单的 TPS 相机

    效果如下: 代码如下: public class TPSCamera : MonoBehaviour { /// <summary> /// 目标对象 /// </summary&g ...

  8. Django 前后端不分离 代码结构详解

    Demo:  hello_pycharm 根目录文件:hello_pycharm [__init__.py  __pycache__  settings.py  urls.py  wsgi.py] A ...

  9. 从零开始的Python学习Episode 17——序列化

    序列化 我们把对象(变量)从内存中变成可存储或传输的过程称之为序列化,在Python中叫pickling,在其他语 言中也被称之为serialization,marshalling,flattenin ...

  10. AS的使用技巧

    title: AS的使用技巧 date: 2016-04-01 23:34:11 tags: [AndroidStudio] categories: [Tool,IDE] --- 概述 本文记录如何使 ...