Authored by 郝肖肖

支付确认接口

@@ -147,26 +147,4 @@ class OrderData @@ -147,26 +147,4 @@ class OrderData
147 // 调用接口获得数据 147 // 调用接口获得数据
148 return Yohobuy::post(Yohobuy::API_URL, $param); 148 return Yohobuy::post(Yohobuy::API_URL, $param);
149 } 149 }
150 -  
151 - /**  
152 - * 支付成功后--支付确认接口  
153 - * @param type int $orderCode 订单号  
154 - * @param type int $paymentId 支付方式  
155 - * @param type int $uid 用户ID  
156 - * @return type []  
157 - */  
158 - public static function payConfirm($orderCode, $paymentId, $uid)  
159 - {  
160 - // 构建必传参数  
161 - $param = Yohobuy::param();  
162 - $param['method'] = 'app.SpaceOrders.payConfirm';  
163 - $param['order_code'] = $orderCode;  
164 - $param['payment_id'] = $paymentId;  
165 - $param['uid'] = intval($uid);  
166 - $param['client_secret'] = Sign::getSign($param);  
167 -  
168 - // 调用接口获得数据  
169 - return Yohobuy::post(Yohobuy::API_URL, $param);  
170 -  
171 - }  
172 } 150 }
@@ -240,4 +240,26 @@ class PayData @@ -240,4 +240,26 @@ class PayData
240 240
241 return Yohobuy::get(Yohobuy::API_URL, $param); 241 return Yohobuy::get(Yohobuy::API_URL, $param);
242 } 242 }
  243 +
  244 + /**
  245 + * 支付成功后--支付确认接口
  246 + * @param type int $orderCode 订单号
  247 + * @param type int $paymentId 支付方式
  248 + * @param type int $uid 用户ID
  249 + * @return type []
  250 + */
  251 + public static function payConfirm($orderCode, $paymentId, $uid)
  252 + {
  253 + // 构建必传参数
  254 + $param = Yohobuy::param();
  255 + $param['method'] = 'app.SpaceOrders.payConfirm';
  256 + $param['order_code'] = $orderCode;
  257 + $param['payment_id'] = $paymentId;
  258 + $param['uid'] = intval($uid);
  259 + $param['client_secret'] = Sign::getSign($param);
  260 +
  261 + // 调用接口获得数据
  262 + return Yohobuy::post(Yohobuy::API_URL, $param);
  263 +
  264 + }
243 } 265 }
@@ -318,10 +318,10 @@ class PaymentModel @@ -318,10 +318,10 @@ class PaymentModel
318 $notify = new WxPayNativePay(); 318 $notify = new WxPayNativePay();
319 $payResult = $notify->GetPayUrl($input); 319 $payResult = $notify->GetPayUrl($input);
320 320
321 -// if ($payResult['result_code'] === 'FAIL') {  
322 -// self::$code['message'] = $payResult['err_code_des'];  
323 -// break;  
324 -// } 321 + if ($payResult['result_code'] === 'FAIL') {
  322 + self::$code['message'] = $payResult['err_code_des'];
  323 + break;
  324 + }
