注意事项:
- 联调时,推送数据的方式是post方式,数据是gbk编码的,并使用urlencode进行了加密处理。
- PHP在接收数据时应使用file_get_contents(“php://input”),如果使用$_POST来接收,会因为编码问题导致验签失败
- 正确显示接收的数据,应使用
$content = file_get_contents("php://input");
$content = urldecode($content);
$content = mb_convert_encoding($content, 'utf-8', 'GBK');
- php验签的代码,此处是官方的代码示例,个人可根据实际业务需要封装 【注: 因为数据本身是gbk编码了, 所以下面代码中$aop->postCharset="UTF-8"可以不要】
$aop = new AopClient ();
$aop->postCharset="UTF-8";
$aop->alipayrsaPublicKey="";
$_POST="buyer_id=20880****42&total_amount=0.01&body=煜雨电脑网站测试&trade_no=2019032922001481941025940236¬ify_time=2019-03-29 19:42:04&subject=煜雨测试电脑网站支付&sign_type=RSA2&charset=UTF-8&auth_app_id=201****22¬ify_type=trade_status_sync&invoice_amount=0.01&out_trade_no=20190329ygyg45484544100003&trade_status=TRADE_SUCCESS&gmt_payment=2019-03-29 19:42:03&version=1.0&point_amount=0.00&sign=LDDUIGQmc+1qNtk3oyoAKVeMUKTngdX3ZjVeZOK0EjiPDJ/+Nk+0WSqcE6J7/5xb96Z/vP0yY3pVhZUiFVJ1G45/ys/HAleHh+EERZ1lkCkule1sSyaGFTKQGKx4uHpTyqIgRB1bouf19RPbSx1EkA0VkCarSy9G/OEG5Qmg8UdL2dRulMhlbOHS7tdMJJycDA8vOspOUMeQmk/H6IK9R2Kou5hN2T3KR1GWLYFK+z1jeZhQB3q52lZynO0OFjSzU4aQUBMW5QskQppBYd/ghtY/2YP+2H6YVGNgVmaheZMQ3PVTBALEV+8rZa91salH9DkKN2UCYGvNSNDT1VGCTQ==&gmt_create=2019-03-29 19:42:00&buyer_pay_amount=0.01&receipt_amount=0.01&fund_bill_list=[{\"amount\":\"0.01\",\"fundChannel\":\"PCREDIT\"}]&seller_id=208850*0**&app_id=20141****2¬ify_id=2019032900222194204081941005192208";
$sign_type="RSA2";
$data = explode('&', $_POST);
$params = array();
foreach ($data as $param) {
$item = explode('=', $param,"2");
$params[$item[0]] = $item[1];
}
$flag = $aop->rsaCheckV1($params, null, $sign_type);
if ($flag)
{
echo "success";
}
else
{
echo "fail";
}