Authored by 梁志锋

Merge branch 'master' of http://git.dev.yoho.cn/web/yohobuy into xin_https

@@ -63,4 +63,14 @@ class Config @@ -63,4 +63,14 @@ class Config
63 */ 63 */
64 var $payType = 0; //非直连为0 64 var $payType = 0; //非直连为0
65 65
  66 + /**
  67 + * @var string 日志目录
  68 + */
  69 + var $logDir = '/Data/logs/pc_pay/allinpay';
  70 +
  71 + /**
  72 + * @var string 日志等级
  73 + */
  74 + var $logLevel = 2; // 记录信息日志
  75 +
66 } 76 }
@@ -14,9 +14,7 @@ abstract class PayAbstract implements PayInterface { @@ -14,9 +14,7 @@ abstract class PayAbstract implements PayInterface {
14 * 14 *
15 * @var 15 * @var
16 */ 16 */
17 - public $baseNoticeUrl = "http://www.yohobuy.com/pay/";  
18 -  
19 -// public $baseNoticeUrl = "http://www.yohobuy.com/pay/"; 17 + public $baseNoticeUrl = "http://gray.yohobuy.com/pay/";
20 18
21 /** 19 /**
22 * 测试的回调地址 20 * 测试的回调地址
@@ -2,12 +2,36 @@ @@ -2,12 +2,36 @@
2 2
3 namespace WebPlugin\Pay\weixin; 3 namespace WebPlugin\Pay\weixin;
4 4
  5 +use LibModels\Web\Home\OrderData;
  6 +use LibModels\Web\Product\PayData;
5 use WebPlugin\Pay\weixin\lib\WxPayApi; 7 use WebPlugin\Pay\weixin\lib\WxPayApi;
6 use WebPlugin\Pay\weixin\lib\WxPayNotify; 8 use WebPlugin\Pay\weixin\lib\WxPayNotify;
7 use WebPlugin\Pay\weixin\lib\WxPayOrderQuery; 9 use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
  10 +use WebPlugin\PhpLog;
8 11
9 class PayNotifyCallBack extends WxPayNotify 12 class PayNotifyCallBack extends WxPayNotify
10 { 13 {
  14 + // 向ERP提交订单状态有关接口调用日志和更新订单状态有关接口调用日志
  15 + const ORDER_STATUS_LOG = '/Data/logs/pc_pay/order_status';
  16 + // 日志等级,2表示记录信息等级的日志
  17 + const LOG_LEVEL = 2;
  18 + // 获取微信订单中的订单号需要截取的开始位置
  19 + const ORDER_CODE_START = 8;
  20 +
  21 + private $log = null;
  22 + private $_uid;
  23 +
  24 + /**
  25 + * PayNotifyCallBack constructor.
  26 + * @param int $uid
  27 + */
  28 + public function __construct($uid)
  29 + {
  30 + // 初始化日志
  31 + $this->log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
  32 + $this->_uid = $uid;
  33 + }
  34 +
11 35
12 //查询订单 36 //查询订单
13 public function Queryorder($transaction_id) 37 public function Queryorder($transaction_id)
@@ -16,8 +40,44 @@ class PayNotifyCallBack extends WxPayNotify @@ -16,8 +40,44 @@ class PayNotifyCallBack extends WxPayNotify
16 $input->SetTransaction_id($transaction_id); 40 $input->SetTransaction_id($transaction_id);
17 $result = WxPayApi::orderQuery($input); 41 $result = WxPayApi::orderQuery($input);
18 if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { 42 if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") {
  43 + $orderCode = substr($result['out_trade_no'], self::ORDER_CODE_START);
  44 + $payment = 21; // 微信扫码支付
  45 + $bankName = 'WX';
  46 + $bankCode = '';
  47 + $amount = $result['total_fee'] / 100;
  48 + $tradeNo = $result['out_trade_no'];
  49 + $bankBillNo = $result['bank_type'];
  50 +
  51 + $this->log->LogInfo('===[' . $orderCode . ']===');
  52 +
  53 + $this->log->LogInfo('==[' . $orderCode . ']=开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');
  54 + $this->log->LogInfo('==[' . $orderCode . ']=请求参数为orderCode=' . $orderCode . '===');
  55 + // ERP提交订单状态
  56 + $erpReturn = PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $orderCode, $tradeNo, $bankBillNo);
  57 + $this->log->LogInfo('==[' . $orderCode . ']=结束调用ERP提交订单状态接口,返回结果为===');
  58 + $this->log->LogInfo(var_export($erpReturn, true));
  59 +
  60 + $this->log->LogInfo('==[' . $orderCode . ']=开始调用获取订单详情方式接口,接口方法为app.SpaceOrders.detail===');
  61 + $orderInfo = OrderData::getOrderDetail('', $orderCode);
  62 + $this->log->LogInfo('==[' . $orderCode . ']=结束调用获取订单详情方式接口,返回结果为===');
  63 + $this->log->LogInfo(var_export($orderInfo, true));
  64 +
  65 + if (!isset($orderInfo['data']) || empty($orderInfo['data'])) {
  66 + $this->log->LogInfo('==[' . $orderCode . ']=微信支付状态同步中未获取到订单详情信息===');
  67 + return false;
  68 + }
  69 +
  70 + $this->log->LogInfo('==[' . $orderCode . ']=开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');
  71 + $this->log->LogInfo('==[' . $orderCode . ']=请求参数为orderId=' . $orderInfo['data']['order_id'] . 'uid=' . $this->_uid . '===');
  72 + // 更新订单的状态
  73 + $updateOrderStatus = PayData::updateOrderStatus($orderInfo['data']['order_id'], $this->_uid, $payment, 'Y', $bankCode);
  74 + $this->log->LogInfo('==[' . $orderCode . ']=结束调用更新订单状态接口,返回结果为===');
  75 + $this->log->LogInfo(var_export($updateOrderStatus, true));
  76 + $this->log->LogInfo('==[' . $orderCode . ']=微信扫码订单支付成功===');
  77 +
19 return true; 78 return true;
20 } 79 }
  80 +
