Authored by 郝肖肖

支付宝 支付notifyurl改成java地址

@@ -496,5 +496,22 @@ class CartData @@ -496,5 +496,22 @@ class CartData
496 496
497 return Yohobuy::get(SearchData::getUrl('search'), $param); 497 return Yohobuy::get(SearchData::getUrl('search'), $param);
498 } 498 }
499 - 499 +
  500 + /**
  501 + * 选择支付,校验时间间隔,插入数据
  502 + * @param string $uid
  503 + * @param string $orderCode
  504 + * @param int $payment 14:银联手机支付 15:支付宝手机 18:支付宝wap(wap) 19:微信支付 22:微信wap(wap) 26:QQ钱包手机支付
  505 + * @return type
  506 + */
  507 + public static function savePrePayInfo($uid, $orderCode, $payment)
  508 + {
  509 + $param = Yohobuy::param();
  510 + $param['method'] = 'app.order.savePrePayInfo';
  511 + $param['uid'] = $uid;
  512 + $param['orderCode'] = $orderCode;
  513 + $param['payment'] = $payment;
  514 + $param['client_secret'] = Sign::getSign($param);
  515 + return Yohobuy::get(Yohobuy::API_URL, $param);
  516 + }
500 } 517 }
@@ -36,14 +36,14 @@ class Config @@ -36,14 +36,14 @@ class Config
36 * Enter description here ... 36 * Enter description here ...
37 * @var String 37 * @var String
38 */ 38 */
39 - var $notify_url = "notice/alipaynotice"; 39 + var $notify_url = "payment/alipay_notify";
40 40
41 /** 41 /**
42 * 浏览器的返回 42 * 浏览器的返回
43 * Enter description here ... 43 * Enter description here ...
44 * @var string 44 * @var string
45 */ 45 */
46 - var $return_url = "notice/alipayreturn"; 46 + var $return_url = "/pay/payreturn/alipayreturn";
47 47
48 /** 48 /**
49 * 签名方式 49 * 签名方式
@@ -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\PhpLog; 8 use WebPlugin\PhpLog;
  9 +use Api\Yohobuy;
  10 +use Plugin\Helpers;
9 11
10 class Service extends PayAbstract 12 class Service extends PayAbstract
11 { 13 {
@@ -50,15 +52,15 @@ class Service extends PayAbstract @@ -50,15 +52,15 @@ class Service extends PayAbstract
50 $this->log->LogInfo("-----请求参数为---"); 52 $this->log->LogInfo("-----请求参数为---");
51 $this->log->LogInfo(var_export($params, true)); 53 $this->log->LogInfo(var_export($params, true));
52 54
53 - $baseUrl = $this->getBaseNoticeUrl($params->isTest); 55 +// $baseUrl = $this->getBaseNoticeUrl($params->isTest);
54 // $loseTime = intval(($params->orderTime + 7200 -time())/60); 56 // $loseTime = intval(($params->orderTime + 7200 -time())/60);
55 // $loseTime = intval((strtotime(date("Y-m-d 10:00:00", strtotime("+1 day")))-time())/60); //第二天十点 57 // $loseTime = intval((strtotime(date("Y-m-d 10:00:00", strtotime("+1 day")))-time())/60); //第二天十点
56 $parameter = array( 58 $parameter = array(
57 'service' => $this->config->service, 59 'service' => $this->config->service,
58 'partner' => $this->config->partner, 60 'partner' => $this->config->partner,
59 '_input_charset' => $this->config->input_charset, 61 '_input_charset' => $this->config->input_charset,
60 - 'notify_url' => $baseUrl . $this->config->notify_url,  
61 - 'return_url' => $baseUrl . $this->config->return_url, 62 + 'notify_url' => Yohobuy::SERVICE_URL . $this->config->notify_url,
  63 + 'return_url' => Helpers::url($this->config->return_url),
62 /* 业务参数 */ 64 /* 业务参数 */
63 'subject' => $params->goodsName, 65 'subject' => $params->goodsName,
64 'out_trade_no' => $params->orderCode, 66 'out_trade_no' => $params->orderCode,
@@ -190,9 +192,10 @@ class Service extends PayAbstract @@ -190,9 +192,10 @@ class Service extends PayAbstract
190 reset($arrResponse); 192 reset($arrResponse);
191 $sign = ''; 193 $sign = '';
192 foreach ($arrResponse AS $key => $val) { 194 foreach ($arrResponse AS $key => $val) {
193 - if ($key != 'sign' && $key != 'sign_type' && $key != 'code') {  
194 - $sign .= "$key=$val&"; 195 + if ($key === 'sign' || $key === 'sign_type' || $key === 'code' || $val === '') {
  196 + continue;
195 } 197 }
  198 + $sign .= "$key=$val&";
196 } 199 }
197 $sign = substr($sign, 0, -1) . $this->config->alipay_key; 200 $sign = substr($sign, 0, -1) . $this->config->alipay_key;
198 201
  1 +<?php
  2 +
  3 +namespace Shopping;
  4 +
  5 +use LibModels\Web\Home\OrderData;
  6 +use LibModels\Web\Product\PayData;
  7 +use Plugin\Helpers;
  8 +use WebPlugin\Cache;
  9 +use WebPlugin\Pay\Banks;
  10 +use WebPlugin\Pay\PayFactory;
  11 +use WebPlugin\Pay\Reqparams;
  12 +use WebPlugin\Pay\Rspparams;
  13 +use WebPlugin\Pay\weixin\lib\WxPayApi;
  14 +use WebPlugin\Pay\weixin\lib\WxPayConfig;
  15 +use WebPlugin\Pay\weixin\lib\WxPayNativePay;
  16 +use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
  17 +use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder;
  18 +
  19 +/**
  20 + * 支付有关方法 改版
  21 + * @copyright 2016/5/22 14:19 xiaoxiao<xiaoxiao.hao@yoho.cn>
  22 + */
  23 +class PaymentModel
  24 +{
  25 + protected static $code = array(
  26 + 'code' => 500,
  27 + 'message' => '支付失败'
  28 + );
  29 + // 存储的UID键名
  30 + const SESSION_UID_KEY = 'payUserid';
  31 +
  32 + public static function procOrderData($payResult)
  33 + {
  34 + do {
  35 + if (empty($payResult->orderCode)) {
  36 + self::$code['message'] = '未查到订单信息,订单状态更新失败!';
  37 + break;
  38 + }
  39 + $orderCode = $payResult->orderCode;
  40 + $uid = '';
  41 + if (USE_CACHE) {
  42 + // 通过订单号,从缓存记录中获取uid
  43 + $uid = Cache::get(self::SESSION_UID_KEY . $orderCode);
  44 + }
  45 + $orderInfo = OrderData::getOrderDetail($uid, $payResult->orderCode);
  46 + if (empty($orderInfo['data'])) {
  47 + self::$code['message'] = '未查到订单信息,订单状态更新失败!';
  48 + break;
  49 + }
  50 +
  51 + $orderData = $orderInfo['data'];
  52 + $amount = $orderData['payment_amount'];
  53 +
  54 + if ($orderData['is_cancel'] === 'Y') {
  55 + // 给用户发送短信
  56 + PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode);
  57 + self::$code['code'] = 417;
  58 + self::$code['message'] = '支付成功,但订单已取消,需联系客服!';
  59 + break;
  60 + }
  61 +
  62 +// if ($orderData['payment_status'] === 'N') {
  63 +// logup::info(
  64 +// '用户支付成功,同步地址返回,查询订单状态为未付款,有可能异步地址还未即时更新状态',
  65 +// array('payResult' => $payResult, 'orderData' => $orderData)
  66 +// );
  67 +// }
  68 +
  69 + // 支付金额与订单金额不一致
  70 + if (round($amount, 2) !== round($payResult->totalFee, 2)) {
  71 + self::$code['code'] = 415;
  72 + self::$code['message'] = '支付金额与订单金额不一致,订单状态更新失败!';
  73 + break;
  74 + }
  75 +
  76 + self::$code['code'] = 200;
  77 + self::$code['message'] = '支付成功,请等待发货';
  78 + self::$code['data'] = array(
  79 + 'pay' => $amount,
  80 + 'orderNum' => $orderData['order_code'],
  81 + 'checkOrderUrl' => Helpers::url('/home/orders/detail', array('orderCode' => $orderData['order_code'])),
  82 + 'payMode' => ($orderData['payment_type'] == 1 ? '在线支付' : '货到付款'),
  83 + 'currency' => $orderData['yoho_give_coin'],
  84 + 'yohoCoinUrl' => Helpers::url('/help', array('category_id' => 87)),
  85 + 'ordersUrl' => Helpers::url('/home/orders'),
  86 + 'returnGoodsUrl' => Helpers::url('/help', array('category_id' => 121)),
  87 + 'vipSum' => $amount,
  88 + 'vipUrl' => Helpers::url('/help', array('category_id' => 91)),
  89 + 'returnHomeUrl' => Helpers::url('/')
  90 + );
  91 +
  92 + } while (false);
  93 +
  94 + return self::$code;
  95 + }
  96 +}
  1 +<?php
  2 +
  3 +use Action\WebAction;
  4 +use Shopping\PayModel;
  5 +use Shopping\PaymentModel;
  6 +use WebPlugin\Pay\PayFactory;
  7 +use WebPlugin\Pay\Rspparams;
  8 +
  9 +/**
  10 + * 支付 同步通知页面
  11 + */
  12 +class PayreturnController extends WebAction
  13 +{
  14 + public function init() {
  15 + parent::init();
  16 + }
  17 +
  18 + /**
  19 + * 支付宝浏览器端返回
  20 + */
  21 + public function alipayreturnAction()
  22 + {
  23 + $payment = PayModel::getPaymentById(2);
  24 + $payService = PayFactory::factory($payment);
  25 + $res = $payService->parseResponse($_GET);
  26 + $dealResult = $this->payResultProc($res, 2);
  27 + $dealResult['payData'] = array('payWay' => '支付宝');
  28 + $this->commonShowResult($dealResult);
  29 + }
  30 +
  31 + /**
  32 + * 通用显示结果的方法
  33 + * @param array $dealResult
  34 + */
  35 + private function commonShowResult($dealResult)
  36 + {
  37 + $code = $dealResult['code'];
  38 + $view = 'wechatqrcodereturn';
  39 + $data = array(
  40 + 'headerData' => true,
  41 + 'payData' => $dealResult['payData']
  42 + );
  43 +
  44 + if ($code == 200) {
  45 + $view = 'index';
  46 + $data = array('payNotice' => $dealResult['data']);
  47 + }
  48 +
  49 + //头部导航
  50 + $this->setSimpleHeader();
  51 + $this->_view->display('../notice/' . $view, $data);
  52 + }
  53 +
  54 + /**
  55 + * 处理支付返回的数据
  56 + *
  57 + * @param Rspparams $payResult 支付返回的结果
  58 + * @param $payment 支付方式id
  59 + * @return array
  60 + */
  61 + private function payResultProc($payResult, $payment)
  62 + {
  63 + $result = array(
  64 + 'code' => 500,
  65 + 'message' => '支付失败'
  66 + );
  67 +
  68 + if ($payResult->payResult == 200) {
  69 + //支付成功
  70 + $result = PaymentModel::procOrderData($payResult, $payment);
  71 + }
  72 +
  73 + return $result;
  74 + }
  75 +}
