用户端敏感字段加密
This commit is contained in:
@@ -23,7 +23,6 @@ class JsonResponseFormatter extends \yii\web\JsonResponseFormatter
|
||||
|
||||
public static function formatData($data, $errno = 0, $msg = '')
|
||||
{
|
||||
// TODO 加密后续再完善
|
||||
if (empty($data)) {
|
||||
$data = [];
|
||||
} else {
|
||||
|
||||
@@ -151,7 +151,10 @@ JJvBfLfudYNUjUCyW3gAcOIJ
|
||||
'accept_tel',
|
||||
'patient',
|
||||
'accept_name',
|
||||
'patient_mobile'
|
||||
'patient_mobile',
|
||||
# 身份证
|
||||
'id_card',
|
||||
'idcard',
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user