From 9a4db24d41c054f91a67e22ce09bde8beaef20c6 Mon Sep 17 00:00:00 2001 From: lin fan Date: Tue, 22 Oct 2024 16:09:32 +0800 Subject: [PATCH] 1 --- home/controllers/Welcome.php | 41 +++++++++++++++++++ .../controllers/h5/market/sytopic/Welcome.php | 4 ++ 2 files changed, 45 insertions(+) diff --git a/home/controllers/Welcome.php b/home/controllers/Welcome.php index 8464456a..f1374d63 100644 --- a/home/controllers/Welcome.php +++ b/home/controllers/Welcome.php @@ -127,6 +127,47 @@ class Welcome extends CI_Controller { var_dump($response); } } + + + public static function encrypt($data, $key) { + $key = base64_decode($key); + if (strlen($key) < 16) { + $key = str_pad($key, 16, "\0"); + } elseif (strlen($key) > 16) { + $key = substr($key, 0, 16); + } + $iv = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; // ECB模式不需要IV,但PHP的openssl_encrypt函数需要 + return openssl_encrypt($data, 'AES-128-ECB', $key, OPENSSL_RAW_DATA, $iv); + } + + /** + * 将加密后的二进制数据转换成十六进制字符串 + * @param string $binaryData 加密后的二进制数据 + * @return string 十六进制字符串 + */ + public static function parseBinary2HexStr($binaryData) { + return bin2hex($binaryData); + } + + /** + * 加密数据并返回十六进制字符串 + * @param mixed $obj 待加密的数据 + * @param string $key 密钥 + * @return string 加密后的十六进制字符串 + */ + public static function encryptData($obj, $key) { + $content = is_string($obj) ? $obj : serialize($obj); + $encrypted = self::encrypt($content, $key); + return self::parseBinary2HexStr($encrypted); + } + + public function tt() + { + $key = "B066+uPhhihfn0CLrU5Cpw=="; + $data = "0534_1716970275384"; + $encryptedData = $this->encryptData($data, $key); + echo "加密内容:" . $encryptedData . "\n"; + } } diff --git a/home/controllers/h5/market/sytopic/Welcome.php b/home/controllers/h5/market/sytopic/Welcome.php index 9e930a02..c73df97d 100644 --- a/home/controllers/h5/market/sytopic/Welcome.php +++ b/home/controllers/h5/market/sytopic/Welcome.php @@ -23,6 +23,10 @@ class Welcome extends Wx throw new Hd_exception("参数错误", 400); } $this->data['skey'] = $this->skey; + + if($this->skey == 'dG9waWNfaWQ9Ng'){ + debug_log("params:". json_encode($this->input->get()), 'auto.txt'); + } } public function index()