api.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. $params = require __DIR__ . '/params.php';
  3. $rsparams['params'] = require_config('ueditor.php');
  4. $rsparams = array_merge_recursive(require_config('coin.php'), $rsparams);
  5. $rsparams = array_merge_recursive(require_config('commission.php'), $rsparams);
  6. $rsparams = array_merge_recursive(require_config('mailer.php'), $rsparams);
  7. $rsparams = array_merge_recursive(require_config('mapp.php'), $rsparams);
  8. $rsparams = array_merge_recursive(require_config('mp.php'), $rsparams);
  9. $rsparams = array_merge_recursive(require_config('openauth.php'), $rsparams);
  10. $rsparams = array_merge_recursive(require_config('openwx.php'), $rsparams);
  11. $rsparams = array_merge_recursive(require_config('oss.php'), $rsparams);
  12. $rsparams = array_merge_recursive(require_config('pay.php'), $rsparams);
  13. $rsparams = array_merge_recursive(require_config('point.php'), $rsparams);
  14. $params = array_merge($params,$rsparams['params']);
  15. $db = require __DIR__ . '/db.php';
  16. $modulesConfig = require __DIR__ . '/modules.php';
  17. $config = [
  18. 'id' => 'api',
  19. 'controllerNamespace' => 'api\controllers',
  20. 'language'=>$params['language'],
  21. 'bootstrap' => ['log'],
  22. //'defaultRoute'=>'user',//设置默认的控制器
  23. 'aliases' => [
  24. '@api' => '@app/api',
  25. ],
  26. 'components' => [
  27. 'request' => [
  28. // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
  29. 'cookieValidationKey' => $params['cookieValidationKey'],
  30. ],
  31. 'cache' => [
  32. 'class' => 'yii\caching\FileCache',
  33. ],
  34. 'user' => [
  35. 'identityClass' => 'app\modules\ucenter\models\User',
  36. 'enableAutoLogin' => true,
  37. 'enableSession'=>false,
  38. ],
  39. //定义错误处理
  40. 'errorHandler' => [
  41. 'errorAction' => 'alert/error',
  42. ],
  43. 'mailer' => [
  44. 'class' => 'yii\swiftmailer\Mailer',
  45. 'viewPath' => BASE_PATH.'mail',
  46. // send all mails to a file by default. You have to set
  47. // 'useFileTransport' to false and configure a transport
  48. // for the mailer to send real emails.
  49. 'useFileTransport' => false,
  50. 'transport' => [
  51. 'class' => 'Swift_SmtpTransport',
  52. 'host' => $params['mailer']['host'],
  53. 'username' => $params['mailer']['username'],
  54. 'password' => $params['mailer']['password'],
  55. 'port' => $params['mailer']['port'],
  56. 'encryption' => $params['mailer']['encryption'],
  57. ],
  58. 'messageConfig'=>[
  59. 'charset'=>'UTF-8',
  60. 'from'=>[$params['mailer']['fromname']=>$params['mailer']['fromtitle']]
  61. ],
  62. ],
  63. 'log' => [
  64. 'traceLevel' => YII_DEBUG ? 3 : 0,
  65. 'targets' => [
  66. [
  67. 'class' => 'yii\log\FileTarget',
  68. 'levels' => ['error', 'warning'],
  69. ],
  70. ],
  71. ],
  72. 'response' => [
  73. 'class' => 'yii\web\Response',
  74. 'on beforeSend' => function ($event) {
  75. $response = $event -> sender;
  76. $resdata = $response -> data;
  77. if ($response->data !== null && !isset($resdata['error'])) {
  78. $resdata['message'] = str_replace("Your request was made with invalid credentials.","接口凭证已失效,请刷新页面后重试",$resdata['message']);
  79. $response -> data = [
  80. 'error' => $resdata['status'],
  81. 'msg' => $resdata['message'],
  82. 'data' => [
  83. 'name' => $resdata['name'],
  84. 'code' => $resdata['code'],
  85. 'type' => $resdata['type'],
  86. ],
  87. ];
  88. $response -> statusCode = 200;
  89. }
  90. $response->format = yii\web\Response::FORMAT_JSON;
  91. },
  92. ],
  93. 'urlManager' => [
  94. 'enablePrettyUrl' => true,
  95. 'enableStrictParsing' => false,
  96. 'showScriptName' => false,
  97. 'rules' => [
  98. ['class' => 'yii\rest\UrlRule',
  99. 'controller' => 'alert',
  100. 'pluralize' => false,
  101. 'extraPatterns'=>[
  102. 'GET error'=>'error',
  103. ],
  104. ],
  105. ['class' => 'yii\rest\UrlRule',
  106. 'controller' => 'default',
  107. 'pluralize' => false,
  108. 'extraPatterns'=>[
  109. 'GET imgcode'=>'imgcode',
  110. 'POST setfield'=>'setfield',
  111. 'GET test'=>'test',
  112. ],
  113. ],
  114. ],
  115. ],
  116. //多语言设置
  117. 'i18n' => [
  118. 'translations' => [
  119. 'admin' => [
  120. 'class' => 'yii\i18n\PhpMessageSource',
  121. 'basePath' => '@app/messages',
  122. ],
  123. 'attr' => [
  124. 'class' => 'yii\i18n\PhpMessageSource',
  125. 'basePath' => '@app/messages',
  126. ],
  127. 'error' => [
  128. 'class' => 'yii\i18n\PhpMessageSource',
  129. 'basePath' => '@app/messages',
  130. ],
  131. ],
  132. ],
  133. ],
  134. 'params' => $params,
  135. 'modules' =>$modulesConfig,
  136. ];
  137. $config['components'] = array_merge($config['components'],$db);
  138. if (YII_ENV_DEV) {
  139. // configuration adjustments for 'dev' environment
  140. $config['bootstrap'][] = 'debug';
  141. $config['modules']['debug'] = [
  142. 'class' => 'yii\debug\Module',
  143. // uncomment the following to add your IP if you are not connecting from localhost.
  144. //'allowedIPs' => ['127.0.0.1', '::1'],
  145. ];
  146. $config['bootstrap'][] = 'gii';
  147. $config['modules']['gii'] = [
  148. 'class' => 'yii\gii\Module',
  149. // uncomment the following to add your IP if you are not connecting from localhost.
  150. //'allowedIPs' => ['127.0.0.1', '::1'],
  151. ];
  152. }
  153. return $config;