How to get the WeChat applet OpenGID and name details

Background: Since the company may need to use card card in WeChat group, there is a technical research.

Solution: After updating the shared interface, the original one directly in OnShareAppMessage is directly SHARETICKET without existence. According to the latest documentation, you need to get app.onlaunch () to get in app.onshow ().


Page ({/ ** * page initial data * / data: {OpenGID: ”}, / ** * Lifecycle Function – Listening Page Load * / 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 })}}}}}}}}}}: 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 the load group name    { {OpenGID? OpenGID: 'No'}}     App.js      // app.jsapp ({globaldata: {shareticket: '', OpenGID: ''}, ONLAUNCH: Function (options) {}}}}}}}} {let this = this impions& Options.scene == 1044) {That.globalData.Shareticket = Options.Shareticket} console.log ('Onshow --- Options = --->' + JSON.STRINGYFY (OPTIONS)})} {let this = this // Display local storage capability IF (That.globalData.Shareticket) {wx.getshareInfo ({Shareticket:That.globalData.Shareticket, Success: Function (RES) {Console.log ('getShareTiket --- Shareticket ->' + JSON.STRINGIFY (RES)) Let JS_ENCRYPTEDDATA = Res.EncryptedData Let JS_IV = Res.iv wx.login ({Success: Function (RES) {let js_code = res.code console.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 = console.log ( 'getShareTiket --- openGid' + that.globalData . gaNGID) TYPEOF CB == "Function" && Cb (That.globalData)}, fail: function (err) {consolE.log ('getShareTiket --- Err' + JSON.STRINGYFY (ERR))}}}}}})}}}})}}}})}}}}}}) 

1: This interface WX.Showsharemenu ({withshareticket: true}), Otherwise, when app.onlaunch (), you can’t get Shareticket.
  2: WeChat developer tool can simulate 1044 scene, but will not display the group name because You are not in the group. So when testing, pull a WeChat group yourself, then share the test group, you can get the group name.  
The above is all the content of this article, I hope to help everyone, I hope everyone will support Tumi Cloud.
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment