123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- $params = require __DIR__ . '/params.php';
- $rsparams['params'] = require_config('ueditor.php');
- $rsparams = array_merge_recursive(require_config('coin.php'), $rsparams);
- $rsparams = array_merge_recursive(require_config('commission.php'), $rsparams);
- $rsparams = array_merge_recursive(require_config('mailer.php'), $rsparams);
- $rsparams = array_merge_recursive(require_config('mapp.php'), $rsparams);
- $rsparams = array_merge_recursive(require_config('mp.php'), $rsparams);
- $rsparams = array_merge_recursive(require_config('openauth.php'), $rsparams);
- $rsparams = array_merge_recursive(require_config('openwx.php'), $rsparams);
- $rsparams = array_merge_recursive(require_config('oss.php'), $rsparams);
- $rsparams = array_merge_recursive(require_config('pay.php'), $rsparams);
- $rsparams = array_merge_recursive(require_config('point.php'), $rsparams);
- $params = array_merge($params,$rsparams['params']);
- $db = require __DIR__ . '/db.php';
- $modulesConfig = require __DIR__ . '/modules.php';
- $config = [
- 'id' => 'api',
- 'controllerNamespace' => 'api\controllers',
- 'language'=>$params['language'],
- 'bootstrap' => ['log'],
- //'defaultRoute'=>'user',//设置默认的控制器
- 'aliases' => [
- '@api' => '@app/api',
- ],
- 'components' => [
- 'request' => [
- // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
- 'cookieValidationKey' => $params['cookieValidationKey'],
- ],
- 'cache' => [
- 'class' => 'yii\caching\FileCache',
- ],
- 'user' => [
- 'identityClass' => 'app\modules\ucenter\models\User',
- 'enableAutoLogin' => true,
- 'enableSession'=>false,
- ],
- //定义错误处理
- 'errorHandler' => [
- 'errorAction' => 'alert/error',
- ],
- 'mailer' => [
- 'class' => 'yii\swiftmailer\Mailer',
- 'viewPath' => BASE_PATH.'mail',
- // send all mails to a file by default. You have to set
- // 'useFileTransport' to false and configure a transport
- // for the mailer to send real emails.
- 'useFileTransport' => false,
- 'transport' => [
- 'class' => 'Swift_SmtpTransport',
- 'host' => $params['mailer']['host'],
- 'username' => $params['mailer']['username'],
- 'password' => $params['mailer']['password'],
- 'port' => $params['mailer']['port'],
- 'encryption' => $params['mailer']['encryption'],
- ],
- 'messageConfig'=>[
- 'charset'=>'UTF-8',
- 'from'=>[$params['mailer']['fromname']=>$params['mailer']['fromtitle']]
- ],
- ],
- 'log' => [
- 'traceLevel' => YII_DEBUG ? 3 : 0,
- 'targets' => [
- [
- 'class' => 'yii\log\FileTarget',
- 'levels' => ['error', 'warning'],
- ],
- ],
- ],
- 'response' => [
- 'class' => 'yii\web\Response',
- 'on beforeSend' => function ($event) {
- $response = $event -> sender;
- $resdata = $response -> data;
- if ($response->data !== null && !isset($resdata['error'])) {
- $resdata['message'] = str_replace("Your request was made with invalid credentials.","接口凭证已失效,请刷新页面后重试",$resdata['message']);
- $response -> data = [
- 'error' => $resdata['status'],
- 'msg' => $resdata['message'],
- 'data' => [
- 'name' => $resdata['name'],
- 'code' => $resdata['code'],
- 'type' => $resdata['type'],
- ],
- ];
- $response -> statusCode = 200;
- }
- $response->format = yii\web\Response::FORMAT_JSON;
- },
- ],
-
- 'urlManager' => [
- 'enablePrettyUrl' => true,
- 'enableStrictParsing' => false,
- 'showScriptName' => false,
- 'rules' => [
- ['class' => 'yii\rest\UrlRule',
- 'controller' => 'alert',
- 'pluralize' => false,
- 'extraPatterns'=>[
- 'GET error'=>'error',
- ],
- ],
- ['class' => 'yii\rest\UrlRule',
- 'controller' => 'default',
- 'pluralize' => false,
- 'extraPatterns'=>[
- 'GET imgcode'=>'imgcode',
- 'POST setfield'=>'setfield',
- 'GET test'=>'test',
- ],
- ],
- ],
- ],
- //多语言设置
- 'i18n' => [
- 'translations' => [
- 'admin' => [
- 'class' => 'yii\i18n\PhpMessageSource',
- 'basePath' => '@app/messages',
- ],
- 'attr' => [
- 'class' => 'yii\i18n\PhpMessageSource',
- 'basePath' => '@app/messages',
- ],
- 'error' => [
- 'class' => 'yii\i18n\PhpMessageSource',
- 'basePath' => '@app/messages',
- ],
- ],
- ],
- ],
- 'params' => $params,
- 'modules' =>$modulesConfig,
- ];
- $config['components'] = array_merge($config['components'],$db);
- if (YII_ENV_DEV) {
- // configuration adjustments for 'dev' environment
- $config['bootstrap'][] = 'debug';
- $config['modules']['debug'] = [
- 'class' => 'yii\debug\Module',
- // uncomment the following to add your IP if you are not connecting from localhost.
- //'allowedIPs' => ['127.0.0.1', '::1'],
- ];
- $config['bootstrap'][] = 'gii';
- $config['modules']['gii'] = [
- 'class' => 'yii\gii\Module',
- // uncomment the following to add your IP if you are not connecting from localhost.
- //'allowedIPs' => ['127.0.0.1', '::1'],
- ];
- }
- return $config;
|