Skip to content

Commit

Permalink
增加码支付,使用方法看wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
xcxnig committed Mar 29, 2018
1 parent c9d31e6 commit 8d5e7bc
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ss-panel-v3-mod_UIChanges</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.aptana.ide.core.unifiedBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.aptana.projects.webnature</nature>
</natures>
<filteredResources>
<filter>
<id>1522297588605</id>
<name></name>
<type>26</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-node_modules</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
10 changes: 10 additions & 0 deletions app/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ public function page500($request, $response, $args)
return $newResponse;
}

public function codepay_callback($request, $response, $args)
{
echo '
<script>
window.location.href="/user/code";
</script>
';
return;
}

public function pay_callback($request, $response, $args)
{
Pay::callback($request);
Expand Down
56 changes: 56 additions & 0 deletions app/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,62 @@ function ($query) {
return $this->view()->assign('codes', $codes)->assign('total_in', Code::where('isused', 1)->where('type', -1)->sum('number'))->assign('total_out', Code::where('isused', 1)->where('type', -2)->sum('number'))->display('user/donate.tpl');
}

function isHTTPS()
{
define('HTTPS', false);
if (defined('HTTPS') && HTTPS) return true;
if (!isset($_SERVER)) return FALSE;
if (!isset($_SERVER['HTTPS'])) return FALSE;
if ($_SERVER['HTTPS'] === 1) { //Apache
return TRUE;
} elseif ($_SERVER['HTTPS'] === 'on') { //IIS
return TRUE;
} elseif ($_SERVER['SERVER_PORT'] == 443) { //其他
return TRUE;
}
return FALSE;
}

public function codepay($request, $response, $args)
{
$codepay_id=Config::get('codepay_id');//这里改成码支付ID
$codepay_key=Config::get('codepay_key'); //这是您的通讯密钥
$uid = $this->user->id;
$price = $request->getParam('price');
$type = $request->getParam('type');
$url = (UserController::isHTTPS() ? 'https://' : 'http://').$_SERVER['HTTP_HOST'];
$data = array(
"id" => $codepay_id,//你的码支付ID
"pay_id" => $uid, //唯一标识 可以是用户ID,用户名,session_id(),订单ID,ip 付款后返回
"type" => $type,//1支付宝支付 2QQ钱包 3微信支付
"price" => $price,//金额100元
"param" => "",//自定义参数
"notify_url"=> $url.'/codepay_callback',//通知地址
"return_url"=> $url.'/codepay_callback',//跳转地址
); //构造需要传递的参数

ksort($data); //重新排序$data数组
reset($data); //内部指针指向数组中的第一个元素

$sign = ''; //初始化需要签名的字符为空
$urls = ''; //初始化URL参数为空

foreach ($data AS $key => $val) { //遍历需要传递的参数
if ($val == ''||$key == 'sign') continue; //跳过这些不参数签名
if ($sign != '') { //后面追加&拼接URL
$sign .= "&";
$urls .= "&";
}
$sign .= "$key=$val"; //拼接为url参数形式
$urls .= "$key=" . urlencode($val); //拼接为url参数形式并URL编码参数值

}
$query = $urls . '&sign=' . md5($sign .$codepay_key); //创建订单所需的参数
$url = "http://api2.fateqq.com:52888/creat_order/?".$query; //支付页面

header("Location:".$url);
}



public function code_check($request, $response, $args)
Expand Down
130 changes: 130 additions & 0 deletions app/Utils/Pay.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static function getHTML($user)
return Pay::f2fpay_html($user);
case 'yftpay':
return Pay::yftpay_html($user);
case 'codepay':
return Pay::codepay_html($user);
default:
return "";
}
Expand Down Expand Up @@ -95,6 +97,22 @@ private static function yftpay_html($user)
</form>
';
}

