AlipayNotify::verifyNotify PHP Method

verifyNotify() public method

针对notify_url验证消息是否是支付宝发出的合法消息
public verifyNotify ( ) : 验证结果
return 验证结果
    public function verifyNotify()
    {
        if (empty($_POST)) {
            //判断POST来的数组是否为空
            return false;
        } else {
            //生成签名结果
            $isSign = $this->getSignVeryfy($_POST, $_POST['sign']);
            //获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
            $responseTxt = 'true';
            if (!empty($_POST['notify_id'])) {
                $responseTxt = $this->getResponse($_POST['notify_id']);
            }
            // //写日志记录
            // if ($isSign) {
            // 	$isSignStr = 'true';
            // }
            // else {
            // 	$isSignStr = 'false';
            // }
            // $log_text = "responseTxt=".$responseTxt."\n notify_url_log:isSign=".$isSignStr.",";
            // $log_text = $log_text.createLinkString($_POST);
            // logResult($log_text);
            //验证
            //$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
            //isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
            if (preg_match('/true$/i', $responseTxt) && $isSign) {
                return true;
            } else {
                return false;
            }
        }
    }

Usage Example

Example #1
0
 public function actionNotifyUrl()
 {
     //计算得出通知验证结果
     $alipayNotify = new \AlipayNotify($this->alipayConfig());
     $verify_result = $alipayNotify->verifyNotify();
     if ($verify_result) {
         //验证成功
         if ($_REQUEST['trade_status'] == 'TRADE_FINISHED') {
             //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
             echo '退款';
         } else {
             if ($_REQUEST['trade_status'] == 'TRADE_SUCCESS') {
                 //付款完成后,支付宝系统发送该交易状态通知
                 if (ChargeOrder::getInstance()->setOrderStatus($_REQUEST['out_trade_no'])) {
                     // 设置订单状态
                     return $this->redirect('http://wechat.baihey.com/wap/site/main#/charge_order?orderId=' . $_REQUEST['out_trade_no'] . '&payType=4');
                 } else {
                     // 设置订单状态失败
                     return $this->redirect('http://wechat.baihey.com/wap/site/main#/charge_order?orderId=' . $_REQUEST['out_trade_no'] . '&payType=4');
                 }
             } else {
                 // 未付款
                 return $this->redirect('http://wechat.baihey.com/wap/site/main#/charge_order?orderId=' . $_REQUEST['out_trade_no'] . '&payType=4');
             }
         }
         echo "success";
         //请不要修改或删除
     } else {
         //验证失败
         echo "fail";
         return $this->redirect('http://wechat.baihey.com/wap/site/main#/charge_order?orderId=' . $_REQUEST['out_trade_no'] . '&payType=4');
     }
 }
All Usage Examples Of AlipayNotify::verifyNotify