PHP code example of seffeng / wechat

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


/**
 * SiteController
 */
use Seffeng\Wechat\Wechat;
use Seffeng\Wechat\Exceptions\WechatException;

class SiteController extends Controller
{
    public function index()
    {
        try {
            $appid = '';
            $secret = '';
            
            /**
             * 缓存处理类,提供 get($key) 和 set($key, $value, $ttl) 方法
             *
             * 可实现接口 Seffeng\Wechat\Contracts\Cache
             */
            $cacheClass = null;
            $wechat = new Wechat($appid, $secret, null, $cacheClass);
            var_dump($wechat->getAccessToken());
            var_dump($wechat->getJsapiTicket());
            print_r($wechat->getSignPackage('https://url.cn'));
        } catch (WechatException $e) {
            echo $e->getMessage();
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
    }
}

├─src
│  │  Wechat.php
│  ├─Errors
│  │      Error.php
│  ├─Exceptions
│  │      WechatException.php
│  └─Helpers
│         ArrayHelper.php
└─tests
    WechatTest.php