PHP code example of vicleos / wxxcx

1. Go to this page and download the library: Download vicleos/wxxcx 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/ */

    

vicleos / wxxcx example snippets


Vicleos\Wxxcx\WxxcxServiceProvider::class,

...
use Vicleos\Wxxcx\Wxxcx;
...
class YourController extends Controller
{
    ...

    private function getWxxcx()
    {
        return new Wxxcx(config('wxxcx'));
    }
    
    /* 根据 code , encryptedData , iv 获取用户解密后的信息 */
    public function getWxUserInfo(Request $rq)
    {
        //使用 ajax 请求将获取的加密数据和参数发送到这里

        //code 在小程序端使用 wx.login 获取
        $code = $rq->input('code');
        //encryptedData 和 iv 在小程序端使用 wx.getUserInfo 获取
        $encryptedData = $rq->input('encryptedData');
        $iv = $rq->input('iv');
        
        //小程序类实例化
        $wxxcx = $this->getWxxcx();
        //根据 code 获取用户 session_key 等信息
        $wxxcx->getLoginInfo($code);
        //获取解密后的用户信息
        return $wxxcx->getUserInfo($encryptedData, $iv);
    }

    ...
}
bash
php artisan vendor:publish --provider="Vicleos\Wxxcx\WxxcxServiceProvider"