This article mainly introduces the Laravel small program to obtain user details and the analysis with the parameter code extension, has a certain reference value, now share to everyone, the need for friends can refer to
function Introduction
This Extension pack contains user details for decryption, with the parameter applet generated and saved in the local directory feature.
User Details decryption is also available in multiple language versions of the SDK (C + +, PHP, Node, Python) and is only encapsulated in this expansion pack.
With the parameter small code generation, the official give three kinds of interfaces, in this expansion package uses
interface B (for the need of a large number of business scenarios, through the interface generated by the small code, permanent effective, unlimited number of temporary).
Project Address
Https://github.com/icharle/Wxtool
How to use
Run the following command to get the latest version:
Composer Require Icharle/wxtool 1.0
Add the service provider to the array in the configuration file providers
config/app.php
, as follows:
' Providers ' = [ ... Icharle\wxtool\wxtoolserviceprovider::class,]
Publish a configuration file
PHP Artisan vendor:publish--tag=wxtool
There is a file at this time config/wxtool.php
.
Configuring AppID and Appsecret
Add the following code to the root directory .env
file
Wx_appid = Your applet applet Idwx_secret = Your applet key
Open storage Access file (optional)
You must execute the following command to use the generate features with the parameter applet code . The generated applet is saved in the folder by default storage/app/public/qrcode
PHP Artisan Storage:link
Quick Start
<?php namespace App\http\controllers; Use Icharle\wxtool\wxtool; Use Illuminate\http\request; Class TestController extends Controller { /** * Gets the parameter applet * @param $scene scene values (maximum 32 visible characters, numbers only, Uppercase and lowercase English and some special characters) * @param $pages page (must be a page with a published applet (otherwise error) * @return $imgpath applet path (direct access to http://xxx.com/$ Imgpath) * /Public Function Getimgcode ($scene, $pages) { $a = new Wxtool (); $imgpath = $a->getqrcode ($scene, $pages); } }
<?php namespace App\http\controllers; Use Icharle\wxtool\wxtool; Use Illuminate\http\request; Class TestController extends Controller {/** * get user Details * @param Re Quest $request */Public Function GetInfo (Request $request) {$a = new Wx Tool (); $code = $request->code; Wx.login Get $encryptedData = $request->encrypteddata; Wx.getuserinfo Get $iv = $request->iv; Wx.getuserinfo Get $res = $a->getsessionkey ($code); Get user OpenID and Session_key $userinfo = $a->getuserinfo ($encryptedData, $IV); Get user details DD ($userinfo); } }
Decrypt return results
{ "OpenID": "OpenID", "nickname": "nickname", "gender": Gender, "city": "City", "province": " Province ", " country ":" Country ", " Avatarurl ":" Avatarurl ", " Unionid ":" Unionid ", " watermark ": { "AppID": "AppID", "timestamp": Timestamp } }
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!