PHP code example of tsingsun / yii2-easy-wechat
1. Go to this page and download the library: Download tsingsun/yii2-easy-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/ */
tsingsun / yii2-easy-wechat example snippets
'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',
],
]
],
]
//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();