shaoguo il y a 9 mois
Parent
commit
5c34af24e9

+ 1 - 0
hua_fei/2024-01-26notify.log

@@ -0,0 +1 @@
+20:29:56响应[]

+ 11 - 0
hua_fei/2024-01-26pay.log

@@ -5,3 +5,14 @@
 01:54:40{"code":"-1","msg":"pay\u7f3a\u5c11\u53c2\u6570"}
 01:59:51{"code":"-1","msg":"pay\u7f3a\u5c11\u53c2\u6570"}
 02:28:45{"code":"-1","msg":"pay\u7f3a\u5c11\u53c2\u6570"}
+18:14:15请求:{"user_id":"1","price":"30","phone":"17607184412","order_sn":"order_sn65b385f7ce73d","created_at":"2024-01-26 18:14:15","updated_at":"2024-01-26 18:14:15"}
+18:14:16响应{"code":"-1","msg":"pay\u7f3a\u5c11\u53c2\u6570"}
+18:15:16请求:{"client_ip":"127.0.0.1","format":"json","from_name":"\u6d4b\u8bd5","goods_desc":"\u6d4b\u8bd5","mch_id":"tongue","money":"30","notify_url":"http:\/\/test.com","order_sn":"order_sn65b3863438be1","pay_backurl":"http:\/\/127.0.0.1:8000\/pay","ptype":82,"time":1706264116,"key":"37cd2d09c84f6ff7f1d28960ef82c4e533a3c047","sign":"f41d8619f630a26aafc1123192d98e5b"}
+18:15:16响应{"code":"-1","msg":"pay\u7f3a\u5c11\u53c2\u6570"}
+18:28:22请求:client_ip=127.0.0.1&format=json&from_name=%E6%B5%8B%E8%AF%95&goods_desc=%E6%B5%8B%E8%AF%95&mch_id=tongue&money=30&notify_url=http%3A%2F%2Ftest.com&order_sn=order_sn65b3894635f9c&pay_backurl=http%3A%2F%2F127.0.0.1%3A8000%2Fpay&ptype=82&time=1706264902&key=37cd2d09c84f6ff7f1d28960ef82c4e533a3c047&sign=120c0a78451b3defbb4083f370530fa9
+18:28:22响应{"code":"-1","msg":"pay\u7f3a\u5c11\u53c2\u6570"}
+18:32:13请求:client_ip=127.0.0.1&format=json&from_name=%E6%B5%8B%E8%AF%95&goods_desc=%E6%B5%8B%E8%AF%95&mch_id=tongue&money=30&notify_url=http%3A%2F%2Ftest.com&order_sn=order_sn65b38a2d9b2b2&pay_backurl=http%3A%2F%2F127.0.0.1%3A8000%2Fpay&ptype=82&time=1706265133&key=37cd2d09c84f6ff7f1d28960ef82c4e533a3c047&sign=cdee210d2fddc22901a7261d43c45358
+18:32:14响应{"code":"-1","msg":"pay\u7f3a\u5c11\u53c2\u6570"}
+18:34:11请求:client_ip=127.0.0.1&format=json&from_name=%E6%B5%8B%E8%AF%95&goods_desc=%E6%B5%8B%E8%AF%95&mch_id=tongue&money=30&notify_url=http%3A%2F%2Ftest.com&order_sn=order_sn65b38aa32b381&pay_backurl=http%3A%2F%2F127.0.0.1%3A8000%2Fpay&ptype=82&time=1706265251&key=37cd2d09c84f6ff7f1d28960ef82c4e533a3c047&sign=a25bc8cbbfa0162e8df8e94564f98f57
+18:34:36请求:client_ip=127.0.0.1&format=json&from_name=%E6%B5%8B%E8%AF%95&goods_desc=%E6%B5%8B%E8%AF%95&mch_id=tongue&money=30&notify_url=http%3A%2F%2Ftest.com&order_sn=order_sn65b38abc02f8d&pay_backurl=http%3A%2F%2F127.0.0.1%3A8000%2Fpay&ptype=82&time=1706265276&key=37cd2d09c84f6ff7f1d28960ef82c4e533a3c047&sign=5576ac2aaa959fbace5b539b3c978296
+18:34:37响应{"code":"1","msg":"\u4e0b\u5355\u6210\u529f","data":{"order_sn":"ZZHF20240126183436808","ptype":"82","ptype_name":"","realname":null,"account":null,"money":"30","bank":"","branch_name":"","qrcode":"https:\/\/hh5ad.hnapay.com\/pay\/order.shtml?orderId=2024012676093324&orderKey=e7e1e69242a234c3e766438b507b70a6f7b6cd2a"}}

BIN
hua_fei/config/huafei.sqlite3


+ 30 - 2
hua_fei/index.php

@@ -5,14 +5,42 @@ include WEB_ROOT_CONFIG."/config.php";
 
 $type=trim($_SERVER['PATH_INFO']??"home",'/');
 
