zoukankan      html  css  js  c++  java
  • 微信小程序 功能函数 openid本地和网络请求

    本地-----------------------------------------------------------------------------------------------------
    // 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
    // })
    }
    })
  • 相关阅读:
    log4j.properties配置
    5.1properties属性
    Bootstrap-datepicker设置开始时间结束时间范围
    mybatis学习笔记2
    mysql中插入中文时显示乱码
    mybatis入门总结一
    mybatis学习笔记一
    SqlMapConfig.xml配置文件
    Java连接SQL Server:jTDS驱动兼容性问题
    Sublime Text3注册码(可用)
  • 原文地址:https://www.cnblogs.com/dianzan/p/7927337.html
Copyright © 2011-2022 走看看