test3.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. require('../vendor/autoload.php');
  3. // 设置接口路径
  4. $api_url = 'http://58.213.156.66/qjpt/f/interactive/dealRfidData';
  5. $data = [
  6. "data" => [
  7. [
  8. "rfid" => "000001004968",
  9. "location" => "01393A3173657005",
  10. "volt" => "0"
  11. ]
  12. ]
  13. ];
  14. //{"data":[{"rfid":"000001004968","location":"01393A3173657005","volt":"0"}]}
  15. // 1. 将数据转换为 JSON 格式并进行 Base64 编码
  16. $json_data = json_encode($data);
  17. var_dump($json_data);
  18. $base64_data = base64_encode($json_data);
  19. // 2. 设置 POST 请求数据
  20. $post_data = [
  21. 'data' => $base64_data
  22. ];
  23. $curl = curl_init();
  24. curl_setopt_array($curl, array(
  25. CURLOPT_URL => $api_url,
  26. CURLOPT_RETURNTRANSFER => true,
  27. CURLOPT_ENCODING => '',
  28. CURLOPT_MAXREDIRS => 10,
  29. CURLOPT_TIMEOUT => 0,
  30. CURLOPT_FOLLOWLOCATION => true,
  31. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  32. CURLOPT_CUSTOMREQUEST => 'POST',
  33. CURLOPT_POSTFIELDS =>$base64_data,
  34. CURLOPT_HTTPHEADER => array(
  35. 'Content-Type: text/plain'
  36. ),
  37. ));
  38. // 3. 接口返回的数据
  39. $response = curl_exec($curl);
  40. curl_close($curl);
  41. var_dump($response);
  42. // 4. AES 解密函数
  43. function aes_decrypt($data, $key) {
  44. $decrypted_data = openssl_decrypt(base64_decode($data), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  45. return $decrypted_data;
  46. }
  47. // 5. 返回数据处理 AES 解密
  48. // 解密密码
  49. $password = 'njmind.comnjsjly';
  50. $decrypted_response = aes_decrypt($response, $password);
  51. $base64_decrypted_data = base64_decode($decrypted_response);
  52. $final_response = json_decode($base64_decrypted_data, true);
  53. // 6. 输出解密后的结果
  54. var_dump($final_response);