Authored by Rock Zhang

添加详细的支付日志记录

@@ -17,7 +17,7 @@ class Service extends PayAbstract @@ -17,7 +17,7 @@ class Service extends PayAbstract
17 { 17 {
18 $this->logProjectPrefix = 'alibank'; 18 $this->logProjectPrefix = 'alibank';
19 $this->config = new Config(); 19 $this->config = new Config();
20 - $myConfig = json_decode($paymentParams["pay_params"]) ; 20 + $myConfig = json_decode($paymentParams["pay_params"]);
21 $this->config->partner = $myConfig->merchant_id; 21 $this->config->partner = $myConfig->merchant_id;
22 $this->config->alipay_key = $myConfig->merchant_key; 22 $this->config->alipay_key = $myConfig->merchant_key;
23 $this->config->sellerMail = $myConfig->merchant_other_code; 23 $this->config->sellerMail = $myConfig->merchant_other_code;
@@ -43,7 +43,7 @@ class Service extends PayAbstract @@ -43,7 +43,7 @@ class Service extends PayAbstract
43 public function getPayRequestPars(Reqparams $params) 43 public function getPayRequestPars(Reqparams $params)
44 { 44 {
45 $baseUrl = $this->getBaseNoticeUrl($params->isTest); 45 $baseUrl = $this->getBaseNoticeUrl($params->isTest);
46 - $loseTime = intval(($params->orderTime + 7200 -time())/60); 46 + $loseTime = intval(($params->orderTime + 7200 - time()) / 60);
47 // $loseTime = intval((strtotime(date("Y-m-d 10:00:00", strtotime("+1 day")))-time())/60); 47 // $loseTime = intval((strtotime(date("Y-m-d 10:00:00", strtotime("+1 day")))-time())/60);
48 48
49 $parameter = array( 49 $parameter = array(
@@ -54,27 +54,27 @@ class Service extends PayAbstract @@ -54,27 +54,27 @@ class Service extends PayAbstract
54 'return_url' => $baseUrl . $this->config->return_url, 54 'return_url' => $baseUrl . $this->config->return_url,
55 /* 业务参数 */ 55 /* 业务参数 */
56 'subject' => $params->goodsName, 56 'subject' => $params->goodsName,
57 - 'out_trade_no' => $params->orderCode.'_'.$params->paymentParameter, 57 + 'out_trade_no' => $params->orderCode . '_' . $params->paymentParameter,
58 'total_fee' => $params->totalFee / 100, //单位为元 58 'total_fee' => $params->totalFee / 100, //单位为元
59 'payment_type' => $this->config->payment_type, 59 'payment_type' => $this->config->payment_type,
60 'defaultbank' => $params->paymentParameter, 60 'defaultbank' => $params->paymentParameter,
61 'seller_email' => $this->config->sellerMail, 61 'seller_email' => $this->config->sellerMail,
62 // 'it_b_pay' => $loseTime . 'm' 62 // 'it_b_pay' => $loseTime . 'm'
63 ); 63 );
64 - if($this->config->anti_fishing['timestamp_enable']) { 64 + if ($this->config->anti_fishing['timestamp_enable']) {
65 $anti_phishing_key = $this->getTimestamp(); 65 $anti_phishing_key = $this->getTimestamp();
66 - if(!empty($anti_phishing_key)) { 66 + if (!empty($anti_phishing_key)) {
67 $parameter['anti_phishing_key'] = $anti_phishing_key; 67 $parameter['anti_phishing_key'] = $anti_phishing_key;
68 } 68 }
69 } 69 }
70 - if($this->config->anti_fishing['ip_enable']) { 70 + if ($this->config->anti_fishing['ip_enable']) {
71 $parameter['exter_invoke_ip'] = $params->spbill_create_ip; 71 $parameter['exter_invoke_ip'] = $params->spbill_create_ip;
72 } 72 }
73 73
74 // 除去数组中的空值和签名参数 74 // 除去数组中的空值和签名参数
75 $para_filter = array(); 75 $para_filter = array();
76 foreach ($parameter AS $k => $v) { 76 foreach ($parameter AS $k => $v) {
77 - if($k == "sign" || $k == "sign_type" || $v == "") { 77 + if ($k == "sign" || $k == "sign_type" || $v == "") {
78 continue; 78 continue;
79 } else { 79 } else {
80 $para_filter[$k] = $parameter[$k]; 80 $para_filter[$k] = $parameter[$k];
@@ -87,18 +87,20 @@ class Service extends PayAbstract @@ -87,18 +87,20 @@ class Service extends PayAbstract
87 $param = ''; 87 $param = '';
88 $sign = ''; 88 $sign = '';
89 foreach ($para_filter AS $key => $val) { 89 foreach ($para_filter AS $key => $val) {
90 - $param .= "$key=" .urlencode($val). "&"; 90 + $param .= "$key=" . urlencode($val) . "&";
91 $sign .= "$key=$val&"; 91 $sign .= "$key=$val&";
92 } 92 }
93 $param = substr($param, 0, -1); 93 $param = substr($param, 0, -1);
94 $sign = substr($sign, 0, -1); 94 $sign = substr($sign, 0, -1);
95 //如果存在转义字符,那么去掉转义 95 //如果存在转义字符,那么去掉转义
96 - if(get_magic_quotes_gpc()){$sign = stripslashes($sign);} 96 + if (get_magic_quotes_gpc()) {
  97 + $sign = stripslashes($sign);
  98 + }
97 $sign .= $this->config->alipay_key; 99 $sign .= $this->config->alipay_key;
98 100
99 $result = array( 101 $result = array(
100 'pay_url' => $this->config->pay_url, 102 'pay_url' => $this->config->pay_url,
101 - 'pars' => $param . "&sign=" . md5($sign). "&sign_type=" . $this->config-> sign_type, 103 + 'pars' => $param . "&sign=" . md5($sign) . "&sign_type=" . $this->config->sign_type,
102 'reqType' => 'get' 104 'reqType' => 'get'
103 ); 105 );
104 106
@@ -114,29 +116,29 @@ class Service extends PayAbstract @@ -114,29 +116,29 @@ class Service extends PayAbstract
114 $this->log->logInfo("-----回调参数为---"); 116 $this->log->logInfo("-----回调参数为---");
115 $this->log->logInfo(var_export($arrResponse), true); 117 $this->log->logInfo(var_export($arrResponse), true);
116 118
117 - if(isset($arrResponse['q'])){ 119 + if (isset($arrResponse['q'])) {
118 unset($arrResponse['q']); 120 unset($arrResponse['q']);
119 } 121 }
120 $rsp = new Rspparams(); 122 $rsp = new Rspparams();
121 - if(!$this->checkResponse($arrResponse))  
122 - {  
123 - $this->log->LogInfo("验证支付宝银行的回调参数失败"); 123 + if (!$this->checkResponse($arrResponse)) {
  124 + $this->log->LogInfo("---验证支付宝银行的回调参数失败---");
  125 +
124 //验证不成功 126 //验证不成功
125 $rsp->payResult = -1; 127 $rsp->payResult = -1;
126 - }  
127 - else  
128 - { 128 + } else {
  129 + $this->log->LogInfo("---验证支付宝银行的回调参数成功---");
  130 +
129 $rsp->bankName = ""; 131 $rsp->bankName = "";
130 $outTradeNo = $arrResponse["out_trade_no"]; 132 $outTradeNo = $arrResponse["out_trade_no"];
131 // if(strlen($outTradeNo) > 9) { 133 // if(strlen($outTradeNo) > 9) {
132 // $outTradeNo = substr($outTradeNo, 2); 134 // $outTradeNo = substr($outTradeNo, 2);
133 // } 135 // }
134 //支付订单处理 136 //支付订单处理
135 - $orderCodeArr = explode('_',$outTradeNo);  
136 - if(count($orderCodeArr) == 2){ 137 + $orderCodeArr = explode('_', $outTradeNo);
  138 + if (count($orderCodeArr) == 2) {
137 $rsp->orderCode = $orderCodeArr[0]; 139 $rsp->orderCode = $orderCodeArr[0];
138 $rsp->bankName = $orderCodeArr[1]; 140 $rsp->bankName = $orderCodeArr[1];
139 - }else{ 141 + } else {
140 $rsp->orderCode = $outTradeNo; 142 $rsp->orderCode = $outTradeNo;
141 $rsp->bankName = ""; 143 $rsp->bankName = "";
142 } 144 }
@@ -148,14 +150,17 @@ class Service extends PayAbstract @@ -148,14 +150,17 @@ class Service extends PayAbstract
148 $rsp->payOrderCode = $outTradeNo; 150 $rsp->payOrderCode = $outTradeNo;
149 $rsp->tradeNo = $arrResponse['trade_no']; 151 $rsp->tradeNo = $arrResponse['trade_no'];
150 $rsp->bankBillNo = $arrResponse['bank_seq_no'] ? $arrResponse['bank_seq_no'] : ""; 152 $rsp->bankBillNo = $arrResponse['bank_seq_no'] ? $arrResponse['bank_seq_no'] : "";
  153 +
  154 + $this->log->LogInfo('----支付宝银行回调处理结果为----');
  155 + $this->log->LogInfo(var_export($rsp, true));
151 } 156 }
  157 +
152 return $rsp; 158 return $rsp;
153 } 159 }
154 160
155 protected function convertResult($resultCode) 161 protected function convertResult($resultCode)
156 { 162 {
157 - if($resultCode == "TRADE_SUCCESS")  
158 - { 163 + if ($resultCode == "TRADE_SUCCESS") {
159 return 200; 164 return 200;
160 } 165 }
161 return 400; 166 return 400;
@@ -166,10 +171,11 @@ class Service extends PayAbstract @@ -166,10 +171,11 @@ class Service extends PayAbstract
166 * @param $para 签名参数组 171 * @param $para 签名参数组
167 * return 去掉空值与签名参数后的新签名参数组 172 * return 去掉空值与签名参数后的新签名参数组
168 */ 173 */
169 - private function paraFilter($para) { 174 + private function paraFilter($para)
  175 + {
170 $para_filter = array(); 176 $para_filter = array();
171 - foreach ($para as $key=>$val) {  
172 - if($key == "sign" || $key == "sign_type" || $val == "")continue; 177 + foreach ($para as $key => $val) {
  178 + if ($key == "sign" || $key == "sign_type" || $val == "") continue;
173 else $para_filter[$key] = $para[$key]; 179 else $para_filter[$key] = $para[$key];
174 } 180 }
175 return $para_filter; 181 return $para_filter;
@@ -180,7 +186,8 @@ class Service extends PayAbstract @@ -180,7 +186,8 @@ class Service extends PayAbstract
180 * @param $para 排序前的数组 186 * @param $para 排序前的数组
181 * return 排序后的数组 187 * return 排序后的数组
182 */ 188 */
183 - private function argSort($para) { 189 + private function argSort($para)
  190 + {
184 ksort($para); 191 ksort($para);
185 reset($para); 192 reset($para);
186 return $para; 193 return $para;
@@ -195,10 +202,8 @@ class Service extends PayAbstract @@ -195,10 +202,8 @@ class Service extends PayAbstract
195 ksort($arrResponse); 202 ksort($arrResponse);
196 reset($arrResponse); 203 reset($arrResponse);
197 $sign = ''; 204 $sign = '';
198 - foreach ($arrResponse AS $key=>$val)  
199 - {  
200 - if ($key != 'sign' && $key != 'sign_type' && $key != 'code')  
201 - { 205 + foreach ($arrResponse AS $key => $val) {
  206 + if ($key != 'sign' && $key != 'sign_type' && $key != 'code') {
202 $sign .= "$key=$val&"; 207 $sign .= "$key=$val&";
203 } 208 }
204 } 209 }
@@ -100,6 +100,10 @@ class Service extends PayAbstract @@ -100,6 +100,10 @@ class Service extends PayAbstract
100 'pars' => $param . "&sign=" . md5($sign) . "&sign_type=" . $this->config->sign_type, 100 'pars' => $param . "&sign=" . md5($sign) . "&sign_type=" . $this->config->sign_type,
101 'reqType' => 'get' 101 'reqType' => 'get'
102 ); 102 );
  103 +
  104 + $this->log->LogInfo('----支付宝回调处理结果为----');
  105 + $this->log->LogInfo(var_export($result, true));
  106 +
103 return $result; 107 return $result;
104 } 108 }
105 109
@@ -117,9 +121,11 @@ class Service extends PayAbstract @@ -117,9 +121,11 @@ class Service extends PayAbstract
117 } 121 }
118 $rsp = new Rspparams(); 122 $rsp = new Rspparams();
119 if (!$this->checkResponse($arrResponse)) { 123 if (!$this->checkResponse($arrResponse)) {
  124 + $this->log->logInfo("-----支付宝回调参数验证签名失败---");
120 //验证不成功 125 //验证不成功
121 $rsp->payResult = -1; 126 $rsp->payResult = -1;
122 } else { 127 } else {
  128 + $this->log->logInfo("-----支付宝回调参数验证签名成功---");
123 $rsp->bankName = ""; 129 $rsp->bankName = "";
124 $outTradeNo = $arrResponse["out_trade_no"]; 130 $outTradeNo = $arrResponse["out_trade_no"];
125 $rsp->orderCode = $outTradeNo; 131 $rsp->orderCode = $outTradeNo;
@@ -5,10 +5,12 @@ namespace WebPlugin\Pay\Allinpay; @@ -5,10 +5,12 @@ namespace WebPlugin\Pay\Allinpay;
5 use WebPlugin\Pay\PayAbstract; 5 use WebPlugin\Pay\PayAbstract;
6 use WebPlugin\Pay\Reqparams; 6 use WebPlugin\Pay\Reqparams;
7 use WebPlugin\Pay\Rspparams; 7 use WebPlugin\Pay\Rspparams;
  8 +use WebPlugin\PhpLog;
8 9
9 class Service extends PayAbstract 10 class Service extends PayAbstract
10 { 11 {
11 - var $config; 12 + public $config;
  13 + private $log;
12 14
13 public function __construct(array $paymentParams) 15 public function __construct(array $paymentParams)
14 { 16 {
@@ -17,6 +19,8 @@ class Service extends PayAbstract @@ -17,6 +19,8 @@ class Service extends PayAbstract
17 $myConfig = json_decode($paymentParams["pay_params"]); 19 $myConfig = json_decode($paymentParams["pay_params"]);
18 $this->config->merchantId = $myConfig->merchant_id; 20 $this->config->merchantId = $myConfig->merchant_id;
19 $this->config->merchantKey = $myConfig->merchant_key; 21 $this->config->merchantKey = $myConfig->merchant_key;
  22 +
  23 + $this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
20 } 24 }
21 25
22 /** 26 /**
@@ -63,10 +67,18 @@ class Service extends PayAbstract @@ -63,10 +67,18 @@ class Service extends PayAbstract
63 */ 67 */
64 public function parseResponse(array $arrResponse) 68 public function parseResponse(array $arrResponse)
65 { 69 {
  70 + $this->log->LogInfo("===开始处理通联支付的回调参数===");
  71 + $this->log->logInfo("-----回调参数为---");
  72 + $this->log->logInfo(var_export($arrResponse, true));
  73 +
66 $rsp = new Rspparams(); 74 $rsp = new Rspparams();
67 if (!$this->checkResponse($arrResponse)) { 75 if (!$this->checkResponse($arrResponse)) {
  76 + $this->log->logInfo("-----验证通联支付回调参数失败---");
  77 +
68 $rsp->payResult = -1; 78 $rsp->payResult = -1;
69 } else { 79 } else {
  80 + $this->log->logInfo("-----验证通联支付回调参数成功---");
  81 +
70 $rsp->bankName = ""; 82 $rsp->bankName = "";
71 $rsp->orderCode = $arrResponse["orderNo"]; 83 $rsp->orderCode = $arrResponse["orderNo"];
72 $rsp->payResult = $this->convertResult($arrResponse["payResult"]); 84 $rsp->payResult = $this->convertResult($arrResponse["payResult"]);
@@ -108,15 +108,19 @@ class Service extends PayAbstract @@ -108,15 +108,19 @@ class Service extends PayAbstract
108 */ 108 */
109 function parseResponse(Array $arrResponse) 109 function parseResponse(Array $arrResponse)
110 { 110 {
111 - $this->log->LogInfo("===开始处理盛付通的请求参数===");  
112 - $this->log->logInfo("-----请求参数为---"); 111 + $this->log->LogInfo("===开始处理盛付通的回调参数===");
  112 + $this->log->logInfo("-----回调参数为---");
113 $this->log->logInfo(var_export($arrResponse, true)); 113 $this->log->logInfo(var_export($arrResponse, true));
114 114
115 $rsp = new Rspparams(); 115 $rsp = new Rspparams();
116 if (!$this->checkResponse($arrResponse)) { 116 if (!$this->checkResponse($arrResponse)) {
  117 + $this->log->logInfo("-----验证盛付通回调参数失败---");
  118 +
117 //验证不成功 119 //验证不成功
118 $rsp->payResult = -1; 120 $rsp->payResult = -1;
119 } else { 121 } else {
  122 + $this->log->logInfo("-----验证盛付通回调参数成功---");
  123 +
120 $rsp->bankName = ""; 124 $rsp->bankName = "";
121 $rsp->orderCode = $arrResponse["OrderNo"]; 125 $rsp->orderCode = $arrResponse["OrderNo"];
122 $rsp->payResult = $this->convertResult($arrResponse["Status"]); 126 $rsp->payResult = $this->convertResult($arrResponse["Status"]);
@@ -35,20 +35,22 @@ class Service extends PayAbstract @@ -35,20 +35,22 @@ class Service extends PayAbstract
35 */ 35 */
36 public function parseResponse(array $package) 36 public function parseResponse(array $package)
37 { 37 {
  38 + $this->log->logInfo("===开始解析银联支付的回调参数===");
  39 + $this->log->logInfo("===回调参数为===");
38 $this->log->LogInfo(var_export($package, true)); 40 $this->log->LogInfo(var_export($package, true));
39 41
40 $verify = false; 42 $verify = false;
41 $responseData = new Rspparams(); 43 $responseData = new Rspparams();
42 44
43 if (!isset($package['respCode']) || $package['respCode'] !== '00') { 45 if (!isset($package['respCode']) || $package['respCode'] !== '00') {
44 - $this->log->LogInfo('支付返回码有误'); 46 + $this->log->LogInfo('银联支付返回码有误');
45 $responseData->payResult = -1; 47 $responseData->payResult = -1;
46 return $responseData; 48 return $responseData;
47 } 49 }
48 50
49 if (isset($package['signature'])) { // TODO isset($package['signature']) && verify($package)验证签名待做 51 if (isset($package['signature'])) { // TODO isset($package['signature']) && verify($package)验证签名待做
50 $verify = true; 52 $verify = true;
51 - $this->log->LogInfo('验签成功'); 53 + $this->log->LogInfo('银联支付验签成功');
52 } 54 }
53 55
54 if ($verify) { 56 if ($verify) {
@@ -67,6 +69,7 @@ class Service extends PayAbstract @@ -67,6 +69,7 @@ class Service extends PayAbstract
67 $responseData->payResult = -1; 69 $responseData->payResult = -1;
68 } 70 }
69 71
  72 + $this->log->logInfo("===银联支付的回调参数处理结果为===");
70 $this->log->LogInfo(var_export($responseData, true)); 73 $this->log->LogInfo(var_export($responseData, true));
71 74
72 return $responseData; 75 return $responseData;
@@ -21,10 +21,11 @@ class Service extends PayAbstract @@ -21,10 +21,11 @@ class Service extends PayAbstract
21 private $payCurl; 21 private $payCurl;
22 private $log; 22 private $log;
23 23
24 - public function __construct(array $paymentParams) { 24 + public function __construct(array $paymentParams)
  25 + {
25 $this->logProjectPrefix = 'wechatpay'; 26 $this->logProjectPrefix = 'wechatpay';
26 $this->config = new Config(); 27 $this->config = new Config();
27 - $environParam = 'pay_'.APPLICATION_ENV.'_url'; 28 + $environParam = 'pay_' . APPLICATION_ENV . '_url';
28 $this->payCurl = $this->config->$environParam; 29 $this->payCurl = $this->config->$environParam;
29 $this->appKey = $this->config->app_key; 30 $this->appKey = $this->config->app_key;
30 $this->privateKey = $this->config->private_key; 31 $this->privateKey = $this->config->private_key;
@@ -33,7 +34,8 @@ class Service extends PayAbstract @@ -33,7 +34,8 @@ class Service extends PayAbstract
33 $this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel); 34 $this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
34 } 35 }
35 36
36 - public function getPayRequestPars(Reqparams $params) { 37 + public function getPayRequestPars(Reqparams $params)
  38 + {
37 $this->orderCode = $params->orderCode; 39 $this->orderCode = $params->orderCode;
38 $result = array( 40 $result = array(
39 'pay_url' => $this->config->payment_url, 41 'pay_url' => $this->config->payment_url,
@@ -49,7 +51,8 @@ class Service extends PayAbstract @@ -49,7 +51,8 @@ class Service extends PayAbstract
49 * @return string 51 * @return string
50 * @internal param array $orderCode 52 * @internal param array $orderCode
51 */ 53 */
52 - public function pay(array $orderInfo) { 54 + public function pay(array $orderInfo)
  55 + {
53 $this->log->LogInfo("===开始处理微信扫码支付的请求参数==="); 56 $this->log->LogInfo("===开始处理微信扫码支付的请求参数===");
54 $this->log->logInfo("-----请求参数为---"); 57 $this->log->logInfo("-----请求参数为---");
55 $this->log->logInfo(var_export($orderInfo, true)); 58 $this->log->logInfo(var_export($orderInfo, true));
@@ -74,7 +77,7 @@ class Service extends PayAbstract @@ -74,7 +77,7 @@ class Service extends PayAbstract
74 ); 77 );
75 $pars = ''; 78 $pars = '';
76 foreach ($parameter as $p_key => $p_val) { 79 foreach ($parameter as $p_key => $p_val) {
77 - $pars.=$p_key . '=' . urlencode($p_val) . '&'; 80 + $pars .= $p_key . '=' . urlencode($p_val) . '&';
78 } 81 }
79 $payUrlInfo = array( 82 $payUrlInfo = array(
80 'pay_url' => $this->payCurl, 83 'pay_url' => $this->payCurl,
@@ -90,7 +93,8 @@ class Service extends PayAbstract @@ -90,7 +93,8 @@ class Service extends PayAbstract
90 return array('pay_url' => $payUrl); 93 return array('pay_url' => $payUrl);
91 } 94 }
92 95
93 - public function parseResponse(array $data) { 96 + public function parseResponse(array $data)
  97 + {
94 /* 返回示例 98 /* 返回示例
95 * http://www.yohobuy.com/pay/notice/wechatqrcodereturn?ordercode=93465435 99 * http://www.yohobuy.com/pay/notice/wechatqrcodereturn?ordercode=93465435
96 */ 100 */
@@ -108,7 +112,7 @@ class Service extends PayAbstract @@ -108,7 +112,7 @@ class Service extends PayAbstract
108 112
109 $rsp = new Rspparams(); 113 $rsp = new Rspparams();
110 // 支付成功 114 // 支付成功
111 - if(isset($result['trade_state']) && $result['trade_state'] === 'SUCCESS'){ 115 + if (isset($result['trade_state']) && $result['trade_state'] === 'SUCCESS') {
112 $rsp->payResult = 200; 116 $rsp->payResult = 200;
113 $rsp->bankName = "WX"; 117 $rsp->bankName = "WX";
114 $rsp->orderCode = $data['orderCode']; 118 $rsp->orderCode = $data['orderCode'];
@@ -119,7 +123,8 @@ class Service extends PayAbstract @@ -119,7 +123,8 @@ class Service extends PayAbstract
119 $rsp->payOrderCode = $data["orderCode"]; 123 $rsp->payOrderCode = $data["orderCode"];
120 $rsp->tradeNo = $result["out_trade_no"]; 124 $rsp->tradeNo = $result["out_trade_no"];
121 $rsp->bankBillNo = $result['bank_type']; 125 $rsp->bankBillNo = $result['bank_type'];
122 - }else{ 126 + } else {
  127 + $this->log->logInfo("===微信扫码支付失败===");
123 $rsp->payResult = -1; 128 $rsp->payResult = -1;
124 } 129 }
125 130
@@ -14,6 +14,7 @@ use WebPlugin\Pay\weixin\lib\WxPayConfig; @@ -14,6 +14,7 @@ use WebPlugin\Pay\weixin\lib\WxPayConfig;
14 use WebPlugin\Pay\weixin\lib\WxPayNativePay; 14 use WebPlugin\Pay\weixin\lib\WxPayNativePay;
15 use WebPlugin\Pay\weixin\lib\WxPayOrderQuery; 15 use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
16 use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder; 16 use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder;
  17 +use WebPlugin\PhpLog;
17 18
18 /** 19 /**
19 * 支付有关方法 20 * 支付有关方法
@@ -25,6 +26,22 @@ use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder; @@ -25,6 +26,22 @@ use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder;
25 */ 26 */
26 class PayModel 27 class PayModel
27 { 28 {
  29 + // 日志等级,2表示记录信息等级的日志
  30 + const LOG_LEVEL = 2;
  31 + // 支付方式有关接口调用日志
  32 + const PAYMENT_LIST_LOG = '/Data/logs/pc_pay/payment_list';
  33 + // 向ERP提交订单状态有关接口调用日志和更新订单状态有关接口调用日志
  34 + const ORDER_STATUS_LOG = '/Data/logs/pc_pay/order_status';
  35 + // 获取或者更新订单支付银行的接口调用日志
  36 + const ORDER_BANK_LOG = '/Data/logs/pc_pay/order_bank';
  37 + // 根据用户UID获取订单数有关接口调用日志
  38 + const ORDER_COUNT_LOG = '/Data/logs/pc_pay/order_count';
  39 + // 发送短信有关接口调用日志
  40 + const SEND_MESSAGE_LOG = '/Data/logs/pc_pay/send_message';
  41 +
  42 + // 是否老用户订单数判断值
  43 + const OLD_USER_LIMIT = 1;
  44 +
28 /** 45 /**
29 * 获取支付方式选择页面有关信息 46 * 获取支付方式选择页面有关信息
30 * 47 *
@@ -94,8 +111,14 @@ class PayModel @@ -94,8 +111,14 @@ class PayModel
94 // 用户ID 111 // 用户ID
95 $result['uid'] = $uid; 112 $result['uid'] = $uid;
96 113
  114 + // 初始化日志
  115 + $log = new PhpLog(self::PAYMENT_LIST_LOG, 'PRC', self::LOG_LEVEL);
97 // 获取支付途径列表 116 // 获取支付途径列表
  117 + $log->LogInfo('===开始调用支付方式列表接口,接口方法为web.SpaceOrders.getPaymentList===');
98 $payTypes = PayData::getPaymentList(); 118 $payTypes = PayData::getPaymentList();
  119 + $log->LogInfo('===结束调用支付方式列表接口,返回结果为===');
  120 + $log->LogInfo(var_export($payTypes, true));
  121 +
99 $defaultPayType = 0; 122 $defaultPayType = 0;
100 $types = array(); 123 $types = array();
101 if (isset($payTypes['data']) && !empty($payTypes['data'])) { 124 if (isset($payTypes['data']) && !empty($payTypes['data'])) {
@@ -125,16 +148,37 @@ class PayModel @@ -125,16 +148,37 @@ class PayModel
125 148
126 // 无需付款 149 // 无需付款
127 if (isset($order["payment_amount"]) && $order["payment_amount"] == 0) { 150 if (isset($order["payment_amount"]) && $order["payment_amount"] == 0) {
  151 + // 初始化日志
  152 + $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
  153 + $log->LogInfo('===[' . $orderCode . ']===');
  154 +
128 // ERP提交订单状态 155 // ERP提交订单状态
129 - PayData::submitOrderStatus($orderCode, 0, '', '', 0, '', '', ''); 156 + $log->LogInfo('===开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');
  157 + $log->LogInfo('===请求参数为orderCode=' . $orderCode . '===');
  158 + $erpReturn = PayData::submitOrderStatus($orderCode, 0, '', '', 0, '', '', '');
  159 + $log->LogInfo('===结束调用ERP提交订单状态接口,返回结果为===');
  160 + $log->LogInfo(var_export($erpReturn, true));
  161 +
130 // 更新订单的状态 162 // 更新订单的状态
131 - PayData::updateOrderStatus($order['order_id'], $uid, 0, 'Y', ''); 163 + $log->LogInfo('===开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');
  164 + $log->LogInfo('===请求参数为orderId=' . $order['order_id'] . 'uid=' . $uid . '===');
  165 + $updateOrderStatus = PayData::updateOrderStatus($order['order_id'], $uid, 0, 'Y', '');
  166 + $log->LogInfo('===结束调用更新订单状态接口,返回结果为===');
  167 + $log->LogInfo(var_export($updateOrderStatus, true));
  168 +
132 $result['notNeedPay'] = true; 169 $result['notNeedPay'] = true;
133 break; 170 break;
134 } 171 }
135 172
136 // 记录支付方式 173 // 记录支付方式
  174 + // 初始化日志
  175 + $log = new PhpLog(self::ORDER_BANK_LOG, 'PRC', self::LOG_LEVEL);
  176 + $log->LogInfo('===开始调用记录支付方式接口,接口方法为web.SpaceOrders.getOrderPayBank===');
  177 + $log->LogInfo('===请求参数为orderCode=' . $orderCode . '===');
137 $bankRecord = PayData::getBankByOrder($orderCode); 178 $bankRecord = PayData::getBankByOrder($orderCode);
  179 + $log->LogInfo('===结束调用记录支付方式接口,返回结果为===');
  180 + $log->LogInfo(var_export($bankRecord, true));
  181 +
138 if (isset($bankRecord['data']['bankCode']) && !empty($bankRecord['data']['bankCode'])) { 182 if (isset($bankRecord['data']['bankCode']) && !empty($bankRecord['data']['bankCode'])) {
139 $payRecord = $bankRecord['data']['bankCode']; 183 $payRecord = $bankRecord['data']['bankCode'];
140 } else { 184 } else {
@@ -158,11 +202,17 @@ class PayModel @@ -158,11 +202,17 @@ class PayModel
158 202
159 // 是否是老用户(用于订单统计) 203 // 是否是老用户(用于订单统计)
160 $orderCount = 0; 204 $orderCount = 0;
  205 + // 初始化日志
  206 + $log = new PhpLog(self::ORDER_COUNT_LOG, 'PRC', self::LOG_LEVEL);
  207 + $log->LogInfo('===开始调用查询用户订单数接口,接口方法为web.SpaceOrders.getOrderCountByUid===');
161 $orders = PayData::getOrderCountByUid($uid); 208 $orders = PayData::getOrderCountByUid($uid);
  209 + $log->LogInfo('===结束调用查询用户订单数接口,返回结果为===');
  210 + $log->LogInfo(var_export($orders, true));
  211 +
162 if (isset($orders['data']) && !empty($orders['data'])) { 212 if (isset($orders['data']) && !empty($orders['data'])) {
163 $orderCount = $orders['data']['total']; 213 $orderCount = $orders['data']['total'];
164 } 214 }
165 - $result['isOldUser'] = (intval($orderCount) > 1) ? true : false; 215 + $result['isOldUser'] = (intval($orderCount) > self::OLD_USER_LIMIT) ? true : false;
166 // 订单数(用于订单统计) 216 // 订单数(用于订单统计)
167 $result['orderCount'] = $orderCount; 217 $result['orderCount'] = $orderCount;
168 $result['is_advance'] = $order['attribute'] == 5 ? 'Y' : 'N'; 218 $result['is_advance'] = $order['attribute'] == 5 ? 'Y' : 'N';
@@ -424,6 +474,11 @@ class PayModel @@ -424,6 +474,11 @@ class PayModel
424 break; 474 break;
425 } 475 }
426 476
  477 + // 初始化日志
  478 + $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
  479 + $log->LogInfo('========[' . $orderCode . ']========');
  480 + $log->LogInfo('========开始查询微信扫码支付状态========');
  481 +
427 // 组装微信支付的订单号 482 // 组装微信支付的订单号
428 $tradeNo = 'YOHOBuy_' . $orderCode; 483 $tradeNo = 'YOHOBuy_' . $orderCode;
429 $input = new WxPayOrderQuery(); 484 $input = new WxPayOrderQuery();
@@ -431,6 +486,7 @@ class PayModel @@ -431,6 +486,7 @@ class PayModel
431 $payResult = WxPayApi::orderQuery($input); 486 $payResult = WxPayApi::orderQuery($input);
432 487
433 if (isset($payResult['trade_state']) && $payResult['trade_state'] === 'SUCCESS') { 488 if (isset($payResult['trade_state']) && $payResult['trade_state'] === 'SUCCESS') {
  489 + $log->LogInfo('========微信扫码支付成功========');
434 $result = array( 490 $result = array(
435 'code' => '200', 491 'code' => '200',
436 'message' => 'success' 492 'message' => 'success'
@@ -457,8 +513,18 @@ class PayModel @@ -457,8 +513,18 @@ class PayModel
457 ); 513 );
458 514
459 do { 515 do {
  516 + // 初始化日志
  517 + $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
  518 + $log->LogInfo('========[' . $payResult->orderCode . ']========');
  519 + $log->LogInfo(var_export($payResult, true));
  520 +
  521 + $log->LogInfo('===开始调用获取订单详情方式接口,接口方法为app.SpaceOrders.detail===');
460 $orderInfo = OrderData::getOrderDetail($uid, $payResult->orderCode); 522 $orderInfo = OrderData::getOrderDetail($uid, $payResult->orderCode);
  523 + $log->LogInfo('===结束调用获取订单详情方式接口,返回结果为===');
  524 + $log->LogInfo(var_export($orderInfo, true));
  525 +
461 if (!isset($orderInfo['data']) || empty($orderInfo['data'])) { 526 if (!isset($orderInfo['data']) || empty($orderInfo['data'])) {
  527 + $log->LogInfo('===订单支付失败,未获取到订单详情信息===');
462 break; 528 break;
463 } 529 }
464 530
@@ -470,7 +536,14 @@ class PayModel @@ -470,7 +536,14 @@ class PayModel
470 // 订单已取消 536 // 订单已取消
471 if ($orderData['is_cancel'] === 'Y' && $paymentStatus === 'N') { 537 if ($orderData['is_cancel'] === 'Y' && $paymentStatus === 'N') {
472 // 给用户发送短信 538 // 给用户发送短信
473 - PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode); 539 + // 初始化日志
  540 + $log = new PhpLog(self::SEND_MESSAGE_LOG, 'PRC', self::LOG_LEVEL);
  541 + $log->LogInfo('===[' . $orderCode . ']===');
  542 + $log->LogInfo('===开始调用订单取消时给用户发短信接口,接口方法为app.message.sendMsg===');
  543 + $messageReturn = PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode);
  544 + $log->LogInfo('===结束调用给用户发短信接口,返回结果为===');
  545 + $log->LogInfo(var_export($messageReturn, true));
  546 +
474 $result['code'] = 417; 547 $result['code'] = 417;
475 $result['message'] = '支付成功,但订单已取消,需联系客服'; 548 $result['message'] = '支付成功,但订单已取消,需联系客服';
476 break; 549 break;
@@ -478,6 +551,8 @@ class PayModel @@ -478,6 +551,8 @@ class PayModel
478 551
479 // 支付金额与订单金额不一致 552 // 支付金额与订单金额不一致
480 if (round($amount, 2) != round($payResult->totalFee, 2)) { 553 if (round($amount, 2) != round($payResult->totalFee, 2)) {
  554 + $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
  555 + $log->LogInfo('===订单支付失败,支付金额与订单金额不一致===');
481 $result['code'] = 415; 556 $result['code'] = 415;
482 $result['message'] = '支付金额与订单金额不一致'; 557 $result['message'] = '支付金额与订单金额不一致';
483 break; 558 break;
@@ -489,10 +564,25 @@ class PayModel @@ -489,10 +564,25 @@ class PayModel
489 $bankBillNo = $payResult->bankBillNo ? $payResult->bankBillNo : ""; 564 $bankBillNo = $payResult->bankBillNo ? $payResult->bankBillNo : "";
490 $bankName = $payResult->bankName; 565 $bankName = $payResult->bankName;
491 $bankCode = $payResult->bankCode; 566 $bankCode = $payResult->bankCode;
  567 +
  568 + // 初始化日志
  569 + $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
  570 + $log->LogInfo('===[' . $orderCode . ']===');
  571 +
  572 + $log->LogInfo('===开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');
  573 + $log->LogInfo('===请求参数为orderCode=' . $orderCode . '===');
492 // ERP提交订单状态 574 // ERP提交订单状态
493 - PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $payOrderCode, $tradeNo, $bankBillNo); 575 + $erpReturn = PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $payOrderCode, $tradeNo, $bankBillNo);
  576 + $log->LogInfo('===结束调用ERP提交订单状态接口,返回结果为===');
  577 + $log->LogInfo(var_export($erpReturn, true));
  578 +
  579 + $log->LogInfo('===开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');
  580 + $log->LogInfo('===请求参数为orderId=' . $orderData['order_id'] . 'uid=' . $uid . '===');
494 // 更新订单的状态 581 // 更新订单的状态
495 - PayData::updateOrderStatus($orderData['order_id'], $uid, $payment, 'Y', $bankCode); 582 + $updateOrderStatus = PayData::updateOrderStatus($orderData['order_id'], $uid, $payment, 'Y', $bankCode);
  583 + $log->LogInfo('===结束调用更新订单状态接口,返回结果为===');
  584 + $log->LogInfo(var_export($updateOrderStatus, true));
  585 + $log->LogInfo('===订单支付成功,请等待发货===');
496 586
497 $result['code'] = 200; 587 $result['code'] = 200;
498 $result['message'] = '支付成功,请等待发货'; 588 $result['message'] = '支付成功,请等待发货';
@@ -200,8 +200,6 @@ class NoticeController extends WebAction @@ -200,8 +200,6 @@ class NoticeController extends WebAction
200 */ 200 */
201 public function shengpayreturnAction() 201 public function shengpayreturnAction()
202 { 202 {
203 -// $strData = '{"Amount":"0.01","PayAmount":"0.01","OrderNo":"1070021504","serialno":"B000110726001873577","Status":"01","MerchantNo":"408258","PayChannel":"04","Discount":"1","SignType":"2","PayTime":"20110726162126","CurrencyType":"RMB","ProductNo":"","ProductDesc":"","Remark1":"","Remark2":"","ExInfo":"bankid:SDTBNK","Branch":"SHB","MAC":"8ABC0FBAA3EE3202F16A915B42571B58"}';  
204 - // $pars = json_decode($strData, true);  
205 $payment = PayModel::getPaymentById(11); 203 $payment = PayModel::getPaymentById(11);
206 $payService = PayFactory::factory($payment); 204 $payService = PayFactory::factory($payment);
207 $res = $payService->parseResponse($_POST); 205 $res = $payService->parseResponse($_POST);