Authored by 梁志锋

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

... ... @@ -61,6 +61,16 @@ class Config
* 支付方式
* @var unknown_type
*/
var $payType = 0; //非直连为0
var $payType = 0; //非直连为0
/**
* @var string 日志目录
*/
var $logDir = '/Data/logs/pc_pay/allinpay';
/**
* @var string 日志等级
*/
var $logLevel = 2; // 记录信息日志
}
\ No newline at end of file
... ...
... ... @@ -14,9 +14,7 @@ abstract class PayAbstract implements PayInterface {
*
* @var
*/
public $baseNoticeUrl = "http://www.yohobuy.com/pay/";
// public $baseNoticeUrl = "http://www.yohobuy.com/pay/";
public $baseNoticeUrl = "http://gray.yohobuy.com/pay/";
/**
* 测试的回调地址
... ...
... ... @@ -2,12 +2,36 @@
namespace WebPlugin\Pay\weixin;
use LibModels\Web\Home\OrderData;
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;
class PayNotifyCallBack extends WxPayNotify
{
// 向ERP提交订单状态有关接口调用日志和更新订单状态有关接口调用日志
const ORDER_STATUS_LOG = '/Data/logs/pc_pay/order_status';
// 日志等级,2表示记录信息等级的日志
const LOG_LEVEL = 2;
// 获取微信订单中的订单号需要截取的开始位置
const ORDER_CODE_START = 8;
private $log = null;
private $_uid;
/**
* PayNotifyCallBack constructor.
* @param int $uid
*/
public function __construct($uid)
{
// 初始化日志
$this->log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$this->_uid = $uid;
}
//查询订单
public function Queryorder($transaction_id)
... ... @@ -16,8 +40,44 @@ class PayNotifyCallBack extends WxPayNotify
$input->SetTransaction_id($transaction_id);
$result = WxPayApi::orderQuery($input);
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);
$payment = 21; // 微信扫码支付
$bankName = 'WX';
$bankCode = '';
$amount = $result['total_fee'] / 100;
$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));
if (!isset($orderInfo['data']) || empty($orderInfo['data'])) {
$this->log->LogInfo('==[' . $orderCode . ']=微信支付状态同步中未获取到订单详情信息===');
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 . ']=微信扫码订单支付成功===');
return true;
}
return false;
}
... ... @@ -33,6 +93,9 @@ class PayNotifyCallBack extends WxPayNotify
$msg = "订单查询失败";
return false;
}
$this->log->LogInfo('=====微信扫码支付通知结果为:' . $msg . '=====');
return true;
}
... ...
... ... @@ -31,7 +31,7 @@ class WxPayConfig
const APPSECRET = 'ce21ae4a3f93852279175a167e54509b';
//=======【异步通知url设置】===================================
//异步通知url,商户根据实际开发过程设定
const NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/wechatqrcodenotify';
const NOTIFY_URL = 'http://gray.yohobuy.com/pay/notice/wechatqrcodenotify';
//=======【证书路径设置】=====================================
/**
* TODO:设置商户证书路径
... ...
... ... @@ -401,7 +401,12 @@ 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;
... ... @@ -410,6 +415,7 @@ class PayModel
/* 判断订单信息是否存在 */
$orderDetail = OrderData::getOrderDetail($uid, $orderCode);
if (!isset($orderDetail['data']) || empty($orderDetail['data'])) {
$log->LogInfo('=====[' . $orderCode . ']===微信支付时,订单信息未查到========');
$result['error'] = true;
$result['message'] = '没有找到该订单';
break;
... ... @@ -436,6 +442,8 @@ class PayModel
$input->SetProduct_id($orderCode);
$notify = new WxPayNativePay();
$payResult = $notify->GetPayUrl($input);
$log->LogInfo('=====[' . $orderCode . ']===微信支付时,微信统一下单的返回结果为:========');
$log->LogInfo(var_export($payResult, true));
$orderData = $orderDetail['data'];
$firstGoods = current($orderData['order_goods']);
... ... @@ -447,10 +455,12 @@ class PayModel
'tellphoneNum' => $orderData['mobile'],
'tradeName' => $firstGoods['product_name'],
'choosePayUrl' => Helpers::url('/shopping/pay', array('order_code' => $orderData['order_code'])),
'qrcodeUrl' => $payResult['code_url']//$reqPars['pay_url'] // 'http://paysdk.weixin.qq.com/example/qrcode.php?data=' . $result['code_url']
'qrcodeUrl' => $payResult['code_url'] // 'http://paysdk.weixin.qq.com/example/qrcode.php?data=' . $result['code_url']
);
} while (false);
$log->LogInfo('=====[' . $orderCode . ']===微信支付时,处理微信支付的结果为:========');
$log->LogInfo(var_export($result, true));
return $result;
}
... ... @@ -476,22 +486,24 @@ class PayModel
// 初始化日志
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('========[' . $orderCode . ']========');
$log->LogInfo('========开始查询微信扫码支付状态========');
$log->LogInfo('=====[' . $orderCode . ']===开始查询微信扫码支付状态========');
// 组装微信支付的订单号
$tradeNo = 'YOHOBuy_' . $orderCode;
$input = new WxPayOrderQuery();
$input->SetOut_trade_no($tradeNo);
$payResult = WxPayApi::orderQuery($input);
$log->LogInfo(var_export($payResult, true));
if (isset($payResult['trade_state']) && $payResult['trade_state'] === 'SUCCESS') {
$log->LogInfo('========微信扫码支付成功========');
$log->LogInfo('====[' . $orderCode . ']====微信扫码支付成功========');
$result = array(
'code' => '200',
'message' => 'success'
);
}
$log->LogInfo('====[' . $orderCode . ']====微信扫码支付失败========');
} while (false);
return $result;
... ... @@ -518,13 +530,13 @@ class PayModel
$log->LogInfo('========[' . $payResult->orderCode . ']========');
$log->LogInfo(var_export($payResult, true));
$log->LogInfo('===开始调用获取订单详情方式接口,接口方法为app.SpaceOrders.detail===');
$log->LogInfo('==[' . $payResult->orderCode . ']=开始调用获取订单详情方式接口,接口方法为app.SpaceOrders.detail===');
$orderInfo = OrderData::getOrderDetail($uid, $payResult->orderCode);
$log->LogInfo('===结束调用获取订单详情方式接口,返回结果为===');
$log->LogInfo('==[' . $payResult->orderCode . ']=结束调用获取订单详情方式接口,返回结果为===');
$log->LogInfo(var_export($orderInfo, true));
if (!isset($orderInfo['data']) || empty($orderInfo['data'])) {
$log->LogInfo('===订单支付失败,未获取到订单详情信息===');
$log->LogInfo('==[' . $payResult->orderCode . ']=订单支付失败,未获取到订单详情信息===');
break;
}
... ... @@ -539,9 +551,9 @@ class PayModel
// 初始化日志
$log = new PhpLog(self::SEND_MESSAGE_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===[' . $orderCode . ']===');
$log->LogInfo('===开始调用订单取消时给用户发短信接口,接口方法为app.message.sendMsg===');
$log->LogInfo('==[' . $orderCode . ']=开始调用订单取消时给用户发短信接口,接口方法为app.message.sendMsg===');
$messageReturn = PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode);
$log->LogInfo('===结束调用给用户发短信接口,返回结果为===');
$log->LogInfo('==[' . $orderCode . ']=结束调用给用户发短信接口,返回结果为===');
$log->LogInfo(var_export($messageReturn, true));
$result['code'] = 417;
... ... @@ -552,7 +564,7 @@ class PayModel
// 支付金额与订单金额不一致
if (round($amount, 2) != round($payResult->totalFee, 2)) {
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===订单支付失败,支付金额与订单金额不一致===');
$log->LogInfo('==[' . $orderCode . ']=订单支付失败,支付金额与订单金额不一致===');
$result['code'] = 415;
$result['message'] = '支付金额与订单金额不一致';
break;
... ... @@ -569,20 +581,20 @@ class PayModel
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===[' . $orderCode . ']===');
$log->LogInfo('===开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');
$log->LogInfo('===请求参数为orderCode=' . $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('===结束调用ERP提交订单状态接口,返回结果为===');
$log->LogInfo('==[' . $orderCode . ']=结束调用ERP提交订单状态接口,返回结果为===');
$log->LogInfo(var_export($erpReturn, true));
$log->LogInfo('===开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');
$log->LogInfo('===请求参数为orderId=' . $orderData['order_id'] . 'uid=' . $uid . '===');
$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('===结束调用更新订单状态接口,返回结果为===');
$log->LogInfo('==[' . $orderCode . ']=结束调用更新订单状态接口,返回结果为===');
$log->LogInfo(var_export($updateOrderStatus, true));
$log->LogInfo('===订单支付成功,请等待发货===');
$log->LogInfo('==[' . $orderCode . ']=订单支付成功,请等待发货===');
$result['code'] = 200;
$result['message'] = '支付成功,请等待发货';
... ...
... ... @@ -278,7 +278,13 @@ class NoticeController extends WebAction
public function wechatqrcodenotifyAction()
{
$this->log->LogInfo("begin wechatqrcodenotifyAction");
$notify = new PayNotifyCallBack();
$uid = $this->getUid();
if (empty($uid)) { // cookie中获取为空时再从之前保存的session中获取
$uid = $this->getSession(self::SESSION_UID_KEY);
$this->setSession(self::SESSION_UID_KEY, null);
}
$notify = new PayNotifyCallBack($uid);
$notify->handle(false);
}
... ...