mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-22 03:32:47 +08:00
60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use EasyWeChat\Factory;
|
|
use Phalcon\Logger\Adapter\File as FileLogger;
|
|
|
|
class Wechat extends Service
|
|
{
|
|
|
|
/**
|
|
* @var FileLogger
|
|
*/
|
|
public $logger;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->logger = $this->getLogger('wechat');
|
|
}
|
|
|
|
public function getOfficialAccount()
|
|
{
|
|
$settings = $this->getSettings('wechat.oa');
|
|
|
|
$config = [
|
|
'app_id' => $settings['app_id'],
|
|
'secret' => $settings['app_secret'],
|
|
'token' => $settings['app_token'],
|
|
'aes_key' => $settings['aes_key'],
|
|
'log' => $this->getLogOptions(),
|
|
];
|
|
|
|
return Factory::officialAccount($config);
|
|
}
|
|
|
|
protected function getLogOptions()
|
|
{
|
|
$config = $this->getConfig();
|
|
|
|
$default = $config->get('env') == ENV_DEV ? 'dev' : 'prod';
|
|
|
|
return [
|
|
'default' => $default,
|
|
'channels' => [
|
|
'dev' => [
|
|
'driver' => 'daily',
|
|
'path' => log_path('wechat.log'),
|
|
'level' => 'debug',
|
|
],
|
|
'prod' => [
|
|
'driver' => 'daily',
|
|
'path' => log_path('wechat.log'),
|
|
'level' => 'info',
|
|
],
|
|
]
|
|
];
|
|
}
|
|
|
|
}
|