Authored by 毕凯

Merge branch 'hotfix/payNotifyUrl'

Showing 40 changed files with 1436 additions and 520 deletions
... ... @@ -667,6 +667,22 @@ class WebAction extends Controller_Abstract
echo "alert(\"{$message}\");";
echo "</script>";
}
if ($expression === 'history.back()') {
$expression = '';
echo <<<EOF
<script language="javascript">
if (navigator.userAgent.indexOf('MSIE') >= 0 && history.length > 0) {
window.history.go( -1 );
} else if (history.length > 1) {
window.history.go( -1 );
} else {
window.opener = null;
window.close();
}
</script>
EOF;
}
if ($expression != '') {
echo "<script language=\"javascript\">\n";
echo $expression . "\n";
... ...
... ... @@ -496,5 +496,22 @@ class CartData
return Yohobuy::get(SearchData::getUrl('search'), $param);
}
/**
* 选择支付,校验时间间隔,插入数据
* @param string $uid
* @param string $orderCode
* @param int $payment 14:银联手机支付 15:支付宝手机 18:支付宝wap(wap) 19:微信支付 22:微信wap(wap) 26:QQ钱包手机支付
* @return type
*/
public static function savePrePayInfo($uid, $orderCode, $payment)
{
$param = Yohobuy::param();
$param['method'] = 'app.order.savePrePayInfo';
$param['uid'] = $uid;
$param['orderCode'] = $orderCode;
$param['payment'] = $payment;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -147,5 +147,4 @@ class OrderData
// 调用接口获得数据
return Yohobuy::post(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -218,5 +218,53 @@ class PayData
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 支付成功后--更新订单状态
* @param type string $orderCode 订单号
* @param type int $payment 支付方式
* @param type double $amount 金额(单位:元)
* @param type string $bankName 银行名称
* @param type string $bankCode 银行代码
* @param type string $tradeNo 交易流水号
* @param type string $bankBillNo 银行流水号
* @return type []
*/
public static function pcpayNotify($orderCode, $payment, $amount, $bankName = '', $bankCode = '', $tradeNo = '', $bankBillNo = '')
{
$param = Yohobuy::param();
$param['method'] = 'web.SpaceOrders.pcpayNotify';
$param['order_code'] = $orderCode;
$param['payment'] = $payment;
$param['bank_name'] = $bankName;
$param['bank_code'] = $bankCode;
$param['amount'] = $amount;
$param['trade_no'] = $tradeNo;
$param['bank_bill_no'] = $bankBillNo;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 支付成功后--支付确认接口
* @param type int $orderCode 订单号
* @param type int $paymentId 支付方式
* @param type int $uid 用户ID
* @return type []
*/
public static function payConfirm($orderCode, $paymentId, $uid)
{
// 构建必传参数
$param = Yohobuy::param();
$param['method'] = 'app.SpaceOrders.payConfirm';
$param['order_code'] = $orderCode;
$param['payment_id'] = $paymentId;
$param['uid'] = intval($uid);
$param['client_secret'] = Sign::getSign($param);
// 调用接口获得数据
return Yohobuy::post(Yohobuy::API_URL, $param);
}
}
\ No newline at end of file
... ...
... ... @@ -6,6 +6,7 @@ use DOMDocument;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\UdpLog;
class Service extends PayAbstract
{
... ... @@ -107,6 +108,7 @@ class Service extends PayAbstract
/* 返回示例
* http://www.yohobuy.com/pay/notice/aliexpressgatewayreturn?buyer_email=tds%40smartunite.com&buyer_id=2088302294447308&exterface=create_direct_pay_by_user&is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3I7xtEV5W65QRToFQ5fPrXsVxt12e%252FExCtC1XNiKnuRwupLaVLAR&notify_time=2011-06-11+07%3A48%3A10&notify_type=trade_status_sync&out_trade_no=1061003000&payment_type=1&seller_email=shop%40yoho.cn&seller_id=2088001550230585&subject=YOHO%E5%95%86%E5%93%81&total_fee=0.01&trade_no=2011061199833830&trade_status=TRADE_SUCCESS&sign=ca1c49f58d17eaa57aac308d0ac64434&sign_type=MD5
*/
UdpLog::info("【{$this->logProjectPrefix}-支付】,function:parseResponse,参数", $arrResponse);
if(isset($arrResponse['q'])){
unset($arrResponse['q']);
}
... ... @@ -129,6 +131,7 @@ class Service extends PayAbstract
$rsp->tradeNo = $arrResponse['trade_no'];
$rsp->bankBillNo = "";
}
UdpLog::info("【{$this->logProjectPrefix}-支付】,function:parseResponse,处理结果", $rsp);
return $rsp;
}
... ... @@ -177,13 +180,12 @@ class Service extends PayAbstract
ksort($arrResponse);
reset($arrResponse);
$sign = '';
foreach ($arrResponse AS $key=>$val)
{
if ($key != 'sign' && $key != 'sign_type' && $key != 'code')
{
$sign .= "$key=$val&";
}
}
foreach ($arrResponse AS $key => $val) {
if ($key === 'sign' || $key === 'sign_type' || $key === 'code' || $val === '') {
continue;
}
$sign .= "$key=$val&";
}
$sign = substr($sign, 0, -1) . $this->config->alipay_key;
return md5($sign) != $arrResponse['sign'] ? false : true;
... ...
... ... @@ -33,14 +33,14 @@ class Config
* Enter description here ...
* @var String
*/
var $notify_url = "notice/alibanknotice";
var $notify_url = "payment/alipay_notify";
/**
* 浏览器的返回
* Enter description here ...
* @var string
*/
var $return_url = "notice/alibankreturn";
var $return_url = "/pay/payreturn/alibankreturn";
/**
* 签名方式
... ... @@ -77,15 +77,5 @@ class Config
'ip_enable' => false,
'timestamp_enable' => false
);
/**
* @var string 日志目录
*/
var $logDir = '/Data/logs/pc_pay/alibank';
/**
* @var int 日志等级
*/
var $logLevel = 2; // 记录信息日志
}
... ...
... ... @@ -6,12 +6,13 @@ use DOMDocument;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
use WebPlugin\UdpLog;
use Api\Yohobuy;
use Plugin\Helpers;
class Service extends PayAbstract
{
public $config;
private $log;
public function __construct(array $paymentParams)
{
... ... @@ -21,8 +22,6 @@ class Service extends PayAbstract
$this->config->partner = $myConfig->merchant_id;
$this->config->alipay_key = $myConfig->merchant_key;
$this->config->sellerMail = $myConfig->merchant_other_code;
$this->log = new PhpLog($this->config->logDir, "PRC", $this->config->logLevel);
}
/**
... ... @@ -42,19 +41,19 @@ class Service extends PayAbstract
public function getPayRequestPars(Reqparams $params)
{
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
$loseTime = intval(($params->orderTime + 7200 - time()) / 60);
// $baseUrl = $this->getBaseNoticeUrl($params->isTest);
// $loseTime = intval(($params->orderTime + 7200 - time()) / 60);
// $loseTime = intval((strtotime(date("Y-m-d 10:00:00", strtotime("+1 day")))-time())/60);
UdpLog::info("【{$this->logProjectPrefix}-支付宝银行支付】,function:getPayRequestPars,参数", $params);
$parameter = array(
'service' => $this->config->service,
'partner' => $this->config->partner,
'_input_charset' => $this->config->input_charset,
'notify_url' => $baseUrl . $this->config->notify_url,
'return_url' => $baseUrl . $this->config->return_url,
'notify_url' => Yohobuy::SERVICE_URL . $this->config->notify_url,
'return_url' => Helpers::url($this->config->return_url),
/* 业务参数 */
'subject' => $params->goodsName,
'out_trade_no' => $params->orderCode . '_' . $params->paymentParameter,
'out_trade_no' => $params->orderCode,
'total_fee' => $params->totalFee / 100, //单位为元
'payment_type' => $this->config->payment_type,
'defaultbank' => $params->paymentParameter,
... ... @@ -112,36 +111,23 @@ class Service extends PayAbstract
/* 返回示例
* http://www.yohobuy.com/pay/notice/alipayreturn?buyer_email=tds%40smartunite.com&buyer_id=2088302294447308&exterface=create_direct_pay_by_user&is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3I7xtEV5W65QRToFQ5fPrXsVxt12e%252FExCtC1XNiKnuRwupLaVLAR&notify_time=2011-06-11+07%3A48%3A10&notify_type=trade_status_sync&out_trade_no=1061003000&payment_type=1&seller_email=shop%40yoho.cn&seller_id=2088001550230585&subject=YOHO%E5%95%86%E5%93%81&total_fee=0.01&trade_no=2011061199833830&trade_status=TRADE_SUCCESS&sign=ca1c49f58d17eaa57aac308d0ac64434&sign_type=MD5
*/
$this->log->LogInfo("===开始解析支付宝银行的回调参数===");
$this->log->LogInfo("-----回调参数为---");
$this->log->LogInfo(var_export($arrResponse, true));
UdpLog::info("【{$this->logProjectPrefix}-支付宝银行支付】,function:parseResponse,回调参数", $arrResponse);
if (isset($arrResponse['q'])) {
unset($arrResponse['q']);
}
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
$this->log->LogInfo("---验证支付宝银行的回调参数失败---");
//验证不成功
$rsp->payResult = -1;
} else {
$this->log->LogInfo("---验证支付宝银行的回调参数成功---");
$rsp->bankName = "";
$outTradeNo = $arrResponse["out_trade_no"];
// if(strlen($outTradeNo) > 9) {
// $outTradeNo = substr($outTradeNo, 2);
// }
//支付订单处理
$orderCodeArr = explode('_', $outTradeNo);
if (count($orderCodeArr) == 2) {
$rsp->orderCode = $orderCodeArr[0];
$rsp->bankName = $orderCodeArr[1];
} else {
$rsp->orderCode = $outTradeNo;
$rsp->bankName = "";
}
$rsp->orderCode = intval($outTradeNo);
$rsp->bankName = "";
$rsp->payResult = $this->convertResult($arrResponse["trade_status"]);
$rsp->payTime = isset($arrResponse["gmt_payment"]) ? $arrResponse["gmt_payment"] : time();
$rsp->totalFee = $arrResponse["total_fee"];
... ... @@ -150,11 +136,8 @@ class Service extends PayAbstract
$rsp->payOrderCode = $outTradeNo;
$rsp->tradeNo = $arrResponse['trade_no'];
$rsp->bankBillNo = $arrResponse['bank_seq_no'] ? $arrResponse['bank_seq_no'] : "";
$this->log->LogInfo('----支付宝银行回调处理结果为----');
$this->log->LogInfo(var_export($rsp, true));
}
UdpLog::info("【{$this->logProjectPrefix}-支付宝银行支付】,function:parseResponse,回调参数处理结果", $rsp);
return $rsp;
}
... ... @@ -203,9 +186,10 @@ class Service extends PayAbstract
reset($arrResponse);
$sign = '';
foreach ($arrResponse AS $key => $val) {
if ($key != 'sign' && $key != 'sign_type' && $key != 'code') {
$sign .= "$key=$val&";
if ($key === 'sign' || $key === 'sign_type' || $key === 'code' || $val === '') {
continue;
}
$sign .= "$key=$val&";
}
$sign = substr($sign, 0, -1) . $this->config->alipay_key;
... ...
... ... @@ -6,7 +6,7 @@ use DOMDocument;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\UdpLog;
class Service extends PayAbstract
{
... ... @@ -40,7 +40,7 @@ class Service extends PayAbstract
public function getPayRequestPars(Reqparams $params)
{
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
$loseTime = intval(($params->orderTime + 7200 -time())/60);
// $loseTime = intval(($params->orderTime + 7200 -time())/60);
// $loseTime = intval((strtotime(date("Y-m-d 10:00:00", strtotime("+1 day")))-time())/60); //第二天十点
$parameter = array(
'service' => $this->config->service,
... ... @@ -99,6 +99,7 @@ class Service extends PayAbstract
/* 返回示例
* http://www.yohobuy.com/pay/notice/alibarcodereturn?buyer_email=tds%40smartunite.com&buyer_id=2088302294447308&exterface=create_direct_pay_by_user&is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3I7xtEV5W65QRToFQ5fPrXsVxt12e%252FExCtC1XNiKnuRwupLaVLAR&notify_time=2011-06-11+07%3A48%3A10&notify_type=trade_status_sync&out_trade_no=1061003000&payment_type=1&seller_email=shop%40yoho.cn&seller_id=2088001550230585&subject=YOHO%E5%95%86%E5%93%81&total_fee=0.01&trade_no=2011061199833830&trade_status=TRADE_SUCCESS&sign=ca1c49f58d17eaa57aac308d0ac64434&sign_type=MD5
*/
UdpLog::info("【{$this->logProjectPrefix}-支付】,function:parseResponse,参数", $arrResponse);
if(isset($arrResponse['q'])){
unset($arrResponse['q']);
}
... ... @@ -122,6 +123,7 @@ class Service extends PayAbstract
$rsp->tradeNo = $arrResponse['trade_no'];
$rsp->bankBillNo = "";
}
UdpLog::info("【{$this->logProjectPrefix}-支付】,function:parseResponse,处理结果", $rsp);
return $rsp;
}
... ... @@ -167,19 +169,18 @@ class Service extends PayAbstract
*/
protected function checkResponse(array $arrResponse)
{
ksort($arrResponse);
reset($arrResponse);
$sign = '';
foreach ($arrResponse AS $key=>$val)
{
if ($key != 'sign' && $key != 'sign_type' && $key != 'code')
{
ksort($arrResponse);
reset($arrResponse);
$sign = '';
foreach ($arrResponse AS $key => $val) {
if ($key === 'sign' || $key === 'sign_type' || $key === 'code' || $val === '') {
continue;
}
$sign .= "$key=$val&";
}
}
$sign = substr($sign, 0, -1) . $this->config->alipay_key;
$sign = substr($sign, 0, -1) . $this->config->alipay_key;
return md5($sign) != $arrResponse['sign'] ? false : true;
return md5($sign) != $arrResponse['sign'] ? false : true;
}
}
\ No newline at end of file
... ...
... ... @@ -4,7 +4,7 @@ namespace WebPlugin\Pay\Alimobilemini;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
use WebPlugin\UdpLog;
/**
* 手机支付返回
... ... @@ -14,7 +14,6 @@ use WebPlugin\PhpLog;
class Service extends PayAbstract
{
public $config;
private $log;
private $utils;
... ... @@ -23,8 +22,6 @@ class Service extends PayAbstract
$this->logProjectPrefix = 'alimobilemini';
$this->utils = new Utils();
$this->config = new Config();
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
... ... @@ -48,7 +45,7 @@ class Service extends PayAbstract
// $datastr=implode("&", $data);
// ##################################
UdpLog::info("【{$this->logProjectPrefix}-支付宝极简支付】,function:parseResponse,参数", $arrResponse);
$isVerify = $this->utils->getSignVeryfy($arrResponse);
if ($isVerify) {
//验证成功
... ... @@ -62,16 +59,11 @@ class Service extends PayAbstract
$rsp->payOrderCode = $arrResponse['out_trade_no'];
$rsp->tradeNo = $arrResponse['trade_no'];
$rsp->bankBillNo = "";
$this->log->LogInfo(var_export($arrResponse, true));
$this->log->LogInfo('======alimobilemini成功===');
} else {
//不成功
$rsp->payResult = -1;
$this->log->LogInfo(var_export($arrResponse, true));
$this->log->LogInfo('======alimobilemini失败===订单号----->' . $arrResponse['out_trade_no']);
}
UdpLog::info("【{$this->logProjectPrefix}-支付宝极简支付】,function:parseResponse,处理结果", $rsp);
return $rsp;
}
... ...
... ... @@ -36,14 +36,14 @@ class Config
* Enter description here ...
* @var String
*/
var $notify_url = "notice/alipaynotice";
var $notify_url = "payment/alipay_notify";
/**
* 浏览器的返回
* Enter description here ...
* @var string
*/
var $return_url = "notice/alipayreturn";
var $return_url = "/pay/payreturn/alipayreturn";
/**
* 签名方式
... ... @@ -80,14 +80,4 @@ class Config
'ip_enable' => false,
'timestamp_enable' => false
);
/**
* @var string 日志目录
*/
var $logDir = '/Data/logs/pc_pay/alipay';
/**
* @var string 日志等级
*/
var $logLevel = 2; // 记录信息日志
}
\ No newline at end of file
... ...
... ... @@ -5,13 +5,14 @@ namespace WebPlugin\Pay\Alipay;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
use WebPlugin\UdpLog;
use Api\Yohobuy;
use Plugin\Helpers;
class Service extends PayAbstract
{
public $config;
private $log;
public function __construct(array $paymentParams)
{
... ... @@ -21,8 +22,6 @@ class Service extends PayAbstract
$this->config->partner = $myConfig->merchant_id;
$this->config->alipay_key = $myConfig->merchant_key;
$this->config->sellerMail = $myConfig->merchant_other_code;
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
/**
... ... @@ -46,19 +45,16 @@ class Service extends PayAbstract
*/
public function getPayRequestPars(Reqparams $params)
{
$this->log->LogInfo("===开始处理支付宝的请求参数===");
$this->log->LogInfo("-----请求参数为---");
$this->log->LogInfo(var_export($params, true));
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
UdpLog::info("【{$this->logProjectPrefix}-支付宝支付】,function:getPayRequestPars,参数", $params);
// $baseUrl = $this->getBaseNoticeUrl($params->isTest);
// $loseTime = intval(($params->orderTime + 7200 -time())/60);
// $loseTime = intval((strtotime(date("Y-m-d 10:00:00", strtotime("+1 day")))-time())/60); //第二天十点
$parameter = array(
'service' => $this->config->service,
'partner' => $this->config->partner,
'_input_charset' => $this->config->input_charset,
'notify_url' => $baseUrl . $this->config->notify_url,
'return_url' => $baseUrl . $this->config->return_url,
'notify_url' => Yohobuy::SERVICE_URL . $this->config->notify_url,
'return_url' => Helpers::url($this->config->return_url),
/* 业务参数 */
'subject' => $params->goodsName,
'out_trade_no' => $params->orderCode,
... ... @@ -101,9 +97,7 @@ class Service extends PayAbstract
'reqType' => 'get'
);
$this->log->LogInfo('----支付宝请求处理结果为----');
$this->log->LogInfo(var_export($result, true));
UdpLog::info("【{$this->logProjectPrefix}-支付宝支付】,function:getPayRequestPars,请求处理结果", $result);
return $result;
}
... ... @@ -112,20 +106,15 @@ class Service extends PayAbstract
/* 返回示例
* http://www.yohobuy.com/pay/notice/alipayreturn?buyer_email=tds%40smartunite.com&buyer_id=2088302294447308&exterface=create_direct_pay_by_user&is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3I7xtEV5W65QRToFQ5fPrXsVxt12e%252FExCtC1XNiKnuRwupLaVLAR&notify_time=2011-06-11+07%3A48%3A10&notify_type=trade_status_sync&out_trade_no=1061003000&payment_type=1&seller_email=shop%40yoho.cn&seller_id=2088001550230585&subject=YOHO%E5%95%86%E5%93%81&total_fee=0.01&trade_no=2011061199833830&trade_status=TRADE_SUCCESS&sign=ca1c49f58d17eaa57aac308d0ac64434&sign_type=MD5
*/
$this->log->LogInfo("===开始解析支付宝的回调参数===");
$this->log->LogInfo("-----回调参数为---");
$this->log->LogInfo(var_export($arrResponse, true));
UdpLog::info("【{$this->logProjectPrefix}-支付宝支付】,function:parseResponse,回调参数", $arrResponse);
if (isset($arrResponse['q'])) {
unset($arrResponse['q']);
}
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
$this->log->LogInfo("-----支付宝回调参数验证签名失败---");
//验证不成功
$rsp->payResult = -1;
} else {
$this->log->LogInfo("-----支付宝回调参数验证签名成功---");
$rsp->bankName = "";
$outTradeNo = $arrResponse["out_trade_no"];
$rsp->orderCode = $outTradeNo;
... ... @@ -139,9 +128,7 @@ class Service extends PayAbstract
$rsp->bankBillNo = "";
}
$this->log->LogInfo("-----解析支付宝回调参数的结果为---");
$this->log->LogInfo(var_export($rsp, true));
UdpLog::info("【{$this->logProjectPrefix}-支付宝支付】,function:parseResponse,回调参数的结果", $arrResponse);
return $rsp;
}
... ... @@ -190,9 +177,10 @@ class Service extends PayAbstract
reset($arrResponse);
$sign = '';
foreach ($arrResponse AS $key => $val) {
if ($key != 'sign' && $key != 'sign_type' && $key != 'code') {
$sign .= "$key=$val&";
if ($key === 'sign' || $key === 'sign_type' || $key === 'code' || $val === '') {
continue;
}
$sign .= "$key=$val&";
}
$sign = substr($sign, 0, -1) . $this->config->alipay_key;
... ...
... ... @@ -62,15 +62,4 @@ class Config
* @var unknown_type
*/
var $payType = 0; //非直连为0
/**
* @var string 日志目录
*/
var $logDir = '/Data/logs/pc_pay/allinpay';
/**
* @var string 日志等级
*/
var $logLevel = 2; // 记录信息日志
}
\ No newline at end of file
... ...
... ... @@ -5,12 +5,11 @@ namespace WebPlugin\Pay\Allinpay;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
use WebPlugin\UdpLog;
class Service extends PayAbstract
{
public $config;
private $log;
public function __construct(array $paymentParams)
{
... ... @@ -19,8 +18,6 @@ class Service extends PayAbstract
$myConfig = json_decode($paymentParams["pay_params"]);
$this->config->merchantId = $myConfig->merchant_id;
$this->config->merchantKey = $myConfig->merchant_key;
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
/**
... ... @@ -67,18 +64,11 @@ class Service extends PayAbstract
*/
public function parseResponse(array $arrResponse)
{
$this->log->LogInfo("===开始处理通联支付的回调参数===");
$this->log->LogInfo("-----回调参数为---");
$this->log->LogInfo(var_export($arrResponse, true));
UdpLog::info("【{$this->logProjectPrefix}-通联支付】,function:parseResponse,参数", $arrResponse);
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
$this->log->LogInfo("-----验证通联支付回调参数失败---");
$rsp->payResult = -1;
} else {
$this->log->LogInfo("-----验证通联支付回调参数成功---");
$rsp->bankName = "";
$rsp->orderCode = $arrResponse["orderNo"];
$rsp->payResult = $this->convertResult($arrResponse["payResult"]);
... ... @@ -90,7 +80,7 @@ class Service extends PayAbstract
$rsp->tradeNo = "";
$rsp->bankBillNo = "";
}
UdpLog::info("【{$this->logProjectPrefix}-通联支付】,function:parseResponse,回调参数处理结果", $arrResponse);
return $rsp;
}
... ...
... ... @@ -5,7 +5,7 @@ namespace WebPlugin\Pay\Chinabank;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\UdpLog;
class Service extends PayAbstract
{
... ... @@ -53,6 +53,7 @@ class Service extends PayAbstract
* @return void|QCPay_Utils_Rspparams
*/
function parseResponse(Array $arrResponse){
UdpLog::info("【{$this->logProjectPrefix}-支付】,function:parseResponse,参数", $arrResponse);
// {"v_md5all":"8F7E33B3759DC55F0E776120B5C16A55","v_md5info":"e42e938417bd01d8eb69235c1ebe9be3","remark1":"110610002420","v_pmode":null,"remark2":"","v_idx":"5607406315","v_md5":"2E9135262B2729B23B049EBBE80E5183","v_pstatus":"20","v_pstring":null,"v_md5str":"2E9135262B2729B23B049EBBE80E5183","v_md5money":"9330e642e14622f4993ce5a6e9781bbd","v_moneytype":"CNY","v_oid":"110610002420","v_amount":"0.01"}
//把中文进行转码
$arrResponse["v_pmode"] = mb_convert_encoding($arrResponse["v_pmode"], "UTF-8", "GBK");
... ... @@ -75,6 +76,7 @@ class Service extends PayAbstract
$rsp->tradeNo = "";
$rsp->bankBillNo = "";
}
UdpLog::info("【{$this->logProjectPrefix}-支付】,function:parseResponse,解析结果", $rsp);
return $rsp;
}
... ...
... ... @@ -5,13 +5,11 @@ namespace WebPlugin\Pay\Shengpay;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
use WebPlugin\UdpLog;
class Service extends PayAbstract
{
public $config;
private $log;
public function __construct(array $paymentParams)
{
... ... @@ -20,8 +18,6 @@ class Service extends PayAbstract
$myConfig = json_decode($paymentParams["pay_params"]);
$this->config->merchant_no = $myConfig->merchant_id;
$this->config->merchant_key = $myConfig->merchant_key;
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
/**
... ... @@ -30,10 +26,7 @@ class Service extends PayAbstract
*/
public function getPayRequestPars(Reqparams $params)
{
$this->log->LogInfo("===开始处理盛付通的请求参数===");
$this->log->LogInfo("-----请求参数为---");
$this->log->LogInfo(var_export($params, true));
UdpLog::info("【{$this->logProjectPrefix}-支付】,function:getPayRequestPars,参数", $params);
$bankCode = $params->paymentParameter == 'platform' ? '' : $params->paymentParameter;
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
... ... @@ -60,7 +53,7 @@ class Service extends PayAbstract
'pars' => $parameters,
'reqType' => 'post'
);
UdpLog::info("【{$this->logProjectPrefix}-支付】,orderCode:{$params->orderCode},function:getPayRequestPars,处理结果", $result);
return $result;
}
... ... @@ -108,19 +101,12 @@ class Service extends PayAbstract
*/
function parseResponse(Array $arrResponse)
{
$this->log->LogInfo("===开始处理盛付通的回调参数===");
$this->log->LogInfo("-----回调参数为---");
$this->log->LogInfo(var_export($arrResponse, true));
UdpLog::info("【{$this->logProjectPrefix}-支付】,function:parseResponse,参数", $arrResponse);
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
$this->log->LogInfo("-----验证盛付通回调参数失败---");
//验证不成功
$rsp->payResult = -1;
} else {
$this->log->LogInfo("-----验证盛付通回调参数成功---");
$rsp->bankName = "";
$rsp->orderCode = $arrResponse["OrderNo"];
$rsp->payResult = $this->convertResult($arrResponse["Status"]);
... ... @@ -132,7 +118,7 @@ class Service extends PayAbstract
$rsp->tradeNo = "";
$rsp->bankBillNo = "";
}
UdpLog::info("【{$this->logProjectPrefix}-支付】,function:parseResponse,处理结果", $rsp);
return $rsp;
}
... ...
... ... @@ -5,13 +5,12 @@ namespace WebPlugin\Pay\Tenpay;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
use WebPlugin\UdpLog;
class Service extends PayAbstract
{
public $config;
private $log;
/**
* Service constructor.
... ... @@ -24,8 +23,6 @@ class Service extends PayAbstract
$myConfig = json_decode($paymentParams["pay_params"]);
$this->config->bargainor_id = $myConfig->merchant_id;
$this->config->sp_key = $myConfig->merchant_key;
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
/**
... ... @@ -34,10 +31,7 @@ class Service extends PayAbstract
*/
public function getPayRequestPars(Reqparams $params)
{
$this->log->LogInfo("===开始处理财付通的请求参数===");
$this->log->LogInfo("-----请求参数为---");
$this->log->LogInfo(var_export($params, true));
UdpLog::info("【{$this->logProjectPrefix}-支付】,function:getPayRequestPars,参数", $params);
parent::getPayRequestPars($params);
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
... ... @@ -65,7 +59,7 @@ class Service extends PayAbstract
'pars' => $sign_text,
'reqType' => 'get'
);
UdpLog::info("【{$this->logProjectPrefix}-支付】,ordercode:{$params->orderCode},function:getPayRequestPars,处理结果", $result);
return $result;
}
... ... @@ -76,10 +70,7 @@ class Service extends PayAbstract
*/
public function parseResponse(array $arrResponse)
{
$this->log->LogInfo("===开始处理财付通的回调参数===");
$this->log->LogInfo("-----回调参数为---");
$this->log->LogInfo(var_export($arrResponse, true));
UdpLog::info("【{$this->logProjectPrefix}-支付】,function:parseResponse,参数", $arrResponse);
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
//验证不成功
... ... @@ -96,6 +87,7 @@ class Service extends PayAbstract
$rsp->tradeNo = "";
$rsp->bankBillNo = "";
}
UdpLog::info("【{$this->logProjectPrefix}-支付】,function:parseResponse,处理结果", $rsp);
return $rsp;
}
... ...
... ... @@ -5,12 +5,13 @@ namespace WebPlugin\Pay\Unionpayweb;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
use WebPlugin\UdpLog;
use WebPlugin\Helpers;
use Api\Yohobuy;
class Service extends PayAbstract
{
private $merId;
private $log;
public function __construct(array $paymentParams)
{
... ... @@ -19,7 +20,6 @@ class Service extends PayAbstract
include_once 'Func/common.php';
include_once 'Func/secureUtil.php';
$this->log = new PhpLog(SDK_LOG_FILE_PATH, "PRC", SDK_LOG_LEVEL);
$this->merId = array(
'mobile' => '898111453110482',//手机支付
'pc_nocard' => '898111453110464',//无卡支付
... ... @@ -35,22 +35,17 @@ class Service extends PayAbstract
*/
public function parseResponse(array $package)
{
$this->log->LogInfo("===开始解析银联支付的回调参数===");
$this->log->LogInfo("===回调参数为===");
$this->log->LogInfo(var_export($package, true));
UdpLog::info("【{$this->logProjectPrefix}-银联支付】,function:parseResponse,参数", $package);
$verify = false;
$responseData = new Rspparams();
if (!isset($package['respCode']) || $package['respCode'] !== '00') {
$this->log->LogInfo('银联支付返回码有误');
$responseData->payResult = -1;
return $responseData;
}
if (isset($package['signature'])) { // TODO isset($package['signature']) && verify($package)验证签名待做
$verify = true;
$this->log->LogInfo('银联支付验签成功');
}
if ($verify) {
... ... @@ -68,9 +63,7 @@ class Service extends PayAbstract
} else {
$responseData->payResult = -1;
}
$this->log->LogInfo("===银联支付的回调参数处理结果为===");
$this->log->LogInfo(var_export($responseData, true));
UdpLog::info("【{$this->logProjectPrefix}-银联支付】,function:parseResponse,处理结果", $responseData);
return $responseData;
}
... ... @@ -85,8 +78,8 @@ class Service extends PayAbstract
'txnType' => '01', //交易类型
'txnSubType' => '01', //交易子类
'bizType' => '000201', //业务类型
'frontUrl' => $front_notify_url, //前台通知地址
'backUrl' => SDK_BACK_NOTIFY_URL, //后台通知地址
'frontUrl' => $front_notify_url, //前台通知地址--同步地址
'backUrl' => SDK_BACK_NOTIFY_URL,//后台通知地址--异步地址
'signMethod' => '01', //签名方法
'channelType' => '07', //渠道类型,07-PC,08-手机
'accessType' => '0', //接入类型
... ... @@ -108,8 +101,7 @@ class Service extends PayAbstract
'reqType' => 'post'
);
$this->log->LogInfo(var_export($requestParams, true));
UdpLog::info("【{$this->logProjectPrefix}-银联支付】,orderCode:{$params->orderCode},function:getPayRequestPars,处理结果", $result);
return $result;
}
... ...
... ... @@ -8,7 +8,8 @@ use WebPlugin\Pay\Rspparams;
use WebPlugin\Pay\Signature;
use WebPlugin\Pay\weixin\lib\WxPayApi;
use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
use WebPlugin\PhpLog;
use WebPlugin\UdpLog;
use WebPlugin\Helpers;
class Service extends PayAbstract
{
... ... @@ -19,7 +20,6 @@ class Service extends PayAbstract
private $appKey;
private $privateKey;
private $payCurl;
private $log;
public function __construct(array $paymentParams)
{
... ... @@ -30,15 +30,13 @@ class Service extends PayAbstract
$this->appKey = $this->config->app_key;
$this->privateKey = $this->config->private_key;
$this->paymentCode = $paymentParams['id'];
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
public function getPayRequestPars(Reqparams $params)
{
$this->orderCode = $params->orderCode;
$result = array(
'pay_url' => $this->config->payment_url,
'pay_url' => Helpers::url('/pay/wechatqrcode'),
'pars' => 'order_code=' . $this->orderCode . '&payment_code=' . $this->paymentCode,
'reqType' => 'get'
);
... ... @@ -53,10 +51,7 @@ class Service extends PayAbstract
*/
public function pay(array $orderInfo)
{
$this->log->LogInfo("===开始处理微信扫码支付的请求参数===");
$this->log->LogInfo("-----请求参数为---");
$this->log->LogInfo(var_export($orderInfo, true));
UdpLog::info("【{$this->logProjectPrefix}-微信支付】,function:pay,参数", $orderInfo);
//生成签名
$this->orderCode = $orderInfo['order_code'];
$payParams = array(
... ... @@ -84,11 +79,8 @@ class Service extends PayAbstract
'pars' => trim($pars, '&')
);
$this->log->LogInfo("===开始处理微信扫码支付的支付地址===");
$this->log->LogInfo("-----支付地址数据为---");
$this->log->LogInfo(var_export($payUrlInfo, true));
$payUrl = $payUrlInfo['pay_url'] . '?' . $payUrlInfo['pars'];
UdpLog::info("【{$this->logProjectPrefix}-微信支付】,order_code:{$orderInfo['order_code']},function:pay,结果", $payUrl);
return array('pay_url' => $payUrl);
}
... ... @@ -98,17 +90,14 @@ class Service extends PayAbstract
/* 返回示例
* http://www.yohobuy.com/pay/notice/wechatqrcodereturn?ordercode=93465435
*/
$this->log->LogInfo("===开始查询微信扫码支付的结果===");
UdpLog::info("{$this->logProjectPrefix}-微信支付】,function:parseResponse,参数", $data);
// 组装微信支付的订单号
$tradeNo = 'YOHOBuy_' . $data['orderCode'];
$input = new WxPayOrderQuery();
$input->SetOut_trade_no($tradeNo);
$result = WxPayApi::orderQuery($input);
$this->log->LogInfo("===查询微信扫码支付的结果结束,结果为===");
$this->log->LogInfo(var_export($result, true));
UdpLog::info("【{$this->logProjectPrefix}-微信支付】,orderCode:{$data['orderCode']},function:parseResponse,组装微信支付的订单号", $result);
$rsp = new Rspparams();
// 支付成功
... ... @@ -124,13 +113,10 @@ class Service extends PayAbstract
$rsp->tradeNo = $result["out_trade_no"];
$rsp->bankBillNo = $result['bank_type'];
} else {
$this->log->LogInfo("===微信扫码支付失败===");
$rsp->payResult = -1;
}
$this->log->LogInfo("===微信扫码支付回调参数解析结果为===");
$this->log->LogInfo(var_export($rsp, true));
UdpLog::info("{$this->logProjectPrefix}-微信支付】,orderCode:{$data['orderCode']},function:parseResponse,处理结果", $rsp);
return $rsp;
}
... ...
... ... @@ -7,18 +7,13 @@ use LibModels\Web\Product\PayData;
use WebPlugin\Pay\weixin\lib\WxPayApi;
use WebPlugin\Pay\weixin\lib\WxPayNotify;
use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
use WebPlugin\PhpLog;
use WebPlugin\UdpLog;
class PayNotifyCallBack extends WxPayNotify
{
// 向ERP提交订单状态有关接口调用日志和更新订单状态有关接口调用日志
const ORDER_STATUS_LOG = '/Data/logs/pc_pay/order_status';
// 日志等级,2表示记录信息等级的日志
const LOG_LEVEL = 2;
// 获取微信订单中的订单号需要截取的开始位置
// 获取微信订单中的orderCode需要截取的开始位置
const ORDER_CODE_START = 8;
private $log = null;
private $_uid;
/**
... ... @@ -27,8 +22,6 @@ class PayNotifyCallBack extends WxPayNotify
*/
public function __construct($uid)
{
// 初始化日志
$this->log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$this->_uid = $uid;
}
... ... @@ -38,12 +31,9 @@ class PayNotifyCallBack extends WxPayNotify
{
$input = new WxPayOrderQuery();
$input->SetTransaction_id($transaction_id);
$this->log->LogInfo('微信扫码支付交易号:' . $transaction_id);
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,function:Queryorder,微信扫码支付交易号", $transaction_id);
$result = WxPayApi::orderQuery($input);
$this->log->LogInfo('begin PayNotifyCallBack->Queryorder');
$this->log->LogInfo('===开始查询微信扫码订单=====');
$this->log->LogInfo(var_export($result, true));
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,function:Queryorder,扫码订单结果", $result);
if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") {
$orderCode = substr($result['out_trade_no'], self::ORDER_CODE_START);
... ... @@ -54,33 +44,17 @@ class PayNotifyCallBack extends WxPayNotify
$tradeNo = $result['out_trade_no'];
$bankBillNo = $result['bank_type'];
$this->log->LogInfo('===[' . $orderCode . ']===');
$this->log->LogInfo('==[' . $orderCode . ']=开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');
$this->log->LogInfo('==[' . $orderCode . ']=请求参数为orderCode=' . $orderCode . '===');
// ERP提交订单状态
$erpReturn = PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $orderCode, $tradeNo, $bankBillNo);
$this->log->LogInfo('==[' . $orderCode . ']=结束调用ERP提交订单状态接口,返回结果为===');
$this->log->LogInfo(var_export($erpReturn, true));
$this->log->LogInfo('==[' . $orderCode . ']=开始调用获取订单详情方式接口,接口方法为app.SpaceOrders.detail===');
$orderInfo = OrderData::getOrderDetail('', $orderCode);
$this->log->LogInfo('==[' . $orderCode . ']=结束调用获取订单详情方式接口,返回结果为===');
$this->log->LogInfo(var_export($orderInfo, true));
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,orderCode:{$orderCode},function:Queryorder,订单详情", $orderInfo);
if (!isset($orderInfo['data']) || empty($orderInfo['data'])) {
$this->log->LogInfo('==[' . $orderCode . ']=微信支付状态同步中未获取到订单详情信息===');
UdpLog::error("【{$this->logProjectPrefix}-微信扫码支付】,orderCode:{$orderCode},function:Queryorder,微信支付状态同步中未获取到订单详情信息", $orderInfo);
return false;
}
$this->log->LogInfo('==[' . $orderCode . ']=开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');
$this->log->LogInfo('==[' . $orderCode . ']=请求参数为orderId=' . $orderInfo['data']['order_id'] . 'uid=' . $this->_uid . '===');
// 更新订单的状态
$updateOrderStatus = PayData::updateOrderStatus($orderInfo['data']['order_id'], $this->_uid, $payment, 'Y', $bankCode);
$this->log->LogInfo('==[' . $orderCode . ']=结束调用更新订单状态接口,返回结果为===');
$this->log->LogInfo(var_export($updateOrderStatus, true));
$this->log->LogInfo('==[' . $orderCode . ']=微信扫码订单支付成功===');
//更新订单状态
$updateOrderStatus = PayData::pcpayNotify($orderCode, $payment, $amount, $bankName, $bankCode, $tradeNo, $bankBillNo);
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,orderCode:{$orderCode},function:Queryorder,更新订单状态结果", $updateOrderStatus);
return true;
}
... ... @@ -90,23 +64,19 @@ class PayNotifyCallBack extends WxPayNotify
//重写回调处理函数
public function NotifyProcess($data, &$msg)
{
$this->log->LogInfo('begin notifyProcess');
$this->log->LogInfo(var_export($data, true));
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,function:NotifyProcess,参数", $data);
if (!array_key_exists("transaction_id", $data)) {
$msg = "输入参数不正确";
$this->log->LogInfo('=====微信扫码支付通知结果为:' . $msg . '=====');
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,function:NotifyProcess,输入参数不正确", $data);
return false;
}
//查询订单,判断订单真实性
if (!$this->Queryorder($data["transaction_id"])) {
$msg = "订单查询失败";
$this->log->LogInfo('=====微信扫码支付通知结果为:' . $msg . '=====');
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,function:NotifyProcess,订单查询失败", $data);
return false;
}
$this->log->LogInfo('=====微信扫码支付通知结果为:' . $msg . '=====');
return true;
}
... ...
... ... @@ -2,7 +2,7 @@
namespace WebPlugin\Pay\weixin\lib;
use WebPlugin\PhpLog;
use Api\Yohobuy;
/**
*
* 接口访问类,包含所有微信支付API列表的封装,类中方法为static方法,
... ... @@ -48,10 +48,8 @@ class WxPayApi
throw new WxPayException("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
}
//异步通知url未设置,则使用配置文件中的url
if (!$inputObj->IsNotify_urlSet()) {
$inputObj->SetNotify_url(WxPayConfig::NOTIFY_URL); //异步通知url
}
//异步通知url
$inputObj->SetNotify_url(Yohobuy::SERVICE_URL . 'payment/weixin_notify'); //异步通知url
$inputObj->SetAppid(WxPayConfig::APPID); //公众账号ID
$inputObj->SetMch_id(WxPayConfig::MCHID); //商户号
... ... @@ -547,7 +545,7 @@ class WxPayApi
curl_setopt($ch, CURLOPT_PROXYPORT, WxPayConfig::CURL_PROXY_PORT);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //严格校验
//设置header
curl_setopt($ch, CURLOPT_HEADER, FALSE);
... ...
<?php
namespace WebPlugin;
/**
* 发送短信
*/
class SendSms
{
private static $url = 'http://www.ztsms.cn/sendSms.do';
private static $username = 'youhuo';
private static $password = '22b5d8454c5cea4d972b1b4958227d8f';
private static $productid = '333333';
protected static $code = array(
'-1' => '用户名或者密码不正确或用户禁用或者是管理账户',
'1' => '发送短信成功',
'0' => '发送短信失败',
'2' => '余额不够或扣费错误',
'3' => '扣费失败异常',
'5' => '短信定时成功',
'6' => '有效号码为空',
'7' => '短信内容为空',
'8' => '无签名,必须,格式:【签名】',
'9' => '没有Url提交权限',
'10' => '发送号码过多,最多支持2000个号码',
'11' => '产品ID异常或产品禁用',
'12' => '参数异常',
'15' => 'Ip验证失败',
'19' => '短信内容过长,最多支持500个,或提交编码异常导致',
);
/**
* 发送普通短信
* @param type array $mobiles 手机号
* @param type string $content 内容
* @return type []
*/
public static function ordinarySms($mobiles, $content)
{
if (empty($mobiles)) {
return self::$code[6];
}
if (empty($content)) {
return self::$code[7];
}
if (is_string($mobiles)) {
$mobiles = array($mobiles);
}
$mobiles = array_unique($mobiles);
$data = array(
'mobile' => implode(',', $mobiles),
'content' => $content
);
$result = self::post($data);
if (isset($result[0]) && $result[0] * 1 === 1) {
return array('code' => 200, 'msg' => self::$code[$result[0]]);
}
return array('code' => 400, 'msg' => isset(self::$code[$result[0]]) ? self::$code[$result[0]] : '发送失败');
}
private static function post($data = array(), $timeout = 50)
{
$ch = curl_init(self::$url);
$data['username'] = self::$username;
$data['password'] = self::$password;
$data['productid'] = self::$productid;
$data['content'] = $data['content'];
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 YOHOWEB');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
if (!empty($data)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data, null, '&'));
}
$result = curl_exec($ch);
if (!empty($result)) {
$result = explode(',', $result);
}
curl_close($ch);
unset($ch, $data);
return $result;
}
}
... ...
<?php
/**
* Created by IntelliJ IDEA.
* User: hbomb_000
* Date: 2016/5/5
* Time: 18:17
*/
namespace WebPlugin;
/**
* Class UdpLog
* @useage:
* UdpLog::info('get payment list begin',array('order_code'=>123231));
* @package WebPlugin
*/
class UdpLog
{
//influxdb url
public static $url = 'influxdb.yohobuy.com';
//influxdb port
public static $port = '4444';
//influxdb measurement
public static $measurement = 'php_log';
public static $filePath = '/Data/logs/';
const RECORD_MODE_FILE = 'FILE';
const RECORD_MODE_UDP = 'UDP';
const RECORD_MODE = 'FILE';//mode: FILE | UDP
/**
* proc line and send log to influxdb
* @param $level
* @param $message
* @param $meta
*/
private static function procLog($level, $message, $debugInfo, $meta = '') {
date_default_timezone_set('PRC');
$level = str_replace(__CLASS__.'::','',$level);
$file = $debugInfo[0]["file"];
$line = $debugInfo[0]["line"];
$string = '';
//make tags
$tags = array(
'time' => date('Y-m-d H:i:s',time()),
'level' => $level,
'host'=> gethostname(),
'file'=> $file,
'line'=> $line,
'message' => $message,
'meta' => serialize($meta)
);
//make a line
$string = implode('|', $tags); //format: time|level|host|file|line|message|meta
if(self::RECORD_MODE == self::RECORD_MODE_UDP) {
self::send($string);
}
else if(self::RECORD_MODE == self::RECORD_MODE_FILE) {
self::fileLog($level, $string);
}
}
/**
* 文件日志记录
*
* @param string $level
* @param string $message
*/
private static function fileLog($level, $message)
{
$filename = $level . '.log'; //日志文件
$logFile = self::createPath(self::$filePath, $filename);
if (!file_exists(self::$filePath))//判断文件路径是否存在
{
if (!empty(self::$filePath))//判断路径是否为空
{
if (!(self::createDir(self::$filePath))) {
return false;
}
if (!is_writable($logFile)) {
return false;
}
}
}
@error_log($message."\r\n", 3, $logFile);
}
/**
* 作用:创建目录
* 输入:要创建的目录
* 输出:true | false
*/
private static function createDir($dir)
{
return is_dir($dir) or (self::createDir(dirname($dir)) and mkdir($dir, 0777));
}
/**
* 作用:构建路径
* 输入:文件的路径,要写入的文件名
* 输出:构建好的路径字串
*/
private static function createPath($dir, $filename)
{
if (empty($dir)) {
return $filename;
} else {
return $dir . "/" . $filename;
}
}
/**
* send by udp
* @param $string
*/
private static function send($string) {
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$len = strlen($string);
socket_sendto($sock, $string, $len, 0, self::$url, self::$port);
socket_close($sock);
}
/**
* info log
* @param $message
* @param mixed $meta
*/
public static function info($message, $meta = '') {
self::procLog(__METHOD__, $message, debug_backtrace(), $meta);
}
/**
* warn log
* @param $message
* @param mixed $meta
*/
public static function warn($message, $meta = '') {
self::procLog(__METHOD__, $message, debug_backtrace(), $meta);
}
/**
* error log
* @param $message
* @param mixed $meta
*/
public static function error($message, $meta = '') {
self::procLog(__METHOD__, $message, debug_backtrace(), $meta);
}
/**
* debug log
* @param $message
* @param mixed $meta
*/
public static function debug($message, $meta = '') {
self::procLog(__METHOD__, $message, debug_backtrace(), $meta);
}
}
\ No newline at end of file
... ...
{{> layout/header}}
<div class="pay-notice-page yoho-page">
{{# payNotice}}
<h1>
<i class="ok-icon"></i>
<span class="font-red">恭喜您,购买完成!</span>
您已成功支付
<span class="font-red">{{pay}}</span>
元!
</h1>
<div class="order-info">
<ul class="order-table-header table-row">
<li class="order-num">订单号</li>
<li>实际支付金额</li>
<li>支付方式</li>
<li>获得YOHO币</li>
<li>获得VIP累计金额</li>
</ul>
<ul class="table-row">
<li class="order-num">
<a class="notice-link" href="{{checkOrderUrl}}">{{orderNum}}</a>
</li>
<li class="pay font-red">{{pay}}</li>
<li class="pay-mode">{{payMode}}</li>
<li class="yoho-coin">
<em class="font-red">{{currency}}</em>
<a class="notice-link" href="{{yohoCoinUrl}}">YOHO币能做什么</a>
</li>
<li class="vip">
<em class="font-red">{{vipSum}}</em>
<a class="notice-link" href="{{vipUrl}}">查看VIP特权</a>
</li>
</ul>
</div>
<div class="notice-tip">
1.每天1500以前成功付款的订单将在当天发货,1500-0000成功付款的订单将在第二天发货。<br>
2.当订单发货后,您可以登录<a href="{{ordersUrl}}" class="notice-link" target="_blank">订单中心</a>查询快递发货详情。<br>
3.有货网支持"开箱验货""15天退换货保障"收货后请当面验货,如果发现商品有任何问题请致电客服电话400-889-9646,<a href="{{returnGoodsUrl}}" class="notice-link"
target="_blank">退换货政策</a><br>
4.VIP金额的累计,将在您订单签收15天后积累到您的账户,请您知悉。<br>
5.购买商品及参与促销活动赠送的YOHO币,将在您订单签收7天后积累到您的账户,您可以在个人中心-我的YOHO币中查看。<br>
<b style="color:#c00;">6.尊敬的用户:近期为网络诈骗高发期,有货郑重声明,不会以任何形式索取客户的账户信息或引导转账,敬请提高警惕,谨防诈骗。</b>
</div>
<p class="btns">
<a class="check-order" href="{{checkOrderUrl}}">查看订单</a>
<a class="return-home" href="{{returnHomeUrl}}">返回首页</a>
</p>
{{#if devEnv}}
<img class="notice-img" src="http://webstatic.dev.yohobuy.com/img/pay/notice.jpg">
{{^}}
<img class="notice-img" src="http://cdn.yoho.cn/yohobuy/assets/img/pay/notice.jpg">
{{/if}}
{{/ payNotice}}
</div>
{{> pay/pay-analysis}}
{{> layout/footer}}
\ No newline at end of file
... ...
{{> layout/header}}
<div class="pay-notice-wechatqrcodereturn-page yoho-page clearfix">
{{# payData}}
<div class="wechatqrcodereturn">
<div class="pay-title">
<div class="step5"></div>
<ul>
<li><span>查看购物车</span></li>
<li><span>填写订单</span></li>
<li class="end"><span>付款,完成购买</span></li>
</ul>
</div>
<div class="pay-wechat-return">
<p class="payerror">
很抱歉,订单支付失败,请立即联系客服!
</p>
<p class="arrival-time">
客服电话:
<b class="tell-phone">
400-889-9646
</b>
</p>
</div>
<div class="cart-bigbtns">
<span class="btn-type">
<a href="/">返回首页</a>
</span>
</div>
<div class="we-alert">
<span class="we-font">感谢您选择{{payWay}}的方式,我们的客服随后会和您确认订单。</span>
</div>
</div>
{{/ payData}}
</div>
{{> layout/footer}}
\ No newline at end of file
... ...
... ... @@ -68,7 +68,7 @@
<p>完成付款后请根据您的情况点击下面的按钮</p>
</div>
<div class="btns">
<a href="{{ordersUrl}}" class="over">已完成付款</a>
<a href="javascript:void(0);" data-url = "{{ordersUrl}}"class="pay-over over">已完成付款</a>
<a href="#" class="change">更换支付方式</a>
</div>
<a href="#" class="close">x</a>
... ...
No preview for this file type
... ... @@ -16069,7 +16069,8 @@ var $ = require("jquery"),
showDiv,
imgAlt,
imgSrc,
orderCode;
orderCode,
payment;
$.jqtab = function(tabtit, tabcon) {
... ... @@ -16128,28 +16129,40 @@ $('.change').click(function() {
});
//支付方式选择按钮
function getData(payment,orderCode){
$.ajax({
type:"get",
url:"/common/addpaymentinterval",
dataType:'json',
data:{
orderCode:orderCode,
payment:payment
}
});
function getData(payment, orderCode) {
$.ajax({
type: 'get',
url: '/common/addpaymentinterval',
dataType: 'json',
data: {
orderCode: orderCode,
payment: payment
}
});
}
$("#btnby").click(function(){
payment = $(".choose-type").attr("data-id");
orderCode = $('.order-num').text();
getData(payment,orderCode);
$('#btnby').click(function() {
payment = $('.choose-type').attr('data-id');
orderCode = $('.order-num').text();
getData(payment, orderCode);
window.open($payUrl + '?order_code=' + orderCode + '&payment_type=' + $showValue);
$lightBox.show();
})
});
//发送支付确认
$('.pay-over').unbind('click').bind('click', function() {
var _this = this;
$.post('/shopping/pay/sendPay',
{
orderCode: orderCode,
paymentId: payment
},
function() {
window.location.href = $(_this).data('url');
}
);
});
});
define("js/pay/wechatqrcode", ["jquery"], function(require, exports, module){
/**
... ...
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
... ... @@ -18,7 +18,8 @@ var $ = require('yoho.jquery'),
showDiv,
imgAlt,
imgSrc,
orderCode;
orderCode,
payment;
$.jqtab = function(tabtit, tabcon) {
... ... @@ -77,24 +78,37 @@ $('.change').click(function() {
});
//支付方式选择按钮
function getData(payment,orderCode){
$.ajax({
type:"get",
url:"/common/addpaymentinterval",
dataType:'json',
data:{
orderCode:orderCode,
payment:payment
}
});
function getData(payment, orderCode) {
$.ajax({
type: 'get',
url: '/common/addpaymentinterval',
dataType: 'json',
data: {
orderCode: orderCode,
payment: payment
}
});
}
$("#btnby").click(function(){
payment = $(".choose-type").attr("data-id");
orderCode = $('.order-num').text();
getData(payment,orderCode);
$('#btnby').click(function() {
payment = $('.choose-type').attr('data-id');
orderCode = $('.order-num').text();
getData(payment, orderCode);
window.open($payUrl + '?order_code=' + orderCode + '&payment_type=' + $showValue);
$lightBox.show();
})
});
//发送支付确认
$('.pay-over').unbind('click').bind('click', function() {
var _this = this;
$.post('/shopping/pay/sendPay',
{
orderCode: orderCode,
paymentId: payment
},
function() {
window.location.href = $(_this).data('url');
}
);
});
\ No newline at end of file
... ...
... ... @@ -68,7 +68,7 @@ class PayController extends AbstractAction
// 此处是咨询过JAVA开发任明明,按照老代码的实现方式判断,更新支付方式
$paymentRecod = OrderData::updateOrderPayment($orderCode, 2, $uid);
if (empty($paymentRecod) || $paymentRecod['code'] != 200) {
$this->helpJsRedirect('系统繁忙,请稍后再试');
$this->helpJsRedirect(isset($paymentRecod['message']) ? $paymentRecod['message'] : '系统繁忙,请稍后再试');
break;
}
... ...
... ... @@ -393,6 +393,9 @@ class ItemModel
Cache::set($key, $navs);
}
}
if (empty($navs) || !is_array($navs)) {
return array();
}
return $navs;
}
... ...
... ... @@ -14,7 +14,7 @@ use WebPlugin\Pay\weixin\lib\WxPayConfig;
use WebPlugin\Pay\weixin\lib\WxPayNativePay;
use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder;
use WebPlugin\PhpLog;
use WebPlugin\UdpLog;
/**
* 支付有关方法
... ... @@ -26,19 +26,6 @@ use WebPlugin\PhpLog;
*/
class PayModel
{
// 日志等级,2表示记录信息等级的日志
const LOG_LEVEL = 2;
// 支付方式有关接口调用日志
const PAYMENT_LIST_LOG = '/Data/logs/pc_pay/payment_list';
// 向ERP提交订单状态有关接口调用日志和更新订单状态有关接口调用日志
const ORDER_STATUS_LOG = '/Data/logs/pc_pay/order_status';
// 获取或者更新订单支付银行的接口调用日志
const ORDER_BANK_LOG = '/Data/logs/pc_pay/order_bank';
// 根据用户UID获取订单数有关接口调用日志
const ORDER_COUNT_LOG = '/Data/logs/pc_pay/order_count';
// 发送短信有关接口调用日志
const SEND_MESSAGE_LOG = '/Data/logs/pc_pay/send_message';
// 是否老用户订单数判断值
const OLD_USER_LIMIT = 1;
... ... @@ -51,7 +38,7 @@ class PayModel
*/
public static function getPayTypeData($uid, $orderCode)
{
$result = array();
$result = array('orderNum' => 0, 'count' => 0, 'pinyouGoods' => '', 'orderNum' => 0, 'orderGoods' => '');
do {
// 订单详情
... ... @@ -117,13 +104,7 @@ class PayModel
// 用户ID
$result['uid'] = $uid;
// 初始化日志
$log = new PhpLog(self::PAYMENT_LIST_LOG, 'PRC', self::LOG_LEVEL);
// 获取支付途径列表
$log->LogInfo('===开始调用支付方式列表接口,接口方法为web.SpaceOrders.getPaymentList===');
$payTypes = PayData::getPaymentList();
$log->LogInfo('===结束调用支付方式列表接口,返回结果为===');
$log->LogInfo(var_export($payTypes, true));
$defaultPayType = 0;
$types = array();
... ... @@ -154,37 +135,15 @@ class PayModel
// 无需付款
if (isset($order["payment_amount"]) && $order["payment_amount"] == 0) {
// 初始化日志
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===[' . $orderCode . ']===');
// ERP提交订单状态
$log->LogInfo('===开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');
$log->LogInfo('===请求参数为orderCode=' . $orderCode . '===');
$erpReturn = PayData::submitOrderStatus($orderCode, 0, '', '', 0, '', '', '');
$log->LogInfo('===结束调用ERP提交订单状态接口,返回结果为===');
$log->LogInfo(var_export($erpReturn, true));
// 更新订单的状态
$log->LogInfo('===开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');
$log->LogInfo('===请求参数为orderId=' . $order['order_id'] . 'uid=' . $uid . '===');
$updateOrderStatus = PayData::updateOrderStatus($order['order_id'], $uid, 0, 'Y', '');
$log->LogInfo('===结束调用更新订单状态接口,返回结果为===');
$log->LogInfo(var_export($updateOrderStatus, true));
//无需付款-更新订单状态
$updateOrderStatus = PayData::pcpayNotify($orderCode, 0, 0);
UdpLog::info("【无需付款】,orderCode:{$orderCode},更新订单状态结果", $updateOrderStatus);
$result['notNeedPay'] = true;
break;
}
// 记录支付方式
// 初始化日志
$log = new PhpLog(self::ORDER_BANK_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===开始调用记录支付方式接口,接口方法为web.SpaceOrders.getOrderPayBank===');
$log->LogInfo('===请求参数为orderCode=' . $orderCode . '===');
$bankRecord = PayData::getBankByOrder($orderCode);
$log->LogInfo('===结束调用记录支付方式接口,返回结果为===');
$log->LogInfo(var_export($bankRecord, true));
if (isset($bankRecord['data']['bankCode']) && !empty($bankRecord['data']['bankCode'])) {
$payRecord = $bankRecord['data']['bankCode'];
} else {
... ... @@ -208,12 +167,7 @@ class PayModel
// 是否是老用户(用于订单统计)
$orderCount = 0;
// 初始化日志
$log = new PhpLog(self::ORDER_COUNT_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===开始调用查询用户订单数接口,接口方法为web.SpaceOrders.getOrderCountByUid===');
$orders = PayData::getOrderCountByUid($uid);
$log->LogInfo('===结束调用查询用户订单数接口,返回结果为===');
$log->LogInfo(var_export($orders, true));
if (isset($orders['data']) && !empty($orders['data'])) {
$orderCount = $orders['data']['total'];
... ... @@ -340,7 +294,7 @@ class PayModel
$paymentRecod = OrderData::updateOrderPayment($orderCode, $payId, $uid);
if (empty($paymentRecod) || $paymentRecod['code'] != 200) {
$result['error'] = true;
$result['message'] = '系统繁忙,请稍后再试';
$result['message'] = isset($paymentRecod['message']) ? $paymentRecod['message'] : '系统繁忙,请稍后再试';
break;
}
$bankRecord = PayData::getBankByOrder($orderCode);
... ... @@ -384,6 +338,7 @@ class PayModel
$result = array(
'id' => $payId,
'pay_code' => $paymentParams['data']['payCode'],
'payName' => $paymentParams['data']['payName'],
'pay_params' => isset($paymentParams['data']['payParams']) ? $paymentParams['data']['payParams'] : ''
);
}
... ... @@ -404,12 +359,7 @@ class PayModel
$result = array();
do {
// 初始化日志
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('=====[' . $orderCode . ']===开始生成微信支付二维码========');
if (empty($orderCode)) {
$log->LogInfo('=====[' . $orderCode . ']===微信支付时,订单号为空========');
$result['error'] = true;
$result['message'] = '订单号不能为空';
break;
... ... @@ -418,7 +368,7 @@ class PayModel
/* 判断订单信息是否存在 */
$orderDetail = OrderData::getOrderDetail($uid, $orderCode);
if (!isset($orderDetail['data']) || empty($orderDetail['data'])) {
$log->LogInfo('=====[' . $orderCode . ']===微信支付时,订单信息未查到========');
UdpLog::info("【微信支付时】,function:weixinQrcode,orderCode:{$orderCode},订单信息未查到", array('uid' => $uid, 'orderCode' => $orderCode));
$result['error'] = true;
$result['message'] = '没有找到该订单';
break;
... ... @@ -445,8 +395,7 @@ class PayModel
$input->SetProduct_id($orderCode);
$notify = new WxPayNativePay();
$payResult = $notify->GetPayUrl($input);
$log->LogInfo('=====[' . $orderCode . ']===微信支付时,微信统一下单的返回结果为:========');
$log->LogInfo(var_export($payResult, true));
UdpLog::info("【微信支付时】,function:weixinQrcode,orderCode:{$orderCode},微信统一下单的返回结果为", array('uid' => $uid, 'payResult' => $payResult));
$orderData = $orderDetail['data'];
$firstGoods = current($orderData['order_goods']);
... ... @@ -462,8 +411,7 @@ class PayModel
);
} while (false);
$log->LogInfo('=====[' . $orderCode . ']===微信支付时,处理微信支付的结果为:========');
$log->LogInfo(var_export($result, true));
UdpLog::info("【微信支付】,function:weixinQrcode,orderCode:{$orderCode},处理微信支付的结果为", array('uid' => $uid, 'result' => $result));
return $result;
}
... ... @@ -487,26 +435,19 @@ class PayModel
break;
}
// 初始化日志
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('=====[' . $orderCode . ']===开始查询微信扫码支付状态========');
// 组装微信支付的订单号
$tradeNo = 'YOHOBuy_' . $orderCode;
$input = new WxPayOrderQuery();
$input->SetOut_trade_no($tradeNo);
$payResult = WxPayApi::orderQuery($input);
$log->LogInfo(var_export($payResult, true));
UdpLog::info("【微信支付】,function:checkWechatPayStatus,orderCode:{$orderCode},检查微信扫码支付结果", array('uid' => $uid, 'payResult' => $payResult));
if (isset($payResult['trade_state']) && $payResult['trade_state'] === 'SUCCESS') {
$log->LogInfo('====[' . $orderCode . ']====微信扫码支付成功========');
$result = array(
'code' => '200',
'message' => 'success'
);
}
$log->LogInfo('====[' . $orderCode . ']====微信扫码支付失败========');
} while (false);
return $result;
... ... @@ -528,18 +469,10 @@ class PayModel
);
do {
// 初始化日志
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('========[' . $payResult->orderCode . ']========');
$log->LogInfo(var_export($payResult, true));
$log->LogInfo('==[' . $payResult->orderCode . ']=开始调用获取订单详情方式接口,接口方法为app.SpaceOrders.detail===');
$orderInfo = OrderData::getOrderDetail($uid, $payResult->orderCode);
$log->LogInfo('==[' . $payResult->orderCode . ']=结束调用获取订单详情方式接口,返回结果为===');
$log->LogInfo(var_export($orderInfo, true));
UdpLog::info("【订单支付后处理】,function:procOrderData,orderCode:{$payResult->orderCode},订单信息", $orderInfo);
if (!isset($orderInfo['data']) || empty($orderInfo['data'])) {
$log->LogInfo('==[' . $payResult->orderCode . ']=订单支付失败,未获取到订单详情信息===');
break;
}
... ... @@ -551,14 +484,11 @@ class PayModel
// 订单已取消
if ($orderData['is_cancel'] === 'Y' && $paymentStatus === 'N') {
// 给用户发送短信
// 初始化日志
$log = new PhpLog(self::SEND_MESSAGE_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===[' . $orderCode . ']===');
$log->LogInfo('==[' . $orderCode . ']=开始调用订单取消时给用户发短信接口,接口方法为app.message.sendMsg===');
$messageReturn = PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode);
$log->LogInfo('==[' . $orderCode . ']=结束调用给用户发短信接口,返回结果为===');
$log->LogInfo(var_export($messageReturn, true));
UdpLog::info(
"【订单支付后处理】,function:procOrderData,orderCode:{$payResult->orderCode},支付成功,但订单已取消,给用户发信息",
array('orderInfo' => $orderInfo, 'messageReturn' => $messageReturn)
);
$result['code'] = 417;
$result['message'] = '支付成功,但订单已取消,需联系客服';
break;
... ... @@ -566,8 +496,10 @@ class PayModel
// 支付金额与订单金额不一致
if (round($amount, 2) != round($payResult->totalFee, 2)) {
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('==[' . $orderCode . ']=订单支付失败,支付金额与订单金额不一致===');
UdpLog::info(
"【订单支付后处理】,function:procOrderData,orderCode:{$payResult->orderCode},订单支付失败,支付金额与订单金额不一致",
array('orderInfo' => $orderInfo)
);
$result['code'] = 415;
$result['message'] = '支付金额与订单金额不一致';
break;
... ... @@ -580,24 +512,12 @@ class PayModel
$bankName = $payResult->bankName;
$bankCode = $payResult->bankCode;
// 初始化日志
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===[' . $orderCode . ']===');
$log->LogInfo('==[' . $orderCode . ']=开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');
$log->LogInfo('==[' . $orderCode . ']=请求参数为orderCode=' . $orderCode . '===');
// ERP提交订单状态
$erpReturn = PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $payOrderCode, $tradeNo, $bankBillNo);
$log->LogInfo('==[' . $orderCode . ']=结束调用ERP提交订单状态接口,返回结果为===');
$log->LogInfo(var_export($erpReturn, true));
$log->LogInfo('==[' . $orderCode . ']=开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');
$log->LogInfo('==[' . $orderCode . ']=请求参数为orderId=' . $orderData['order_id'] . 'uid=' . $uid . '===');
// 更新订单的状态
$updateOrderStatus = PayData::updateOrderStatus($orderData['order_id'], $uid, $payment, 'Y', $bankCode);
$log->LogInfo('==[' . $orderCode . ']=结束调用更新订单状态接口,返回结果为===');
$log->LogInfo(var_export($updateOrderStatus, true));
$log->LogInfo('==[' . $orderCode . ']=订单支付成功,请等待发货===');
//更新订单状态
$updateOrderStatus = PayData::pcpayNotify($orderCode, $payment, $amount, $bankName, $bankCode, $tradeNo, $bankBillNo);
UdpLog::info(
"【订单支付后处理】,function:procOrderData,orderCode:{$payResult->orderCode},更新订单状态",
array('orderInfo' => $orderInfo, 'updateOrderStatus' => $updateOrderStatus)
);
$result['code'] = 200;
$result['message'] = '支付成功,请等待发货';
... ...
<?php
namespace Shopping;
use LibModels\Web\Home\OrderData;
use LibModels\Web\Product\PayData;
use Plugin\Helpers;
use WebPlugin\Cache;
use WebPlugin\Pay\Banks;
use WebPlugin\Pay\PayFactory;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\Pay\weixin\lib\WxPayApi;
use WebPlugin\Pay\weixin\lib\WxPayConfig;
use WebPlugin\Pay\weixin\lib\WxPayNativePay;
use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder;
use WebPlugin\UdpLog;
/**
* 支付有关方法 改版
* @copyright 2016/5/22 14:19 xiaoxiao<xiaoxiao.hao@yoho.cn>
*/
class PaymentModel
{
protected static $code = array(
'code' => 500,
'message' => '支付失败'
);
// 存储的UID键名
const SESSION_UID_KEY = 'payUserid';
// 是否老用户订单数判断值
const OLD_USER_LIMIT = 1;
/**
* 获取支付方式选择页面有关信息
*
* @param int $uid 用户ID
* @param string $orderCode 订单号
* @return array
*/
public static function getPayTypeData($uid, $orderCode)
{
$result = array('orderNum' => 0, 'count' => 0, 'pinyouGoods' => '', 'orderNum' => 0, 'orderGoods' => '');
do {
// 订单详情
$orderDetail = OrderData::getOrderDetail($uid, $orderCode);
if (!$orderDetail || empty($orderDetail['data'])) {
$result['noOrder'] = true;
break;
}
$order = $orderDetail['data'];
$result['orderNum'] = $orderCode;
$result['count'] = $order['payment_amount'];
$result['paymentType'] = ($order['payment_type'] == 1 ? '在线支付' : '货到付款');
// 订单商品(用于订单统计)
$result['orderGoods'] = $order['order_goods'];
//统计成交的skn
$sknList = array();
$skuList = array();
$goodsData = array();
$pinyouGoodsArr = array();
foreach ($order['order_goods'] as $val) {
$sknList[] = $val['product_skn'];
$skuList[] = $val['product_sku'];
$goodsData[] = array(
'goods_name' => $val['product_name'],
'product_sku' => $val['product_sku'],
'price' => $val['goods_price'],
'number' => $val['buy_number']
);
$pinyouGoodsArr[] = $val['product_id'] . ',' . $val['buy_number'];
}
$result['goodsData'] = $goodsData;
// skn列表
$result['sknList'] = implode(',', $sknList);
// sku列表
$result['skuList'] = implode(',', $skuList);
// 品友统计需要的商品数据
$result['pinyouGoods'] = implode(';', $pinyouGoodsArr);
// 货到付款的情况
if ($order['payment_type'] == 2) {
$result['finish'] = true;
// 有货币
$result['yohoCoin'] = $order['yoho_give_coin'];
// 订单详情链接地址
$result['checkOrderUrl'] = Helpers::url('/home/orders/detail', array('orderCode' => $orderCode));
// 有货币地址
$result['yohoCoinUrl'] = Helpers::url('/help', array('category_id' => 87));
// vip地址
$result['vipUrl'] = Helpers::url('/help', array('category_id' => 91));
// 订单中心地址
$result['ordersUrl'] = Helpers::url('/home/orders');
// 退换货地址
$result['backGoodsUrl'] = Helpers::url('/help', array('category_id' => 121));
// 返回首页地址
$result['returnHomeUrl'] = Helpers::url('/');
break;
}
$result['deliveryType'] = isset($order['delivery_time']) ? $order['delivery_time'] : '';
// 用户ID
$result['uid'] = $uid;
// 获取支付途径列表
$payTypes = PayData::getPaymentList();
$defaultPayType = 0;
$types = array();
if (isset($payTypes['data']) && !empty($payTypes['data'])) {
$oneType = array();
foreach ($payTypes['data'] as $key => $payType) {
if (empty($payType['payIcon'])) { // 排除图标不存在的支付方式
continue;
}
// 获取第一个支付方式
if ($key === 0) {
$defaultPayType = $payType['id'];
}
$oneType = array();
$oneType['name'] = $payType['payName'];
$oneType['ico'] = $payType['payIcon'];
$types[$payType['id']] = $oneType;
}
$result['list'] = self::procPayType($types);
}
// 获取银行列表
$result['entry'] = self::procPayType(Banks::getList(), true);
// 无需付款
if (isset($order["payment_amount"]) && $order["payment_amount"] == 0) {
//更新订单状态
PayData::pcpayNotify($orderCode, 0, 0);
$result['notNeedPay'] = true;
break;
}
// 记录支付方式
$bankRecord = PayData::getBankByOrder($orderCode);
if (isset($bankRecord['data']['bankCode']) && !empty($bankRecord['data']['bankCode'])) {
$payRecord = $bankRecord['data']['bankCode'];
} else {
$payCode = $order['payment'] ?: $defaultPayType;
//记录app上的支付方式
$changeCodes = array(
19 => 21,// app上微信支付
22 => 21,// h5微信支付
18 => $defaultPayType// h5支付宝支付
);
$platformCode = isset($changeCodes[$payCode]) && $changeCodes[$payCode] ? $changeCodes[$payCode] : $payCode;
$platformCodeList = array_keys($types);
$payRecord = in_array($platformCode, $platformCodeList) ? $platformCode : $defaultPayType;
}
$result['payRecord'] = $payRecord;
// 已完成付款的链接地址
$result['ordersUrl'] = Helpers::url('/home/orders');
// 支付地址
$result['payUrl'] = Helpers::url('/pay/index/index');
// 是否是老用户(用于订单统计)
$orderCount = 0;
//查询用户订单数接口
$orders = PayData::getOrderCountByUid($uid);
if (isset($orders['data']) && !empty($orders['data'])) {
$orderCount = $orders['data']['total'];
}
$result['isOldUser'] = (intval($orderCount) > self::OLD_USER_LIMIT) ? true : false;
// 订单数(用于订单统计)
$result['orderCount'] = $orderCount;
$result['is_advance'] = $order['attribute'] == 5 ? 'Y' : 'N';
// 订单商品数(用于订单统计)
$result['ordersGoodsNums'] = count($order['order_goods']);
} while (false);
return $result;
}
/**
* 处理支付类型数据
*
* @param array $pays 支付方式数据
* @param bool $isBank 是否是银行数据
* @return array
*/
private static function procPayType($pays, $isBank = false)
{
$result = array();
$onePay = array();
foreach ($pays as $code => $pay) {
$onePay = array();
$onePay['dataId'] = $code;
$onePay['dataVal'] = $isBank ? '12_' . $code : $code . '_platform';
$onePay['idNum'] = $code;
$onePay['ico'] = $pay['ico'];
$onePay['name'] = $pay['name'];
$onePay['imgId'] = $onePay['dataVal'];
$result[] = $onePay;
}
return $result;
}
/**
* 支付成功处理方法
* @param type object $payResult 支付成功返回对象
* @return type []
*/
public static function procOrderData($payResult)
{
do {
if (empty($payResult->orderCode)) {
self::$code['message'] = '未查到订单信息,订单状态更新失败!';
break;
}
$orderCode = $payResult->orderCode;
$uid = self::getUid($orderCode);
$orderInfo = OrderData::getOrderDetail($uid, $orderCode);
if (empty($orderInfo['data'])) {
self::$code['message'] = '未查到订单信息,订单状态更新失败!';
break;
}
$orderData = $orderInfo['data'];
$amount = $orderData['payment_amount'];
if ($orderData['is_cancel'] === 'Y') {
UdpLog::warn(
"【支付成功】,但订单已取消,orderCode:{$orderData},参数",
array('payResult' => $payResult, 'orderData' => $orderData)
);
// 给用户发送短信
PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode);
self::$code['code'] = 417;
self::$code['message'] = '支付成功,但订单已取消,需联系客服!';
break;
}
if ($orderData['payment_status'] === 'N') {
UdpLog::warn(
"【支付成功,同步地址返回】,查询订单状态为未付款,有可能异步地址还未即时更新状态,orderCode:{$orderCode},参数",
array('payResult' => $payResult, 'orderData' => $orderData)
);
}
// 支付金额与订单金额不一致
if (round($amount, 2) !== round($payResult->totalFee, 2)) {
UdpLog::warn(
"【支付成功】,支付金额与订单金额不一致,orderCode:{$orderCode},参数",
array('payResult' => $payResult, 'orderData' => $orderData)
);
self::$code['code'] = 415;
self::$code['message'] = '支付金额与订单金额不一致,订单状态更新失败!';
break;
}
self::$code['code'] = 200;
self::$code['message'] = '支付成功,请等待发货';
self::$code['data'] = array(
'pay' => $amount,
'orderNum' => $orderData['order_code'],
'checkOrderUrl' => Helpers::url('/home/orders/detail', array('orderCode' => $orderData['order_code'])),
'payMode' => ($orderData['payment_type'] == 1 ? '在线支付' : '货到付款'),
'currency' => $orderData['yoho_give_coin'],
'yohoCoinUrl' => Helpers::url('/help', array('category_id' => 87)),
'ordersUrl' => Helpers::url('/home/orders'),
'returnGoodsUrl' => Helpers::url('/help', array('category_id' => 121)),
'vipSum' => $amount,
'vipUrl' => Helpers::url('/help', array('category_id' => 91)),
'returnHomeUrl' => Helpers::url('/')
);
} while (false);
return self::$code;
}
/**
* 处理微信支付
*
* @param int $uid 用户ID
* @param string $orderCode 订单号
* @return array
*/
public static function weixinQrcode($orderCode)
{
do {
if (empty($orderCode)) {
self::$code['message'] = '订单号不能为空';
break;
}
$uid = self::getUid($orderCode);
/* 判断订单信息是否存在 */
$orderDetail = OrderData::getOrderDetail($uid, $orderCode);
if (empty($orderDetail['data'])) {
self::$code['message'] = '没有找到该订单';
break;
}
if ($orderDetail['data']['is_cancel'] === 'Y') {
self::$code['message'] = '该订单已被取消';
break;
}
if ($orderDetail['data']['payment_status'] === 'Y') {
self::$code['message'] = '该订单已付款,不需要再次付款';
break;
}
//统一下单
$totalFee = strval($orderDetail['data']['payment_amount'] * 100);
$input = new WxPayUnifiedOrder();
$input->SetBody('有货订单号:' . $orderCode);
$input->SetOut_trade_no('YOHOBuy_' . $orderCode); // 商户订单号
$input->SetTotal_fee($totalFee);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetTrade_type("NATIVE");
$input->SetProduct_id($orderCode);
$notify = new WxPayNativePay();
$payResult = $notify->GetPayUrl($input);
if ($payResult['result_code'] === 'FAIL') {
self::$code['message'] = $payResult['err_code_des'];
break;
}
$orderData = $orderDetail['data'];
$firstGoods = current($orderData['order_goods']);
self::$code = array(
'code' => 200,
'orderNum' => $orderData['order_code'],
'amount' => $orderData['payment_amount'],
'address' => $orderData['address'],
'name' => $orderData['user_name'],
'tellphoneNum' => $orderData['mobile'],
'tradeName' => $firstGoods['product_name'],
'choosePayUrl' => Helpers::url('/shopping/pay', array('order_code' => $orderData['order_code'])),
'qrcodeUrl' => isset($payResult['code_url']) ? $payResult['code_url'] : '' // 'http://paysdk.weixin.qq.com/example/qrcode.php?data=' . $result['code_url']
);
} while (false);
return self::$code;
}
/**
* 轮询查询--检查微信扫码支付结果
*
* @param int $uid 用户ID
* @param int $orderCode 订单号
* @return array 订单支付结果
*/
public static function checkWechatPayStatus($orderCode)
{
do {
if (empty($orderCode)) {
self::$code['message'] = '未查询到订单号';
break;
}
// 组装微信支付的订单号
$tradeNo = 'YOHOBuy_' . $orderCode;
$input = new WxPayOrderQuery();
$input->SetOut_trade_no($tradeNo);
$payResult = WxPayApi::orderQuery($input);
if (isset($payResult['trade_state']) && $payResult['trade_state'] === 'SUCCESS') {
self::$code = array(
'code' => '200',
'message' => 'success'
);
}
} while (false);
return self::$code;
}
/**
* 根据支付ID获取支付相关参数
*
* @param int $payId 支付ID
* @return array
*/
public static function getPaymentById($payId)
{
$result = array();
$paymentParams = PayData::getPaymentById($payId);
if (isset($paymentParams['data']) && !empty($paymentParams['data'])) {
$result = array(
'id' => $payId,
'pay_code' => $paymentParams['data']['payCode'],
'payName' => $paymentParams['data']['payName'],
'pay_params' => isset($paymentParams['data']['payParams']) ? $paymentParams['data']['payParams'] : ''
);
}
return $result;
}
/**
* 通过订单号,从缓存记录中获取uid
* @param type string $orderCode 订单号
* @return type int
*/
private static function getUid($orderCode)
{
$uid = '';
if (USE_CACHE) {
// 通过订单号,从缓存记录中获取uid
$uid = Cache::get(self::SESSION_UID_KEY . $orderCode);
}
return $uid;
}
/**
* 支付成功后--发送支付确认接口
* @param type object $orderCode 订单号
* @param type int $paymentId 支付方式id
* @param type int $uid 用户ID
* @return type []
*/
public static function sendPayConfirm($orderCode, $paymentId, $uid)
{
UdpLog::info(
"【支付成功-发送确认接口】,function:sendPayConfirm,支付方式ID:{$paymentId},参数",
array('orderCode' => $orderCode, 'paymentId' => $paymentId, 'uid' => $uid)
);
if (empty($orderCode)) {
return self::$code;
}
//如果uid,为空,则从缓存中取uid,但还是不排除uid为空的情况下。
$uid = empty($uid) ? self::getUid($orderCode) : $uid;
$confirm = PayData::payConfirm($orderCode, $paymentId, $uid);
UdpLog::info(
"【支付成功-发送确认接口】,function:sendPayConfirm,orderCode:{$orderCode},支付方式ID:{$paymentId},接口返回",
array('orderCode' => $orderCode, 'paymentId' => $paymentId, 'uid' => $uid, 'confirm' => $confirm)
);
return $confirm;
}
/**
* 获取支付有关信息
*
* @param int $uid 用户ID
* @param string $orderCode 订单号
* @param string $paymentType 支付方式
* @param string $userName 用户名
* @param string $alipayToken 支付宝用户token
* @return array
*/
public static function getPayData($uid, $orderCode, $paymentType, $userName, $alipayToken)
{
$result = array();
do {
/* 判断是否有订单号参数 */
if (empty($orderCode)) {
$result['error'] = true;
$result['message'] = '订单号不能为空';
break;
}
/* 判断支付方式是否选择 */
$paymentPars = explode('_', $paymentType);
if (count($paymentPars) != 2) {
$result['error'] = true;
$result['message'] = '请选择一个支付方式';
break;
}
/* 判断订单信息是否存在 */
$orderDetail = OrderData::getOrderDetail($uid, $orderCode);
if (empty($orderDetail['data'])) {
$result['error'] = true;
$result['message'] = '没有找到该订单';
break;
}
/* 判断订单是否已取消 */
if (isset($orderDetail['data']['is_cancel']) && $orderDetail['data']['is_cancel'] === 'Y') {
$result['error'] = true;
$result['message'] = '订单已经取消';
$result['location'] = 'window.location="' . Helpers::url('/home/orders/detail', array('order_code' => $orderCode)) . '";';
break;
}
// 获取支付有关参数
$payId = $paymentPars[0];
$paymentParams = self::getPaymentById($payId);
if (empty($paymentParams)) {
$result['error'] = true;
$result['message'] = '支付系统繁忙,请稍后再试';
break;
}
$payService = PayFactory::factory($paymentParams);
if ($payService == false) { // 没找到支付方式时
$result['error'] = true;
$result['message'] = '请选择一个支付方式';
break;
}
$totalFee = $orderDetail['data']['payment_amount'] * 100;
$isTest = (APPLICATION_ENV === 'developer' || APPLICATION_ENV === 'testing');
$paymentParameter = $paymentPars[1];
// 判断是否传入支付宝token
if ($paymentType == 2 && !empty($alipayToken)) {
$paymentParameter = $alipayToken;
}
$reqParams = new Reqparams($orderCode, $totalFee, '有货订单号:' . $orderCode, '', $orderDetail['data']['create_time'], $paymentParameter, $isTest, $uid, $userName);
$reqPars = $payService->getPayRequestPars($reqParams);
if (empty($reqPars)) {
$result['error'] = true;
$result['message'] = '支付系统繁忙,请稍后再试';
break;
}
// 记录并更新订单支付方式
$paymentRecod = OrderData::updateOrderPayment($orderCode, $payId, $uid);
if (empty($paymentRecod) || $paymentRecod['code'] != 200) {
$result['error'] = true;
$result['message'] = isset($paymentRecod['message']) ? $paymentRecod['message'] : '系统繁忙,请稍后再试';
break;
}
$bankRecord = PayData::getBankByOrder($orderCode);
$bankCode = ($paymentParameter != 'platform' ? $paymentParameter : '');
if (isset($bankRecord['data']['bankCode']) && !empty($bankRecord['data']['bankCode'])) {
$bankPayRecord = PayData::updateOrderPayBank($orderCode, $payId, $bankCode);
} else {
$bankPayRecord = PayData::setOrderPayBank($orderCode, $payId, $bankCode);
}
if (!isset($bankPayRecord['code']) || $bankPayRecord['code'] != 200) {
$result['error'] = true;
$result['message'] = '支付方式记录失败';
break;
}
if ($reqPars['reqType'] == 'get') {
//直接跳转到支付界面
$result['go'] = true;
$result['payUrl'] = $reqPars['pay_url'] . '?' . $reqPars['pars'];
} else {
//如果是post,去form提交
$result = array('reqPars' => $reqPars);
}
} while (false);
return $result;
}
}
\ No newline at end of file
... ...
<?php
use Action\WebAction;
use Shopping\PayModel;
use Shopping\PaymentModel;
use WebPlugin\Helpers;
/**
... ... @@ -20,7 +20,7 @@ class IndexController extends WebAction
$orderCode = $this->get('order_code', $this->get('ordercode'));
$paymentType = $this->get('payment_type');
$alipayToken = $this->getSession('alipay_user_token');
$data = PayModel::getPayData($uid, $orderCode, $paymentType, $this->_uname, $alipayToken);
$data = PaymentModel::getPayData($uid, $orderCode, $paymentType, $this->_uname, $alipayToken);
if (isset($data['error'])) {
$this->helpJsRedirect($data['message']);
}
... ...
... ... @@ -5,26 +5,17 @@ use Shopping\PayModel;
use WebPlugin\Pay\PayFactory;
use WebPlugin\Pay\Rspparams;
use WebPlugin\Pay\weixin\PayNotifyCallBack;
use WebPlugin\PhpLog;
/**
* 支付Notice
*/
class NoticeController extends WebAction
{
// 日志等级,2表示记录信息等级的日志
const LOG_LEVEL = 2;
// 向回调通知有关调用日志
const ORDER_STATUS_LOG = '/Data/logs/pc_pay/order_status';
// 存储的UID键名
const SESSION_UID_KEY = 'payUserid';
private $log = null;
public function init() {
parent::init();
$this->log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
}
/**
... ... @@ -32,12 +23,7 @@ class NoticeController extends WebAction
*/
public function alipaynoticeAction()
{
$payment = PayModel::getPaymentById(2);
$payService = PayFactory::factory($payment);
$this->log->LogInfo("begin alipaynoticeAction");
$res = $payService->parseResponse($_POST); //支付宝通知使用的
$res = $this->getParseResponse($_POST, 2);
if ($res->payResult != -1) {
$this->payResultProc($res, 2);
echo "success";
... ... @@ -50,11 +36,7 @@ class NoticeController extends WebAction
*/
public function alipayreturnAction()
{
$this->log->LogInfo("begin alipayreturnAction");
$payment = PayModel::getPaymentById(2);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_GET);
$res = $this->getParseResponse($_GET, 2);
$dealResult = $this->payResultProc($res, 2);
$dealResult['payData'] = array('payWay' => '支付宝');
$this->commonShowResult($dealResult);
... ... @@ -65,10 +47,7 @@ class NoticeController extends WebAction
*/
public function alibarcodenoticeAction()
{
$this->log->LogInfo("begin alibarcodenoticeAction");
$payment = PayModel::getPaymentById(17);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_POST); //支付宝通知使用的
$res = $this->getParseResponse($_POST, 17);
if ($res->payResult != -1) {
$this->payResultProc($res, 17);
echo "success";
... ... @@ -81,10 +60,7 @@ class NoticeController extends WebAction
*/
public function alibarcodereturnAction()
{
$this->log->LogInfo("begin alibarcodereturnAction");
$payment = PayModel::getPaymentById(17);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_GET);
$res = $this->getParseResponse($_GET, 17);
$dealResult = $this->payResultProc($res, 17);
$dealResult['payData'] = array('payWay' => '支付宝');
$this->commonShowResult($dealResult);
... ... @@ -95,10 +71,7 @@ class NoticeController extends WebAction
*/
public function allinpaynoticeAction()
{
$this->log->LogInfo("begin allinpaynoticeAction");
$payment = PayModel::getPaymentById(16);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_POST);
$res = $this->getParseResponse($_POST, 16);
if ($res->payResult != -1) {
$this->payResultProc($res, 16);
echo "success";
... ... @@ -111,10 +84,7 @@ class NoticeController extends WebAction
*/
public function allinpayreturnAction()
{
$this->log->LogInfo("begin allinpayreturnAction");
$payment = PayModel::getPaymentById(16);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_POST);
$res = $this->getParseResponse($_POST, 16);
$dealResult = $this->payResultProc($res, 16);
$dealResult['payData'] = array('payWay' => '通联支付');
$this->commonShowResult($dealResult);
... ... @@ -125,10 +95,7 @@ class NoticeController extends WebAction
*/
public function aliexpressgatewayreturnAction()
{
$this->log->LogInfo("begin aliexpressgatewayreturnAction");
$payment = PayModel::getPaymentById(13);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_GET);
$res = $this->getParseResponse($_GET, 13);
$dealResult = $this->payResultProc($res, 13);
$dealResult['payData'] = array('payWay' => '支付宝');
$this->commonShowResult($dealResult);
... ... @@ -139,10 +106,7 @@ class NoticeController extends WebAction
*/
public function aliexpressgatewaynoticeAction()
{
$this->log->LogInfo("begin aliexpressgatewaynoticeAction");
$payment = PayModel::getPaymentById(13);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_POST); //支付宝通知使用的
$res = $this->getParseResponse($_POST, 13);
if ($res->payResult != -1) {
$this->payResultProc($res, 13);
echo "success";
... ... @@ -155,11 +119,7 @@ class NoticeController extends WebAction
*/
public function alibanknoticeAction()
{
$this->log->LogInfo("begin alibanknoticeAction");
$payment = PayModel::getPaymentById(12);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_POST);
$res = $this->getParseResponse($_POST, 12);
if ($res->payResult != -1) {
$this->payResultProc($res, 12);
echo "success";
... ... @@ -173,10 +133,7 @@ class NoticeController extends WebAction
*/
public function alibankreturnAction()
{
$this->log->LogInfo("begin alibanknoticeAction");
$payment = PayModel::getPaymentById(12);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_GET);
$res = $this->getParseResponse($_GET, 12);
$dealResult = $this->payResultProc($res, 12);
$dealResult['payData'] = array('payWay' => '银行卡');
$this->commonShowResult($dealResult);
... ... @@ -187,10 +144,7 @@ class NoticeController extends WebAction
*/
public function chinabankAction()
{
$this->log->LogInfo("begin chinabankAction");
$payment = PayModel::getPaymentById(4);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_POST);
$res = $this->getParseResponse($_POST, 4);
$dealResult = $this->payResultProc($res, 4);
$dealResult['payData'] = array('payWay' => '网银在线');
$this->commonShowResult($dealResult);
... ... @@ -201,10 +155,7 @@ class NoticeController extends WebAction
*/
public function chinabankautorevAction()
{
$this->log->LogInfo("begin chinabankautorevAction");
$payment = PayModel::getPaymentById(4);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_POST);
$res = $this->getParseResponse($_POST, 4);
if ($res->payResult != -1) {
$this->payResultProc($res, 4);
echo "ok";
... ... @@ -219,11 +170,10 @@ class NoticeController extends WebAction
*/
public function tenpayAction()
{
$this->log->LogInfo("begin tenpayAction");
$payment = PayModel::getPaymentById(1);
$payService = PayFactory::factory($payment);
$rspParams = $payService->parseResponse($_GET); //财付通是以get方式回复的。
$this->payResultProc($rspParams, 1);
$res = $this->getParseResponse($_GET, 1);
$dealResult = $this->payResultProc($res, 1);
$dealResult['payData'] = array('payWay' => '财付通');
$this->commonShowResult($dealResult);
}
/**
... ... @@ -232,10 +182,7 @@ class NoticeController extends WebAction
*/
public function shengpayreturnAction()
{
$this->log->LogInfo("begin shengpayreturnAction");
$payment = PayModel::getPaymentById(11);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_POST);
$res = $this->getParseResponse($_POST, 11);
$dealResult = $this->payResultProc($res, 11);
$dealResult['payData'] = array('payWay' => '盛付通');
$this->commonShowResult($dealResult);
... ... @@ -246,10 +193,7 @@ class NoticeController extends WebAction
*/
public function shengpaynoticeAction()
{
$this->log->LogInfo("begin shengpaynoticeAction");
$payment = PayModel::getPaymentById(11);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_POST);
$res = $this->getParseResponse($_POST, 11);
if ($res->payResult != -1) {
$this->payResultProc($res, 11);
echo "OK";
... ... @@ -262,7 +206,6 @@ class NoticeController extends WebAction
*/
public function wechatcallbackAction()
{
$this->log->LogInfo("begin wechatcallbackAction");
$callback = $this->get('callback');
$orderCode = $this->get('ordercode');
... ... @@ -277,14 +220,11 @@ class NoticeController extends WebAction
*/
public function wechatqrcodenotifyAction()
{
$this->log->LogInfo("begin wechatqrcodenotifyAction");
$uid = $this->getUid();
if (empty($uid)) { // cookie中获取为空时再从之前保存的session中获取
$uid = $this->getSession(self::SESSION_UID_KEY);
$this->setSession(self::SESSION_UID_KEY, null);
}
$this->log->LogInfo($uid);
$notify = new PayNotifyCallBack($uid);
$notify->handle(false);
}
... ... @@ -294,7 +234,6 @@ class NoticeController extends WebAction
*/
public function wechatqrcodereturnAction()
{
$this->log->LogInfo("begin wechatqrcodereturnAction");
$dealResult = array(
'code' => 500,
'message' => '支付失败'
... ... @@ -321,10 +260,7 @@ class NoticeController extends WebAction
*/
public function unionpaywebreturnAction()
{
$this->log->LogInfo("begin unionpaywebreturnAction");
$payment = PayModel::getPaymentById(25);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_REQUEST);
$res = $this->getParseResponse($_REQUEST, 25);
$dealResult = $this->payResultProc($res, 25);
$dealResult['payData'] = array('payWay' => '银联在线支付');
$this->commonShowResult($dealResult);
... ... @@ -335,10 +271,7 @@ class NoticeController extends WebAction
*/
public function unionpaywebnoticeAction()
{
$this->log->LogInfo("begin unionpaywebnoticeAction");
$payment = PayModel::getPaymentById(25);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_REQUEST);
$res = $this->getParseResponse($_REQUEST, 25);
if ($res->payResult != -1) {
$this->payResultProc($res, 25);
echo "OK";
... ... @@ -352,10 +285,7 @@ class NoticeController extends WebAction
*/
public function alimobilenoticeminiAction()
{
$this->log->LogInfo("begin alimobilenoticeminiAction");
$payment = PayModel::getPaymentById(20);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_POST); //支付宝通知使用的
$res = $this->getParseResponse($_POST, 20);
if ($res->payResult != -1) {
$this->payResultProc($res, 20);
echo "OK";
... ... @@ -365,7 +295,28 @@ class NoticeController extends WebAction
exit();
}
/**
* 获取支付方式类对象
* @param type array $Parameters 回调参数
* @param type int $payment 支付方式
* @return type object
*/
private function getParseResponse($Parameters, $payment)
{
$payment = PayModel::getPaymentById($payment);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($Parameters);
if (empty($res->bankName)) {
$res->bankName = empty($payment['payName']) ? '' : $payment['payName'];
}
if (empty($res->bankCode)) {
$res->bankCode = empty($payment['pay_code']) ? '' : $payment['pay_code'];
}
return $res;
}
/**
* 通用显示结果的方法
... ... @@ -405,12 +356,6 @@ class NoticeController extends WebAction
*/
private function payResultProc($payResult, $payment)
{
// 初始化日志
$log = $this->log;
$log->LogInfo('================开始验证登录状态============');
$log->LogInfo('================支付结果数据为============');
$log->LogInfo(var_export($payResult, true));
//判断是否登录
$uid = $this->getUid();
if (empty($uid)) { // cookie中获取为空时再从之前保存的session中获取
... ... @@ -418,8 +363,6 @@ class NoticeController extends WebAction
$this->setSession(self::SESSION_UID_KEY, null);
}
$log->LogInfo('================已登录,获取到用户ID============');
$result = array(
'code' => 500,
'message' => '支付失败'
... ... @@ -430,9 +373,6 @@ class NoticeController extends WebAction
$result = PayModel::procOrderData($uid, $payResult, $payment);
}
$log->LogInfo('================支付结果为============');
$log->LogInfo(var_export($result, true));
return $result;
}
}
... ...
<?php
use Action\WebAction;
use Shopping\PaymentModel;
use WebPlugin\Pay\PayFactory;
use WebPlugin\Pay\Rspparams;
/**
* 支付 同步通知页面
*/
class PayreturnController extends WebAction
{
/**
* 支付宝浏览器端返回
*/
public function alipayreturnAction()
{
$res = $this->getParseResponse($_GET, 2);
$dealResult = $this->payResultProc($res, 2);
$dealResult['payData'] = array('payWay' => '支付宝');
$this->commonShowResult($dealResult);
}
/**
* 微信支付-轮询--jsonPcallback响应订单支付状态
*/
public function wechatcallbackAction()
{
$callback = $this->get('callback');
$orderCode = $this->get('ordercode');
$response = PaymentModel::checkWechatPayStatus($orderCode);
$this->helpJsonCallbackResult($callback, $response['code'], $response['message']);
}
/**
* 微信扫码支付返回
*/
public function wechatqrcodereturnAction()
{
$dealResult = array(
'code' => 500,
'message' => '支付失败'
);
do {
$orderCode = $this->get('order_code', 0);
if (empty($orderCode)) {
break;
}
$payment = PaymentModel::getPaymentById(21);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse(array('orderCode' => $orderCode));
$dealResult = $this->payResultProc($res, 21);
$dealResult['payData'] = array('payWay' => '微信扫码支付');
} while (false);
$this->commonShowResult($dealResult);
}
/**
* 银联web支付返回
*/
public function unionpaywebreturnAction()
{
$res = $this->getParseResponse($_REQUEST, 25);
$dealResult = $this->payResultProc($res, 25);
$dealResult['payData'] = array('payWay' => '银联在线支付');
$this->commonShowResult($dealResult);
}
/*
* 支付宝银行支付回调-同步地址
*/
public function alibankreturnAction()
{
$res = $this->getParseResponse($_GET, 12);
$dealResult = $this->payResultProc($res, 12);
$dealResult['payData'] = array('payWay' => '支联支付');
$this->commonShowResult($dealResult);
}
/**
* 获取支付方式类对象
* @param type array $Parameters 回调参数
* @param type int $payment 支付方式
* @return type object
*/
private function getParseResponse($Parameters, $payment)
{
$payment = PaymentModel::getPaymentById($payment);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($Parameters);
if (empty($res->bankName)) {
$res->bankName = empty($payment['payName']) ? '' : $payment['payName'];
}
if (empty($res->bankCode)) {
$res->bankCode = empty($payment['pay_code']) ? '' : $payment['pay_code'];
}
return $res;
}
/**
* 通用显示结果的方法
* @param array $dealResult
*/
private function commonShowResult($dealResult)
{
$code = $dealResult['code'];
$view = 'wechatqrcodereturn';
$data = array(
'headerData' => true,
'payData' => $dealResult['payData']
);
if ($code == 200) {
$view = 'index';
$data = array('payNotice' => $dealResult['data']);
}
//头部导航
$this->setSimpleHeader();
$this->_view->display($view, $data);
}
/**
* 处理支付返回的数据
*
* @param Rspparams $payResult 支付返回的结果
* @param $payment 支付方式id
* @return array
*/
private function payResultProc($payResult, $payment)
{
$result = array(
'code' => 500,
'message' => '支付失败'
);
if ($payResult->payResult == 200) {
if (!empty($payResult->orderCode)) {
//支付成功,发送一次支付确认
$uid = $this->getUid(true);
PaymentModel::sendPayConfirm($payResult->orderCode, $payment, $uid);
}
//支付成功
$result = PaymentModel::procOrderData($payResult, $payment);
}
return $result;
}
}
... ...
<?php
use Action\WebAction;
use Shopping\PayModel;
use Shopping\PaymentModel;
use WebPlugin\Helpers;
class WechatqrcodeController extends WebAction
... ... @@ -13,22 +13,20 @@ class WechatqrcodeController extends WebAction
*/
public function indexAction()
{
$uid = $this->getUid(true);
if (!$uid) {
$this->go(Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER'))));
}
$this->autoLogin();
$orderCode = $this->get('order_code', $this->get('ordercode'));
$data = PayModel::weixinQrcode($uid, $orderCode);
if (isset($data['error'])) {
$data = PaymentModel::weixinQrcode($orderCode);
if (empty($data['code']) || $data['code'] !== 200) {
$this->helpJsRedirect($data['message']);
}
$this->setSimpleHeader();
// 轮询是否支付成功地址
$data['payHost'] = Helpers::url('/pay/notice/wechatcallback', array('ordercode' => $orderCode));
$data['payHost'] = Helpers::url('/pay/payreturn/wechatcallback', array('ordercode' => $orderCode));
// 支付成功跳转地址
$data['paySuccessUrl'] = Helpers::url('/pay/notice/wechatqrcodereturn', array('order_code' => $orderCode));
$data['paySuccessUrl'] = Helpers::url('/pay/payreturn/wechatqrcodereturn', array('order_code' => $orderCode));
$this->_view->display('index', array(
'wechatqrcode' => $data,
'wechatqrcodePage' => true
... ...
<?php
use Action\WebAction;
use Shopping\PayModel;
use Shopping\PaymentModel;
use WebPlugin\Helpers;
use LibModels\Web\Home\UserData;
use WebPlugin\Cache;
/**
* 支付相关的控制器
*
... ... @@ -29,11 +30,14 @@ class PayController extends WebAction
if (!$uid) {
$this->go( Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN))) );
}
// 将用户UID存入session中以便支付成功回调使用
$this->setSession(self::SESSION_UID_KEY, $uid);
// 订单号
$orderCode = $this->get('order_code', $this->get('ordercode'));
if (USE_CACHE) {
// 将用户UID存入session中以便支付成功回调使用
$this->setSession(self::SESSION_UID_KEY, $uid);
Cache::set(self::SESSION_UID_KEY . $orderCode, $uid, 3600 * 10);
}
//支付宝快捷支付
$alipayToken = $this->getSession('alipay_user_token');
... ... @@ -41,7 +45,7 @@ class PayController extends WebAction
$this->go(Helpers::url('/pay/index/index', array('order_code' => $orderCode, 'payment_type' => '2_platform')));
}
$data = PayModel::getPayTypeData($uid, $orderCode);
$data = PaymentModel::getPayTypeData($uid, $orderCode);
//不存在订单时
if (isset($data['noOrder'])) {
$this->helpJsRedirect('没有找到该订单');
... ... @@ -76,7 +80,25 @@ class PayController extends WebAction
'payPage' => true
));
}
/**
* 单击已完成支付按钮--发送一次支付确认
*/
public function sendPayAction()
{
$result = array('code' => 400, 'message' => '操作失败!');
if ($this->isAjax()) {
do {
$uid = $this->getUid(true);
$orderCode = $this->post('orderCode', 0);
$paymentId = $this->post('paymentId', 0);
if (empty($orderCode) || empty($uid) || empty($paymentId)) {
break;
}
$result = PaymentModel::sendPayConfirm($orderCode, $paymentId, $uid);
} while (false);
}
$this->echoJson($result);
}
}
... ...
... ... @@ -184,7 +184,7 @@ routes.coupons.route.action = Index
; 商品支付方式选择
routes.paytypechoose.type = "rewrite"
routes.paytypechoose.match = "/shopping/pay"
routes.paytypechoose.match = "/shopping/pay$"
routes.paytypechoose.route.module = Shopping
routes.paytypechoose.route.controller = Pay
routes.paytypechoose.route.action = Index
... ...