12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- ini_set('date.timezone', 'Asia/Shanghai');
- error_reporting(E_ERROR);
- require_once __DIR__ . '/../../../../main.php'; # 导入game utils
- include_once __DIR__ . '/../../Mo/payResp.php'; # 导入通用返回值结构
- include_once __DIR__ . '/../../Mo/payRequest.php'; # 导入通用返回值结构
- require_once __DIR__ . '/../../Mo/OrderNotice.php'; # 导入通知数据接收模型
- require_once __DIR__ . '/wx.php'; # 导入微信支付lib
- use loyalsoft\CLog;
- use loyalsoft\HttpUtil;
- class PayNotifyCallBack extends WxPayNotify {
- //查询订单
- public function Queryorder($transaction_id) {
- $input = new WxPayOrderQuery();
- $input->SetTransaction_id($transaction_id);
- $result = WxPayApi::orderQuery($input);
- CLog::pay("[notify.wx]query:" . json_encode($result));
- if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result)#
- && $result["return_code"] == "SUCCESS" #
- && $result["result_code"] == "SUCCESS") {
- return true;
- }
- return false;
- }
- //重写回调处理函数
- public function NotifyProcess($data, &$msg) {
- CLog::pay("[notify.wx]call back:" . json_encode($data));
- // $notfiyOutput = array();
- if (!array_key_exists("transaction_id", $data)) {
- $msg = "输入参数不正确";
- CLog::pay("[notify.wx] $msg"); # 日志
- return false;
- }
- //查询订单,判断订单真实性
- if (!$this->Queryorder($data["transaction_id"])) {
- $msg = "订单查询失败";
- CLog::pay("[notify.wx] $msg"); # 日志
- return false;
- }
- $order = loyalsoft\pay\OrderNotice::Parse_weixinpayOrder($data); # 提取参数
- CLog::pay($order);
- if ($order == null) { #
- $msg = "提取通知参数失败";
- CLog::pay("[notify.wx] $msg"); # 日志
- return false;
- }
- if (!$order->Check()) { # 订单校验,
- $msg = "订单校验失败";
- CLog::pay("[notify.wx] $msg"); # 日志
- return false;
- }
- if ($order->status == 2) { # status为2(failed)的情况
- $order->UpdateOrderStatus(); # [数据库操作]直接更新订单状态,->支付失败
- $msg = "订单状态异常";
- CLog::pay("[notify.wx] 异常的订单状态, 此处微信验证已通过,为啥自己的验证不通过!!!" . $order->cpOrderId);
- return false;
- }
- if ($order->status == 1) { # 订单状态是成功 1代表支付成功
- $order->UpdateOrderStatus(); # [数据库操作]更新订单状态,->已付款
- // if (PLAT == 'tap') {
- loyalsoft\TapDBUtil::PushPayEvent($order, 'wxpay'); # 向tapdb推送充值记录
- // }
- CLog::pay("[notify.wx] [发货] " . $order->cpOrderId . " >>> " . $order->amount);
- $msg = "success";
- return true;
- }
- $msg = "未知的支付状态";
- CLog::pay("[notify.wx][处理结果]: FAILURE ($msg)"); # 日志
- return false;
- }
- }
- HttpUtil::PostOnly();
- CLog::pay("[notify.wx] [收到通知]: " . HttpUtil::getQueryString()); # 日志
- $notify = new PayNotifyCallBack();
- $notify->Handle(false); # 处理
|