21 return false; 81 return false;
22 } 82 }
23 83
@@ -33,6 +93,9 @@ class PayNotifyCallBack extends WxPayNotify @@ -33,6 +93,9 @@ class PayNotifyCallBack extends WxPayNotify
33 $msg = "订单查询失败"; 93 $msg = "订单查询失败";
34 return false; 94 return false;
35 } 95 }
  96 +
  97 + $this->log->LogInfo('=====微信扫码支付通知结果为:' . $msg . '=====');
  98 +
36 return true; 99 return true;
37 } 100 }
38 101
@@ -31,7 +31,7 @@ class WxPayConfig @@ -31,7 +31,7 @@ class WxPayConfig
31 const APPSECRET = 'ce21ae4a3f93852279175a167e54509b'; 31 const APPSECRET = 'ce21ae4a3f93852279175a167e54509b';
32 //=======【异步通知url设置】=================================== 32 //=======【异步通知url设置】===================================
33 //异步通知url,商户根据实际开发过程设定 33 //异步通知url,商户根据实际开发过程设定
34 - const NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/wechatqrcodenotify'; 34 + const NOTIFY_URL = 'http://gray.yohobuy.com/pay/notice/wechatqrcodenotify';
35 //=======【证书路径设置】===================================== 35 //=======【证书路径设置】=====================================
36 /** 36 /**
37 * TODO:设置商户证书路径 37 * TODO:设置商户证书路径
@@ -401,7 +401,12 @@ class PayModel @@ -401,7 +401,12 @@ class PayModel
401 $result = array(); 401 $result = array();
402 402
403 do { 403 do {
  404 + // 初始化日志
  405 + $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
  406 + $log->LogInfo('=====[' . $orderCode . ']===开始生成微信支付二维码========');
  407 +
404 if (empty($orderCode)) { 408 if (empty($orderCode)) {
  409 + $log->LogInfo('=====[' . $orderCode . ']===微信支付时,订单号为空========');
405 $result['error'] = true; 410 $result['error'] = true;
406 $result['message'] = '订单号不能为空'; 411 $result['message'] = '订单号不能为空';
407 break; 412 break;
@@ -410,6 +415,7 @@ class PayModel @@ -410,6 +415,7 @@ class PayModel
410 /* 判断订单信息是否存在 */ 415 /* 判断订单信息是否存在 */
411 $orderDetail = OrderData::getOrderDetail($uid, $orderCode); 416 $orderDetail = OrderData::getOrderDetail($uid, $orderCode);
412 if (!isset($orderDetail['data']) || empty($orderDetail['data'])) { 417 if (!isset($orderDetail['data']) || empty($orderDetail['data'])) {
  418 + $log->LogInfo('=====[' . $orderCode . ']===微信支付时,订单信息未查到========');
413 $result['error'] = true; 419 $result['error'] = true;
414 $result['message'] = '没有找到该订单'; 420 $result['message'] = '没有找到该订单';
415 break; 421 break;
@@ -436,6 +442,8 @@ class PayModel @@ -436,6 +442,8 @@ class PayModel
436 $input->SetProduct_id($orderCode); 442 $input->SetProduct_id($orderCode);
437 $notify = new WxPayNativePay(); 443 $notify = new WxPayNativePay();
438 $payResult = $notify->GetPayUrl($input); 444 $payResult = $notify->GetPayUrl($input);
  445 + $log->LogInfo('=====[' . $orderCode . ']===微信支付时,微信统一下单的返回结果为:========');
  446 + $log->LogInfo(var_export($payResult, true));
439 447
440 $orderData = $orderDetail['data']; 448 $orderData = $orderDetail['data'];
441 $firstGoods = current($orderData['order_goods']); 449 $firstGoods = current($orderData['order_goods']);
@@ -447,10 +455,12 @@ class PayModel @@ -447,10 +455,12 @@ class PayModel
447 'tellphoneNum' => $orderData['mobile'], 455 'tellphoneNum' => $orderData['mobile'],
448 'tradeName' => $firstGoods['product_name'], 456 'tradeName' => $firstGoods['product_name'],
449 'choosePayUrl' => Helpers::url('/shopping/pay', array('order_code' => $orderData['order_code'])), 457 'choosePayUrl' => Helpers::url('/shopping/pay', array('order_code' => $orderData['order_code'])),
450 - 'qrcodeUrl' => $payResult['code_url']//$reqPars['pay_url'] // 'http://paysdk.weixin.qq.com/example/qrcode.php?data=' . $result['code_url'] 458 + 'qrcodeUrl' => $payResult['code_url'] // 'http://paysdk.weixin.qq.com/example/qrcode.php?data=' . $result['code_url']
451 ); 459 );
452 460
453 } while (false); 461 } while (false);
  462 + $log->LogInfo('=====[' . $orderCode . ']===微信支付时,处理微信支付的结果为:========');
  463 + $log->LogInfo(var_export($result, true));
