tsingsun 2017-08-15 17:33:55 3211次浏览 1条评论 5 1 0

分享之前写的扩展:

Github: https://github.com/tsingsun/yii2-easy-wechat

Yii2 EasyWechat

  1. Installation
  2. Configuration

wechat extension for Yii2. this is base on EasyWechat

Installation

    composer require --prefer-dist tsingsun/yii2-easy-wechat

Configuration

'components' => [       
        'cache' => [
            'class'=>'yii\caching\FileCache',
            'keyPrefix' => 'yak',
        ],
        'wechat'=>[
            'class'=>'yii\easyWechat\Wechat',
            //the config is all most match the easyWechat office's config,
            //the diffenrece please see Notice
            'config'=>[                
                'debug'  => true,                
                'app_id'=>'',
                'secret'=>'',
                'token'=>'',
                'aes_key'=>'',
                'payment'=>[                   
                    'merchant_id'=>'',
                    'key'=>'',                    
                    'cert_path'=>'',
                    'key_path'=>'',                    
                    'notify_url'=>''

                ],               
                'oauth' => [
                    'scopes'   => ['snsapi_userinfo'],
                    'callback' => '/examples/oauth_callback.php',
                ],
                'guzzle' => [
                    'timeout' => 3.0, //
                    //'verify' => false, // close SSL verify(not suggust!!!)
                ],                
                /**
                 * Cache,if not set ,use Yii default config cache
                 */
                'cache'=>[

                ],
            ],
        ],
        'log'=>[
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'maxFileSize'=> 200,
                    'levels' => [],
                    'logVars' => [],
                    'logFile' => '@runtime/logs/'.date('ymd').'.log',
                ],
            ]
        ],
    ]
Notice

There are some change to better match for yii

  • use Yii Logger component instead of EasyWechat default logger;
  • use Yii Cache component instead of EasyWechat default Cache that based on \Doctrine\Common\Cache\Cache.
how to use
    //after configure,use it as bellow
    /**
    * @var Wechat $wechat use @var doc attribute to code lint
    **/
    $wechat = Yii::$app->get('wechat');
    //$wechat->app is Easywechat's Application instance
    $wechat->app->server->setMessageHandler(function ($message) {
                return "hello world!welcome!";
            });
    $wechat->app->server()->send();
how to Test

In the unit test process, also discovered the WeChat development debugging egg pain, because also combed the test better practice The tests are centered in the test directory. Go to the directory 测试说明

觉得很赞
  • 评论于 2018-03-19 22:32 举报

    注释是英文啊~ 对于我这个英文不好的人来说 只能靠翻译了

您需要登录后才可以评论。登录 | 立即注册