小程序模板网

微信小程序获取openid小程序端及服务器端代码

发布时间:2018-02-10 11:27 所属栏目:小程序开发教程

一:客户端

 
   var that = this
    wx.login({
      success: function (res) {
        var appId = '     ';//微信公众号平台申请的appid
        var appSecret = '   ';//微信公众号平台申请的app secret
        var js_code = res.code;//调用登录接口获得的用户的登录凭证code
        wx.request({
          url: 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appId + '&secret=' + appSecret + '&js_code=' + js_code + '&grant_type=authorization_code',
          data: {},
          method: 'GET',
          success: function (res) {
            var openid = res.data.openid //返回的用户唯一标识符openid
            console.log(openid)
            console.log("试试吧上面就是获得的openid")
          }
        })
      }
    })
    //试验自己的服务器获取openId
    //调用登录接口
    wx.login({
      success: function (res) {
        //console.log(res);
        that.globalData.loginCode = res.code
        wx.getUserInfo({
          success: function (res) {
            that.globalData.userInfo = res.userInfo
            that.globalData.iv = res.iv
            that.globalData.encryptedData = res.encryptedData
            typeof cb == "function" && cb(that.globalData.userInfo)
            that.req(
              'https://lifar网址.aspx?Action=ActionLogin',
              {
                encryptedData: that.globalData.encryptedData,
                iv: that.globalData.iv,
                code: that.globalData.loginCode
              },
              'GET',
              function (res) {
                console.log(res)
                if ( 


易优小程序(企业版)+灵活api+前后代码开源 码云仓库:starfork
本文地址:https://www.eyoucms.com/wxmini/doc/course/21937.html 复制链接 如需定制请联系易优客服咨询:800182392 点击咨询
QQ在线咨询