PHP code example of doyzheng / weixin

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

    

doyzheng / weixin example snippets

`
    $config = [
       'appid'  => 'wxf854059ff2a1243b',
       'secret' => '11351fedf52a81095a5c780e3bb4a7e8',
    ];
    
    $wx = new \doyzheng\weixin\Weixin($config);
`
    $config = [
       'appid'  => 'wxf854059ff2a1243b',
       'secret' => '11351fedf52a81095a5c780e3bb4a7e8',
    ];
    
    $wx = new \doyzheng\weixin\Weixin($config);
    $access_token = $wx->accessToken->getToken();
    echo $access_token;
    // 或 accessToken对象当做字符串处理时会默认返回token字符串
    $access_token = $wx->accessToken . '';
    $access_token = (string)$wx->accessToken . '';
    echo $access_token;
`
    $wx->accessToken->setToken($token);
`
    $wx->runtimePath = '/runtime/'  // 设置项目允许目录(缓存文件,日志文件等储存目录)
    $wx->appDebug = true;           // 开启调试模式,默认不开启(调试模式下会抛出错误异常)
    $wx->log->disable = false;      // 禁止记录日志(请求日志,错误日志,接口回调日志等)    

    $wx->errorHandler = function($exception){
        .... 
        return true;// 如果有返回, 就不会执行系统默认异常处理程序了
    }