454 464
455 return $result; 465 return $result;
456 } 466 }
@@ -476,22 +486,24 @@ class PayModel @@ -476,22 +486,24 @@ class PayModel
476 486
477 // 初始化日志 487 // 初始化日志
478 $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL); 488 $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
479 - $log->LogInfo('========[' . $orderCode . ']========');  
480 - $log->LogInfo('========开始查询微信扫码支付状态========'); 489 + $log->LogInfo('=====[' . $orderCode . ']===开始查询微信扫码支付状态========');
481 490
482 // 组装微信支付的订单号 491 // 组装微信支付的订单号
483 $tradeNo = 'YOHOBuy_' . $orderCode; 492 $tradeNo = 'YOHOBuy_' . $orderCode;
484 $input = new WxPayOrderQuery(); 493 $input = new WxPayOrderQuery();
485 $input->SetOut_trade_no($tradeNo); 494 $input->SetOut_trade_no($tradeNo);
486 $payResult = WxPayApi::orderQuery($input); 495 $payResult = WxPayApi::orderQuery($input);
  496 + $log->LogInfo(var_export($payResult, true));
487 497
488 if (isset($payResult['trade_state']) && $payResult['trade_state'] === 'SUCCESS') { 498 if (isset($payResult['trade_state']) && $payResult['trade_state'] === 'SUCCESS') {
489 - $log->LogInfo('========微信扫码支付成功========'); 499 + $log->LogInfo('====[' . $orderCode . ']====微信扫码支付成功========');
490 $result = array( 500 $result = array(
491 'code' => '200', 501 'code' => '200',
492 'message' => 'success' 502 'message' => 'success'
493 ); 503 );
494 } 504 }
  505 +
  506 + $log->LogInfo('====[' . $orderCode . ']====微信扫码支付失败========');
