123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?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_hykb.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(); # [数据库操作]更新订单状态,->已付款
- 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;
- }
- /**
- * 获得用户的平台字符串
- * @return string
- */
- static function getPlatStr($uid) {
- if (strrpos($uid, '_') > 0) {
- return substr($uid, strrpos($uid, '_') + 1); # 提取平台字符串
- } else {
- return "";
- }
- //PS. substr() 函数返回字符串的一部分 strrpos() 函数查找字符串在另一字符串中最后一次出现的位置。
- }
- }
- HttpUtil::PostOnly();
- CLog::pay("[notify.wx] [收到通知]: " . HttpUtil::getQueryString()); # 日志
- $notify = new PayNotifyCallBack();
- $notify->Handle(false); # 处理
|