From 780e31d3ba5478d17fb770ee5e1dd8329264c5c1 Mon Sep 17 00:00:00 2001 From: flyqieqq Date: Mon, 22 Jul 2019 19:52:06 +0800 Subject: [PATCH] =?UTF-8?q?1.1=E6=AD=A3=E5=BC=8F=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WhmcsPay/vmq_alipay.php | 6 +- WhmcsPay/vmq_alipay/themes.tpl | 4 +- WhmcsPay/vmq_wechat.php | 6 +- WhmcsPay/vmq_wechat/themes.tpl | 4 +- composer.json | 1 - start_pay_api.php | 108 +++++++++++++++++++++++---------- start_paywatch.php | 8 +-- 7 files changed, 93 insertions(+), 44 deletions(-) diff --git a/WhmcsPay/vmq_alipay.php b/WhmcsPay/vmq_alipay.php index 224e701..acabd81 100644 --- a/WhmcsPay/vmq_alipay.php +++ b/WhmcsPay/vmq_alipay.php @@ -43,7 +43,7 @@ function vmq_alipay_link($params) { $RandomString = chr(rand(97, 122)).chr(rand(97, 122)).chr(rand(97, 122)).chr(rand(97, 122)).chr(rand(97, 122)); $PayID = $RandomString.'|'.$params['invoiceid']; $PaySign = md5('alipay'.$PayID.$params['amount'].$params['systemurl'].'/modules/gateways/vmq_alipay/callback.php'.trim($params['appsk'])); - $GetInfo = json_decode(vmq_alipay_curl_post(trim($params['appurl']),array("appkey"=>trim($params['appsk']),"payid"=>$PayID,"type"=>'alipay',"price"=>$params['amount'],"sign"=>$PaySign,"notifyurl"=>$params['systemurl'].'/modules/gateways/vmq_alipay/callback.php')),true); + $GetInfo = json_decode(vmq_alipay_curl_post(trim($params['appurl']).'/createorder',array("appkey"=>trim($params['appsk']),"payid"=>$PayID,"type"=>'alipay',"price"=>$params['amount'],"sign"=>$PaySign,"notifyurl"=>$params['systemurl'].'/modules/gateways/vmq_alipay/callback.php')),true); if(!$GetInfo){ exit('订单添加错误:服务器未返回任何有效信息'); } @@ -57,8 +57,8 @@ function vmq_alipay_link($params) { $userdata['make_time'] = date('Y-m-d H:i:s',$GetInfo['data']['maketime']); $userdata['end_time'] = date('Y-m-d H:i:s',$GetInfo['data']['stoptime']); $userdata['order_id'] = $GetInfo['data']['orderid']; - $userdata['outTime'] = ($GetInfo['data']['timeout']) * 60; - $userdata['logoShowTime'] = 2; + $userdata['outTime'] = $GetInfo['data']['timeout']; + $userdata['logoShowTime'] = 1; exit(vmq_alipay_makehtml(json_encode($userdata))); } if(stristr($_SERVER['PHP_SELF'],'viewinvoice')){ diff --git a/WhmcsPay/vmq_alipay/themes.tpl b/WhmcsPay/vmq_alipay/themes.tpl index 3f3b2b5..52a1ae9 100644 --- a/WhmcsPay/vmq_alipay/themes.tpl +++ b/WhmcsPay/vmq_alipay/themes.tpl @@ -28,7 +28,7 @@
加载中... - +
@@ -84,10 +84,12 @@ var user_data ={$userdata} show_Qrcode(user_data); + \ No newline at end of file diff --git a/WhmcsPay/vmq_wechat.php b/WhmcsPay/vmq_wechat.php index 680fe52..43a3f58 100644 --- a/WhmcsPay/vmq_wechat.php +++ b/WhmcsPay/vmq_wechat.php @@ -43,7 +43,7 @@ function vmq_wechat_link($params) { $RandomString = chr(rand(97, 122)).chr(rand(97, 122)).chr(rand(97, 122)).chr(rand(97, 122)).chr(rand(97, 122)); $PayID = $RandomString.'|'.$params['invoiceid']; $PaySign = md5('wechat'.$PayID.$params['amount'].$params['systemurl'].'/modules/gateways/vmq_wechat/callback.php'.trim($params['appsk'])); - $GetInfo = json_decode(vmq_wechat_curl_post(trim($params['appurl']),array("appkey"=>trim($params['appsk']),"payid"=>$PayID,"type"=>'wechat',"price"=>$params['amount'],"sign"=>$PaySign,"notifyurl"=>$params['systemurl'].'/modules/gateways/vmq_wechat/callback.php')),true); + $GetInfo = json_decode(vmq_wechat_curl_post(trim($params['appurl']).'/createorder',array("appkey"=>trim($params['appsk']),"payid"=>$PayID,"type"=>'wechat',"price"=>$params['amount'],"sign"=>$PaySign,"notifyurl"=>$params['systemurl'].'/modules/gateways/vmq_wechat/callback.php')),true); if(!$GetInfo){ exit('订单添加错误:服务器未返回任何有效信息'); } @@ -57,8 +57,8 @@ function vmq_wechat_link($params) { $userdata['make_time'] = date('Y-m-d H:i:s',$GetInfo['data']['maketime']); $userdata['end_time'] = date('Y-m-d H:i:s',$GetInfo['data']['stoptime']); $userdata['order_id'] = $GetInfo['data']['orderid']; - $userdata['outTime'] = ($GetInfo['data']['timeout']) * 60; - $userdata['logoShowTime'] = 2; + $userdata['outTime'] = $GetInfo['data']['timeout']; + $userdata['logoShowTime'] = 1; exit(vmq_wechat_makehtml(json_encode($userdata))); } if(stristr($_SERVER['PHP_SELF'],'viewinvoice')){ diff --git a/WhmcsPay/vmq_wechat/themes.tpl b/WhmcsPay/vmq_wechat/themes.tpl index 9ce8b50..e18d08a 100644 --- a/WhmcsPay/vmq_wechat/themes.tpl +++ b/WhmcsPay/vmq_wechat/themes.tpl @@ -28,7 +28,7 @@
加载中... - +
@@ -84,10 +84,12 @@ var user_data ={$userdata} show_Qrcode(user_data); + \ No newline at end of file diff --git a/composer.json b/composer.json index 0c4b61f..1e2860c 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,6 @@ { "require": { "workerman/workerman": "^3.5", - "phpmailer/phpmailer": "^6.0", "topthink/think-orm": "^1.2" } } diff --git a/start_pay_api.php b/start_pay_api.php index e50f071..4278339 100644 --- a/start_pay_api.php +++ b/start_pay_api.php @@ -10,39 +10,85 @@ $http_worker->onMessage = function($connection, $data) { include __DIR__.'/config.php'; - $Nowtime = time(); - $EndPaytime = ($Endtime*60)+time(); - $orderid = date("YmdHms").rand(1,9).rand(1,9).rand(1,9).rand(1,9); - if(!@$_REQUEST['appkey'] || !@$_REQUEST['payid'] || !@$_REQUEST['type'] || !@$_REQUEST['price'] || !@$_REQUEST['notifyurl'] || !@$_REQUEST['sign']){ - $connection->send(json_encode(array('code' => 500,'msg' => '参数不全'))); - return ; - } - if(Db::table('payinfo')->where('payid',$_REQUEST['payid'])->find()){ - $connection->send(json_encode(array('code' => 500,'msg' => '订单号重复'))); - return ; - } - if(trim($_REQUEST['type']) != 'alipay' && trim($_REQUEST['type']) != 'wechat'){ - $connection->send(json_encode(array('code' => 500,'msg' => '支付接口不存在'))); - return ; - } - $PaySign = md5($_REQUEST['type'].$_REQUEST['payid'].$_REQUEST['price'].$_REQUEST['notifyurl'].$AppKey); - if(trim($_REQUEST['sign']) != $PaySign){ - $connection->send(json_encode(array('code' => 500,'msg' => 'Sign不正确'))); - return ; - } - if(!is_numeric(trim($_REQUEST['price']))){ - $connection->send(json_encode(array('code' => 500,'msg' => '金额必须为number类型'))); - return ; - } - if(filter_var(trim($_REQUEST['notifyurl']), FILTER_VALIDATE_URL) === FALSE) { - $connection->send(json_encode(array('code' => 500,'msg' => 'NotifyUrl错误'))); - return ; - } - if(!(Db::table('payinfo')->insert(["price" => trim($_REQUEST['price']),"time" => $Nowtime,"endtime" => $EndPaytime,"status" => 'waitpay',"payid" => $_REQUEST['payid'],"notifyurl" => $_REQUEST['notifyurl'],"type" => $_REQUEST['type'],"orderid" => $orderid]))){ - $connection->send(json_encode(array('code' => 500,'msg' => '数据添加错误'))); + $Action = (explode('?',trim(substr($_SERVER['REQUEST_URI'],1))))[0]; + if($Action == 'createorder'){ + $Nowtime = time(); + $EndPaytime = ($Endtime*60)+$Nowtime; + $orderid = date("YmdHms").rand(1,9).rand(1,9).rand(1,9).rand(1,9); + if(!@$_REQUEST['appkey'] || !@$_REQUEST['payid'] || !@$_REQUEST['type'] || !@$_REQUEST['price'] || !@$_REQUEST['notifyurl'] || !@$_REQUEST['sign']){ + $connection->send(json_encode(array('code' => 500,'msg' => '参数不全'))); + return ; + } + if(Db::table('payinfo')->where('payid',$_REQUEST['payid'])->find()){ + $connection->send(json_encode(array('code' => 500,'msg' => '订单号重复'))); + return ; + } + if(trim($_REQUEST['type']) != 'alipay' && trim($_REQUEST['type']) != 'wechat'){ + $connection->send(json_encode(array('code' => 500,'msg' => '支付接口不存在'))); + return ; + } + $PaySign = md5($_REQUEST['type'].$_REQUEST['payid'].$_REQUEST['price'].$_REQUEST['notifyurl'].$AppKey); + if(trim($_REQUEST['sign']) != $PaySign){ + $connection->send(json_encode(array('code' => 500,'msg' => 'Sign不正确'))); + return ; + } + if(!is_numeric(trim($_REQUEST['price']))){ + $connection->send(json_encode(array('code' => 500,'msg' => '金额必须为number类型'))); + return ; + } + if(filter_var(trim($_REQUEST['notifyurl']), FILTER_VALIDATE_URL) === FALSE) { + $connection->send(json_encode(array('code' => 500,'msg' => 'NotifyUrl错误'))); + return ; + } + if(!(Db::table('payinfo')->insert(["price" => trim($_REQUEST['price']),"time" => $Nowtime,"endtime" => $EndPaytime,"status" => 'waitpay',"payid" => $_REQUEST['payid'],"notifyurl" => $_REQUEST['notifyurl'],"type" => $_REQUEST['type'],"orderid" => $orderid]))){ + $connection->send(json_encode(array('code' => 500,'msg' => '数据添加错误'))); + return ; + }else{ + $connection->send(json_encode(array('code' => 200,'msg' => '订单添加成功','data' => array('maketime'=>$Nowtime,'stoptime'=>$EndPaytime,'orderid'=>$orderid,'timeout'=>($EndPaytime-$Nowtime))))); + return ; + } + }elseif($Action == 'getorder'){ + $OrderData = array(); + if(!@$_REQUEST['appkey'] || !@$_REQUEST['orderid']){ + $connection->send(json_encode(array('code' => 500,'msg' => '参数不全'))); + return ; + } + if(trim($_REQUEST['appkey']) != $AppKey){ + $connection->send(json_encode(array('code' => 403,'msg' => '鉴权错误'))); + return ; + } + $OrderData = Db::table('payinfo')->where('orderid',trim($_REQUEST['orderid']))->find(); + if(!$OrderData){ + $OrderData['code'] = 404; + }else{ + $OrderData['code'] = 200; + } + $connection->send(json_encode(array('code' => 200,'msg' => '订单获取成功','data' => $OrderData))); return ; + }elseif($Action == 'closeorder'){ + if(!@$_REQUEST['appkey'] || !@$_REQUEST['orderid']){ + $connection->send(json_encode(array('code' => 500,'msg' => '参数不全'))); + return ; + } + if(trim($_REQUEST['appkey']) != $AppKey){ + $connection->send(json_encode(array('code' => 403,'msg' => '鉴权错误'))); + return ; + } + $OrderData = Db::table('payinfo')->where('orderid',trim($_REQUEST['orderid']))->find(); + if(!$OrderData){ + $connection->send(json_encode(array('code' => 1404,'msg' => '订单不存在'))); + return ; + } + if(!(Db::table('payinfo')->where('orderid',trim($_REQUEST['orderid']))->delete())){ + $connection->send(json_encode(array('code' => 500,'msg' => '数据删除错误'))); + return ; + }else{ + $connection->send(json_encode(array('code' => 200,'msg' => '订单删除成功'))); + return ; + } }else{ - $connection->send(json_encode(array('code' => 200,'msg' => '订单添加成功','data' => array('maketime'=>$Nowtime,'stoptime'=>$EndPaytime,'orderid'=>$orderid,'timeout'=>$Endtime)))); + $connection->send(json_encode(array('code' => 404,'msg' => '未知操作'))); + return ; } }; diff --git a/start_paywatch.php b/start_paywatch.php index 2898462..83a889c 100644 --- a/start_paywatch.php +++ b/start_paywatch.php @@ -2,7 +2,7 @@ use Workerman\Worker; use think\Db; require_once __DIR__ . '/vendor/autoload.php'; -function curl_post_https($url,$data){ +function curl_get_https($url,$data){ $url = preg_replace('/([^:])[\/\\\\]{2,}/','$1/',$url); $urlfields = ""; foreach($data as $k => $v ){ @@ -17,12 +17,12 @@ function curl_post_https($url,$data){ return $tmpInfo; // 返回数据 } $worker = new Worker(); -$worker->count = 1; +$worker->count = 6; $worker->name = 'Pay Watch'; $worker->onWorkerStart = function($worker) { Db::setConfig(['type'=> 'sqlite','database'=> __DIR__.'/database.db','prefix'=> '','debug'=> true]); - \Workerman\Lib\Timer::add(30, function(){ + \Workerman\Lib\Timer::add(40, function(){ $data = Db::table('payinfo')->where('status','waitnotify')->select(); include __DIR__.'/config.php'; foreach ($data as $item) { @@ -30,7 +30,7 @@ function curl_post_https($url,$data){ if($data2 == 'waitnotify'){ Db::table('payinfo')->where('payid',$item['payid'])->update(["status" => 'donotify']); $PaySign = md5($item['type'].$item['payid'].$item['orderid'].$item['price'].$AppKey); - $NotifyReturn = curl_post_https($item["notifyurl"],array('type' => $item['type'],'price' => $item['price'],'orderid' => $item['orderid'],'payid' => $item['payid'],'sign' => $PaySign)); + $NotifyReturn = curl_get_https($item["notifyurl"],array('type' => $item['type'],'price' => $item['price'],'orderid' => $item['orderid'],'payid' => $item['payid'],'sign' => $PaySign)); if(trim($NotifyReturn) == 'success'){ //异步请求成功 Db::table('payinfo')->where('id',$item['id'])->delete();