* @copyright walkor * @link http://www.workerman.net/ * @license http://www.opensource.org/licenses/mit-license.php MIT License */ namespace app\middleware; use Illuminate\Support\Arr; use Webman\MiddlewareInterface; use Webman\Http\Response; use Webman\Http\Request; /** * Class StaticFile * @package app\middleware */ class Decrypt implements MiddlewareInterface { public function process(Request $request, callable $handler): Response { $transfersecret=$request->header('transfersecret'); if(empty($transfersecret)){ return $this->transfer(); } $string_data = openssl_decrypt(base64_decode($transfersecret),'AES-128-ECB',getenv ("JWT_AESKEY"),OPENSSL_RAW_DATA); if(!$string_data){ return $this->transfer(); } $param_data = json_decode($string_data,true); if(!$param_data){ return $this->transfer(); } $request->param_data=$param_data; /** @var Response $response */ return $handler($request); } public function transfer() { $arr=[ 0=>'https://www.baidu.com', 1=>'https://weibo.com', 2=>'https://www.douyin.com', 3=>'https://www.jd.com', 4=>'https://uland.taobao.com', 5=>'https://news.qq.com', 6=>'https://www.toutiao.com', 7=>'https://www.kuaishou.com', 8=>'https://www.sohu.com', ]; return redirect($arr[mt_rand(0,8)]); } public function sign($array) { ksort($array); //ASCII码排序 $md5str = ""; foreach ($array as $key => $val) { $md5str = $md5str . $key . "=" . $val . "&"; } return md5($md5str . "key=".getenv('JWT_PRIVATEKEY')); } }