private static function codepay_html($user)
{
return '
<p class="card-heading">请输入充值金额</p>
<form name="codepay" action="/user/code/codepay" method="get">
<input class="form-control" id="price" name="price" placeholder="输入充值金额后,点击你要付款的应用图标即可" autofocus="autofocus" type="number" min="0.01" max="1000" step="0.01" required="required">
<br>
<button class="btn btn-flat waves-attach" id="btnSubmit" type="submit" name="type" value="1" ><img src="/images/alipay.jpg" width="50px" height="50px" /></button>
<button class="btn btn-flat waves-attach" id="btnSubmit" type="submit" name="type" value="2" ><img src="/images/qqpay.jpg" width="50px" height="50px" /></button>
<button class="btn btn-flat waves-attach" id="btnSubmit" type="submit" name="type" value="3" disabled><img src="/images/weixin.jpg" width="50px" height="50px" /></button>
</form>
';
}

private static function pmw_html($user)
{
\Paymentwall_Config::getInstance()->set(array(
Expand Down Expand Up @@ -658,6 +676,116 @@ private static function f2fpay_callback()
echo "fail"; //请不要修改或删除
}
}

private static function codepay_callback(){
//以下五行无需更改
ksort($_POST); //排序post参数
reset($_POST); //内部指针指向数组中的第一个元素
$codepay_key=Config::get('codepay_key'); //这是您的密钥
$sign = '';//初始化
foreach ($_POST AS $key => $val) { //遍历POST参数
if ($val == '' || $key == 'sign') continue; //跳过这些不签名
if ($sign) $sign .= '&'; //第一个字符串签名不加& 其他加&连接起来参数
$sign .= "$key=$val"; //拼接为url参数形式
}
if (!$_POST['pay_no'] || md5($sign . $codepay_key) != $_POST['sign']) { //不合法的数据
exit('fail'); //返回成功 不要删除哦
} else { //合法的数据
//业务处理
$pay_id = $_POST['pay_id']; //需要充值的ID 或订单号 或用户名
$money = (float)$_POST['money']; //实际付款金额
$price = (float)$_POST['price']; //订单的原价
//$param = $_POST['param']; //自定义参数
$pay_no = $_POST['pay_no']; //流水号
$codeq=Code::where("code", "=", $pay_no)->first();
if ($codeq==null){
$user=User::find($pay_id);
$codeq=new Code();
$codeq->code=$pay_no;
$codeq->isused=1;
$codeq->type=-1;
$codeq->number=$price;
$codeq->usedatetime=date("Y-m-d H:i:s");
$codeq->userid=$user->id;
$codeq->save();
$user->money=$user->money+$price;
$user->save();

//更新返利
if ($user->ref_by!=""&&$user->ref_by!=0&&$user->ref_by!=null) {
$gift_user=User::where("id", "=", $user->ref_by)->first();
$gift_user->money=($gift_user->money+($codeq->number*(Config::get('code_payback')/100)));
$gift_user->save();

$Payback=new Payback();
$Payback->total=$total;
$Payback->userid=$user->id;
$Payback->ref_by=$user->ref_by;
$Payback->ref_get=$codeq->number*(Config::get('code_payback')/100);
$Payback->datetime=time();
$Payback->save();
}
exit('success'); //返回成功 不要删除哦
}
}
if ($codeq!=null){
echo '
<script>
alert("支付成功,第三方支付小飞机pay祝您购物愉快");
window.location.href="/user/code";
</script>
';
return;
}
}

private static function notify(){
//系统订单号
$trade_no = $_POST['pay_no'];
//交易用户
$trade_id = strtok($_POST['pay_id'], "@");
//金额
$trade_num = $_POST['price'];
$param = urldecode($_POST['param']);
$codeq=Code::where("code", "=", $trade_no)->first();
if($codeq!=null){
exit('success'); //说明数据已经处理完毕
return;
}
if($param!=Config::get('alipay')||$trade_no==''){ //鉴权失败
exit('fail');
return;
}

//更新用户账户
$user=User::find($trade_id);
$codeq=new Code();
$codeq->code=$trade_no;
$codeq->isused=1;
$codeq->type=-1;
$codeq->number=$_POST['price'];
$codeq->usedatetime=date("Y-m-d H:i:s");
$codeq->userid=$user->id;
$codeq->save();
$user->money=$user->money+$trade_num;
$user->save();
//更新返利
if ($user->ref_by!=""&&$user->ref_by!=0&&$user->ref_by!=null) {
$gift_user=User::where("id", "=", $user->ref_by)->first();
$gift_user->money=($gift_user->money+($codeq->number*(Config::get('code_payback')/100)));
$gift_user->save();

$Payback=new Payback();
$Payback->total=$trade_num;
$Payback->userid=$user->id;
$Payback->ref_by=$user->ref_by;
$Payback->ref_get=$codeq->number*(Config::get('code_payback')/100);
$Payback->datetime=time();
$Payback->save();
}
exit('success'); //返回成功 不要删除哦
}

public static function callback($request)
{
$driver = Config::get("payment_system");
Expand All @@ -670,6 +798,8 @@ public static function callback($request)
return Pay::zfbjk_callback($request);
case 'f2fpay':
return Pay::f2fpay_callback();
case 'codepay':
return Pay::codepay_callback();
default:
return "";
}
Expand Down
7 changes: 6 additions & 1 deletion config/.config.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,14 @@ $System_Config['sendgrid_sender'] = '';

#支付系统

#取值 doiampay,paymentwall,zfbjk,spay,f2fpay,yftpay,none
#取值 codepay,doiampay,paymentwall,zfbjk,spay,f2fpay,yftpay,none
$System_Config['payment_system']='none';

#codepay码支付
#wiki地址:https://github.com/NimaQu/ss-panel-v3-mod_UIChanges/wiki/%E7%A0%81%E6%94%AF%E4%BB%98%E5%AF%B9%E6%8E%A5%E6%95%99%E7%A8%8B/
$System_Config['codepay_id']='';//码支付ID
$System_Config['codepay_key']='';//码支付通信密钥

#doiampay,https://www.daimiyun.cn/v3/
$System_Config['doiampay']=[
'enabled' => [
Expand Down
5 changes: 4 additions & 1 deletion config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
$app->get('/405', 'App\Controllers\HomeController:page405');
$app->get('/500', 'App\Controllers\HomeController:page500');
$app->get('/pwm_pingback', 'App\Controllers\HomeController:pay_callback');
$app->post('/notify', 'App\Controllers\HomeController:notify');
$app->post('/alipay_callback', 'App\Controllers\HomeController:pay_callback');
$app->post('/pay_callback', 'App\Controllers\HomeController:pay_callback');
$app->get('/pay_callback', 'App\Controllers\HomeController:pay_callback');
Expand All @@ -81,7 +82,8 @@
$app->get('/gfwlistjs', 'App\Controllers\LinkController:GetGfwlistJs');
$app->post('/telegram_callback', 'App\Controllers\HomeController:telegram');
$app->get('/yft/notify','App\Controllers\YFTPayCallBackController:yft_notify');

$app->get('/codepay_callback', 'App\Controllers\HomeController:codepay_callback');
$app->post('/codepay_callback', 'App\Controllers\HomeController:pay_callback');


// User Center
Expand Down Expand Up @@ -147,6 +149,7 @@
$this->get('/alipay', 'App\Controllers\UserController:alipay');
$this->post('/code/f2fpay', 'App\Controllers\UserController:f2fpay');
$this->get('/code/f2fpay', 'App\Controllers\UserController:f2fpayget');
$this->get('/code/codepay', 'App\Controllers\UserController:codepay');
$this->get('/code_check', 'App\Controllers\UserController:code_check');
$this->post('/code', 'App\Controllers\UserController:codepost');
$this->post('/gacheck', 'App\Controllers\UserController:GaCheck');
Expand Down
Binary file added public/images/alipay.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/qqpay.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/weixin.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8d5e7bc

Please sign in to comment.