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 to get the group name ID through Mini Program

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

Share

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

This article is about how to get the group name ID through Mini Program. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Let's see how to display the group name in Mini Program.

Get group ID

The premise of displaying the group name is that the group ID of the group has been obtained. If you already know something about getting group ID, you can skip to the back.

We get the group ID of the corresponding group by forwarding Mini Program to the group.

First of all, you need to set the forwarding button that displays the current page, and return ShareTicket after forwarding. Only with this button can you get the group ID:

Wx.showShareMenu ({

WithShareTicket: true

})

Add the onShareAppMessage method to the code, which is used to control the forwarding function. After the forwarding is successful, get the ShareTicket, and then call wx.getShareInfo to obtain the information of the forwarding destination. The code is as follows:

OnShareAppMessage: function () {

Var that = this

Return {

Title: "forward title"

Path: 'page path'

Success (res) {

Wx.getShareInfo ({

ShareTicket: res.shareTickets [0]

Success (res) {

Console.log (res.encryptedData)

Console.log (res.iv)

/ / decrypt the backend to get the openGId

}

})

}

}

}

Like wx.getUserInfo, Wechat gives us a piece of encrypted data in the same way, and the background can decrypt it with the same code. The decrypted format is as follows:

{

"openGId": "xxxxxxxx"

"watermark": {

"appid": "xxxxxxxx"

"timestamp": 1499841984

}

}

OpenGId is the group ID we want. Save it.

Show group name

Next we come to the layout file.

Mini Program has just been updated with a new component open-data:

Easy to use, use the following code where you want to display the group name:

Pass in the openGId and the group name will be displayed. It's all right.

But this thing is only available in the base library 1.4.0, so it's best to use wx.getSystemInfo to get the basic library version of the current client and make the lower version compatible.

Thank you for reading! This is the end of the article on "how to get the group name ID through Mini Program". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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