495 } while (false); 507 } while (false);
496 508
497 return $result; 509 return $result;
@@ -518,13 +530,13 @@ class PayModel @@ -518,13 +530,13 @@ class PayModel
518 $log->LogInfo('========[' . $payResult->orderCode . ']========'); 530 $log->LogInfo('========[' . $payResult->orderCode . ']========');
519 $log->LogInfo(var_export($payResult, true)); 531 $log->LogInfo(var_export($payResult, true));
520 532
521 - $log->LogInfo('===开始调用获取订单详情方式接口,接口方法为app.SpaceOrders.detail==='); 533 + $log->LogInfo('==[' . $payResult->orderCode . ']=开始调用获取订单详情方式接口,接口方法为app.SpaceOrders.detail===');
522 $orderInfo = OrderData::getOrderDetail($uid, $payResult->orderCode); 534 $orderInfo = OrderData::getOrderDetail($uid, $payResult->orderCode);
523 - $log->LogInfo('===结束调用获取订单详情方式接口,返回结果为==='); 535 + $log->LogInfo('==[' . $payResult->orderCode . ']=结束调用获取订单详情方式接口,返回结果为===');
524 $log->LogInfo(var_export($orderInfo, true)); 536 $log->LogInfo(var_export($orderInfo, true));
525 537
526 if (!isset($orderInfo['data']) || empty($orderInfo['data'])) { 538 if (!isset($orderInfo['data']) || empty($orderInfo['data'])) {
527 - $log->LogInfo('===订单支付失败,未获取到订单详情信息==='); 539 + $log->LogInfo('==[' . $payResult->orderCode . ']=订单支付失败,未获取到订单详情信息===');
528 break; 540 break;
529 } 541 }
530 542
@@ -539,9 +551,9 @@ class PayModel @@ -539,9 +551,9 @@ class PayModel
539 // 初始化日志 551 // 初始化日志
540 $log = new PhpLog(self::SEND_MESSAGE_LOG, 'PRC', self::LOG_LEVEL); 552 $log = new PhpLog(self::SEND_MESSAGE_LOG, 'PRC', self::LOG_LEVEL);
541 $log->LogInfo('===[' . $orderCode . ']==='); 553 $log->LogInfo('===[' . $orderCode . ']===');
542 - $log->LogInfo('===开始调用订单取消时给用户发短信接口,接口方法为app.message.sendMsg==='); 554 + $log->LogInfo('==[' . $orderCode . ']=开始调用订单取消时给用户发短信接口,接口方法为app.message.sendMsg===');
543 $messageReturn = PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode); 555 $messageReturn = PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode);
544 - $log->LogInfo('===结束调用给用户发短信接口,返回结果为==='); 556 + $log->LogInfo('==[' . $orderCode . ']=结束调用给用户发短信接口,返回结果为===');
545 $log->LogInfo(var_export($messageReturn, true)); 557 $log->LogInfo(var_export($messageReturn, true));
546 558
547 $result['code'] = 417; 559 $result['code'] = 417;
@@ -552,7 +564,7 @@ class PayModel @@ -552,7 +564,7 @@ class PayModel
552 // 支付金额与订单金额不一致 564 // 支付金额与订单金额不一致
553 if (round($amount, 2) != round($payResult->totalFee, 2)) { 565 if (round($amount, 2) != round($payResult->totalFee, 2)) {
554 $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL); 566 $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
555 - $log->LogInfo('===订单支付失败,支付金额与订单金额不一致==='); 567 + $log->LogInfo('==[' . $orderCode . ']=订单支付失败,支付金额与订单金额不一致===');
556 $result['code'] = 415; 568 $result['code'] = 415;
557 $result['message'] = '支付金额与订单金额不一致'; 569 $result['message'] = '支付金额与订单金额不一致';
558 break; 570 break;
@@ -569,20 +581,20 @@ class PayModel @@ -569,20 +581,20 @@ class PayModel
569 $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL); 581 $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
570 $log->LogInfo('===[' . $orderCode . ']==='); 582 $log->LogInfo('===[' . $orderCode . ']===');
571 583
572 - $log->LogInfo('===开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');  
573 - $log->LogInfo('===请求参数为orderCode=' . $orderCode . '==='); 584 + $log->LogInfo('==[' . $orderCode . ']=开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');
  585 + $log->LogInfo('==[' . $orderCode . ']=请求参数为orderCode=' . $orderCode . '===');
