Authored by 郝肖肖

支付确认接口

... ... @@ -147,26 +147,4 @@ class OrderData
// 调用接口获得数据
return Yohobuy::post(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);
}
}
... ...
... ... @@ -240,4 +240,26 @@ class PayData
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
... ...
... ... @@ -318,10 +318,10 @@ class PaymentModel
$notify = new WxPayNativePay();
$payResult = $notify->GetPayUrl($input);
// if ($payResult['result_code'] === 'FAIL') {
// self::$code['message'] = $payResult['err_code_des'];
// break;
// }
if ($payResult['result_code'] === 'FAIL') {
self::$code['message'] = $payResult['err_code_des'];
break;
}
$orderData = $orderDetail['data'];
$firstGoods = current($orderData['order_goods']);
... ... @@ -425,7 +425,7 @@ class PaymentModel
$orderCode = $payResult->orderCode;
//如果uid,为空,则从缓存中取uid,但还是不排除uid为空的情况下。
$uid = empty($uid) ? self::getUid($orderCode) : $uid;
$confirm = OrderData::payConfirm($orderCode, $paymentId, $uid);
$confirm = PayData::payConfirm($orderCode, $paymentId, $uid);
// UdpLog::info(
// "【支付成功-发送确认接口】,function:payConfirm,orderCode:{$orderCode},支付方式ID:{$paymentId},接口返回",
... ... @@ -433,4 +433,116 @@ class PaymentModel
// );
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']);
}
... ...