PayNotifyCallBack.php
3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
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\UdpLog;
class PayNotifyCallBack extends WxPayNotify
{
// 获取微信订单中的orderCode需要截取的开始位置
const ORDER_CODE_START = 8;
private $_uid;
/**
* PayNotifyCallBack constructor.
* @param int $uid
*/
public function __construct($uid)
{
$this->_uid = $uid;
}
//查询订单
public function Queryorder($transaction_id)
{
$input = new WxPayOrderQuery();
$input->SetTransaction_id($transaction_id);
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,function:Queryorder,微信扫码支付交易号", $transaction_id);
$result = WxPayApi::orderQuery($input);
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);
$payment = 21; // 微信扫码支付
$bankName = 'WX';
$bankCode = '';
$amount = $result['total_fee'] / 100;
$tradeNo = $result['out_trade_no'];
$bankBillNo = $result['bank_type'];
$orderInfo = OrderData::getOrderDetail('', $orderCode);
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,orderCode:{$orderCode},function:Queryorder,订单详情", $orderInfo);
if (!isset($orderInfo['data']) || empty($orderInfo['data'])) {
UdpLog::error("【{$this->logProjectPrefix}-微信扫码支付】,orderCode:{$orderCode},function:Queryorder,微信支付状态同步中未获取到订单详情信息", $orderInfo);
return false;
}
//更新订单状态
$updateOrderStatus = PayData::pcpayNotify($orderCode, $payment, $amount, $bankName, $bankCode, $tradeNo, $bankBillNo);
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,orderCode:{$orderCode},function:Queryorder,更新订单状态结果", $updateOrderStatus);
return true;
}
return false;
}
//重写回调处理函数
public function NotifyProcess($data, &$msg)
{
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,function:NotifyProcess,参数", $data);
if (!array_key_exists("transaction_id", $data)) {
$msg = "输入参数不正确";
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,function:NotifyProcess,输入参数不正确", $data);
return false;
}
//查询订单,判断订单真实性
if (!$this->Queryorder($data["transaction_id"])) {
$msg = "订单查询失败";
UdpLog::info("【{$this->logProjectPrefix}-微信扫码支付】,function:NotifyProcess,订单查询失败", $data);
return false;
}
return true;
}
}