Skip to content

Commit

Permalink
1.1正式版
Browse files Browse the repository at this point in the history
  • Loading branch information
flyqieqq authored Jul 22, 2019
1 parent a27bdf1 commit 780e31d
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 44 deletions.
6 changes: 3 additions & 3 deletions WhmcsPay/vmq_alipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('订单添加错误:服务器未返回任何有效信息');
}
Expand All @@ -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')){
Expand Down
4 changes: 3 additions & 1 deletion WhmcsPay/vmq_alipay/themes.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<div class="ui-loading qrcode-loading" data-role="qrPayImgLoading" style="display: none;">加载中</div>
<div style="position: relative;display: inline-block;">
<img id='show_qrcode' alt="加载中..." src="" width="210" height="210" style="display: block;">
<img onclick="$('#use').hide()" id="use" src="modules/gateways/vmq_alipay/img/use_1.png" style="position: absolute;top: 50%;left: 50%;width:32px;height:32px;margin-left: -21px;margin-top: -21px">
<!-- <img onclick="$('#use').hide()" id="use" src="modules/gateways/vmq_alipay/img/use_1.png" style="position: absolute;top: 50%;left: 50%;width:32px;height:32px;margin-left: -21px;margin-top: -21px"> -->
</div>
</div>

Expand Down Expand Up @@ -84,10 +84,12 @@
var user_data ={$userdata}
show_Qrcode(user_data);
</script>
<!--
<script>
setTimeout(function () {
$('#use').hide() //2秒后隐藏中间那LOGO
}, user_data.logoShowTime || 2000);
</script>
-->
</body>
</html>
6 changes: 3 additions & 3 deletions WhmcsPay/vmq_wechat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('订单添加错误:服务器未返回任何有效信息');
}
Expand All @@ -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')){
Expand Down
4 changes: 3 additions & 1 deletion WhmcsPay/vmq_wechat/themes.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<div class="ui-loading qrcode-loading" data-role="qrPayImgLoading" style="display: none;">加载中</div>
<div style="position: relative;display: inline-block;">
<img id='show_qrcode' alt="加载中..." src="" width="210" height="210" style="display: block;">
<img onclick="$('#use').hide()" id="use" src="modules/gateways/vmq_wechat/img/use_3.png" style="position: absolute;top: 50%;left: 50%;width:32px;height:32px;margin-left: -21px;margin-top: -21px">
<!-- <img onclick="$('#use').hide()" id="use" src="modules/gateways/vmq_wechat/img/use_3.png" style="position: absolute;top: 50%;left: 50%;width:32px;height:32px;margin-left: -21px;margin-top: -21px"> -->
</div>
</div>

Expand Down Expand Up @@ -84,10 +84,12 @@
var user_data ={$userdata}
show_Qrcode(user_data);
</script>
<!--
<script>
setTimeout(function () {
$('#use').hide() //2秒后隐藏中间那LOGO
}, user_data.logoShowTime || 2000);
</script>
-->
</body>
</html>
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"require": {
"workerman/workerman": "^3.5",
"phpmailer/phpmailer": "^6.0",
"topthink/think-orm": "^1.2"
}
}
108 changes: 77 additions & 31 deletions start_pay_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
}
};

Expand Down
8 changes: 4 additions & 4 deletions start_paywatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ){
Expand All @@ -17,20 +17,20 @@ 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) {
$data2 = @(Db::table('payinfo')->where('payid',$item['payid'])->find())['status'];
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();
Expand Down

0 comments on commit 780e31d

Please sign in to comment.