tsingsun / yii2-easy-wechat
为yii2 PHP框架提供Easywechat SDK
0.1
2017-07-11 01:21 UTC
Requires
- overtrue/wechat: ~3.1
- yiisoft/yii2: ~2.0.10
Requires (Dev)
- phpunit/phpunit: 4.8.*
This package is not auto-updated.
Last update: 2024-09-29 02:58:49 UTC
README
为Yii2提供的微信扩展。这是基于 EasyWechat 开发的
安装
composer require --prefer-dist tsingsun/yii2-easy-wechat
配置
'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', ], ] ], ]
注意
有一些修改以更好地匹配yii
- 使用Yii Logger组件代替EasyWechat默认的logger;
- 使用Yii Cache组件代替基于 \Doctrine\Common\Cache\Cache 的EasyWechat默认缓存;
如何使用
//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();
如何测试
在单元测试过程中,还发现了微信开发调试的痛点,因为也梳理了更好的测试实践。测试主要集中在测试目录。请访问目录 测试说明