feature: added epay & mGate payment

This commit is contained in:
Tokumeikoi
2020-07-20 19:56:39 +08:00
parent e500fb77dc
commit cff5d205bc
7 changed files with 116 additions and 31 deletions

42
library/Epay.php Normal file
View File

@ -0,0 +1,42 @@
<?php
namespace Library;
class Epay
{
private $pid;
private $key;
private $url;
public function __construct($url, $pid, $key)
{
$this->pid = $pid;
$this->key = $key;
$this->url = $url;
}
public function pay($params)
{
$params['pid'] = $this->pid;
ksort($params);
reset($params);
$str = stripslashes(urldecode(http_build_query($params))) . $this->key;
$params['sign'] = md5($str);
$params['sign_type'] = 'MD5';
return $this->url . '/submit.php?' . http_build_query($params);
}
public function verify($params)
{
$sign = $params['sign'];
unset($params['sign']);
unset($params['sign_type']);
ksort($params);
reset($params);
$str = stripslashes(urldecode(http_build_query($params))) . $this->key;
if ($sign !== md5($str)) {
return false;
}
return true;
}
}

View File

@ -4,15 +4,17 @@ namespace Library;
use \Curl\Curl;
class PayTaro
class MGate
{
private $appId;
private $appSecret;
private $url;
public function __construct($appId, $appSecret)
public function __construct($url, $appId, $appSecret)
{
$this->appId = $appId;
$this->appSecret = $appSecret;
$this->url = $url;
}
public function pay($params)
@ -21,7 +23,7 @@ class PayTaro
$str = http_build_query($params) . $this->appSecret;
$params['sign'] = md5($str);
$curl = new Curl();
$curl->post('https://api.paytaro.com/v1/gateway/fetch', http_build_query($params));
$curl->post($this->url . '/v1/gateway/fetch', http_build_query($params));
$result = $curl->response;
if (!$result) {
abort(500, '网络异常');