加密
<h2>实际测试值</h2>
<p>app_key: EHHuRFRdj7xyTjRRlRYLlA93IJHedHen
域名: <a href="http://kingdom.nuws.cn">http://kingdom.nuws.cn</a></p>
<h2>接口文档示例值</h2>
<p>app_key: qthuv4ohMRxV68UEPlFqHrD6okX0vACn</p>
<p>timestamp: 1713890387</p>
<p>notstr: kutciyozow64</p>
<h3>Body参数加密流程</h3>
<ol>
<li>
<p>将需要的签名的字段(body), 进行按照 ASCII 码值进行排序, 请求参数内说明. </p>
</li>
<li>
<p>按照 键=值&键=值 形式进行拼接, 示例值: notstr=kutciyozow64&timestamp=1713890387</p>
</li>
<li>
<p>签名字符串后需要加上app_key, 示例值: notstr=kutciyozow64&timestamp=1713890387qthuv4ohMRxV68UEPlFqHrD6okX0vACn</p>
</li>
<li>将字符串进行md5加密, 示例值: 496337b3b139d7a8a2ec129e65156a9d</li>
</ol>
<h3>敏感字段加密(password)</h3>
<pre><code class="language-php">
&lt;?php
// AES加密函数
function aesEncrypt($data, $key) {
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
$encrypted = openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv);
return base64_encode($encrypted . '::' . $iv);
}
// AES解密函数
function aesDecrypt($data, $key) {
list($encryptedData, $iv) = explode('::', base64_decode($data), 2);
return openssl_decrypt($encryptedData, 'aes-256-cbc', $key, 0, $iv);
}
// 测试
$appKey = 'qthuv4ohMRxV68UEPlFqHrD6okX0vACn';
$password = 'myPassword123';
$encryptedPassword = aesEncrypt($password, $appKey);
echo &quot;加密后的密码: &quot; . $encryptedPassword . &quot;\n&quot;;
$decryptedPassword = aesDecrypt($encryptedPassword, $appKey);
echo &quot;解密后的密码: &quot; . $decryptedPassword . &quot;\n&quot;;
?&gt;
</code></pre>