diff --git a/admin/foundation/Cors.php b/admin/foundation/Cors.php index 88b7e17..9fcf18c 100644 --- a/admin/foundation/Cors.php +++ b/admin/foundation/Cors.php @@ -70,6 +70,10 @@ use yii\web\Response; */ class Cors extends ActionFilter { + /** + * @var mixed + */ + private static $param; /** * @var Request the current request. If not set, the `request` application component will be used. */ @@ -94,7 +98,25 @@ class Cors extends ActionFilter 'Access-Control-Expose-Headers' => [], ]; - + private static $arr = [ + 'name', + 'contact', + 'mobile', + 'express_address', + 'clinical_diagnose', + 'drug_name', + 'drug_alias', + 'function', + 'usage', + 'express_mobile', + 'express_name', + 'express_region', + 'doctor', + 'accept_tel', + 'patient', + 'accept_name', + 'patient_mobile' + ]; /** * {@inheritdoc} */ @@ -102,6 +124,23 @@ class Cors extends ActionFilter { $this->request = $this->request ?: Yii::$app->getRequest(); + + // 解密传参 + $method = Yii::$app->request->getMethod(); + self::$param = $method === 'GET' ? Yii::$app->request->get() : Yii::$app->request->post(); + + if (empty(self::$param)) { + self::$param = []; + } else { + self::$param = self::aseDecode(self::$param); + } + + if ($method === 'GET') { + Yii::$app->request->setQueryParams(self::$param); + } else { + Yii::$app->request->setBodyParams(self::$param); + } + $this->response = $this->response ?: Yii::$app->getResponse(); $this->overrideDefaultSettings($action); $requestCorsHeaders = $this->extractHeaders(); @@ -276,4 +315,20 @@ class Cors extends ActionFilter { return 'HTTP_' . strtoupper(str_replace([' ', '-'], ['_', '_'], $string)); } + private static function aseDecode($data) + { +// return $data; + if (is_array($data)) { + foreach ($data as $key => &$value) { + if (is_array($value)) { + $value = self::aseDecode($value); // 递归处理子数组 + } else { + if (in_array($key, self::$arr)) { + $value = ase_decode($value); // 加密指定键值 + } + } + } + } + return $data; + } } diff --git a/admin/foundation/JsonResponseFormatter.php b/admin/foundation/JsonResponseFormatter.php index 432454c..6a3cb00 100644 --- a/admin/foundation/JsonResponseFormatter.php +++ b/admin/foundation/JsonResponseFormatter.php @@ -30,6 +30,7 @@ class JsonResponseFormatter extends \yii\web\JsonResponseFormatter 'doctor', 'accept_tel', 'patient', + 'accept_name', 'patient_mobile' ]; private static $param = [ @@ -41,16 +42,14 @@ class JsonResponseFormatter extends \yii\web\JsonResponseFormatter public static function formatData($data, $errno = 0, $msg = '') { - - // if(empty($data)) $data = new \stdClass(); // TODO 加密后续再完善 - // if (empty($data)) { - // $data = []; - // } else { - // if (array_key_exists('list', $data)) { - // $data['list'] = self::aseEncode($data['list']); - // } - // } + if (empty($data)) { + $data = []; + } else { + if (array_key_exists('list', $data)) { + $data['list'] = self::aseEncode($data['list']); + } + } $result['data'] = $data; $result['msg'] = $msg; $result['errcode'] = $errno; @@ -59,19 +58,19 @@ class JsonResponseFormatter extends \yii\web\JsonResponseFormatter private static function aseEncode($data) { - return $data; -// if (is_array($data)) { -// foreach ($data as $key => &$value) { -// if (is_array($value)) { -// $value = self::aseEncode($value); // 递归处理子数组 -// } else { -// if (in_array($key, self::$arr)) { -// $value = ase_encode($value); // 加密指定键值 -// } -// } -// } -// } // return $data; + if (is_array($data)) { + foreach ($data as $key => &$value) { + if (is_array($value)) { + $value = self::aseEncode($value); // 递归处理子数组 + } else { + if (in_array($key, self::$arr)) { + $value = ase_encode($value); // 加密指定键值 + } + } + } + } + return $data; } public $encrypt = true; //是不加密 diff --git a/helpers/helpers.php b/helpers/helpers.php index d325e3b..692de16 100644 --- a/helpers/helpers.php +++ b/helpers/helpers.php @@ -42,8 +42,6 @@ if (!function_exists('get_device_type')) { 'isMobile' => false, 'isTablet' => false, 'deviceType' => 'Desktop', - 'browser' => '', - 'platform' => '' ]; // 检查是否为移动设备