@@ -4,6 +4,7 @@ use Action\WebAction; @@ -4,6 +4,7 @@ use Action\WebAction;
4 use Shopping\PayModel; 4 use Shopping\PayModel;
5 use WebPlugin\Helpers; 5 use WebPlugin\Helpers;
6 use LibModels\Web\Home\UserData; 6 use LibModels\Web\Home\UserData;
  7 +use WebPlugin\Cache;
7 /** 8 /**
8 * 支付相关的控制器 9 * 支付相关的控制器
9 * 10 *
@@ -29,11 +30,14 @@ class PayController extends WebAction @@ -29,11 +30,14 @@ class PayController extends WebAction
29 if (!$uid) { 30 if (!$uid) {
30 $this->go( Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN))) ); 31 $this->go( Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN))) );
31 } 32 }
32 - // 将用户UID存入session中以便支付成功回调使用  
33 - $this->setSession(self::SESSION_UID_KEY, $uid);  
34 -  
35 // 订单号 33 // 订单号
36 $orderCode = $this->get('order_code', $this->get('ordercode')); 34 $orderCode = $this->get('order_code', $this->get('ordercode'));
  35 +
  36 + if (USE_CACHE) {
  37 + // 将用户UID存入session中以便支付成功回调使用
  38 + $this->setSession(self::SESSION_UID_KEY, $uid);
  39 + Cache::set(self::SESSION_UID_KEY . $orderCode, $uid, 3600 * 10);
  40 + }
37 41
38 //支付宝快捷支付 42 //支付宝快捷支付
39 $alipayToken = $this->getSession('alipay_user_token'); 43 $alipayToken = $this->getSession('alipay_user_token');