Example of a Applet -- Obtain the unique openid and openid of the Applet
1. Effect display
2. Key code
1) WXML File
Obtain the unique openid of a user.Openid: {openid} session_key: {session_key }}
2) JS files
Const APP_ID = ''; // enter the applet appidconst APP_SECRET = ''; // input the applet app_secretvar OPEN_ID = ''// The storage gets openidvar SESSION_KEY ='' // The storage gets session_keyPage ({getOpenIdTap: function () {var that = this; wx. login ({success: function (res) {wx. request ({// obtain openid interface url: 'https: // api.weixin.qq.com/sns/jscode2session', data: {appid: APP_ID, secret: APP_SECRET, js_code: res. code, grant_type: 'authorization _ Code'}, method: 'get', success: function (res) {console. log (res. data) OPEN_ID = res. data. openid; // The obtained openid SESSION_KEY = res. data. session_key; // obtain session_key console. log (OPEN_ID.length) console. log (SESSION_KEY.length) that. setData ({openid: res. data. openid. substr (0, 10) + '********' + res. data. openid. substr (res. data. openid. length-8, res. data. openid. length), session_key: res. data. session_key.substr (0, 8) + '*********' + res. data. session_key.substr (res. data. session_key.length-6, res. data. session_key.length )})}})}})}})
3) WXSS File
button{ margin: 10px; color: white; background: green;}view{ margin: 10px;}
3. Source Code Acquisition Method
Baidu cloud link: http://pan.baidu.com/s/1miqPiBY
4. If you encounter any problems or do not understand the process of obtaining the unique openid, you can add me for consultation. Thank you for your support! No.: FutureJet
5. If you think it is good, please be rewarded. Your satisfaction is the unlimited motivation of the author.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.