本地-----------------------------------------------------------------------------------------------------
// 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. 4011: [HNOI2015]落忆枫音

    4011: [HNOI2015]落忆枫音 链接 分析: 原来是一个DAG,考虑如何构造树形图,显然可以给每个点找一个父节点,所以树形图的个数就是$\prod\limits_u deg[u]$. 那么加 ...

  2. 网络编程的演进——从Apache到Nginx

    Apache 1.Apache HTTP服务器是 Robert McCool 在1995年写成,并在1999年开始在Apache软件基金会的 框架下进行开发. 由于Apache HTTP服务器是基金会 ...

  3. 深入浅出js中的this

    Q:this是什么? A:this是Javascript语言的一个关键字,它代表函数运行时,自动生成的一个内部对象,在每个 function 中自动根据作用域(scope) 确定, 指向的是此次调用者 ...

  4. variadic templates & pass by const reference & member operator [] in const map & gcc sucks

    /// bugs code with comments #include <iostream> #include <memory> #include <unordered ...

  5. Firefox浏览器【书签工具栏】里的网址链接无法删除的解决办法

    今天使用Firefox浏览器,发现有一些我从来都没有访问的网站出现在[书签工具栏], 也不知道是什么原因被添加进来的(可能是安装某个插件被插的),于是点删除,发现还删除不了,很是老火,研究了一番,把删 ...

  6. layui数据表格使用(一:基础篇,数据展示、分页组件、表格内嵌表单和图片)

    表格展示神器之一:layui表格 前言:在写后台管理系统中使用最多的就是表格数据展示了,使用表格组件能提高大量的开发效率,目前主流的数据表格组件有bootstrap table.layui table ...

  7. SharpDevelop 笔记

    1. 下载地址: http://jaist.dl.sourceforge.net/project/sharpdevelop/ 2. 使用 VS2012 去掉编译不通过的 Test ,其它可以运行调试. ...

  8. gzip命令详解

    基础命令学习目录首页 好文链接:https://blog.csdn.net/m0_38132420/article/details/78577247 原文链接:http://www.cnblogs.c ...

  9. python的Socket网络编程 使用模板

    本文给出的是TCP协议的Socket编程. 其中用了一个dbmanager数据库操作模块,这个模块是我自己定义的,可以在我的另一个文章中找到这个模块的分享.python操作mysql数据库的精美实用模 ...

  10. Vue 入门之组件化开发

    Vue 入门之组件化开发 组件其实就是一个拥有样式.动画.js 逻辑.HTML 结构的综合块.前端组件化确实让大的前端团队更高效的开发前端项目.而作为前端比较流行的框架之一,Vue 的组件和也做的非常 ...