From 251692d012fe5d7e402dbc251c4415c1ba919d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BF=97=E5=BC=BA?= <357099073@qq.com> Date: Tue, 28 Apr 2026 15:38:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/controller/Index.php | 120 +++++++++++++++++++++++++ route/route.php | 2 + 2 files changed, 122 insertions(+) diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index 16832eb..ab1617f 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -352,6 +352,52 @@ class Index } } + + //获取待支付订单列表 + public function getPendingOrders() + { + $key = Db::name("setting")->where("vkey", "key")->find(); + $key = $key ? $key['vvalue'] : ""; + $t = input("t"); + $sign = input("sign"); + $type = input("type"); + + if (!$t || !$sign) { + return json($this->getReturn(-1, "请传入时间戳和签名")); + } + + $_sign = md5($t . $key); + if ($_sign != $sign) { + return json($this->getReturn(-1, "签名校验不通过")); + } + + $query = Db::name("pay_order") + ->where("state", 0) + ->order("create_date desc") + ->limit(50); + + if ($type !== null && $type !== '') { + $query->where("type", intval($type)); + } + + $rows = $query->select(); + $data = array(); + foreach ($rows as $row) { + $data[] = array( + "payId" => $row['pay_id'], + "orderId" => $row['order_id'], + "param" => $row['param'], + "payType" => intval($row['type']), + "price" => floatval($row['price']), + "reallyPrice" => floatval($row['really_price']), + "state" => intval($row['state']), + "timeOut" => intval((Db::name("setting")->where("vkey", "close")->find())['vvalue']), + "date" => intval($row['create_date']) + ); + } + + return json($this->getReturn(1, "成功", $data)); + } //关闭订单 public function closeOrder(){ $res2 = Db::name("setting")->where("vkey","key")->find(); @@ -526,6 +572,59 @@ class Index } + //App按订单推送付款数据接口 + public function appPushOrder(){ + $this->closeEndOrder(); + + $res2 = Db::name("setting")->where("vkey","key")->find(); + $key = $res2['vvalue']; + $orderId = input("orderId"); + $tradeNo = input("tradeNo"); + $t = input("t"); + + if (!$orderId || !$t) { + return json($this->getReturn(-1, "参数不完整")); + } + + $_sign = $orderId.$tradeNo.$t.$key; + if (md5($_sign)!=input("sign")){ + return json($this->getReturn(-1, "签名校验不通过")); + } + + Db::name("setting") + ->where("vkey","lastpay") + ->update(array( + "vvalue"=>time() + )); + + $res = Db::name("pay_order")->where("order_id",$orderId)->find(); + if (!$res){ + return json($this->getReturn(-1, "云端订单编号不存在")); + } + + if ($res['state']==1){ + return json($this->getReturn(1, "订单已完成")); + } + + if ($res['state']!=0){ + return json($this->getReturn(-1, "订单状态不允许推送")); + } + + Db::name("tmp_price") + ->where("oid",$res['order_id']) + ->delete(); + + Db::name("pay_order")->where("id",$res['id'])->update(array("state"=>1,"pay_date"=>time(),"close_date"=>time())); + + $notifyResult = $this->notifyOrder($res); + if ($notifyResult === "success"){ + return json($this->getReturn(1, "成功")); + }else{ + Db::name("pay_order")->where("id",$res['id'])->update(array("state"=>2)); + return json($this->getReturn(-1,"异步通知失败",$notifyResult)); + } + } + //关闭过期订单接口(请用定时器至少1分钟调用一次) public function closeEndOrder(){ @@ -612,4 +711,25 @@ class Index return $ret; } + private function notifyOrder($res) + { + $url = $res['notify_url']; + + $res2 = Db::name("setting")->where("vkey","key")->find(); + $key = $res2['vvalue']; + + $p = "payId=".$res['pay_id']."¶m=".$res['param']."&type=".$res['type']."&price=".$res['price']."&reallyPrice=".$res['really_price']; + + $sign = $res['pay_id'].$res['param'].$res['type'].$res['price'].$res['really_price'].$key; + $p = $p . "&sign=".md5($sign); + + if (strpos($url,"?")===false){ + $url = $url."?".$p; + }else{ + $url = $url."&".$p; + } + + return $this->getCurl($url); + } + } \ No newline at end of file diff --git a/route/route.php b/route/route.php index 19f3e92..3d659c0 100644 --- a/route/route.php +++ b/route/route.php @@ -21,10 +21,12 @@ Route::any('createOrder','index/index/createOrder'); Route::any('getOrder','index/index/getOrder'); Route::any('checkOrder','index/index/checkOrder'); +Route::any('getPendingOrders','index/index/getPendingOrders'); Route::any('getState','index/index/getState'); Route::any('appHeart','index/index/appHeart'); Route::any('appPush','index/index/appPush'); +Route::any('appPushOrder','index/index/appPushOrder'); Route::any('closeEndOrder','index/index/closeEndOrder');