https://github.com/tsingsun/yii2-easy-wechat
use Easywechat in yii2
https://github.com/tsingsun/yii2-easy-wechat
easywechat wechat yii2
Last synced: 3 months ago
JSON representation
use Easywechat in yii2
- Host: GitHub
- URL: https://github.com/tsingsun/yii2-easy-wechat
- Owner: tsingsun
- Created: 2017-07-10T07:29:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-11T02:03:20.000Z (almost 8 years ago)
- Last Synced: 2025-02-28T18:34:20.928Z (3 months ago)
- Topics: easywechat, wechat, yii2
- Language: PHP
- Size: 15.6 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Yii2 EasyWechat
===============wechat extension for Yii2. this is base on [EasyWechat](https://easywechat.org)
[](https://packagist.org/packages/tsingsun/yii2-easy-wechat)
[](https://travis-ci.org/tsingsun/yii2-easy-wechat)
[](https://packagist.org/packages/tsingsun/yii2-easy-wechat)Installation
----
```
composer require --prefer-dist tsingsun/yii2-easy-wechat
```Configuration
----```php
'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
```php
//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 [测试说明](./tests/README.md)