Get the App
SLTechnology News&Howtos  ›  Development  › 

How does Mini Program get the openGid and name of the group chat?

Shulou Source: shulou.com Published: 2022-06-01 06:03:29 09月27日 Update

This article mainly explains "how Mini Program gets the openGid and name of group chat". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how Mini Program gets the openGid and name of group chat".

Solution: after Wechat updates the sharing interface, the original shareTicket directly in onShareAppMessage no longer exists. According to the latest documentation, it needs to be obtained in App.onLaunch () and App.onShow ().

Demo core code:

Index.js

Page ({

/ * *

* initial data of the page

, /

Data: {

OpenGid:''

}

/ * *

* Lifecycle function-- listen for page loading

, /

OnLoad: function (options) {

Let that = this

Wx.showShareMenu ({

WithShareTicket: true

})

App.getShareTiket (function (globalData) {

Console.log ('clickReload---globalData-- >' + JSON.stringify (globalData))

That.setData ({

OpenGid: globalData.openGid

})

})

}

ClickReload: function () {

Let that = this

App.getShareTiket (function (globalData) {

Console.log ('clickReload---globalData-- >' + JSON.stringify (globalData))

That.setData ({

OpenGid: globalData.openGid

})

})

}

})

Index.wxml

Group name: click to load the group name {{openGid? OpenGid: 'none'}} app.js

/ app.jsApp ({globalData: {shareTicket:', openGid:'}, onLaunch: function (options) {}, onShow: function (options) {let that = thisif (options & & options.scene = = 1044) {that.globalData.shareTicket = options.shareTicket} console.log ('onShow---options=--- >' + JSON.stringify (options))} GetShareTiket: function (cb) {let that = this// shows local storage capacity if (that.globalData.shareTicket) {wx.getShareInfo ({shareTicket: that.globalData.shareTicket) Success: function (res) {console.log ('getShareTiket---shareTicket-- >' + JSON.stringify (res)) let js_encryptedData = res.encryptedDatalet js_iv = res.ivwx.login ({success: function (res) {let js_code = res.codeconsole.log ('code-- >' + js_code) wx.request ({url: 'xxxxxxxx',method:' POST',data: {code: js_code,appId: 'xxxxx',encryptedData: js_encryptedData,iv: js_iv}) Success: function (res) {that.globalData.openGid = res.data.openGIdconsole.log ('getShareTiket---openGid' + that.globalData.openGid) typeof cb = = "function" & & cb (that.globalData)}, fail: function (err) {console.log (' getShareTiket---err' + JSON.stringify (err)}})} else {console.log ('shareTicket' does not exist)}}) Note

1: you must call this interface wx.showShareMenu ({withShareTicket: true}), otherwise you won't get shareTicket when App.onLaunch () and App.onShow ().

2: the Wechat developer tool can simulate 1044 of the scenarios, but the group name will not be displayed because you are not in the group. So when testing, pull a WeChat group, and then share to the test group, you can get the group name.

Thank you for your reading, the above is the content of "how Mini Program gets the openGid and name of group chat". After the study of this article, I believe you have a deeper understanding of how Mini Program gets the openGid and name of group chat, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Name program learning content interface page test no longer exists item code function cycle periodic function scenario that is tools developers ideas situations data Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Docker vpn Shulou Technology Shulou Information