574 // ERP提交订单状态 586 // ERP提交订单状态
575 $erpReturn = PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $payOrderCode, $tradeNo, $bankBillNo); 587 $erpReturn = PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $payOrderCode, $tradeNo, $bankBillNo);
576 - $log->LogInfo('===结束调用ERP提交订单状态接口,返回结果为==='); 588 + $log->LogInfo('==[' . $orderCode . ']=结束调用ERP提交订单状态接口,返回结果为===');
577 $log->LogInfo(var_export($erpReturn, true)); 589 $log->LogInfo(var_export($erpReturn, true));
578 590
579 - $log->LogInfo('===开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');  
580 - $log->LogInfo('===请求参数为orderId=' . $orderData['order_id'] . 'uid=' . $uid . '==='); 591 + $log->LogInfo('==[' . $orderCode . ']=开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');
  592 + $log->LogInfo('==[' . $orderCode . ']=请求参数为orderId=' . $orderData['order_id'] . 'uid=' . $uid . '===');
581 // 更新订单的状态 593 // 更新订单的状态
582 $updateOrderStatus = PayData::updateOrderStatus($orderData['order_id'], $uid, $payment, 'Y', $bankCode); 594 $updateOrderStatus = PayData::updateOrderStatus($orderData['order_id'], $uid, $payment, 'Y', $bankCode);
583 - $log->LogInfo('===结束调用更新订单状态接口,返回结果为==='); 595 + $log->LogInfo('==[' . $orderCode . ']=结束调用更新订单状态接口,返回结果为===');
584 $log->LogInfo(var_export($updateOrderStatus, true)); 596 $log->LogInfo(var_export($updateOrderStatus, true));
585 - $log->LogInfo('===订单支付成功,请等待发货==='); 597 + $log->LogInfo('==[' . $orderCode . ']=订单支付成功,请等待发货===');
586 598
587 $result['code'] = 200; 599 $result['code'] = 200;
588 $result['message'] = '支付成功,请等待发货'; 600 $result['message'] = '支付成功,请等待发货';
@@ -278,7 +278,13 @@ class NoticeController extends WebAction @@ -278,7 +278,13 @@ class NoticeController extends WebAction
278 public function wechatqrcodenotifyAction() 278 public function wechatqrcodenotifyAction()
279 { 279 {
280 $this->log->LogInfo("begin wechatqrcodenotifyAction"); 280 $this->log->LogInfo("begin wechatqrcodenotifyAction");
281 - $notify = new PayNotifyCallBack(); 281 +
  282 + $uid = $this->getUid();
  283 + if (empty($uid)) { // cookie中获取为空时再从之前保存的session中获取
  284 + $uid = $this->getSession(self::SESSION_UID_KEY);
  285 + $this->setSession(self::SESSION_UID_KEY, null);
  286 + }
  287 + $notify = new PayNotifyCallBack($uid);
282 $notify->handle(false); 288 $notify->handle(false);
283 } 289 }
284 290