Decrypt.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * This file is part of webman.
  4. *
  5. * Licensed under The MIT License
  6. * For full copyright and license information, please see the MIT-LICENSE.txt
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @author walkor<walkor@workerman.net>
  10. * @copyright walkor<walkor@workerman.net>
  11. * @link http://www.workerman.net/
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace app\middleware;
  15. use Illuminate\Support\Arr;
  16. use Webman\MiddlewareInterface;
  17. use Webman\Http\Response;
  18. use Webman\Http\Request;
  19. /**
  20. * Class StaticFile
  21. * @package app\middleware
  22. */
  23. class Decrypt implements MiddlewareInterface
  24. {
  25. public function process(Request $request, callable $handler): Response
  26. {
  27. $transfersecret=$request->header('transfersecret');
  28. if(empty($transfersecret)){
  29. return $this->transfer();
  30. }
  31. $string_data = openssl_decrypt(base64_decode($transfersecret),'AES-128-ECB',getenv ("JWT_AESKEY"),OPENSSL_RAW_DATA);
  32. if(!$string_data){
  33. return $this->transfer();
  34. }
  35. $param_data = json_decode($string_data,true);
  36. if(!$param_data){
  37. return $this->transfer();
  38. }
  39. $request->param_data=$param_data;
  40. /** @var Response $response */
  41. return $handler($request);
  42. }
  43. public function transfer()
  44. {
  45. $arr=[
  46. 0=>'https://www.baidu.com',
  47. 1=>'https://weibo.com',
  48. 2=>'https://www.douyin.com',
  49. 3=>'https://www.jd.com',
  50. 4=>'https://uland.taobao.com',
  51. 5=>'https://news.qq.com',
  52. 6=>'https://www.toutiao.com',
  53. 7=>'https://www.kuaishou.com',
  54. 8=>'https://www.sohu.com',
  55. ];
  56. return redirect($arr[mt_rand(0,8)]);
  57. }
  58. public function sign($array)
  59. {
  60. ksort($array); //ASCII码排序
  61. $md5str = "";
  62. foreach ($array as $key => $val) {
  63. $md5str = $md5str . $key . "=" . $val . "&";
  64. }
  65. return md5($md5str . "key=".getenv('JWT_PRIVATEKEY'));
  66. }
  67. }