Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report