From 6dae8b3dce0170fce1b2d6cc542503c8185b74f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=85=A9=E8=B6=B3=E5=A4=A7=E8=B2=93=E8=B2=93?=
<14369594+M1Screw@users.noreply.github.com>
Date: Sat, 5 Jun 2021 12:57:18 -0400
Subject: [PATCH] update payment gateway
---
app/routes.php | 1 +
config/.config.example.php | 25 +-
src/Services/CoinPayment.php | 43 +++
src/Services/Gateway/CoinPay.php | 187 ++++++++++
src/Services/Gateway/CoinPay/CoinPayApi.php | 67 ++++
.../Gateway/CoinPay/CoinPayConfig.php | 70 ++++
.../CoinPay/CoinPayConfigInterface.php | 30 ++
.../Gateway/CoinPay/CoinPayDataBase.php | 74 ++++
.../Gateway/CoinPay/CoinPayException.php | 10 +
.../Gateway/CoinPay/CoinPayOrderQuery.php | 83 +++++
.../Gateway/CoinPay/CoinPayUnifiedOrder.php | 282 +++++++++++++++
src/Services/Gateway/YftPay.php | 334 ------------------
src/Services/Gateway/YftPayConfig.php | 22 --
src/Services/Gateway/YftPayUtil.php | 119 -------
src/Services/Payment.php | 8 +-
15 files changed, 864 insertions(+), 491 deletions(-)
create mode 100644 src/Services/CoinPayment.php
create mode 100644 src/Services/Gateway/CoinPay.php
create mode 100644 src/Services/Gateway/CoinPay/CoinPayApi.php
create mode 100644 src/Services/Gateway/CoinPay/CoinPayConfig.php
create mode 100644 src/Services/Gateway/CoinPay/CoinPayConfigInterface.php
create mode 100644 src/Services/Gateway/CoinPay/CoinPayDataBase.php
create mode 100644 src/Services/Gateway/CoinPay/CoinPayException.php
create mode 100644 src/Services/Gateway/CoinPay/CoinPayOrderQuery.php
create mode 100644 src/Services/Gateway/CoinPay/CoinPayUnifiedOrder.php
delete mode 100644 src/Services/Gateway/YftPay.php
delete mode 100644 src/Services/Gateway/YftPayConfig.php
delete mode 100644 src/Services/Gateway/YftPayUtil.php
diff --git a/app/routes.php b/app/routes.php
index 10f4fd6ed7..293f3b08d9 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -114,6 +114,7 @@
$this->post('/notify', App\Services\Payment::class . ':notify');
$this->post('/notify/{type}', App\Services\Payment::class . ':notify');
$this->post('/status', App\Services\Payment::class . ':getStatus');
+ $this->post('/coinpay/notify', App\Services\CoinPayment::class. ':notify');
});
// Auth
diff --git a/config/.config.example.php b/config/.config.example.php
index f885ecdaca..bc6adb1807 100644
--- a/config/.config.example.php
+++ b/config/.config.example.php
@@ -285,37 +285,32 @@
//支付系统设置----------------------------------------------------------------------------------------
-#取值 none | codepay | f2fpay | paymentwall | spay | payjs | yftpay | bitpayx | theadpay
+#取值 none | f2fpay | paymentwall | spay | payjs | bitpayx | theadpay | coinpay
$_ENV['payment_system'] = 'none';
-#yft支付设置
-$_ENV['yft_secret'] = '';
-$_ENV['yft_accesskey'] = '';
-
-#codepay码支付
-#wiki地址:https://goo.gl/dRwRDi http://t.cn/RnsWjtB
+# codepay码支付
$_ENV['codepay_id'] = ''; //码支付ID
$_ENV['codepay_key'] = ''; //码支付通信密钥
-#alipay,f2fpay
+# alipay,f2fpay
$_ENV['f2fpay_app_id'] = '';
$_ENV['f2fpay_p_id'] = '';
$_ENV['alipay_public_key'] = '';
$_ENV['merchant_private_key'] = '';
$_ENV['f2fNotifyUrl'] = null; //自定义当面付回调地址
-#PaymentWall
+# PaymentWall
$_ENV['pmw_publickey'] = '';
$_ENV['pmw_privatekey'] = '';
$_ENV['pmw_widget'] = 'm2_1';
$_ENV['pmw_height'] = '350px';
-#alipay,spay
+# alipay,spay
$_ENV['alipay_id'] = '';
$_ENV['alipay_key'] = '';
$_ENV['amount'] = [2, 23, 233, 2333, 23333]; //充值金额选项设定
-#alipay,zfbjk.com
+# alipay,zfbjk.com
$_ENV['zfbjk_pid'] = '';
$_ENV['zfbjk_key'] = '';
$_ENV['zfbjk_qrcodeurl'] = '';
@@ -325,7 +320,7 @@
# 客服和技术 24x7 在线支持: https://t.me/mugglepay
$_ENV['bitpay_secret'] = '';
-#PayJs
+# PayJs
$_ENV['payjs_mchid'] = '';
$_ENV['payjs_key'] = '';
@@ -334,6 +329,12 @@
$_ENV['theadpay_mchid'] = '';
$_ENV['theadpay_key'] = '';
+# CoinPay
+$_ENV['coinpay_appid'] =''; // CoinPay 应用ID (*)
+$_ENV['coinpay_secret'] =''; // CoinPay 验证密钥 (*)
+$_ENV['coinpay_notify'] =''; // 异步回调URL
+$_ENV['coinpay_return'] =''; // 同步返回URL
+
#后台商品列表 销量统计
$_ENV['sales_period'] = 30; //统计指定周期内的销量,值为【expire/任意大于0的整数】
diff --git a/src/Services/CoinPayment.php b/src/Services/CoinPayment.php
new file mode 100644
index 0000000000..27ba957000
--- /dev/null
+++ b/src/Services/CoinPayment.php
@@ -0,0 +1,43 @@
+notify($request, $response, $args);
+ }
+
+ public static function returnHTML($request, $response, $args)
+ {
+ return self::getClient()->getReturnHTML($request, $response, $args);
+ }
+
+ public static function purchaseHTML()
+ {
+ $coinpay_secret = Config::get('coinpay_secret');
+ if (self::getClient() != null && $coinpay_secret != '') {
+ return self::getClient()->getPurchaseHTML();
+ }
+
+ return '';
+ }
+
+ public static function getStatus($request, $response, $args)
+ {
+ return self::getClient()->getStatus($request, $response, $args);
+ }
+
+ public static function purchase($request, $response, $args)
+ {
+ return self::getClient()->purchase($request, $response, $args);
+ }
+}
diff --git a/src/Services/Gateway/CoinPay.php b/src/Services/Gateway/CoinPay.php
new file mode 100644
index 0000000000..6cd9c30f53
--- /dev/null
+++ b/src/Services/Gateway/CoinPay.php
@@ -0,0 +1,187 @@
+coinPaySecret = $coinPaySecret;
+ $this->coinPayAppId = $coinPayAppId;
+ $this->coinPayGatewayUrl = "https://openapi.coinpay.la/"; // 网关地址
+ }
+
+
+ public function purchase($request, $response, $args)
+ {
+ // set timezone
+ date_default_timezone_set('Asia/Hong_Kong');
+ /**************************请求参数**************************/
+ $amount = $request->getParam('price');
+ //var_dump($request->getParam("price"));die();
+ $user = Auth::getUser();
+ $pl = new Paylist();
+ $pl->userid = $user->id;
+ $pl->total = $amount;
+ $pl->tradeno = self::generateGuid();
+ $pl->save();
+ //商户订单号,商户网站订单系统中唯一订单号,必填
+ $out_trade_no = $pl->tradeno;
+ //订单名称,必填
+ $subject = $pl->id . 'UID:' . $user->id . ' 充值' . $amount . '元';
+ //付款金额,必填
+ $total_fee = (float)$amount;
+ /************************************************************/
+ $report_data = new CoinPayUnifiedOrder();
+ $report_data->SetSubject($subject);
+ $report_data->SetOut_trade_no($out_trade_no);
+ $report_data->SetTotal_amount($total_fee);
+ $report_data->SetTimestamp(date('Y-m-d H:i:s', time()));
+ $report_data->SetReturn_url(Config::get('baseUrl') . '/user/code');
+ $report_data->SetNotify_url(Config::get('baseUrl') . '/payment/coinpay/notify');
+// $report_data->SetBody(json_encode($pl));
+// $report_data->SetTransCurrency("CNY");
+// $report_data->SetAttach("");
+ $config = new CoinPayConfig();
+ try {
+ $url = CoinPayApi::unifiedOrder($config, $report_data);
+ return json_encode(['code' => 0, 'url' => $this->coinPayGatewayUrl . 'api/gateway?' . $url]);
+ } catch (CoinPayException $exception) {
+ print_r($exception->getMessage());
+ die();
+ }
+ }
+
+ private function Sign($value, $secret)
+ {
+ ksort($value);
+ reset($value);
+ $sign_param = implode('&', $value);
+ $signature = hash_hmac('sha256', $sign_param, $secret, true);
+ return base64_encode($signature);
+ }
+
+ /**
+ * @param $data
+ * @param $sign
+ * @return bool
+ */
+ public function verify($data, $sign)
+ {
+ $payConfig = new CoinPayConfig();
+ if ($sign === self::Sign($data, $payConfig->GetSecret())) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * 异步通知
+ * @param \Slim\Http\Request $request
+ * @param \Slim\Http\Response $response
+ * @param array $args
+ */
+ public function notify($request, $response, $args)
+ {
+ $raw = file_get_contents("php://input");
+ file_put_contents(BASE_PATH . '/coinpay_purchase.log', $raw . "\r\n", FILE_APPEND);
+ $data = json_decode($raw, true);
+ if (empty($data)) {
+ file_put_contents(BASE_PATH . '/coinpay_purchase.log', "返回数据异常\r\n", FILE_APPEND);
+ echo "fail";
+ die();
+ }
+ // 签名验证
+ $sign = $data['sign'];
+ unset($data['sign']);
+ $resultVerify = self::verify($data, $sign);
+ $isPaid = $data !== null && $data['trade_status'] !== null && $data['trade_status'] === 'TRADE_SUCCESS';
+ if ($resultVerify) {
+ if ($isPaid) {
+ $this->postPayment($data['out_trade_no'], 'CoinPay');
+ echo "success";
+ file_put_contents(BASE_PATH . '/coinpay_purchase.log', "订单{$data['out_trade_no']}支付成功\r\n" . json_encode($data) . "\r\n", FILE_APPEND);
+ } else {
+ echo "success";
+ file_put_contents(BASE_PATH . '/coinpay_purchase.log', "订单{$data['out_trade_no']}未支付自动关闭成功\r\n" . json_encode($data) . "\r\n", FILE_APPEND);
+ }
+ } else {
+ echo "fail";
+ file_put_contents(BASE_PATH . '/coinpay_purchase.log', "订单{$data['out_trade_no']}签名验证失败或者订单未支付成功\r\n" . json_encode($data) . "\r\n", FILE_APPEND);
+ }
+ die();
+ }
+
+ public function getReturnHTML($request, $response, $args)
+ {
+ // TODO: Implement getStatus() method.
+ }
+
+ public function getStatus($request, $response, $args)
+ {
+ // TODO: Implement getStatus() method.
+ }
+
+ public function getPurchaseHTML()
+ {
+ return '
+
+';
+ }
+}
diff --git a/src/Services/Gateway/CoinPay/CoinPayApi.php b/src/Services/Gateway/CoinPay/CoinPayApi.php
new file mode 100644
index 0000000000..15c59aff9f
--- /dev/null
+++ b/src/Services/Gateway/CoinPay/CoinPayApi.php
@@ -0,0 +1,67 @@
+IsSubjectSet()) {
+ throw new CoinPayException("缺少统一支付接口必填参数subject!");
+ } else if (!$inputObj->IsTimestampSet()) {
+ throw new CoinPayException("缺少统一支付接口必填参数timestamp!");
+ } else if (!$inputObj->IsOut_trade_noSet()) {
+ throw new CoinPayException("缺少统一支付接口必填参数out_trade_no!");
+ } else if (!$inputObj->IsTotal_amountSet()) {
+ throw new CoinPayException("缺少统一支付接口必填参数total_amount!");
+ }
+
+ //异步通知url未设置,则使用配置文件中的url
+ if (!$inputObj->IsNotify_urlSet() && $config->GetNotifyUrl() != "") {
+ $inputObj->SetNotify_url($config->GetNotifyUrl());
+ }
+ if (!$inputObj->IsReturn_urlSet() && $config->GetReturnUrl() != "") {
+ $inputObj->SetReturn_url($config->GetReturnUrl());
+ }
+ if (!$inputObj->IsAttachSet() && $config->GetAttach() != "") {
+ $inputObj->SetAttach($config->GetAttach());
+ }
+ if (!$inputObj->IsBodySet() && $config->GetBody() != "") {
+ $inputObj->SetBody($config->GetBody());
+ }
+ if (!$inputObj->IsTransCurrencySet() && $config->GetTransCurrency() != "") {
+ $inputObj->SetTransCurrency($config->GetTransCurrency());
+ }
+
+ // 设置AppID于随机字符串
+ $inputObj->SetAppid($config->GetAppId());
+ $inputObj->SetNonce_str(self::getNonceStr());
+
+ //签名
+ $inputObj->SetSign($config->GetSecret());
+ return http_build_query($inputObj->ReturnArray());
+ }
+
+ /**
+ * 返回随机字符串
+ * @param int $length
+ * @return string
+ */
+ public static function getNonceStr($length = 32)
+ {
+ $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
+ $str = "";
+ for ($i = 0; $i < $length; $i++) {
+ $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
+ }
+ return $str;
+ }
+}
diff --git a/src/Services/Gateway/CoinPay/CoinPayConfig.php b/src/Services/Gateway/CoinPay/CoinPayConfig.php
new file mode 100644
index 0000000000..09fdc2d759
--- /dev/null
+++ b/src/Services/Gateway/CoinPay/CoinPayConfig.php
@@ -0,0 +1,70 @@
+values['app_id'] = $value;
+ }
+
+ /**
+ * 获取APPID
+ * @return 值
+ **/
+ public function GetAppid()
+ {
+ return $this->values['app_id'];
+ }
+
+ /**
+ * 判断应用ID是否存在
+ * @return true 或 false
+ **/
+ public function IsAppidSet()
+ {
+ return array_key_exists('app_id', $this->values);
+ }
+
+ /**
+ * 设置签名,详见签名生成算法
+ * @param $secret
+ */
+ public function SetSign($secret)
+ {
+ ksort($this->values);
+ reset($this->values);
+ $sign_param = implode('&', $this->values);
+ $signature = hash_hmac('sha256', $sign_param, $secret, true);
+ $this->values['sign'] = base64_encode($signature);
+ }
+
+ /**
+ * 获取签名,详见签名生成算法的值
+ * @return 值
+ **/
+ public function GetSign()
+ {
+ return $this->values['sign'];
+ }
+
+ /**
+ * 判断签名,详见签名生成算法是否存在
+ * @return true 或 false
+ **/
+ public function IsSignSet()
+ {
+ return array_key_exists('sign', $this->values);
+ }
+
+ /**
+ * @return array
+ */
+ public function ReturnArray()
+ {
+ return $this->values;
+ }
+}
diff --git a/src/Services/Gateway/CoinPay/CoinPayException.php b/src/Services/Gateway/CoinPay/CoinPayException.php
new file mode 100644
index 0000000000..f81e8a9622
--- /dev/null
+++ b/src/Services/Gateway/CoinPay/CoinPayException.php
@@ -0,0 +1,10 @@
+getMessage();
+ }
+}
diff --git a/src/Services/Gateway/CoinPay/CoinPayOrderQuery.php b/src/Services/Gateway/CoinPay/CoinPayOrderQuery.php
new file mode 100644
index 0000000000..9951bddb76
--- /dev/null
+++ b/src/Services/Gateway/CoinPay/CoinPayOrderQuery.php
@@ -0,0 +1,83 @@
+values['invoice_id'] = $value;
+ }
+ /**
+ * 获取票据ID
+ * @return 值
+ **/
+ public function GetInvoice_id()
+ {
+ return $this->values['invoice_id'];
+ }
+ /**
+ * 判断票据ID是否存在
+ * @return true 或 false
+ **/
+ public function IsInvoice_idSet()
+ {
+ return array_key_exists('invoice_id', $this->values);
+ }
+
+
+ /**
+ * 设置商户系统内部的订单号,当没提供transaction_id时需要传这个。
+ * @param string $value
+ **/
+ public function SetOut_trade_no($value)
+ {
+ $this->values['out_trade_no'] = $value;
+ }
+ /**
+ * 获取商户系统内部的订单号,当没提供transaction_id时需要传这个。的值
+ * @return 值
+ **/
+ public function GetOut_trade_no()
+ {
+ return $this->values['out_trade_no'];
+ }
+ /**
+ * 判断商户系统内部的订单号,当没提供transaction_id时需要传这个。是否存在
+ * @return true 或 false
+ **/
+ public function IsOut_trade_noSet()
+ {
+ return array_key_exists('out_trade_no', $this->values);
+ }
+
+
+ /**
+ * 设置随机字符串,不长于32位。推荐随机数生成算法
+ * @param string $value
+ **/
+ public function SetNonce_str($value)
+ {
+ $this->values['nonce_str'] = $value;
+ }
+ /**
+ * 获取随机字符串,不长于32位。推荐随机数生成算法的值
+ * @return 值
+ **/
+ public function GetNonce_str()
+ {
+ return $this->values['nonce_str'];
+ }
+ /**
+ * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
+ * @return true 或 false
+ **/
+ public function IsNonce_strSet()
+ {
+ return array_key_exists('nonce_str', $this->values);
+ }
+}
diff --git a/src/Services/Gateway/CoinPay/CoinPayUnifiedOrder.php b/src/Services/Gateway/CoinPay/CoinPayUnifiedOrder.php
new file mode 100644
index 0000000000..8573062948
--- /dev/null
+++ b/src/Services/Gateway/CoinPay/CoinPayUnifiedOrder.php
@@ -0,0 +1,282 @@
+values['subject'] = $value;
+ }
+
+ /**
+ * 获取
+ * @return string 值
+ **/
+ public function GetSubject()
+ {
+ return $this->values['subject'];
+ }
+
+ /**
+ * 判断
+ * @return true 或 false
+ **/
+ public function IsSubjectSet()
+ {
+ return array_key_exists('subject', $this->values);
+ }
+
+ /**
+ * 设置
+ * @param string $value
+ **/
+ public function SetBody($value)
+ {
+ $this->values['body'] = $value;
+ }
+
+ /**
+ * 获取
+ * @return string 值
+ **/
+ public function GetBody()
+ {
+ return $this->values['body'];
+ }
+
+ /**
+ * 判断
+ * @return true 或 false
+ **/
+ public function IsBodySet()
+ {
+ return array_key_exists('body', $this->values);
+ }
+
+ /**
+ * 设置商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
+ * @param string $value
+ **/
+ public function SetOut_trade_no($value)
+ {
+ $this->values['out_trade_no'] = $value;
+ }
+
+ /**
+ * 获取商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号的值
+ * @return string 值
+ **/
+ public function GetOut_trade_no()
+ {
+ return $this->values['out_trade_no'];
+ }
+
+ /**
+ * 判断商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号是否存在
+ * @return true 或 false
+ **/
+ public function IsOut_trade_noSet()
+ {
+ return array_key_exists('out_trade_no', $this->values);
+ }
+
+ /**
+ * 设置订单总金额,只能为整数,详见支付金额
+ * @param string $value
+ **/
+ public function SetTotal_amount($value)
+ {
+ $this->values['total_amount'] = $value;
+ }
+
+ /**
+ * 获取订单总金额,只能为整数,详见支付金额的值
+ * @return string 值
+ **/
+ public function GetTotal_amount()
+ {
+ return $this->values['total_amount'];
+ }
+
+ /**
+ * 判断订单总金额,只能为整数,详见支付金额是否存在
+ * @return true 或 false
+ **/
+ public function IsTotal_amountSet()
+ {
+ return array_key_exists('total_amount', $this->values);
+ }
+
+ /**
+ * 设置
+ * @param string $value
+ **/
+ public function SetTimestamp($value)
+ {
+ $this->values['timestamp'] = $value;
+ }
+
+ /**
+ * 获取
+ * @return string 值
+ **/
+ public function GetTimestamp()
+ {
+ return $this->values['timestamp'];
+ }
+
+ /**
+ * 判断
+ * @return true 或 false
+ **/
+ public function IsTimestampSet()
+ {
+ return array_key_exists('timestamp', $this->values);
+ }
+
+ /**
+ * 设置
+ * @param string $value
+ **/
+ public function SetNonce_str($value)
+ {
+ $this->values['nonce_str'] = $value;
+ }
+
+ /**
+ * 获取
+ * @return string 值
+ **/
+ public function GetNonce_str()
+ {
+ return $this->values['nonce_str'];
+ }
+
+ /**
+ * 判断
+ * @return true 或 false
+ **/
+ public function IsNonce_strSet()
+ {
+ return array_key_exists('nonce_str', $this->values);
+ }
+
+ /**
+ * 设置接收coinpay支付异步通知回调地址
+ * @param string $value
+ **/
+ public function SetNotify_url($value)
+ {
+ $this->values['notify_url'] = $value;
+ }
+
+ /**
+ * 获取接收coinpay支付异步通知回调地址的值
+ * @return string 值
+ **/
+ public function GetNotify_url()
+ {
+ return $this->values['notify_url'];
+ }
+
+ /**
+ * 判断接收coinpay支付异步通知回调地址是否存在
+ * @return true 或 false
+ **/
+ public function IsNotify_urlSet()
+ {
+ return array_key_exists('notify_url', $this->values);
+ }
+
+ /**
+ * 设置
+ * @param string $value
+ **/
+ public function SetReturn_url($value)
+ {
+ $this->values['return_url'] = $value;
+ }
+
+ /**
+ * 获取
+ * @return string 值
+ **/
+ public function GetReturn_url()
+ {
+ return $this->values['return_url'];
+ }
+
+ /**
+ * 判断
+ * @return true 或 false
+ **/
+ public function IsReturn_urlSet()
+ {
+ return array_key_exists('return_url', $this->values);
+ }
+
+
+ /**
+ * 设置
+ * @param string $value
+ **/
+ public function SetAttach($value)
+ {
+ $this->values['attach'] = $value;
+ }
+
+ /**
+ * 获取
+ * @return string 值
+ **/
+ public function GetAttach()
+ {
+ return $this->values['attach'];
+ }
+
+ /**
+ * 判断
+ * @return true 或 false
+ **/
+ public function IsAttachSet()
+ {
+ return array_key_exists('attach', $this->values);
+ }
+
+ /**
+ * 设置
+ * @param string $value
+ **/
+ public function SetTransCurrency($value)
+ {
+ $this->values['trans_currency'] = $value;
+ }
+
+ /**
+ * 获取
+ * @return string 值
+ **/
+ public function GetTransCurrency()
+ {
+ return $this->values['trans_currency'];
+ }
+
+ /**
+ * 判断
+ * @return true 或 false
+ **/
+ public function IsTransCurrencySet()
+ {
+ return array_key_exists('trans_currency', $this->values);
+ }
+}
diff --git a/src/Services/Gateway/YftPay.php b/src/Services/Gateway/YftPay.php
deleted file mode 100644
index 6def201d9d..0000000000
--- a/src/Services/Gateway/YftPay.php
+++ /dev/null
@@ -1,334 +0,0 @@
-user = Auth::getUser();
- }
-
- public function purchase($request, $response, $args)
- {
- return $this->constructPayPara($request);
- }
-
- public function notify($request, $response, $args)
- {
- $yftUtil = new YftPayUtil();
- $pay_config = new YftPayConfig();
- $pay_config->init();
- //价格
- $total_fee = $request->getParam("total_fee");
- //易付通返回的订单号
- $yft_order_no = $request->getParam("trade_no");
- //面板生成的订单号
- $ss_order_no = $request->getParam("out_trade_no");
- //订单说明
- $subject = $request->getParam("subject");
- //付款状态
- $trade_status = $request->getParam("trade_status");
- //加密验证字符串
- $sign = $request->getParam("sign");
- $verifyNotify = $yftUtil->md5Verify(floatval($total_fee), $ss_order_no, $yft_order_no, $trade_status, $sign);
- if ($verifyNotify && $trade_status == 'TRADE_SUCCESS') {//验证成功
- /*
- 加入您的入库及判断代码;
- >>>>>>>!!!为了保证数据传达到回调地址,会请求4次。所以必须要先判断订单状态,然后再插入到数据库,这样后面即使请求3次,也不会造成订单重复!!!!<<<<<<<
- 判断返回金额与实金额是否想同;
- 判断订单当前状态;
- 完成以上才视为支付成功
- */
- $order = Paylist::where('tradeno', $ss_order_no)->first();
- if ($order->status == 0) {
- $this->postPayment($ss_order_no, '易付 充值');
- return "success";
- }
- return "fail";
- } else {
- //验证失败
- return "fail";
- }
- }
-
- /**
- * @param $request
- * @return string
- */
- private function constructPayPara($request)
- {
- $yftLib = new YftPayUtil();
- $pay_config = new YftPayConfig();
- $pay_config->init();
- /**************************请求参数**************************/
- //订单名称
- $subject = $request->getParams()['subject'];//必填
- //付款金额
- $total_fee = $request->getParams()['total_fee'];//必填 需为整数
- //服务器异步通知页面路径
- $notify_url = $request->getUri()->getScheme() . "://" . $request->getUri()->getHost() . "/payment/notify";
- //需http://格式的完整路径,不能加?id=123这类自定义参数
- //页面跳转同步通知页面路径
- $return_url = $request->getUri()->getScheme() . "://" . $request->getUri()->getHost() . $pay_config->pay_config["return_url"];
- //需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/
- $secret = $_ENV['yft_secret'];
- $ss_order_no = self::genOrderNumber();
- /************************************************************/
- //构造要请求的参数数组,无需改动
- $parameter = [
- "total_fee" => $total_fee,
- "notify_url" => $notify_url,
- "return_url" => $return_url,
- "secret" => $secret,
- "out_trade_no" => $ss_order_no
- ];
- //向数据库插入订单信息
- $order = new Paylist();
- $order->userid = $this->user->id;
- $order->total = $total_fee;
- $order->status = 0;
- $order->tradeno = $ss_order_no;
- $order->save();
- //建立请求
- $html_text = $yftLib->buildRequestForm($parameter, $ss_order_no, $pay_config);
- return $html_text;
- }
-
- public function getPurchaseHTML()
- {
- return '
-
-
-
- ';
- }
-
-
- public function getReturnHTML($request, $response, $args)
- {
- // TODO: Implement getReturnHTML() method.
- }
-
- public function getStatus($request, $response, $args)
- {
- // TODO: Implement getStatus() method.
- }
-
- private function genOrderNumber()
- {
- //生成订单号
- // 密码字符集,可任意添加你需要的字符
- $date = time();
- $date = "yft" . date("YmdHis", $date);
- $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- $password = "";
- for ($i = 0; $i < 8; $i++) {
- // 这里提供两种字符获取方式
- // 第一种是使用 substr 截取$chars中的任意一位字符;
- // 第二种是取字符数组 $chars 的任意元素
- $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
- }
- return $date . $password;
- }
-}
diff --git a/src/Services/Gateway/YftPayConfig.php b/src/Services/Gateway/YftPayConfig.php
deleted file mode 100644
index cb4b0e4d01..0000000000
--- a/src/Services/Gateway/YftPayConfig.php
+++ /dev/null
@@ -1,22 +0,0 @@
-pay_config = [
- "return_url" => "/user/code",
- "type" => "aliPay"
- ];
- }
-}
diff --git a/src/Services/Gateway/YftPayUtil.php b/src/Services/Gateway/YftPayUtil.php
deleted file mode 100644
index 7bf31271f2..0000000000
--- a/src/Services/Gateway/YftPayUtil.php
+++ /dev/null
@@ -1,119 +0,0 @@
-";
- foreach ($para as $key => $val) {
- $sHtml .= "";
- }
- if ($pay_config->pay_config["type"] == "aliPay") {
- $sHtml .= "";
- } else {
- $sHtml .= "";
- }
- //submit按钮控件请不要含有name属性
- $sHtml = $sHtml . "";
- $sHtml = $sHtml . "";
- return $sHtml;
- }
-
- /**
- * 生成要请求给易付的参数数组
- * @param $para_temp 请求前的参数数组
- * @return 要请求的参数数组
- */
- static function buildRequestPara($para_temp)
- {
- //除去待签名参数数组中的空值和签名参数
- $para_filter = YftPayUtil::paraFilter($para_temp);
- //生成签名结果
- $mysign = YftPayUtil::buildRequestMysign($para_filter);
- //签名结果与签名方式加入请求提交参数组中
- $para_filter['sign'] = $mysign;
- return $para_filter;
- }
-
- /**
- * 除去数组中的空值和签名参数
- * @param $para 签名参数组
- * return 去掉空值与签名参数后的新签名参数组
- */
- static function paraFilter($para)
- {
- $para_filter = array();
- foreach ($para as $key => $val) {
- if ($key == "sign" || $val == "") continue;
- else $para_filter[$key] = $para[$key];
- }
- return $para_filter;
- }
-
- /**
- * 生成签名结果
- * @param $para_filter 要签名的数组
- * return 签名结果字符串
- */
- static function buildRequestMysign($para_filter)
- {
- //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
- $prestr = YftPayUtil::createLinkstring($para_filter);
- $mysign = MD5($prestr);
- return $mysign;
- }
-
- static function md5Sign($prestr)
- {
- return md5($prestr);
- }
-
- /**
- * 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
- * @param $para 需要拼接的数组
- * return 拼接完成以后的字符串
- */
- static function createLinkstring($para)
- {
- $arg = "";
- foreach ($para as $key => $val) {
- $arg .= $key . "=" . $val . "&";
- }
- //去掉最后一个&字符
- $arg = substr($arg, 0, strlen($arg) - 1);
- //如果存在转义字符,那么去掉转义
- if (get_magic_quotes_gpc()) {
- $arg = stripslashes($arg);
- }
- return $arg;
- }
-}
diff --git a/src/Services/Payment.php b/src/Services/Payment.php
index c9901ff201..7400d7a63d 100644
--- a/src/Services/Payment.php
+++ b/src/Services/Payment.php
@@ -8,9 +8,9 @@
PaymentWall,
SPay,
PAYJS,
- YftPay,
BitPayX,
- THeadPay
+ THeadPay,
+ CoinPay
};
class Payment
@@ -29,12 +29,12 @@ public static function getClient()
return new AopF2F();
case ('payjs'):
return new PAYJS($_ENV['payjs_key']);
- case ('yftpay'):
- return new YftPay();
case ('bitpayx'):
return new BitPayX($_ENV['bitpay_secret']);
case ('theadpay'):
return new THeadPay();
+ case ('coinpay'):
+ return new CoinPay(Config::get('coinpay_secret'), Config::get('coinpay_appid'));
default:
return null;
}