diff --git a/app/Command/Job.php b/app/Command/Job.php index c1270f24..901a9b7d 100644 --- a/app/Command/Job.php +++ b/app/Command/Job.php @@ -302,7 +302,7 @@ class Job $ips[$alive_ip->ip] = 1; if ($user->node_connector < count($ips)) { //暂时封禁 - $isDisconnect = Disconnect::where('id', '=', $alive_ip->ip)->where( + $isDisconnect = Disconnect::where('ip', '=', $alive_ip->ip)->where( 'userid', '=', $user->id diff --git a/app/Services/Gateway/IDt/epay_core.function.php b/app/Services/Gateway/IDt/epay_core.function.php new file mode 100755 index 00000000..ecdd2991 --- /dev/null +++ b/app/Services/Gateway/IDt/epay_core.function.php @@ -0,0 +1,176 @@ +$val){ + $arg.=$key."=".$val."&"; + } + //去掉最后一个&字符 + $arg = rtrim($arg,'&'); + + //如果存在转义字符,那么去掉转义 + if(get_magic_quotes_gpc()){$arg = stripslashes($arg);} + + return $arg; +} +/** + * 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码 + * @param $para 需要拼接的数组 + * return 拼接完成以后的字符串 + */ +function createLinkstringUrlencode($para) { + $arg = ""; + foreach ($para as $key=>$val){ + $arg.=$key."=".$val."&"; + } + //去掉最后一个&字符 + $arg = rtrim($arg,'&'); + + //如果存在转义字符,那么去掉转义 + if(get_magic_quotes_gpc()){$arg = stripslashes($arg);} + + return $arg; +} +/** + * 除去数组中的空值和签名参数 + * @param $para 签名参数组 + * return 去掉空值与签名参数后的新签名参数组 + */ +function paraFilter($para) { + $para_filter = array(); + foreach ($para as $key=>$val){ + if($key == "sign" || $key == "sign_type" || $val == "")continue; + else $para_filter[$key] = $para[$key]; + } + return $para_filter; +} +/** + * 对数组排序 + * @param $para 排序前的数组 + * return 排序后的数组 + */ +function argSort($para) { + ksort($para); + reset($para); + return $para; +} +/** + * 写日志,方便测试(看网站需求,也可以改成把记录存入数据库) + * 注意:服务器需要开通fopen配置 + * @param $word 要写入日志里的文本内容 默认值:空值 + */ +function logResult($word='') { + $fp = fopen("log.txt","a"); + flock($fp, LOCK_EX) ; + fwrite($fp,"执行日期:".strftime("%Y%m%d%H%M%S",time())."\n".$word."\n"); + flock($fp, LOCK_UN); + fclose($fp); +} + +/** + * 远程获取数据,POST模式 + * 注意: + * 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了 + * 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem' + * @param $url 指定URL完整路径地址 + * @param $cacert_url 指定当前工作目录绝对路径 + * @param $para 请求的数据 + * @param $input_charset 编码格式。默认值:空值 + * return 远程输出的数据 + */ +function getHttpResponsePOST($url, $cacert_url, $para, $input_charset = '') { + + if (trim($input_charset) != '') { + $url = $url."_input_charset=".$input_charset; + } + $curl = curl_init($url); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL证书认证 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//严格认证 + curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//证书地址 + curl_setopt($curl, CURLOPT_HEADER, 0 ); // 过滤HTTP头 + curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);// 显示输出结果 + curl_setopt($curl,CURLOPT_POST,true); // post传输数据 + curl_setopt($curl,CURLOPT_POSTFIELDS,$para);// post传输数据 + $responseText = curl_exec($curl); + //var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容 + curl_close($curl); + + return $responseText; +} + +/** + * 远程获取数据,GET模式 + * 注意: + * 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了 + * 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem' + * @param $url 指定URL完整路径地址 + * @param $cacert_url 指定当前工作目录绝对路径 + * return 远程输出的数据 + */ +function getHttpResponseGET($url,$cacert_url) { + $curl = curl_init($url); + curl_setopt($curl, CURLOPT_HEADER, 0 ); // 过滤HTTP头 + curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);// 显示输出结果 + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL证书认证 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//严格认证 + curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//证书地址 + $responseText = curl_exec($curl); + //var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容 + curl_close($curl); + + return $responseText; +} + +/** + * 实现多种字符编码方式 + * @param $input 需要编码的字符串 + * @param $_output_charset 输出的编码格式 + * @param $_input_charset 输入的编码格式 + * return 编码后的字符串 + */ +function charsetEncode($input,$_output_charset ,$_input_charset) { + $output = ""; + if(!isset($_output_charset) )$_output_charset = $_input_charset; + if($_input_charset == $_output_charset || $input ==null ) { + $output = $input; + } elseif (function_exists("mb_convert_encoding")) { + $output = mb_convert_encoding($input,$_output_charset,$_input_charset); + } elseif(function_exists("iconv")) { + $output = iconv($_input_charset,$_output_charset,$input); + } else die("sorry, you have no libs support for charset change."); + return $output; +} +/** + * 实现多种字符解码方式 + * @param $input 需要解码的字符串 + * @param $_output_charset 输出的解码格式 + * @param $_input_charset 输入的解码格式 + * return 解码后的字符串 + */ +function charsetDecode($input,$_input_charset ,$_output_charset) { + $output = ""; + if(!isset($_input_charset) )$_input_charset = $_input_charset ; + if($_input_charset == $_output_charset || $input ==null ) { + $output = $input; + } elseif (function_exists("mb_convert_encoding")) { + $output = mb_convert_encoding($input,$_output_charset,$_input_charset); + } elseif(function_exists("iconv")) { + $output = iconv($_input_charset,$_output_charset,$input); + } else die("sorry, you have no libs support for charset changes."); + return $output; +} +?> \ No newline at end of file diff --git a/app/Services/Gateway/IDt/epay_md5.function.php b/app/Services/Gateway/IDt/epay_md5.function.php new file mode 100755 index 00000000..7bb643fe --- /dev/null +++ b/app/Services/Gateway/IDt/epay_md5.function.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/app/Services/Gateway/IDt/epay_notify.class.php b/app/Services/Gateway/IDt/epay_notify.class.php new file mode 100755 index 00000000..fbe41eff --- /dev/null +++ b/app/Services/Gateway/IDt/epay_notify.class.php @@ -0,0 +1,121 @@ +alipay_config = $alipay_config; + $this->http_verify_url = $this->alipay_config['apiurl'].'api.php?'; + } + function AlipayNotify($alipay_config) { + $this->__construct($alipay_config); + } + /** + * 针对notify_url验证消息是否是支付宝发出的合法消息 + * @return 验证结果 + */ + function verifyNotify(){ + if(empty($_GET)) {//判断POST来的数组是否为空 + return false; + } + else { + //生成签名结果 + $isSign = $this->getSignVeryfy($_GET, $_GET["sign"]); + //获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息) + $responseTxt = 'true'; + //if (! empty($_POST["notify_id"])) {$responseTxt = $this->getResponse($_POST["notify_id"]);} + + //验证 + //$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关 + //isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关 + if (preg_match("/true$/i",$responseTxt) && $isSign) { + return true; + } else { + return false; + } + } + } + + /** + * 针对return_url验证消息是否是支付宝发出的合法消息 + * @return 验证结果 + */ + function verifyReturn(){ + if(empty($_GET)) {//判断POST来的数组是否为空 + return false; + } + else { + //生成签名结果 + $isSign = $this->getSignVeryfy($_GET, $_GET["sign"]); + //获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息) + $responseTxt = 'true'; + //if (! empty($_GET["notify_id"])) {$responseTxt = $this->getResponse($_GET["notify_id"]);} + + //验证 + //$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关 + //isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关 + if (preg_match("/true$/i",$responseTxt) && $isSign) { + return true; + } else { + return false; + } + } + } + + /** + * 获取返回时的签名验证结果 + * @param $para_temp 通知返回来的参数数组 + * @param $sign 返回的签名结果 + * @return 签名验证结果 + */ + function getSignVeryfy($para_temp, $sign) { + //除去待签名参数数组中的空值和签名参数 + $para_filter = paraFilter($para_temp); + + //对待签名参数数组排序 + $para_sort = argSort($para_filter); + + //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 + $prestr = createLinkstring($para_sort); + + $isSgin = false; + $isSgin = md5Verify($prestr, $sign, $this->alipay_config['key']); + + return $isSgin; + } + + /** + * 获取远程服务器ATN结果,验证返回URL + * @param $notify_id 通知校验ID + * @return 服务器ATN结果 + * 验证结果集: + * invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空 + * true 返回正确信息 + * false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟 + */ + function getResponse($notify_id) { + $transport = strtolower(trim($this->alipay_config['transport'])); + $partner = trim($this->alipay_config['partner']); + $veryfy_url = ''; + if($transport == 'https') { + $veryfy_url = $this->https_verify_url; + } + else { + $veryfy_url = $this->http_verify_url; + } + $veryfy_url = $veryfy_url."partner=" . $partner . "¬ify_id=" . $notify_id; + $responseTxt = getHttpResponseGET($veryfy_url, $this->alipay_config['cacert']); + + return $responseTxt; + } +} +?> diff --git a/app/Services/Gateway/IDt/epay_submit.class.php b/app/Services/Gateway/IDt/epay_submit.class.php new file mode 100755 index 00000000..a50c9bc5 --- /dev/null +++ b/app/Services/Gateway/IDt/epay_submit.class.php @@ -0,0 +1,98 @@ +alipay_config = $alipay_config; + $this->alipay_gateway_new = $this->alipay_config['apiurl'].'submit.php?'; + } + function AlipaySubmit($alipay_config) { + $this->__construct($alipay_config); + } + + /** + * 生成签名结果 + * @param $para_sort 已排序要签名的数组 + * return 签名结果字符串 + */ + function buildRequestMysign($para_sort) { + //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 + $prestr = createLinkstring($para_sort); + + $mysign = md5Sign($prestr, $this->alipay_config['key']); + + return $mysign; + } + + /** + * 生成要请求给支付宝的参数数组 + * @param $para_temp 请求前的参数数组 + * @return 要请求的参数数组 + */ + function buildRequestPara($para_temp) { + //除去待签名参数数组中的空值和签名参数 + $para_filter = paraFilter($para_temp); + + //对待签名参数数组排序 + $para_sort = argSort($para_filter); + + //生成签名结果 + $mysign = $this->buildRequestMysign($para_sort); + + //签名结果与签名方式加入请求提交参数组中 + $para_sort['sign'] = $mysign; + $para_sort['sign_type'] = strtoupper(trim($this->alipay_config['sign_type'])); + + return $para_sort; + } + + /** + * 生成要请求给支付宝的参数数组 + * @param $para_temp 请求前的参数数组 + * @return 要请求的参数数组字符串 + */ + function buildRequestParaToString($para_temp) { + //待请求参数数组 + $para = $this->buildRequestPara($para_temp); + + //把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码 + $request_data = createLinkstringUrlencode($para); + + return $request_data; + } + + /** + * 建立请求,以表单HTML形式构造(默认) + * @param $para_temp 请求参数数组 + * @param $method 提交方式。两个值可选:post、get + * @param $button_name 确认按钮显示文字 + * @return 提交表单HTML文本 + */ + function buildRequestForm($para_temp, $method='POST', $button_name='正在跳转') { + //待请求参数数组 + $para = $this->buildRequestPara($para_temp); + + $sHtml = "
"; + while (list ($key, $val) = each ($para)) { + $sHtml.= ""; + } + + //submit按钮控件请不要含有name属性 + $sHtml = $sHtml."
"; + + $sHtml = $sHtml.""; + + return $sHtml; + } +} +?> \ No newline at end of file diff --git a/app/Services/Gateway/IDtPay.php b/app/Services/Gateway/IDtPay.php new file mode 100644 index 00000000..eda28f06 --- /dev/null +++ b/app/Services/Gateway/IDtPay.php @@ -0,0 +1,253 @@ +getParsedBodyParam('type'); + $price = $request->getParsedBodyParam('price'); + if ($price <= 0) { + return $response->write(json_encode(['errcode' => -1, 'errmsg' => "非法的金额."])); + } + $user = Auth::getUser(); + $pl = new Paylist(); + $pl->userid = $user->id; + $pl->total = $price; + $pl->tradeno = self::generateGuid(); + $pl->save(); + + $settings = Config::get("idtpay"); + $alipay_config = array( + 'partner' => $settings['partner'], + 'key' => $settings['key'], + 'sign_type' => $settings['sign_type'], + 'input_charset' => $settings['input_charset'], + 'transport' => $settings['transport'], + 'apiurl' => $settings['apiurl'] + ); + + + /**************************请求参数**************************/ + $notify_url = Config::get("baseUrl")."/payment/notify"; + //需http://格式的完整路径,不能加?id=123这类自定义参数 + + //页面跳转同步通知页面路径 + $return_url = Config::get("baseUrl")."/user/payment/return"; + //需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/ + + //商户订单号 + $out_trade_no = $pl->tradeno; + //商户网站订单系统中唯一订单号,必填 + + + //商品名称 + $name =$settings["subjects"][array_rand($settings["subjects"])]; + //付款金额 + $money =$price; + //站点名称 + $sitename = $settings['appname']; + //必填 + + //订单描述 + + /************************************************************/ + //构造要请求的参数数组,无需改动 + $parameter = array( + "pid" => trim($alipay_config['partner']), + "type" => $type, + "notify_url" => $notify_url, + "return_url" => $return_url, + "out_trade_no" => $out_trade_no, + "name" => $name, + "money" => $money, + "sitename" => $sitename + ); + + //建立请求 + $alipaySubmit = new AlipaySubmit($alipay_config); + $html_text = $alipaySubmit->buildRequestForm($parameter); + return $response->write(json_encode(['code' => $html_text, 'errcode' => 0, 'pid' => $pl->id])); + } + + public function notify($request, $response, $args) + { + $pid = $_GET['out_trade_no']; + $p = Paylist::where('tradeno', '=', $pid)->first(); + if ($p->status == 1) { + $success = 1; + } else { + $settings = Config::get("idtpay"); + $alipay_config = array( + 'partner' => $settings['partner'], + 'key' => $settings['key'], + 'sign_type' => $settings['sign_type'], + 'input_charset' => $settings['input_charset'], + 'transport' => $settings['transport'], + 'apiurl' => $settings['apiurl'] + ); + + //计算得出通知验证结果 + $alipayNotify = new AlipayNotify($alipay_config); + $verify_result = $alipayNotify->verifyNotify(); + + if($verify_result) { + + if ($_GET['trade_status'] == 'TRADE_SUCCESS') { + $this->postPayment($_GET['out_trade_no'], "IDtPay"); + $success = 1; + } + else { + $success = 0; + } + + } + else { + $success = 0; + } + } + if ($success==1){ + echo "success"; + }else{ + echo "fail"; + } + } + public function getReturnHTML($request, $response, $args) + { + + $pid = $_GET['out_trade_no']; + $p = Paylist::where('tradeno', '=', $pid)->first(); + $money = $p->total; + if ($p->status == 1) { + $success = 1; + } else { + $settings = Config::get("idtpay"); + $alipay_config = array( + 'partner' => $settings['partner'], + 'key' => $settings['key'], + 'sign_type' => $settings['sign_type'], + 'input_charset' => $settings['input_charset'], + 'transport' => $settings['transport'], + 'apiurl' => $settings['apiurl'] + ); + + //计算得出通知验证结果 + $alipayNotify = new AlipayNotify($alipay_config); + $verify_result = $alipayNotify->verifyNotify(); + + if($verify_result) { + + if ($_GET['trade_status'] == 'TRADE_SUCCESS') { + $this->postPayment($_GET['out_trade_no'], "IDtPay"); + $success = 1; + } + else { + $success = 0; + } + + } + else { + $success = 0; + } + } + return View::getSmarty()->assign('money', $money)->assign('success', $success)->fetch('user/pay_success.tpl'); + + + + } + public function getPurchaseHTML() + { + return ' +
+

充值

+
支付方式:
+
推荐使用支付宝支付,更快到账!
+
+ +
+ + +
+
+
+
+
+
+ +'; + } + public function getStatus($request, $response, $args) + { + $return = []; + $p = Paylist::where('tradeno', $_POST['pid'])->first(); + $return['ret'] = 1; + $return['result'] = $p->status; + // file_put_contents(BASE_PATH.'/bitpay_status_success.log', json_encode($return)."\r\n", FILE_APPEND); + return json_encode($return); + } +} diff --git a/app/Services/Gateway/TomatoPay.php b/app/Services/Gateway/TomatoPay.php index 17badf2c..ce9130f1 100644 --- a/app/Services/Gateway/TomatoPay.php +++ b/app/Services/Gateway/TomatoPay.php @@ -136,4 +136,16 @@ class TomatoPay extends AbstractPayment '; } + public function getReturnHTML($request, $response, $args) + { + // TODO: Implement getReturnHTML() method. + } + public function getStatus($request, $response, $args) + { + $return = []; + $p = Paylist::where('tradeno', $_POST['pid'])->first(); + $return['ret'] = 1; + $return['result'] = $p->status; + return json_encode($return); + } } diff --git a/app/Services/Payment.php b/app/Services/Payment.php index 6bcfee31..667184d5 100644 --- a/app/Services/Payment.php +++ b/app/Services/Payment.php @@ -9,7 +9,7 @@ namespace App\Services; use App\Services\Gateway\{ - AopF2F, Codepay, PaymentWall, ChenPay, SPay, PAYJS, YftPay, BitPayX + AopF2F, Codepay, PaymentWall, ChenPay, SPay, PAYJS, YftPay, BitPayX,TomatoPay,IDtPay }; class Payment @@ -20,6 +20,8 @@ class Payment switch ($method) { case ('codepay'): return new Codepay(); + case ('doiampay'): + return new DoiAMPay(); case ('paymentwall'): return new PaymentWall(); case ('spay'): @@ -28,12 +30,18 @@ class Payment return new AopF2F(); case ('chenAlipay'): return new ChenPay(); + case ('trimepay'): + return new TrimePay(Config::get('trimepay_secret')); case ('bitpayx'): return new BitPayX(Config::get('bitpay_secret')); case ('payjs'): return new PAYJS(Config::get('payjs_key')); case ('yftpay'): return new YftPay(); + case ("tomatopay"): + return new TomatoPay(); + case ("idtpay"): + return new IDtPay(); default: return null; } diff --git a/config/.config.example.php b/config/.config.example.php index b4e8295c..b09df639 100644 --- a/config/.config.example.php +++ b/config/.config.example.php @@ -250,6 +250,34 @@ $_ENV['tomatopay'] = [ ], ]; +#tomatopay番茄云支付 +#使用教程:https://swapidc.fanqieui.com/?t/329.html tg群 https://t.me/fanqiepay +$_ENV['tomatopay'] = [ + 'wxpay'=>[ + 'mchid' => '', // 商户号 + 'account' => '', //您在番茄云支付的登录邮箱 + 'token' => "" // 安全验证码 + ], + 'alipay'=>[ + 'mchid' => '', // 商户号 + 'account' => '', //您在番茄云支付的登录邮箱 + 'token' => "" // 安全验证码 + ], + ]; + + +$_ENV['idtpay']=[ + 'partner'=>"", //商户号 + 'key' =>"", //商户key + 'sign_type'=>strtoupper('MD5'), + 'input_charset'=>strtolower('utf-8'), + 'subjects'=>["内存",'手抓饼'], //商品名称 + 'transport'=>'https' ,//访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http + 'apiurl'=>'https://pay.idt.xyz/', //http开头 + 'appname'=>$_ENV['appName'], + +]; + //其他面板显示设置------------------------------------------------------------------------------------------ diff --git a/config/routes.php b/config/routes.php index 1b32474a..2fbfe083 100644 --- a/config/routes.php +++ b/config/routes.php @@ -166,6 +166,7 @@ $app->group('/user', function () { $app->group('/payment', function () { $this->get('/notify', App\Services\Payment::class . ':notify'); $this->post('/notify', App\Services\Payment::class . ':notify'); + $this->get('/notify', App\Services\Payment::class . ':notify'); $this->post('/notify/{type}', App\Services\Payment::class . ':notify'); $this->post('/status', App\Services\Payment::class . ':getStatus');