-if(isset($_POST['a']) && strtolower($_SERVER['REQUEST_METHOD'])=="post"){
-    header("Content-type: text/json; charset=utf-8");
+
+//退出登录
+if(isset($_POST['a']) && strtolower($_SERVER['REQUEST_METHOD'])=="post" && $_POST['a']=='logout'){
 
        if(!session_unset())exit(json_encode(array("code"=>0,"msg"=>"退出登录失败")));
     exit(json_encode(array("code"=>1,"msg"=>"退出成功")));
 }
 
 
+//回调
+if($type=="notify"){
+    header("Content-type: text/json; charset=utf-8");
+    file_put_contents(date("Y-m-d").'notify.log',date("H:i:s")."回调:".json_encode($_POST)."\r\n",FILE_APPEND);
+    $data=[
+        "sh_order"=>$_POST['sh_order']??"",
+        "pt_order"=>$_POST['pt_order']??"",
+        "money"=>$_POST['money']??"",
+        "time"=>$_POST['time']??"",
+        "status"=>$_POST['status']??"",
+    ];
+    if(isset($_POST['old_money']))$data['old_money']=($_POST['money']??"");
+    ksort($data);
+    $data['key']="37cd2d09c84f6ff7f1d28960ef82c4e533a3c047";
+    $new_sign=md5(urldecode(http_build_query($data)));
+    if($new_sign!=$_POST['sign'])exit("签名错误");
+    $order_simit=$pdo->query("select * from order where `order_sn`='{$data['sh_order']}' and `app_order_sn`='{$data['pt_order']}' limit 1");
+    $order=$order_simit->fetch(PDO::FETCH_ASSOC);
+    if(empty($order))exit("订单不存在");
+    $status=1;
+    if($order['success']!="success")$status=2;
+    $update_simit=$pdo->prepare('update order set status=? where `order_sn`=? and `app_order_sn`=?');
+    $res=$update_simit->execute([$status,$data['sh_order'],$data['pt_order']]);
+    if(!$res)exit("失败");
+    exit("success");
+}
+
 
 if(!isset($_SESSION['admin_id']) && empty($_SESSION['admin_id']) && $type!="login" && $type!="register"){
     header("location:/login");

+ 35 - 10
hua_fei/pay.php

@@ -16,9 +16,9 @@ $data=[
 $statement=$pdo->prepare("insert into recharge(`user_id`,`price`,`phone`,`order_sn`,`created_at`,`updated_at`) values(?,?,?,?,?,?)");
 $res=$statement->execute(array_values($data));
 if(!$res)exit(json_encode(['code'=>0,"msg"=>"创建订单失败"]));
+$id=$pdo->lastInsertId();
 $url  = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http";
 $url .= "://" . $_SERVER['HTTP_HOST'];
-$url .= $_SERVER['REQUEST_URI'];
 
 $request_data=[
     "mch_id"=>"tongue",
@@ -29,25 +29,50 @@ $request_data=[
     "goods_desc"=>"测试",
     "client_ip"=>$_SERVER['REMOTE_ADDR']??"127.0.0.1",
     "format"=>"json",
-    "notify_url"=>"http://test.com",
+    "notify_url"=>$url."/notify",
     "pay_backurl"=>$url,
     "time"=>time(),
 ];
 
+
 ksort($request_data);
 $request_data['key']="37cd2d09c84f6ff7f1d28960ef82c4e533a3c047";
 $request_data['sign']=md5(urldecode(http_build_query($request_data)));
 
-//unset($request_data['key']);
-//echo "<pre>";
-//var_dump(http_build_query($request_data));
-//var_dump($request_data);
-//echo "</pre>";
-//exit();
-$res=curl_request("http://47.236.143.199/?c=Pay",$request_data,"post",array("content-type: application/json"),false);
+unset($request_data['key']);
+echo "<pre>";
+var_dump(http_build_query($request_data));
+var_dump($request_data);
+echo "</pre>";
+exit();
+
+//正式环境打开
+/*file_put_contents(date("Y-m-d").'pay.log',date("H:i:s")."请求:".http_build_query($request_data)."\r\n",FILE_APPEND);
+$res=curl_request("http://47.236.143.199/?c=Pay&".http_build_query($request_data),array(),"get",array("content-type: text/html"),false);
 $res=json_decode($res,true);
-file_put_contents(date("Y-m-d").'pay.log',date("H:i:s").json_encode($res)."\r\n",FILE_APPEND);
+file_put_contents(date("Y-m-d").'pay.log',date("H:i:s")."响应".json_encode($res)."\r\n",FILE_APPEND);*/
+$res=json_decode('{
+"code": "1",
+"msg": "下单成功",
+"data": {
+"order_sn": "ZZHF20240126183436808",
+"ptype": "82",
+"ptype_name": "",
+"realname": null,
+"account": null,
+"money": "30",
+"bank": "",
+"branch_name": "",
+"qrcode": "https://hh5ad.hnapay.com/pay/order.shtml?orderId=2024012676093324&orderKey=e7e1e69242a234c3e766438b507b70a6f7b6cd2a"
+}
+}',true);
 if($res['code']!=1)exit(json_encode(['code'=>0,"msg"=>"下单失败"]));
+$statement=$pdo->exec("update recharge set `app_order_sn`='{$res['data']['order_sn']}' where id={$id}");
+
+exit(json_encode(['code'=>1,'msg'=>'success',"data"=>['pay_url'=>$res['data']['qrcode']]]));
+
+
+
 //exit(json_encode(['code'=>1,"msg"=>"","data"=>[
 //    "pay_url"=>$res['']
 //]]));

+ 10 - 9
hua_fei/static/js/recharge_flow_new.min.js

@@ -123,17 +123,18 @@ $(function () {
                     , r = common.getQuery("digest")
                     , c = common.getQuery("userInfo");
                 console.log(e,i);
-            common.ajax("/pay", {
+            $.post("/pay", {
                 phone:e,
                 price:i,
-            }, {
-                success: function(o) {
-                   console.log(o)
-                },
-                error: function(o, n) {
-                    console.log(o)
-                },
-                type:"post"
+            },function(res) {
+               if(res.code==0){
+                   common.tip(res.msg)
+                   setTimeout(function (){
+                       window.location.reload();
+                   },4*1000)
+               }else{
+                   window.location.href=res.data.pay_url
+               }
             })
             
         }),