Example #1
0
 public function doNotifyUrl($f3)
 {
     // 记录所有的参数,方便调试查找
     printLog('Tenpay Notify Paramters : ' . print_r($_REQUEST, true), 'PAYMENT', Base::INFO);
     /* 创建支付应答对象 */
     $resHandler = new ResponseHandler();
     $resHandler->setKey($this->partnerKey);
     //判断签名
     if (!$resHandler->isTenpaySign()) {
         //签名错误
         printLog('Tenpay Notify sign error:' . $resHandler->getDebugInfo(), 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //通知id
     $notify_id = $resHandler->getParameter("notify_id");
     //通过通知ID查询,确保通知来至财付通
     //创建查询请求
     $queryReq = new RequestHandler();
     $queryReq->init();
     $queryReq->setKey($this->partnerKey);
     $queryReq->setGateUrl("https://gw.tenpay.com/gateway/simpleverifynotifyid.xml");
     $queryReq->setParameter("partner", $this->partnerId);
     $queryReq->setParameter("notify_id", $notify_id);
     //通信对象
     $httpClient = new TenpayHttpClient();
     $httpClient->setTimeOut(10);
     //设置请求内容
     $httpClient->setReqContent($queryReq->getRequestURL());
     //后台调用
     if (!$httpClient->call()) {
         //通信失败 后台调用通信失败,写日志,方便定位问题
         printLog('Tenpay verify notify_id connect error :responseCode[' . $httpClient->getResponseCode() . ']' . $httpClient->getErrInfo(), 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //设置结果参数
     $queryRes = new ClientResponseHandler();
     $queryRes->setContent($httpClient->getResContent());
     $queryRes->setKey($this->partnerKey);
     if ($resHandler->getParameter("trade_mode") == "1") {
         //判断签名及结果(即时到帐)
         //只有签名正确,retcode为0,trade_state为0才是支付成功
         if (!($queryRes->isTenpaySign() && $queryRes->getParameter("retcode") == "0" && $resHandler->getParameter("trade_state") == "0")) {
             $logMsg = "Tenpay sign error or trade_state error : trade_state=" . $resHandler->getParameter("trade_state") . ",retcode=" . $queryRes->getParameter("retcode") . ",retmsg=" . $queryRes->getParameter("retmsg");
             printLog($logMsg, 'PAYMENT', Base::ERROR);
             //更多的错误信息方便调试
             printLog('Tenpay QueryRequestUrl:' . $queryReq->getRequestURL(), 'PAYMENT', Base::ERROR);
             printLog('Tenpay QueryRequestDebugInfo:' . $queryReq->getDebugInfo(), 'PAYMENT', Base::ERROR);
             printLog('Tenpay QueryResponseContent:' . $queryRes->getContent(), 'PAYMENT', Base::ERROR);
             printLog('Tenpay QueryResponseDebugInfo:' . $queryRes->getDebugInfo(), 'PAYMENT', Base::ERROR);
             goto out_fail;
         }
         //取结果参数做业务处理
         $out_trade_no = $resHandler->getParameter("out_trade_no");
         //财付通订单号
         $transaction_id = $resHandler->getParameter("transaction_id");
         //金额,以分为单位
         $total_fee = $resHandler->getParameter("total_fee");
         //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
         $discount = $resHandler->getParameter("discount");
         //------------------------------
         //处理业务开始
         //------------------------------
         if (empty($out_trade_no)) {
             printLog('Tenpay bad out_trade_no', 'PAYMENT', Base::ERROR);
             goto out_fail;
         }
         $paramArray = explode('_', $out_trade_no);
         if (empty($paramArray) || count($paramArray) < 2 || !ctype_digit($paramArray[count($paramArray) - 1])) {
             printLog('Tenpay bad out_trade_no', 'PAYMENT', Base::ERROR);
             goto out_fail;
         }
         // 最后一个应该是订单 ID 号
         $orderId = intval($paramArray[count($paramArray) - 1]);
         if (empty($orderId)) {
             printLog('Tenpay bad out_trade_no', 'PAYMENT', Base::ERROR);
             goto out_fail;
         }
         // 设置订单 ID
         $this->orderId = $orderId;
         $orderBasicService = new OrderBasicService();
         $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
         // 判断金额是否一致,使用 分 做单位来比较
         if ($orderInfo->isEmpty() || Money::storageToCent($orderInfo['order_amount']) != intval($total_fee)) {
             printLog('Tenpay total_fee error, order_amount :{' . Money::storageToCent($orderInfo['order_amount']) . '} total_fee :{' . $total_fee . '}', 'PAYMENT', Base::ERROR);
             goto out_fail;
         }
         //检查订单状态
         if (OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
             printLog('Tenpay order_status is not OS_UNCONFIRMED, order_status[' . $orderInfo['order_status'] . '] orderId[' . $orderId . ']', 'PAYMENT', Base::WARN);
             goto out_succ;
         }
         // 把订单设置为已付款状态
         $orderPaymentService = new OrderPaymentService();
         $orderPaymentService->markOrderInfoPay($orderId, $this->payId, $this->getGatewayType(), $transaction_id);
         printLog('Tenpay orderId[' . $orderId . '] notify success', 'PAYMENT', Base::INFO);
         //------------------------------
         //处理业务完毕
         //------------------------------
     } else {
         printLog('Tenpay trade_mode is not 1', 'PAYMENT', Base::ERROR);
     }
     out_succ:
     // 成功从这里返回
     echo "success";
     return true;
     out_fail:
     // 错误从这里返回
     echo "fail";
     return false;
 }
Example #2
0
 public function doNotifyUrl($f3)
 {
     if (empty($this->orderId)) {
         throw new \InvalidArgumentException('orderId invalid');
     }
     // 记录所有的参数,方便调试查找
     printLog('CreditPay Notify orderId [' . $this->orderId . ']', 'PAYMENT', Base::INFO);
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($this->orderId);
     //判断金额是否一致
     if ($orderInfo->isEmpty() || 0 != $orderInfo['order_amount']) {
         printLog('CreditPay total_fee error, order_amount :' . Money::storageToCent($orderInfo['order_amount']) . ' total_fee : 0 ', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //检查订单状态
     if (OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
         printLog('CreditPay order_status is not OS_UNCONFIRMED, order_status[' . $orderInfo['order_status'] . '] orderId[' . $this->orderId . ']', 'PAYMENT', Base::WARN);
         goto out_succ;
     }
     // 把订单设置为已付款状态
     $orderPaymentService = new OrderPaymentService();
     $orderPaymentService->markOrderInfoPay($this->orderId, $this->payId, $this->getGatewayType(), '0');
     printLog('CreditPay orderId[' . $this->orderId . '] notifyUrl success', 'PAYMENT', Base::INFO);
     //------------------------------
     //处理业务完毕
     //------------------------------
     out_succ:
     return true;
     out_fail:
     // 失败从这里返回
     return false;
 }
Example #3
0
 public function doNotifyUrl($f3)
 {
     // 记录所有的参数,方便调试查找
     printLog($this->getGatewayType() . ' Notify Paramters : ' . print_r($_REQUEST, true), 'PAYMENT', Base::INFO);
     //计算得出通知验证结果
     $notifyArray = array("service" => $_POST['service'], "v" => $_POST['v'], "sec_id" => $_POST['sec_id'], "notify_data" => $_POST['notify_data']);
     $calcSign = build_mysign($notifyArray, $this->partnerKey, $this->configSecId);
     // 如果签名验证失败则直接退出
     if ($calcSign != $_POST["sign"]) {
         printLog($this->getGatewayType() . ' sign error calcSign[' . $calcSign . '] sign[' . $_POST["sign"] . ']', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //交易状态
     $trade_status = getDataForXML($_POST['notify_data'], '/notify/trade_status');
     if ($trade_status != 'TRADE_FINISHED' && $trade_status != 'TRADE_SUCCESS') {
         printLog($this->getGatewayType() . ' trade_status Error [' . $trade_status . ']', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //商户订单号
     $out_trade_no = getDataForXML($_POST['notify_data'], '/notify/out_trade_no');
     //支付宝交易号
     $trade_no = getDataForXML($_POST['notify_data'], '/notify/trade_no');
     //总金额
     $total_fee = getDataForXML($_POST['notify_data'], '/notify/total_fee');
     //$_POST['trade_status'] == 'TRADE_FINISHED'
     //判断该笔订单是否在商户网站中已经做过处理
     //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
     //如果有做过处理,不执行商户的业务程序
     //注意:
     //该种交易状态只在两种情况下出现
     //1、开通了普通即时到账,买家付款成功后。
     //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。
     //$_POST['trade_status'] == 'TRADE_SUCCESS'
     //判断该笔订单是否在商户网站中已经做过处理
     //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
     //如果有做过处理,不执行商户的业务程序
     //注意:
     //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。
     //------------------------------
     //处理业务开始
     //------------------------------
     if (empty($out_trade_no)) {
         goto out_bad_trade_no;
     }
     $paramArray = explode('_', $out_trade_no);
     if (empty($paramArray) || count($paramArray) < 2 || !ctype_digit($paramArray[count($paramArray) - 1])) {
         goto out_bad_trade_no;
     }
     // 最后一个应该是订单 ID 号
     $orderId = intval($paramArray[count($paramArray) - 1]);
     if (empty($orderId)) {
         goto out_bad_trade_no;
     }
     // 设置订单 ID
     $this->orderId = $orderId;
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
     //判断金额是否一致,我们用 分 做单位比较
     if ($orderInfo->isEmpty() || Money::storageToCent($orderInfo['order_amount']) != Money::displayToCent($total_fee)) {
         printLog('Alipay total_fee error, order_amount :{' . Money::storageToCent($orderInfo['order_amount']) . '} total_fee : {' . Money::displayToCent($total_fee) . '}', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //检查订单状态
     if (OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
         printLog($this->getGatewayType() . ' order_status is not OS_UNCONFIRMED, order_status[' . $orderInfo['order_status'] . '] orderId[' . $orderId . ']', 'PAYMENT', Base::WARN);
         goto out_succ;
     }
     // 把订单设置为已付款状态
     $orderPaymentService = new OrderPaymentService();
     $orderPaymentService->markOrderInfoPay($orderId, $this->payId, $this->getGatewayType(), $trade_no);
     printLog($this->getGatewayType() . ' orderId[' . $orderId . '] notifyUrl success', 'PAYMENT', Base::INFO);
     //------------------------------
     //处理业务完毕
     //------------------------------
     out_succ:
     echo "success";
     //成功返回
     return true;
     out_bad_trade_no:
     printLog($this->getGatewayType() . ' bad out_trade_no', 'PAYMENT', Base::ERROR);
     out_fail:
     // 失败从这里返回
     echo "fail";
     return false;
 }
Example #4
0
 /**
  * 把订单手动设置成已经付款
  *
  * @param $f3
  */
 public function MarkPay($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_order_order_markpay');
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1)->validate('order_id');
     if (!$this->validate($validator)) {
         goto out;
     }
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id);
     if ($orderInfo->isEmpty()) {
         $this->addFlashMessage('订单不存在');
         goto out;
     }
     if ($orderBasicService::PS_PAYED == $orderInfo['pay_status']) {
         $this->addFlashMessage('订单已经是支付状态,不允许重复设置');
         goto out;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     $orderPaymentService = new OrderPaymentService();
     $orderPaymentService->markOrderInfoPay($order_id, 1, 'admin_set', '0', '手动设置为已经支付', $authAdminUser['user_name']);
     $this->addFlashMessage('订单成功设置为支付状态');
     out:
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Order/Order/Detail', array('order_id' => $order_id), true));
 }
Example #5
0
 public function doNotifyUrl($f3)
 {
     // 记录所有的参数,方便调试查找
     printLog('Alipay Notify Paramters : ' . print_r($_REQUEST, true), 'PAYMENT', Base::INFO);
     //计算得出通知验证结果
     $alipayNotify = new AlipayNotify($this->alipayConfig);
     $verifyResult = $alipayNotify->verifyNotify();
     if (!$verifyResult) {
         printLog('Alipay verifyNotify Error ', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //验证成功
     //商户订单号
     $out_trade_no = $_POST['out_trade_no'];
     //支付宝交易号
     $trade_no = $_POST['trade_no'];
     //交易状态
     $trade_status = $_POST['trade_status'];
     //总金额
     $total_fee = $_POST['total_fee'];
     if ($_POST['trade_status'] != 'TRADE_FINISHED' && $_POST['trade_status'] != 'TRADE_SUCCESS') {
         printLog('Alipay trade_status Error', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //$_POST['trade_status'] == 'TRADE_FINISHED'
     //判断该笔订单是否在商户网站中已经做过处理
     //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
     //如果有做过处理,不执行商户的业务程序
     //注意:
     //该种交易状态只在两种情况下出现
     //1、开通了普通即时到账,买家付款成功后。
     //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。
     //$_POST['trade_status'] == 'TRADE_SUCCESS'
     //判断该笔订单是否在商户网站中已经做过处理
     //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
     //如果有做过处理,不执行商户的业务程序
     //注意:
     //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。
     //------------------------------
     //处理业务开始
     //------------------------------
     if (empty($out_trade_no)) {
         goto out_bad_trade_no;
     }
     $paramArray = explode('_', $out_trade_no);
     if (empty($paramArray) || count($paramArray) < 2 || !ctype_digit($paramArray[count($paramArray) - 1])) {
         goto out_bad_trade_no;
     }
     // 最后一个应该是订单 ID 号
     $orderId = intval($paramArray[count($paramArray) - 1]);
     if (empty($orderId)) {
         goto out_bad_trade_no;
     }
     // 设置订单 ID
     $this->orderId = $orderId;
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
     //判断金额是否一致,我们用 分 做单位来比较
     if ($orderInfo->isEmpty() || Money::storageToCent($orderInfo['order_amount']) != Money::displayToCent($total_fee)) {
         printLog('Alipay total_fee error, order_amount :{' . Money::storageToCent($orderInfo['order_amount']) . '} total_fee : {' . Money::displayToCent($total_fee) . '}', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //检查订单状态
     if (OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
         printLog('Alipay order_status is not OS_UNCONFIRMED, order_status[' . $orderInfo['order_status'] . '] orderId[' . $orderId . ']', 'PAYMENT', Base::WARN);
         goto out_succ;
     }
     // 把订单设置为已付款状态
     $orderPaymentService = new OrderPaymentService();
     $orderPaymentService->markOrderInfoPay($orderId, $this->payId, $this->getGatewayType(), $trade_no);
     printLog('Alipay orderId[' . $orderId . '] notifyUrl success', 'PAYMENT', Base::INFO);
     //------------------------------
     //处理业务完毕
     //------------------------------
     out_succ:
     echo "success";
     //成功返回
     return true;
     out_bad_trade_no:
     printLog('Alipay bad out_trade_no', 'PAYMENT', Base::ERROR);
     out_fail:
     // 失败从这里返回
     echo "fail";
     return false;
 }
Example #6
0
 /**
  * 取消订单
  */
 public function Cancel($f3)
 {
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1, true, '订单ID非法')->validate('order_id');
     if (!$this->validate($validator)) {
         goto out;
     }
     $userInfo = AuthHelper::getAuthUser();
     // 查询订单
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id, 1);
     // 缓存 1 秒钟
     if ($orderInfo->isEmpty() || $userInfo['user_id'] != $orderInfo['user_id'] || OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status'] || !$this->verifyOrderSystem($orderInfo)) {
         $this->addFlashMessage('订单ID非法');
         goto out;
     }
     // 取消订单
     $orderPaymentService = new OrderPaymentService();
     if ($orderPaymentService->cancelUnpayOrderInfo($order_id)) {
         // 重新加载 authUser,因为退款可能导致用户 余额 之类发生变化
         //AuthHelper::reloadAuthUser();
     }
     $this->addFlashMessage('成功取消订单');
     out:
     // 从这里退出
     RouteHelper::reRoute($this, '/My/Order');
 }