Browse Source

feat():环境

geek 4 years ago
parent
commit
a08620ea9b
3 changed files with 10 additions and 3 deletions
  1. 1 1
      application/api/controller/Admin.php
  2. 7 1
      config/database.php
  3. 2 1
      public/index.php

+ 1 - 1
application/api/controller/Admin.php

@@ -178,7 +178,7 @@ class Admin extends BaseController {
             'uniqueKey|唯一码'    => 'require'
         ];
         Until::check($rule, $input);
-        if( strtolower($input['code']) != strtolower(Cache::get($input['uniqueKey']))) {
+        if( strtolower($input['code']) != strtolower((string)Cache::get($input['uniqueKey']))) {
 //             验证失败
             throw new ApiException('验证码错误');
         }

+ 7 - 1
config/database.php

@@ -9,7 +9,7 @@
 // | Author: liu21st <liu21st@gmail.com>
 // +----------------------------------------------------------------------
 
-return [
+$config = [
     // 数据库类型
     'type'            => 'mysql',
     // 服务器地址
@@ -61,3 +61,9 @@ return [
     // 断线标识字符串
     'break_match_str' => [],
 ];
+
+if (GENV === 'test') {
+    $config['hostname'] = '127.0.0.1';
+}
+
+return $config;

+ 2 - 1
public/index.php

@@ -16,6 +16,7 @@ namespace think;
 require __DIR__ . '/../thinkphp/base.php';
 
 // 支持事先使用静态方法设置Request对象和Config对象
-
+$env = getenv('GENV');
+empty($env) ? define('GENV', 'local') : define('GENV', $env);
 // 执行应用并响应:
 Container::get('app')->run()->send();