PHP code example of seffeng / laravel-wechat

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

    

seffeng / laravel-wechat example snippets


# 1、生成配置文件
$ php artisan vendor:publish --tag="wechat"

# 2、修改配置文件 /config/wechat.php,或 .env

# 1、复制扩展内配置文件 /config/wechat.php 到项目配置目录 /config

# 2、修改配置文件 /config/wechat.php,或 .env

# 3、将以下代码段添加到 /bootstrap/app.php 文件中的 Providers 部分
$app->register(Seffeng\LaravelWechat\WechatServiceProvider::class);

# 4、/bootstrap/app.php 添加配置加载代码
$app->configure('wechat');

# 客户端示例
use Seffeng\Wechat\Exceptions\WechatException;
use Seffeng\LaravelWechat\Facades\Wechat;

class SiteController extends Controller
{
    public function test()
    {
        try {
            var_dump(Wechat::getAccessToken());
            var_dump(Wechat::getJsapiTicket());
            print_r(Wechat::getSignPackage('https://url.cn'));
        } catch (WechatException $e) {
            var_dump($e->getMessage());
        } catch (\Exception $e) {
            var_dump($e->getMessage());
        }
    }
}