Explorar o código

工程师确认上门流程修改

fang hai 1 ano
pai
achega
0d328b37db
Modificáronse 1 ficheiros con 5 adicións e 4 borrados
  1. 5 4
      app/common.php

+ 5 - 4
app/common.php

@@ -573,14 +573,15 @@ function encrypt($data, $key) {
     // 使用AES-256-CBC加密模式进行加密
     $encrypted = openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv);
     // 返回加密后的数据与IV的组合,方便解密时使用
-    return base64_encode($encrypted . '::' . $iv);
+    return rtrim(strtr(base64_encode($encrypted . '::' . $iv), '+/', '-_'), '=');
 }
 
 //解密函数
 function decrypt($data, $key) {
     try {
-        // 将 base64 编码的数据解码
-        list($encrypted_data, $iv) = explode('::', base64_decode($data), 2);
+        // 将 URL 安全的 Base64 编码的数据解码
+        $decoded = base64_decode(strtr($data, '-_', '+/'));
+        list($encrypted_data, $iv) = explode('::', $decoded, 2);
 
         // 检查 IV 长度是否正确
         $expectedIvLength = openssl_cipher_iv_length('aes-256-cbc');
@@ -596,6 +597,6 @@ function decrypt($data, $key) {
         return $decrypted;
     } catch (Exception $e) {
         // 捕获并处理异常
-        throw new Exception('参数不合规');
+        throw new Exception('参数不合规: ' . $e->getMessage());
     }
 }