话不多说,直接上代码
需要注意的是:验签前要将数组内元素处理成GBK,验签时也需要指定字符集为GBK
public function getRiskNotice()
{
foreach ($_POST as $k => &$v) {
$v = iconv('gbk', 'utf-8', $v);
}
$checkRes = $this->checkSign($arr);
if ($checkRes) {
// 验签成功
} else {
// 验签失败'
}
return 'success';
}
public function checkSign($param = [])
{
$app = new \AopClient();
$app->postCharset = 'GBK';
$app->alipayrsaPublicKey = '公钥';
$res = $app->rsaCheckV1($param, '私钥', 'RSA2');
return $res;
}