123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace app\common\controller;
- use app\common\library\Gm;
- use app\zskk\model\Mapping;
- use think\facade\Cache;
- use think\facade\Config;
- use Throwable;
- use think\exception\HttpResponseException;
- class ZskkApi extends Api
- {
- /**
- * 控制器中间件
- * @var array
- */
- protected array $middleware = [
- // 前置中间件先配置先执行
- // 解密中间件 执行顺序 before-1
- \app\common\middleware\Decrypt::class,
- // 解码中间件 执行顺序 before-2
- \app\common\middleware\Decode::class,
- // 后置中间件先配置后执行
- // 加密中间件 执行顺序 after-3
- \app\common\middleware\Encrypt::class,
- // 编码中间件 执行顺序 after-2
- \app\common\middleware\Encode::class,
- // 模糊中间件 执行顺序 after-1
- \app\common\middleware\Blur::class,
- ];
- /**
- * 无需解密的方法
- * 访问本控制器的此方法,无需解密
- * @var array
- */
- protected array $noNeedDecrypt = [];
- /**
- * 无需解码的方法
- * 访问本控制器的此方法,无需解码
- * @var array
- */
- protected array $noNeedDecode = [];
-
- /**
- * 无需模糊的方法
- * @var array
- */
- protected array $noNeedBlur = [];
- /**
- * 无需编码的方法
- * @var array
- */
- protected array $noNeedEncode = [];
- /**
- * 无需加密的方法
- * @var array
- */
- protected array $noNeedEncrypt = [];
- /**
- * 初始化
- * @throws Throwable
- * @throws HttpResponseException
- */
- public function initialize(): void
- {
- parent::initialize();
-
- // 接口调用初始化完成标签位
- // Event::trigger('zskkApiInit');
- $this->_initNeeds();
- }
- private function _initNeeds(): void
- {
- $noNeedDecrypt = action_in_arr($this->noNeedDecrypt);
- $noNeedDecode = action_in_arr($this->noNeedDecode);
- $noNeedEncode = action_in_arr($this->noNeedEncode);
- $noNeedEncrypt = action_in_arr($this->noNeedEncrypt);
- $noNeedBlur = action_in_arr($this->noNeedBlur);
- $this->request->noNeedDecrypt = $noNeedDecrypt;
- $this->request->noNeedDecode = $noNeedDecode;
- $this->request->noNeedEncode = $noNeedEncode;
- $this->request->noNeedEncrypt = $noNeedEncrypt;
- $this->request->noNeedBlur = $noNeedBlur;
- }
- /**
- * $params $data
- */
- public function makeModelData($data,$mapping): array
- {
- $info = [];
- foreach ($data as $k=>$v)
- {
- if($info[$mapping[$k]] ?? '')
- {
- continue;
- }
- $info[$mapping[$k]] = $v;
- }
- return $info;
- }
- public function getDecryptData($data): array
- {
- $key = 'zLxapoeqWYpoeqWY';
- $info = Gm::decrypt($key,$data);
- return json_decode(base64_decode($info),true);
- }
- public function makeEncryptData($data)
- {
- $key = Config::get('gm.key');
- $info = Gm::encrypt($key,(base64_encode(json_encode($data))));
- return $info;
- }
- public function getTokenData($token)
- {
- $data = Cache::get($token);
- return $data;
- }
- }
|