325 325
326 $orderData = $orderDetail['data']; 326 $orderData = $orderDetail['data'];
327 $firstGoods = current($orderData['order_goods']); 327 $firstGoods = current($orderData['order_goods']);
@@ -425,7 +425,7 @@ class PaymentModel @@ -425,7 +425,7 @@ class PaymentModel
425 $orderCode = $payResult->orderCode; 425 $orderCode = $payResult->orderCode;
426 //如果uid,为空,则从缓存中取uid,但还是不排除uid为空的情况下。 426 //如果uid,为空,则从缓存中取uid,但还是不排除uid为空的情况下。
427 $uid = empty($uid) ? self::getUid($orderCode) : $uid; 427 $uid = empty($uid) ? self::getUid($orderCode) : $uid;
428 - $confirm = OrderData::payConfirm($orderCode, $paymentId, $uid); 428 + $confirm = PayData::payConfirm($orderCode, $paymentId, $uid);
429 429
430 // UdpLog::info( 430 // UdpLog::info(
431 // "【支付成功-发送确认接口】,function:payConfirm,orderCode:{$orderCode},支付方式ID:{$paymentId},接口返回", 431 // "【支付成功-发送确认接口】,function:payConfirm,orderCode:{$orderCode},支付方式ID:{$paymentId},接口返回",
@@ -433,4 +433,116 @@ class PaymentModel @@ -433,4 +433,116 @@ class PaymentModel
433 // ); 433 // );
434 return $confirm; 434 return $confirm;
435 } 435 }
  436 +
  437 + /**
  438 + * 获取支付有关信息
  439 + *
  440 + * @param int $uid 用户ID
  441 + * @param string $orderCode 订单号
  442 + * @param string $paymentType 支付方式
  443 + * @param string $userName 用户名
  444 + * @param string $alipayToken 支付宝用户token
  445 + * @return array
  446 + */
  447 + public static function getPayData($uid, $orderCode, $paymentType, $userName, $alipayToken)
  448 + {
  449 + $result = array();
  450 +
  451 + do {
  452 + /* 判断是否有订单号参数 */
  453 + if (empty($orderCode)) {
  454 + $result['error'] = true;
  455 + $result['message'] = '订单号不能为空';
  456 + break;
  457 + }
  458 +
  459 + /* 判断支付方式是否选择 */
  460 + $paymentPars = explode('_', $paymentType);
  461 + if (count($paymentPars) != 2) {
  462 + $result['error'] = true;
  463 + $result['message'] = '请选择一个支付方式';
  464 + break;
  465 + }
  466 +
  467 + /* 判断订单信息是否存在 */
  468 + $orderDetail = OrderData::getOrderDetail($uid, $orderCode);
  469 + if (empty($orderDetail['data'])) {
  470 + $result['error'] = true;
  471 + $result['message'] = '没有找到该订单';
  472 + break;
  473 + }
  474 +
  475 + /* 判断订单是否已取消 */
  476 + if (isset($orderDetail['data']['is_cancel']) && $orderDetail['data']['is_cancel'] === 'Y') {
  477 + $result['error'] = true;
  478 + $result['message'] = '订单已经取消';
  479 + $result['location'] = 'window.location="' . Helpers::url('/home/orders/detail', array('order_code' => $orderCode)) . '";';
  480 + break;
  481 + }
  482 +
  483 + // 获取支付有关参数
  484 + $payId = $paymentPars[0];
  485 + $paymentParams = self::getPaymentById($payId);
  486 + if (empty($paymentParams)) {
  487 + $result['error'] = true;
  488 + $result['message'] = '支付系统繁忙,请稍后再试';
  489 + break;
  490 + }
  491 +
  492 + $payService = PayFactory::factory($paymentParams);
  493 + if ($payService == false) { // 没找到支付方式时
  494 + $result['error'] = true;
  495 + $result['message'] = '请选择一个支付方式';
  496 + break;
  497 + }
  498 +
  499 + $totalFee = $orderDetail['data']['payment_amount'] * 100;
  500 + $isTest = (APPLICATION_ENV === 'developer' || APPLICATION_ENV === 'testing');
  501 + $paymentParameter = $paymentPars[1];
  502 + // 判断是否传入支付宝token
  503 + if ($paymentType == 2 && !empty($alipayToken)) {
  504 +
  505 + $paymentParameter = $alipayToken;
  506 + }
  507 +
  508 + $reqParams = new Reqparams($orderCode, $totalFee, '有货订单号:' . $orderCode, '', $orderDetail['data']['create_time'], $paymentParameter, $isTest, $uid, $userName);
  509 + $reqPars = $payService->getPayRequestPars($reqParams);
  510 + if (empty($reqPars)) {
  511 + $result['error'] = true;
  512 + $result['message'] = '支付系统繁忙,请稍后再试';
  513 + break;
  514 + }
  515 +
  516 + // 记录并更新订单支付方式
  517 + $paymentRecod = OrderData::updateOrderPayment($orderCode, $payId, $uid);
  518 + if (empty($paymentRecod) || $paymentRecod['code'] != 200) {
  519 + $result['error'] = true;
  520 + $result['message'] = isset($paymentRecod['message']) ? $paymentRecod['message'] : '系统繁忙,请稍后再试';
  521 + break;
  522 + }
  523 + $bankRecord = PayData::getBankByOrder($orderCode);
  524 + $bankCode = ($paymentParameter != 'platform' ? $paymentParameter : '');
  525 + if (isset($bankRecord['data']['bankCode']) && !empty($bankRecord['data']['bankCode'])) {
  526 + $bankPayRecord = PayData::updateOrderPayBank($orderCode, $payId, $bankCode);
  527 + } else {
  528 + $bankPayRecord = PayData::setOrderPayBank($orderCode, $payId, $bankCode);
  529 + }
  530 + if (!isset($bankPayRecord['code']) || $bankPayRecord['code'] != 200) {
  531 + $result['error'] = true;
  532 + $result['message'] = '支付方式记录失败';
  533 + break;
  534 + }
  535 +
  536 + if ($reqPars['reqType'] == 'get') {
  537 + //直接跳转到支付界面
  538 + $result['go'] = true;
  539 + $result['payUrl'] = $reqPars['pay_url'] . '?' . $reqPars['pars'];
  540 + } else {
  541 + //如果是post,去form提交
  542 + $result = array('reqPars' => $reqPars);
  543 + }
  544 + } while (false);
  545 +
  546 + return $result;
  547 + }
436 } 548 }
1 <?php 1 <?php
2 2
3 use Action\WebAction; 3 use Action\WebAction;
4 -use Shopping\PayModel; 4 +use Shopping\PaymentModel;
5 use WebPlugin\Helpers; 5 use WebPlugin\Helpers;
6 6
7 /** 7 /**
@@ -20,7 +20,7 @@ class IndexController extends WebAction @@ -20,7 +20,7 @@ class IndexController extends WebAction
20 $orderCode = $this->get('order_code', $this->get('ordercode')); 20 $orderCode = $this->get('order_code', $this->get('ordercode'));
21 $paymentType = $this->get('payment_type'); 21 $paymentType = $this->get('payment_type');
22 $alipayToken = $this->getSession('alipay_user_token'); 22 $alipayToken = $this->getSession('alipay_user_token');
23 - $data = PayModel::getPayData($uid, $orderCode, $paymentType, $this->_uname, $alipayToken); 23 + $data = PaymentModel::getPayData($uid, $orderCode, $paymentType, $this->_uname, $alipayToken);
24 if (isset($data['error'])) { 24 if (isset($data['error'])) {
25 $this->helpJsRedirect($data['message']); 25 $this->helpJsRedirect($data['message']);
26 } 26 }