diff --git a/admin/foundation/JsonResponseFormatter.php b/admin/foundation/JsonResponseFormatter.php index 55a5ccd..ef3fe7a 100644 --- a/admin/foundation/JsonResponseFormatter.php +++ b/admin/foundation/JsonResponseFormatter.php @@ -23,7 +23,6 @@ class JsonResponseFormatter extends \yii\web\JsonResponseFormatter public static function formatData($data, $errno = 0, $msg = '') { - // TODO 加密后续再完善 if (empty($data)) { $data = []; } else { diff --git a/common/config/params-local.php b/common/config/params-local.php index bed87c5..0d7aef0 100644 --- a/common/config/params-local.php +++ b/common/config/params-local.php @@ -151,7 +151,10 @@ JJvBfLfudYNUjUCyW3gAcOIJ 'accept_tel', 'patient', 'accept_name', - 'patient_mobile' + 'patient_mobile', + # 身份证 + 'id_card', + 'idcard', ] ]; diff --git a/common/foundation/Cors.php b/common/foundation/Cors.php index ef62ef8..3cc9df7 100644 --- a/common/foundation/Cors.php +++ b/common/foundation/Cors.php @@ -93,12 +93,34 @@ class Cors extends ActionFilter 'Access-Control-Expose-Headers' => [], ]; + /** + * @var mixed + */ + private static $param; /** * {@inheritdoc} */ public function beforeAction($action) { + + $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->request = $this->request ?: Yii::$app->getRequest(); $this->response = $this->response ?: Yii::$app->getResponse(); @@ -276,4 +298,21 @@ 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, \Yii::$app->params['aseList'])) { + $value = ase_decode($value); // 加密指定键值 + } + } + } + } + return $data; + } } diff --git a/common/foundation/JsonResponseFormatter.php b/common/foundation/JsonResponseFormatter.php index f45e701..e97145f 100644 --- a/common/foundation/JsonResponseFormatter.php +++ b/common/foundation/JsonResponseFormatter.php @@ -14,7 +14,16 @@ class JsonResponseFormatter extends \yii\web\JsonResponseFormatter private $defaultErrorCode = -1; public static function formatData($data,$errno=0,$msg=''){ // if(empty($data)) $data = new \stdClass(); - if(empty($data)) $data = []; + + if (empty($data)) { + $data = []; + } else { +// if (array_key_exists('list', $data)) { +// $data['list'] = self::aseEncode($data['list']); +// } else { +// $data = self::aseEncode($data); +// } + } return ['data'=>$data,'errcode'=>$errno,'msg'=>$msg]; } @@ -75,6 +84,7 @@ class JsonResponseFormatter extends \yii\web\JsonResponseFormatter } } + /** * Formats response data in JSONP format. * @param \yii\web\Response $response @@ -112,4 +122,24 @@ class JsonResponseFormatter extends \yii\web\JsonResponseFormatter Yii::warning("The 'jsonp' response requires that the data be an array consisting of both 'data' and 'callback' elements.", __METHOD__); } } + + + 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, \Yii::$app->params['aseList'])) { + if (is_string($key)) { + $value = ase_encode($value); // 加密指定键值 + } + } + } + } + } + return $data; + } } \ No newline at end of file