In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What this article shares to you is about how WeChat Mini Programs got his mobile phone number after logging in with ThinkPHP5 authorization. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. After we authorize the login, we will get the user's sessionKey, which is an integral part of obtaining the mobile phone number.
Upper code
Wxml:
Get the cell phone number
Js: when we call this method, we can output it on the console. The two boxes under e are also an integral part of getting the mobile phone number.
GetPhoneNumber: function (e) {var that = this; console.log (e.detail.errMsg = = "getPhoneNumber:ok") If (e.detail.errMsg = = "getPhoneNumber:ok") {wx.request ({url: 'http://www.phone.com/test/Seek/getPhone', data: {encryptedData: e.detail.encryptedData, iv: e.detail.iv, sessionKey: that.data.session_key }, method: "post", success: function (res) {console.log (res) })}}
Then there is the background code of Think PHP 5. Before writing the code, you need to download an official folder.
URL: access to open data on server | Wechat open documents
After downloading, there are four languages. We just want PHP.
Put the PHP folder in your Think PHP 5 app directory and remember to change the folder name, like this
Next, add namespaces to WXBizDataCrypt.php and introduce ErrorCode.php files.
Next, introduce WXBizDataCrypt.php into your controller.
Use app\ libs\ WXBizDataCrypt
Then you can write PHP code.
Public function getPhone () {$encryptedData = input ('encryptedData'); $iv = input (' iv'); $sessionKey = input ('sessionKey'); $appID = config (' appID'); $data = null; $pc = new WXBizDataCrypt ($appID, $sessionKey); $errCode = $pc- > decryptData ($encryptedData, $iv, $data); $data = json_decode ($data,true); return json ($data);}
Finally, you can see it after going back to Mini Program and running it again.
Thank you for reading! This is the end of the article on "WeChat Mini Programs how to get his mobile phone number after logging in with ThinkPHP5 authorization". 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 out 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.