nizongfeng 3 years ago
parent
commit
ae8f789fd4
1 changed files with 12 additions and 5 deletions
  1. +12
    -5
      addons/unishop/controller/Pay.php

+ 12
- 5
addons/unishop/controller/Pay.php View File

@@ -126,10 +126,14 @@ class Pay extends Base

$paytype = $this->request->param('type');
$string = date('Y-m-d H:i:s', time()) . PHP_EOL;
file_put_contents(ROOT_PATH . '/runtime/log/' . date('Ym') ."/pay_".date("d"). '.log', $string.$paytype . PHP_EOL, FILE_APPEND);
$body = file_get_contents("php://input");
if (empty($body) == false) {
$string .= 'body : ' . json_encode($body) . PHP_EOL;
}
$pay = Service::checkNotify($paytype);
if (!$pay) {
file_put_contents(ROOT_PATH . '/runtime/log/' . date('Ym') ."/pay_".date("d"). '.log', "签名错误" . PHP_EOL, FILE_APPEND);
$string.="签名错误" . PHP_EOL;
file_put_contents(ROOT_PATH . '/runtime/log/' . date('Ym') ."/pay_".date("d"). '.log',$string , FILE_APPEND);
echo '签名错误';
return;
}
@@ -149,13 +153,15 @@ class Pay extends Base
$orderModel = new \addons\unishop\model\Order(); //($message['out_trade_no']);
$order = $orderModel->where(['out_trade_no' => $out_trade_no])->find();
if (!$order || $order->have_paid != \addons\unishop\model\Order::PAID_NO) {
file_put_contents(ROOT_PATH . '/runtime/log/' . date('Ym') ."/pay_".date("d"). '.log', "订单不存在或已完成" . PHP_EOL, FILE_APPEND);
$string.="订单不存在或已完成" . PHP_EOL;
file_put_contents(ROOT_PATH . '/runtime/log/' . date('Ym') ."/pay_".date("d"). '.log',$string , FILE_APPEND);
throw new Exception('订单不存在或已完成');
}

// 条件二
if ($order->total_price > $payamount || $order->total_price < $payamount) {
file_put_contents(ROOT_PATH . '/runtime/log/' . date('Ym') ."/pay_".date("d"). '.log', "金额不一". PHP_EOL, FILE_APPEND);
$string.="金额不一" . PHP_EOL;
file_put_contents(ROOT_PATH . '/runtime/log/' . date('Ym') ."/pay_".date("d"). '.log',$string , FILE_APPEND);
throw new Exception('金额不一');
}

@@ -164,7 +170,8 @@ class Pay extends Base
$payTypeString = $paytype == 'alipay' ? \addons\unishop\model\Order::PAY_ALIPAY : \addons\unishop\model\Order::PAY_WXPAY;
Hook::listen('paid_success', $order, ['pay_type' => $payTypeString]);
} catch (Exception $e) {
file_put_contents(ROOT_PATH . '/runtime/log/' . date('Ym') ."/pay_".date("d"). '.log', $e->getMessage() . PHP_EOL, FILE_APPEND);
$string.=$e->getMessage() . PHP_EOL;
file_put_contents(ROOT_PATH . '/runtime/log/' . date('Ym') ."/pay_".date("d"). '.log',$string , FILE_APPEND);
}
$pay = new \Yansongda\Pay\Pay();
echo $pay->success();


Loading…
Cancel
Save