支持Wolfpay,修复一些bug

QuickEdition(No-js-Encryption)
Malio 7 years ago
parent edbebf43fd
commit d971fa429e

@ -101,6 +101,23 @@ class MalioPay extends AbstractPayment
);
}
return json_encode($return);
case ('wolfpay'):
$wolfpay = new Wolfpay();
$result = $wolfpay->purchase_maliopay($type, $price);
if ($result['errcode'] == 0) {
$return = array(
'ret' => 1,
'type' => 'url',
'tradeno' => $result['tradeno'],
'url' => $result['url']
);
} else {
$return = array(
'ret' => 0,
'msg' => $result['errmsg']
);
}
return json_encode($return);
}
} else if ($type == 'wechat') {
$payment_system = MalioConfig::get('mups_wechat');
@ -204,7 +221,6 @@ class MalioPay extends AbstractPayment
}
return $return;
case ('tomatopay'):
$type = 'alipay';
$settings = Config::get("tomatopay")[$type];
$order_data = $_REQUEST;
@ -303,7 +319,7 @@ class MalioPay extends AbstractPayment
}
$order = Paylist::where('tradeno', '=', $source['id'])->first();
if ($order->status != 1) {
$this->postPayment($source['id'], 'Stripe '.$type);
$this->postPaymentMaliopay($source['id'], 'Stripe '.$type);
echo 'SUCCESS';
} else {
echo 'ERROR';
@ -316,6 +332,32 @@ class MalioPay extends AbstractPayment
}
http_response_code(200);
case ('wolfpay'):
$type = $args['method'];
$settings = Config::get("wolfpay") ['config'];
$security['orderid'] = $_REQUEST['out_trade_no'];
if ($security['orderid'] == '' OR $security['orderid'] == null) {
header("Location: /user/code");
} else {
//实例化支付类
//$pay = new Pays($settings['hid'], $settings['key']);
$wolfpay = new Wolfpay();
//接收异步通知数据
$data = $_GET;
//商户订单号
$out_trade_no = $data['out_trade_no'];
//验证签名
if ($wolfpay->verify($data)) {
//验证支付状态
if ($data['trade_status'] == 'TRADE_SUCCESS') {
$wolfpay->postPaymentMaliopay($data['out_trade_no'], "在线支付");
echo "success";
header("Location: /user/code");
}
} else {
echo '錯誤';
}
}
default:
return 'failed';
}

@ -0,0 +1,131 @@
<?php
namespace App\Services\Gateway;
use App\Services\View;
use App\Services\Auth;
use App\Services\Config;
use App\Models\Paylist;
class Wolfpay extends AbstractPayment {
private $pid;
private $key;
private $url;
public function __construct() {
$config = Config::get("wolfpay") ['config'];
$this->pid = $config['hid'];
$this->key = $config['key'];
$this->url = $config['url'];
}
public function purchase($request, $response, $args) {
return '';
}
public function purchase_maliopay($type, $price) {
$user = Auth::getUser();
$settings = Config::get("wolfpay")['config'];
$pl = new Paylist();
$pl->userid = $user->id;
$pl->total = $price;
$pl->tradeno = self::generateGuid();
$pl->save();
//支付方式
$type = 'all'; //$type;
//订单号
$out_trade_no = $pl->tradeno;
//异步通知地址
$notify_url = 'https://' . $_SERVER['HTTP_HOST'] . '/payment/notify/wolfpay/' . $type;
//回调通知地址
$return_url = 'https://' . $_SERVER['HTTP_HOST'] . '/user/payment/return';
//商品名称
$name = 'SS商品-' . $_SERVER['HTTP_HOST'];
//支付金额(保留小数点后两位)
$money = round($price, 2);
//站点名称
$sitename = $_SERVER['HTTP_HOST'];
//发起支付
$url = $this->submit($type, $out_trade_no, $notify_url, $return_url, $name, $money, $sitename);
return array(
'url' => $url,
'errcode' => 0,
'tradeno' => $pl->tradeno
);
}
public function notify($request, $response, $args) {
return '';
}
public function getPurchaseHTML() {
return '';
}
public function getReturnHTML($request, $response, $args) {
}
public function getStatus($request, $response, $args) {
// TODO: Implement getStatus() method.
}
public function verify($data) {
if (!isset($data['sign']) || !$data['sign']) {
return false;
}
$sign = $data['sign'];
unset($data['sign']);
unset($data['sign_type']);
$sign2 = $this->getSign($data, $this->key);
if ($sign != $sign2) {
return false;
}
return true;
}
public function submit($type, $out_trade_no, $notify_url, $return_url, $name, $money, $sitename) {
$data = ['pid' => $this->pid, 'type' => $type, 'out_trade_no' => $out_trade_no, 'notify_url' => $notify_url, 'return_url' => $return_url, 'name' => $name, 'money' => $money, 'sitename' => $sitename];
$string = http_build_query($data);
$keys = $this->ensy($string, $this->pid);
$keyss = $this->base64url_encode($this->pid . '-' . $keys);
$sign = substr($this->ensy($keyss, $this->key) , 0, 15);
return 'https://' . $this->url . '/submit?skey=' . $keyss . '&sign=' . $sign . '&sign_type=MD5';
}
private function getSign($data) {
$data = array_filter($data);
ksort($data);
$str1 = '';
foreach ($data as $k => $v) {
$str1.= '&' . $k . "=" . $v;
}
$str = $str1 . $this->key;
$str = trim($str, '&');
$sign = md5($str);
return $sign;
}
public function ensy($data, $key) {
$key = md5($key);
$len = strlen($data);
$code = '';
for ($i = 0; $i < ceil($len / 32); $i++) {
for ($j = 0; $j < 32; $j++) {
$p = $i * 32 + $j;
if ($p < $len) {
$code.= $data{$p} ^ $key{$j};
}
}
}
$code = str_replace(array(
'+',
'/',
'='
) , array(
'_',
'$',
''
) , base64_encode($code));
return $code;
}
public function base64url_encode($data) {
return rtrim(strtr(base64_encode($data) , '+/', '-_') , '=');
}
}

