赞
踩
支付宝签名验证官方sdk下载(此签名验证方法在支付成功异步通知,芝麻信用异步通知等等场景都是通用的)
sdk下载地址:https://docs.open.alipay.com/291/106074
/*根据demo,封装 *验证异步通知签名 * $params 初始化需要的参数,比如appid,开发者私钥,支付宝公钥等等 * $sign 支付宝异步通知返回的全部参数 * return true/false */ function checkSign($params,$sign){ require_once '../extend/zhifu/AopClient.php';//这个对象在封装的sdk中找到它,并引用之 $aop = new AopClient (); $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';//初始化参数 $aop->appId = $params['appid'];//初始化参数 $aop->rsaPrivateKey = $params['private_key'];//初始化参数 $aop->alipayrsaPublicKey=$params['public_key'];//初始化参数 $aop->apiVersion = '1.0';//初始化参数 $aop->signType = 'RSA2';//初始化参数 $aop->postCharset='utf-8';//初始化参数 $aop->format='json';//初始化参数 //注意:$signType='RSA2',支付宝新建应用只支持 RSA2 签名,但是在这个官方demo中$signType='RSA',注意要修改成RSA2 $check_sign=$aop->rsaCheckV1($sign, $rsaPublicKeyFilePath='',$signType='RSA2'); if($check_sign) return true; return false; }
测试:
$params=array('appid)=>'123456****343543','private_key'=>'wuieiorjwerjweiorjdfs.....');//实际参数根据自己的修改
$sign='https://www.merchant.com/receive_notify.htm?notify_type=trade_status_sync¬ify_id=91722adff935e8cfa58b3aabf4dead6ibe¬ify_time=2017-02-16 21:46:15&sign_type=RSA2&sign=WcO+t3D8Kg71dTlKwN7r9PzUOXeaBJwp8/FOuSxcuSkXsoVYxBpsAidprySCjHCjmaglNcjoKJQLJ28/Asl93joTW39FX6i07lXhnbPknezAlwmvPdnQuI01HZsZF9V1i6ggZjBiAd5lG8bZtTxZOJ87ub2i9GuJ3Nr/NUc9VeY=&auth_no=2014070800002001550000014417&out_order_no=4977164666634053&operation_id=2014070800032850551&out_request_no=2014070700166653&operation_type=FREEZE&amount=100.00&status=SUCCESS&gmt_create=2014-09-15 11:23:03&gmt_trans=2014-09-15 11:23:04&payer_logon_id=test***@alitest.com&payer_user_id=2088102000275885&payee_logon_id=tstw***@alitest.com&payee_user_id=2088102138117431&total_freeze_amount=100.00&total_unfreeze_amount=20.00&total_pay_amount=10.00&rest_amount=70.00&credit_amount=0.01&fund_amount=0.01&total_freeze_credit_amount=0.01&total_freeze_fund_amount=0.01&total_unfreeze_credit_amount=0.01&total_unfreeze_fund_amount=0.01&total_pay_credit_amount=0.01&total_pay_fund_amount=0.01&rest_credit_amount=0.01&rest_fund_amount=0.01&pre_auth_type=CREDIT_AUTH&trans_currency=USD';//实际通知根据自己的修改
echo checkSign($params,$sign);
结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。