支付宝移动支付后,php后台无法获取到支付宝异步通知的数据,求大牛急救!!

lewin_he 2016-08-29 09:30:36
支付宝同步通知支付成功,但是异步通知无法接收到支付宝返回给PHP后台的数据,求大牛救急!!!
异步通知可以进入方法,但是接收不到数据
代码如下:
public function con()
{
$alipay_config = array(
//合作身份ID,签约账号,以2088开头由16位纯数字组成的字符串
'partner' => '2088221476947332',
//seller_id=partner收款支付宝账号,以2088开头由16位纯数字组成的字符串,一般情况下收款账号就是签约账号
'seller_id' => '',
//商户的私钥,此处填写原始私钥去头去尾
'private_key' => '',
//支付宝的公钥
'alipay_public_key' => '',

'service' => 'mobile.securitypay.pay',
//签名方式
'sign_type' => strtoupper('RSA'),
//字符编码格式 目前支持 gbk 或 utf-8
'input_charset' => strtolower('utf-8'),
//ca证书路径地址,用于curl中ssl校验,请保证cacert.pem文件在当前文件夹目录中
'cacert' => getcwd().'cacert.pem',
//访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http
'transport' => 'http',
//支付类型,无需修改
'payment_type' => '1',
//卖家支付宝账号
'seller_email' => "",
//卖家支付宝账号别名
'seller_account_name' => "",
//服务器异步通知页面路径 需完整路径
'notify_url' => 'http://**/*/api/public/index.php/index/Alipay/notify_url',
);
return $alipay_config;
}
/**
* 获取返回时的签名验证结果
* @param $para_temp 通知返回来的参数数组
* @param $sign 返回的签名结果
* @return 签名验证结果
*/
public function getSignVeryfy($para_temp, $sign) {
$alipay_config = $this->con();
//除去待签名参数数组中的空值和签名参数
$para_filter = paraFilter($para_temp);

//对待签名参数数组排序
$para_sort = argSort($para_filter);

//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr = createLinkstring($para_sort);

$isSgin = false;
switch (strtoupper(trim($alipay_config['sign_type']))) {
case "RSA" :
$isSgin = rsaVerify($prestr, trim($alipay_config['alipay_public_key']), $sign);
break;
default :
$isSgin = false;
}

return $isSgin;
}


/**
* 获取远程服务器ATN结果,验证返回URL
* @param $notify_id 通知校验ID
* @return 服务器ATN结果
* 验证结果集:
* invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
* true 返回正确信息
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
*/
public function getResponse($notify_id) {
$alipay_config = $this->con();
//HTTPS形式消息验证地址
$https_verify_url = 'https://mapi.alipay.com/gateway.do?service=notify_verify&';
//HTTP形式消息验证地址
$http_verify_url = 'http://notify.alipay.com/trade/notify_query.do?';
$transport = strtolower(trim($alipay_config['transport']));
$partner = trim($alipay_config['partner']);
$veryfy_url = '';
if($transport == 'https') {
$veryfy_url = $https_verify_url;
}
else {
$veryfy_url = $http_verify_url;
}
$veryfy_url = $veryfy_url."partner=" . $partner . "¬ify_id=" . $notify_id;
$responseTxt = getHttpResponseGET($veryfy_url, $alipay_config['cacert']);

return $responseTxt;
}


public function notify_url()
{
$notify = $_POST;
//$notify = $GLOBALS["HTTP_RAW_POST_DATA"];
//计算得出通知验证结果
$alipay_config = $this->con();
if($this->getResponse($notify['notify_id'])){
//判断成功之后使用getResponse方法判断是否是支付宝发来的异步通知
if($this->getSignVeryfy($notify, $notify['sign'])) {//使用支付宝公钥验签
//获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表
if($notify['trade_status'] == 'TRADE_FINISHED') {
//注意:
//退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
//请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
}
else if ($notify['trade_status'] == 'TRADE_SUCCESS') {
$order_sn = $notify['out_trade_no'];//商户订单号
$trade_no = $notify['trade_no'];//支付宝交易号
$trade_status = $notify['trade_status'];//交易状态
$total_fee = $notify['total_fee'];//交易金额
$notify_id = $notify['notify_id'];//通知校验ID
$notify_time = $notify['notify_time'];//通知的发送时间,格式为yyyy-MM-dd HH:mm:ss
$gmt_create = $notify['gmt_create'];//交易创建时间
$gmt_payment = $notify['gmt_payment'];//买家付款时间
$subject = $notify['subject'];//商品名称
$seller_id = $notify['seller_id'];//卖家支付宝账号,以2088开头的16位纯数字
$seller_email = $notify['seller_email'];//卖家支付宝账号
$buyer_email = $notify['buyer_email'];//买家支付宝账号,邮箱或手机号

//异步通知数组
$parameter = array(
"order_sn" => $order_sn,
"trade_no" => $trade_no,
"total_fee" => $total_fee,
"trade_status" => $trade_status,
"notify_id" => $notify_id,
"notify_time" => $notify_time,
"gmt_create" => $gmt_create,
"gmt_payment" => $gmt_payment,
"seller_email" => $seller_email,
"buyer_email" => $buyer_email,
);

//注意:
//付款完成后,支付宝系统发送该交易状态通知
//请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
$ord = new Model\Alipay();
$ordinfo = $ord->getinfo($order_sn);
if( $ordinfo['name'] == $subject && $ordinfo['total_fee'] == $total_fee && $alipay_config['seller_id'] == $selle r_id ){
$ord->orderhandle($parameter);
}else{
echo "订单异常,此交易失败!";
echo "fail";
exit;
}
}
echo "success"; //请不要修改或删除
}
else //验证签名失败
{
echo "sign fail";
}
}
else //验证是否来自支付宝的通知失败
{
echo "response fail";
}

}

...全文
3287 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
byd666 2017-05-13
  • 打赏
  • 举报
回复
请问楼主解决了吗
yizan7183 2016-10-31
  • 打赏
  • 举报
回复
'notify_url' => 'http://**/*/api/public/index.php/index/Alipay/notify_url', ); notify_url是什么?没有后缀? 必须是可访问文件,不能带参数

1,170

社区成员

发帖
与我相关
我的任务
社区描述
移动支付相关内容讨论专区
社区管理员
  • 移动支付
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