Laravel WeChat Small program get user details and analysis of small program code extension with parameter

Source: Internet
Author: User
Tags openid
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


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

    • Get small Code with parameters (sample code)

      <?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$ Imgpath)             *            /Public Function Getimgcode ($scene, $pages)            {                $a = new Wxtool ();                $imgpath = $a->getqrcode ($scene, $pages);             }        }
    • Get User Details (sample code)

 <?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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.