PHP code example of wechate / appletlogin

1. Go to this page and download the library: Download wechate/appletlogin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wechate / appletlogin example snippets


composer 

'providers' => [
    //在你原来的服务列表中添加如下服务
    Wechat\Appletlogin\WeChatAppletLoginServiceProvider::class
],
'aliases' => [
    //在你原来的别名列表中添加WxLogin别名
     'WxLogin' => Wechat\Appletlogin\Facades\WxLogin::class
]


/**
 * Created by PhpStorm.
 * User: zzqzz
 * Date: 2018/12/18
 * Time: 9:52
 */

namespace App\Libs;

use WxLogin;
class WSign
{

    private $appid;
    private $appSecret;

    public function __construct($type = 1)
    {
        
        $this->appid = config('app.appId');//你自己的小程序的appId
        $this->appSecret = config('app.appSecret');//你自己的小程序的appSecret      
        
    }

    public function getUserInfo($data)
    {

        $data['appId']=$this->appid;
        $data['appSecret']=$this->appSecret;

        return  WxLogin::run($data);

    }

}


/**
 * Created by PhpStorm.
 * User: zzqzz
 * Date: 2018/12/16
 * Time: 21:06
 */

namespace App\Http\Controllers\Api;

use App\Libs\WSign;
use Illuminate\Http\Request;


class UserLoginController
{
    public function login(Request $request)
    {
        //微信小程序登录后返回的cood
        $s_code = $request->input('s_code', false);
        //微信小程序登录后返回的encryptedData
        $encryptedData = $request->input('encryptedData', false);
        //微信小程序登录后返回的iv
        $iv = $request->input('iv', false);        
        $data['code'] = $s_code;
        $data['encryptedData'] = $encryptedData;
        $data['iv'] = $iv;
        $ws = new WSign();
        $res = $ws->getUserInfo($data);
        return $res;
    }
}