diff --git a/app/Services/Gateway/MalioPay.php b/app/Services/Gateway/MalioPay.php index 3da01049..c3b7c90a 100644 --- a/app/Services/Gateway/MalioPay.php +++ b/app/Services/Gateway/MalioPay.php @@ -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'; } diff --git a/app/Services/Gateway/Wolfpay.php b/app/Services/Gateway/Wolfpay.php new file mode 100644 index 00000000..3eaf5e2d --- /dev/null +++ b/app/Services/Gateway/Wolfpay.php @@ -0,0 +1,131 @@ +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) , '+/', '-_') , '='); + } +} diff --git a/config/.config.example.php b/config/.config.example.php index 1ed1b806..8608b242 100644 --- a/config/.config.example.php +++ b/config/.config.example.php @@ -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'] = ''; diff --git a/config/.malio_config.example.php b/config/.malio_config.example.php index 90aa6bb1..1ae5e3b9 100644 --- a/config/.malio_config.example.php +++ b/config/.malio_config.example.php @@ -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 聚合支付系统里面的 微信支付 要用的支付平台 diff --git a/config/routes.php b/config/routes.php index ebc412f5..db0d04c5 100644 --- a/config/routes.php +++ b/config/routes.php @@ -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(); diff --git a/resources/views/malio/auth/login.tpl b/resources/views/malio/auth/login.tpl index a2340aea..0204eca0 100644 --- a/resources/views/malio/auth/login.tpl +++ b/resources/views/malio/auth/login.tpl @@ -215,7 +215,7 @@ -