zoukankan      html  css  js  c++  java
  • 小程序获取openid

    var openId = (wx.getStorageSync('openId'))
    if (openId) {
    wx.getUserInfo({
    success: function (res) {
    that.setData({
    nickName: res.userInfo.nickName,
    avatarUrl: res.userInfo.avatarUrl,
    })
    },
    fail: function () {
    // fail
    console.log("获取失败!")
    },
    complete: function () {
    // complete
    console.log("获取用户信息完成!")
    }
    })
    } else {
    wx.login({
    success: function (res) {
    if (res.code) {
    wx.getUserInfo({
    withCredentials: true,
    success: function (res_user) {
    wx.login({
    success: function (res) {
    wx.request({
    url: 'https://api.weixin.qq.com/sns/jscode2session',
    data: {
    appid: 'wx6286d06fe538aed9',
    secret: '63ca18846d28001d334fecb84bd9bafb',
    js_code: res.code,
    grant_type: 'authorization_code'
    },
    method: 'GET',
    success: function (res) {
    var openid = res.data.openid;//获取到的openid
    console.log(openid);
    }
    })
    }
    })
    }, fail: function () {

    }, complete: function (res) {

    }
    })
    }
    }
    })

    }



    但行好事,莫问前程。
  • 相关阅读:
    面向对象和面向过程
    视图代理(转帖)
    qt中的多线程(转)
    QT GUI总结
    Qt探秘——谈ui文件的用法
    Qt的Model/View Framework解析
    编程入门指南 v1.4
    设计模式总结(经典)
    地址
    QLayout的属性介绍
  • 原文地址:https://www.cnblogs.com/txhy/p/8343220.html
Copyright © 2011-2022 走看看