Authored by 周少峰

Merge branch 'temp' of git.dev.yoho.cn:web/yohobuy into temp

@@ -6,6 +6,8 @@ use WebPlugin\Pay\PayAbstract; @@ -6,6 +6,8 @@ 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\Pay\Signature; 8 use WebPlugin\Pay\Signature;
  9 +use WebPlugin\Pay\weixin\lib\WxPayApi;
  10 +use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
9 11
10 class Service extends PayAbstract 12 class Service extends PayAbstract
11 { 13 {
@@ -74,25 +76,33 @@ class Service extends PayAbstract @@ -74,25 +76,33 @@ class Service extends PayAbstract
74 return array('pay_url' => $payUrl); 76 return array('pay_url' => $payUrl);
75 } 77 }
76 78
77 - public function parseResponse(array $arrResponse) { 79 + public function parseResponse(array $data) {
78 /* 返回示例 80 /* 返回示例
79 * http://www.yohobuy.com/pay/notice/wechatqrcodereturn?ordercode=93465435 81 * http://www.yohobuy.com/pay/notice/wechatqrcodereturn?ordercode=93465435
80 */ 82 */
  83 + // 组装微信支付的订单号
  84 + $tradeNo = 'YOHOBuy_' . $data['orderCode'];
  85 + $input = new WxPayOrderQuery();
  86 + $input->SetOut_trade_no($tradeNo);
  87 + $result = WxPayApi::orderQuery($input);
  88 +
81 $rsp = new Rspparams(); 89 $rsp = new Rspparams();
82 - if($arrResponse['payResult'] == 200){ 90 + // 支付成功
  91 + if(isset($result['trade_state']) && $result['trade_state'] === 'SUCCESS'){
83 $rsp->payResult = 200; 92 $rsp->payResult = 200;
84 $rsp->bankName = "WX"; 93 $rsp->bankName = "WX";
85 - $rsp->orderCode = $arrResponse['order_code'];  
86 - $rsp->payTime = $arrResponse["arrive_time"];  
87 - $rsp->totalFee = $arrResponse["amount"]; 94 + $rsp->orderCode = $data['orderCode'];
  95 + $rsp->payTime = $result["time_end"];
  96 + $rsp->totalFee = $result["total_fee"] / 100;
88 $rsp->resultMsg = '支付成功'; 97 $rsp->resultMsg = '支付成功';
89 //添加支付订单号和交易号 98 //添加支付订单号和交易号
90 - $rsp->payOrderCode = $arrResponse["order_code"];  
91 - $rsp->tradeNo = "";  
92 - $rsp->bankBillNo = ""; 99 + $rsp->payOrderCode = $data["orderCode"];
  100 + $rsp->tradeNo = $result["out_trade_no"];
  101 + $rsp->bankBillNo = $result['bank_type'];
93 }else{ 102 }else{
94 $rsp->payResult = -1; 103 $rsp->payResult = -1;
95 } 104 }
  105 +
96 return $rsp; 106 return $rsp;
97 } 107 }
98 108
@@ -4,6 +4,7 @@ namespace WebPlugin\Pay\weixin; @@ -4,6 +4,7 @@ namespace WebPlugin\Pay\weixin;
4 4
5 use WebPlugin\Pay\weixin\lib\WxPayApi; 5 use WebPlugin\Pay\weixin\lib\WxPayApi;
6 use WebPlugin\Pay\weixin\lib\WxPayNotify; 6 use WebPlugin\Pay\weixin\lib\WxPayNotify;
  7 +use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