@ -207,6 +207,13 @@ $_ENV['payment_system']='none';
$_ENV['stripe_key'] = '';
$_ENV['stripe_webhook_endpoint_secret'] = '';
# wolfpay 以下内容可以在用户中心首页下方取得 (仅在malio聚合支付系统下生效)
$_ENV['wolfpay']=['config'=>[
'hid'=>'商户ID',
'key'=>'商户KEY',
'url'=>'商户API网址'
]];
# payssion
$_ENV['payssion_api_key'] = '';
$_ENV['payssion_secret_key'] = '';

@ -38,7 +38,7 @@ $Malio_Config['enable_i18n'] = true; // 是否显示切换语言的按钮
####### 支付系统 #######
// 支付系统写 none 意味着不启用此收款方式
// 支付宝目前支持 bitpayx | tomatopay | f2fpay
// 支付宝目前支持 bitpayx | stripe | tomatopay | f2fpay | wolfpay
$Malio_Config['mups_alipay'] = 'bitpayx'; // Malio 聚合支付系统里面的 支付宝 要用的支付平台
// 微信支付目前支持 bitpayx | stripe
$Malio_Config['mups_wechat'] = 'bitpayx'; // Malio 聚合支付系统里面的 微信支付 要用的支付平台

@ -171,7 +171,10 @@ $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/{type}', App\Services\Payment::class . ':notify');
$this->post('/notify/{type}', App\Services\Payment::class . ':notify');
$this->get('/notify/{type}/{method}', App\Services\Payment::class . ':notify');
$this->post('/notify/{type}/{method}', App\Services\Payment::class . ':notify');
$this->post('/status', App\Services\Payment::class . ':getStatus');
$this->post('/bitpay/notify', App\Services\BitPayment::class . ':notify');
@ -439,5 +442,9 @@ $app->post('/flyfoxpay_back/{type}', 'App\Services\Payment:notify');
$app->get('/flyfoxpay_back/{type}', 'App\Services\Payment:notify');
// end of flyfox
// wolfpay
$app->post('/wolfpay_back/{type}', 'App\Services\Payment:notify');
$app->get('/wolfpay_back/{type}', 'App\Services\Payment:notify');
// Run Slim Routes for App
$app->run();

@ -215,7 +215,7 @@
</div>
</div>
</div>
<div class="col-lg-8 col-12 order-lg-2 order-1 min-vh-100 background-walk-y position-relative overlay-gradient-bottom" data-background="/theme/malio/assets/img/unsplash/login-bg.jpg">
<div class="col-lg-8 col-12 order-lg-2 order-1 min-vh-100 background-walk-y position-relative overlay-gradient-bottom" data-background="/theme/malio/assets/img/unsplash/login-bg.jpg" style='background-image: url("/theme/malio/assets/img/unsplash/login-bg.jpg");'>
<div class="absolute-bottom-left index-2">
<div class="text-light p-5 pb-2">
<div class="mb-5 pb-3">

@ -18,7 +18,7 @@
</div>
</li>
{else}
<li class="dropdown dropdown-list-toggle"><a href="#" data-toggle="dropdown" class="nav-link nav-link-lg nav-link-user"></li>
<li class="dropdown dropdown-list-toggle"></li>
{/if}
<li class="dropdown"><a href="#" data-toggle="dropdown" class="nav-link dropdown-toggle nav-link-lg nav-link-user">
<img alt="image" src="{$user->gravatar}?d=retro" class="rounded-circle mr-1">

@ -23,4 +23,4 @@ CREATE TABLE IF NOT EXISTS `sms_verify` (
ALTER TABLE `user` ADD COLUMN `lang` varchar(128) NOT NULL DEFAULT 'zh-cn' COMMENT '用户的语言';
UPDATE `user` SET `lang` = `zh-cn`;
UPDATE `user` SET `lang` = 'zh-cn';

Loading…
Cancel
Save