E企盈营销工具技术服务商 热线:4006-838-530

微信小程序获取群Gopenid,及用户进入群后,用户在此群的Gopenid

E企盈直播平台营销卖货系统

最近在开发微信小程序,遇到的坑非常多。上面标题上的问题,在网上搜索,找不到直接的答案。下面我就直接进入主题。定义一个button<button open-type=’share’ type=’primary’>获取群id</button>在对应的js文件里面定义onShareAppMessage监听。onShareAppMessage: function () {    wx.showShareMenu({      withShareTicket: true    })    return{      title:”test”,      path:”/pages/index/index”,      success:function(res){        var shareTickets=res.shareTickets;        if(shareTickets.length==0){          return false;        }        wx.getShareInfo({          shareTicket: shareTickets[0],          success:function(res){            var encryptedData=res.encryptedData;            var iv =res.iv;                        wx.login({              success: function (res) {                var code = res.code;                console.log(code)                wx.request({                  url: ‘xx’,//写上你后台服务器路径(用途:解析出Gopenid)                  //解析出Gopenid需要session_key,encryptedData,iv。具体后台怎么写,                  //可以参照https://www.jianshu.com/p/856fe2195ffe                  data: { ‘code’: code, ‘encryptedData’: encryptedData,”iv”:iv},                  header: {                    ‘content-type’: ‘application/json’ // 默认值                  },                  success: function (res) {                    wx.showModal({                      title: ‘GopenId’,                      content: res.data.openGId                    })                  }                })              }            })            console.log(encryptedData)          }        })      },      fail:function(){      }    }  }这样就能得到Gopenid了。第二个问题,用户点击群里面,分享了的小程序后,怎么获取这个群的Gopenid呢?在App.js的onLaunch里面定义如下代码就可以了 //1044代码是从群进入的代码    if (ops.scene == 1044) {      wx.showModal({        title: ‘test’,        content: ops.shareTicket+””      })      wx.getShareInfo({        shareTicket:ops.shareTicket,        success:function(res){          var encryptedData = res.encryptedData;          var iv = res.iv;                    wx.login({            success: function (res) {              var code = res.code;              console.log(code)              wx.request({                url: ‘xxx’,//跟前面一样,是服务器地址                data: { ‘code’: code, ‘encryptedData’: encryptedData, “iv”: iv },                header: {                  ‘content-type’: ‘application/json’ // 默认值                },                success: function (res) {                  wx.showModal({                    title: ‘GopenId’,                    content: res.data.openGId                  })                }              })            }          })        }      })    }

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 微信小程序获取群Gopenid,及用户进入群后,用户在此群的Gopenid
分享到: 更多 (0)
E企盈小程序直播营销卖货系统
E企盈直播平台营销卖货系统

评论 抢沙发

E企盈小程序开发

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