7 8
8 class PayNotifyCallBack extends WxPayNotify 9 class PayNotifyCallBack extends WxPayNotify
9 { 10 {
@@ -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/wechatqrcodereturn'; 34 + const NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/wechatqrcodenotify';
35 //=======【证书路径设置】===================================== 35 //=======【证书路径设置】=====================================
36 /** 36 /**
37 * TODO:设置商户证书路径 37 * TODO:设置商户证书路径
@@ -80,7 +80,7 @@ class WxPayNotify extends WxPayNotifyReply @@ -80,7 +80,7 @@ class WxPayNotify extends WxPayNotifyReply
80 { 80 {
81 //如果需要签名 81 //如果需要签名
82 if ($needSign == true && 82 if ($needSign == true &&
83 - $this->GetReturn_code($return_code) == "SUCCESS") { 83 + $this->GetReturn_code() == "SUCCESS") {
84 $this->SetSign(); 84 $this->SetSign();
85 } 85 }
86 WxpayApi::replyNotify($this->ToXml()); 86 WxpayApi::replyNotify($this->ToXml());
@@ -9,8 +9,10 @@ use WebPlugin\Pay\Banks; @@ -9,8 +9,10 @@ use WebPlugin\Pay\Banks;
9 use WebPlugin\Pay\PayFactory; 9 use WebPlugin\Pay\PayFactory;
10 use WebPlugin\Pay\Reqparams; 10 use WebPlugin\Pay\Reqparams;
11 use WebPlugin\Pay\Rspparams; 11 use WebPlugin\Pay\Rspparams;
  12 +use WebPlugin\Pay\weixin\lib\WxPayApi;
12 use WebPlugin\Pay\weixin\lib\WxPayConfig; 13 use WebPlugin\Pay\weixin\lib\WxPayConfig;
13 use WebPlugin\Pay\weixin\lib\WxPayNativePay; 14 use WebPlugin\Pay\weixin\lib\WxPayNativePay;
  15 +use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
14 use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder; 16 use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder;
15 17
16 /** 18 /**
@@ -342,10 +344,9 @@ class PayModel @@ -342,10 +344,9 @@ class PayModel
342 * 344 *
343 * @param int $uid 用户ID 345 * @param int $uid 用户ID
344 * @param string $orderCode 订单号 346 * @param string $orderCode 订单号
345 - * @param int $paymentCode 支付方式ID  
346 * @return array 347 * @return array
347 */ 348 */
348 - public static function weixinQrcode($uid, $orderCode, $paymentCode) 349 + public static function weixinQrcode($uid, $orderCode)
349 { 350 {
350 $result = array(); 351 $result = array();
351 352
@@ -404,46 +405,6 @@ class PayModel @@ -404,46 +405,6 @@ class PayModel
404 return $result; 405 return $result;
405 } 406 }
406 407
407 -  
408 - /**  
409 - * 处理支付结果数据  
410 - *  
411 - * @param int $uid 用户ID  
412 - * @param string $orderCode 订单号  
413 - * @return array  
414 - */  
415 - public static function getPayDetail($uid, $orderCode)  
416 - {  
417 - $result = array(  
418 - 'code' => 500,  
419 - 'message' => '支付失败'  
420 - );  
421 -  
422 - do {  
423 - $orderInfo = OrderData::getOrderDetail($uid, $orderCode);  
424 - if (!isset($orderInfo['data']['payment_status']) || $orderInfo['data']['payment_status'] !== 'Y') {  
425 - break;  
426 - }  
427 - $result['code'] = 200;  
428 - $result['message'] = '支付成功,请等待发货';  
429 - $orderData = $orderInfo['data'];  
430 - $result['data'] = array(  
431 - 'pay' => $orderData['payment_amount'],  
432 - 'orderNum' => $orderData['order_code'],  
433 - 'checkOrderUrl' => Helpers::url('/home/orders/detail', array('order_code' => $orderData['order_code'])),  
434 - 'payMode' => ($orderData['payment_type'] == 1 ? '在线支付' : '货到付款'),  
435 - 'currency' => $orderData['yoho_give_coin'],  
436 - 'yohoCoinUrl' => Helpers::url('/help', array('category_id' => 87)),  
437 - 'vipSum' => $orderData['order_code'],  
438 - 'returnGoodsUrl' => Helpers::url('/help', array('category_id' => 121)),  
439 - 'vipUrl' => Helpers::url('/help', array('category_id' => 91)),  
440 - 'returnHomeUrl' => Helpers::url('/')  
441 - );  
442 - } while (false);  
443 -  
444 - return $result;  
445 - }  
446 -  
447 /** 408 /**
448 * 检查微信扫码支付结果 409 * 检查微信扫码支付结果
449 * 410 *
@@ -463,12 +424,13 @@ class PayModel @@ -463,12 +424,13 @@ class PayModel
463 break; 424 break;
464 } 425 }
465 426
466 - $orderInfo = OrderData::getOrderDetail($uid, $orderCode);  
467 - if (!isset($orderInfo['data']) || empty($orderInfo['data'])) {  
468 - break;  
469 - } 427 + // 组装微信支付的订单号
  428 + $tradeNo = 'YOHOBuy_' . $orderCode;
  429 + $input = new WxPayOrderQuery();
  430 + $input->SetOut_trade_no($tradeNo);
  431 + $payResult = WxPayApi::orderQuery($input);
470 432
471 - if ($orderInfo['data']['payment_status'] === 'Y') { 433 + if (isset($payResult['trade_state']) && $payResult['trade_state'] === 'SUCCESS') {
472 $result = array( 434 $result = array(
473 'code' => '200', 435 'code' => '200',
474 'message' => 'success' 436 'message' => 'success'
@@ -2,9 +2,9 @@ @@ -2,9 +2,9 @@
2 2
3 use Action\WebAction; 3 use Action\WebAction;
4 use Shopping\PayModel; 4 use Shopping\PayModel;
5 -use WebPlugin\Helpers;  
6 use WebPlugin\Pay\PayFactory; 5 use WebPlugin\Pay\PayFactory;
7 use WebPlugin\Pay\Rspparams; 6 use WebPlugin\Pay\Rspparams;
  7 +use WebPlugin\Pay\weixin\PayNotifyCallBack;
8 8
9 /** 9 /**
10 * 支付Notice 10 * 支付Notice
@@ -237,24 +237,34 @@ class NoticeController extends WebAction @@ -237,24 +237,34 @@ class NoticeController extends WebAction
237 } 237 }
238 238
239 /** 239 /**
240 - * 微信扫码支付返回返回 240 + * 微信扫码支付结果商户通知地址
241 */ 241 */
242 - public function wechatqrcodereturnAction() 242 + public function wechatqrcodenotifyAction()
243 { 243 {
244 - //判断是否登录  
245 - $uid = $this->auditJumpLogin(); 244 + $notify = new PayNotifyCallBack();
  245 + $notify->handle(false);
  246 + }
246 247
247 - do {  
248 - $orderCode = isset($_GET['order_code']) ? $_GET['order_code'] : 0;  
249 - if (empty($orderCode)) { 248 + /**
  249 + * 微信扫码支付返回
  250 + */
  251 + public function wechatqrcodereturnAction()
  252 + {
250 $dealResult = array( 253 $dealResult = array(
251 'code' => 500, 254 'code' => 500,
252 'message' => '支付失败' 255 'message' => '支付失败'
253 ); 256 );
  257 +
  258 + do {
  259 + $orderCode = isset($_GET['order_code']) ? $_GET['order_code'] : 0;
  260 + if (empty($orderCode)) {
254 break; 261 break;
255 } 262 }
256 263
257 - $dealResult = PayModel::getPayDetail($uid, $orderCode); 264 + $payment = PayModel::getPaymentById(21);
  265 + $payService = PayFactory::factory($payment);
  266 + $res = $payService->parseResponse(array('orderCode' => $orderCode));
  267 + $dealResult = $this->payResultProc($res, 21);
258 $dealResult['payData'] = array('payWay' => '微信扫码支付'); 268 $dealResult['payData'] = array('payWay' => '微信扫码支付');
259 } while (false); 269 } while (false);
260 270
@@ -266,23 +276,11 @@ class NoticeController extends WebAction @@ -266,23 +276,11 @@ class NoticeController extends WebAction
266 */ 276 */
267 public function unionpaywebreturnAction() 277 public function unionpaywebreturnAction()
268 { 278 {
269 - //判断是否登录  
270 - $uid = $this->auditJumpLogin();  
271 -  
272 - do {  
273 - $orderCode = isset($_GET['order_code']) ? $_GET['order_code'] : 0;  
274 - if (empty($orderCode)) {  
275 - $dealResult = array(  
276 - 'code' => 500,  
277 - 'message' => '支付失败'  
278 - );  
279 - break;  
280 - }  
281 -  
282 - $dealResult = PayModel::getPayDetail($uid, $orderCode); 279 + $payment = PayModel::getPaymentById(25);
  280 + $payService = PayFactory::factory($payment);
  281 + $res = $payService->parseResponse($_REQUEST);
  282 + $dealResult = $this->payResultProc($res, 25);
283 $dealResult['payData'] = array('payWay' => '银联在线支付'); 283 $dealResult['payData'] = array('payWay' => '银联在线支付');
284 - } while (false);  
285 -  
286 $this->commonShowResult($dealResult); 284 $this->commonShowResult($dealResult);
287 } 285 }
288 286
@@ -19,8 +19,7 @@ class WechatqrcodeController extends WebAction @@ -19,8 +19,7 @@ class WechatqrcodeController extends WebAction
19 } 19 }
20 20
21 $orderCode = $this->get('order_code', $this->get('ordercode')); 21 $orderCode = $this->get('order_code', $this->get('ordercode'));
22 - $paymentCode = $this->get('payment_code');  
23 - $data = PayModel::weixinQrcode($uid, $orderCode, $paymentCode); 22 + $data = PayModel::weixinQrcode($uid, $orderCode);
24 if (isset($data['error'])) { 23 if (isset($data['error'])) {
25 $this->helpJsRedirect($data['message']); 24 $this->helpJsRedirect($data['message']);
26 } 25 }