找了半天没找到对应的方法,后来自己捯饬出来了,记录一下
PHP实现代码
private function verifySign($data)
{
//字典序排列 $data 为百度回调参数
$signature = $data['signature'];
unset($data['signature']);
ksort($data);
$str = base64_encode(utf8_encode(json_encode($data)));
$dataLength = strlen($str);
if ($dataLength % 16 != 0) {
$dataLength = $dataLength + (16 - ceil($dataLength % 16));
}
$source = str_pad($str, $dataLength, "\0");
$encrypted = openssl_encrypt($source, "AES-128-CBC", substr($this->secretKey, 0 ,16), OPENSSL_RAW_DATA);
$newSignature = strtoupper(bin2hex(substr($encrypted,0,strlen($source))));
if ($signature != $newSignature) {
error('sign error', -1);
}
}