diff --git a/app/Services/Gateway/YftPay.php b/app/Services/Gateway/YftPay.php
new file mode 100644
index 00000000..ef0b3993
--- /dev/null
+++ b/app/Services/Gateway/YftPay.php
@@ -0,0 +1,335 @@
+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 = Config::get('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/app/Services/Gateway/YftPayConfig.php b/app/Services/Gateway/YftPayConfig.php
new file mode 100644
index 00000000..7df7b28a
--- /dev/null
+++ b/app/Services/Gateway/YftPayConfig.php
@@ -0,0 +1,19 @@
+pay_config = [
+ "return_url" => "/user/code",
+ "type" => "aliPay"
+ ];
+ }
+}
diff --git a/app/Services/Gateway/YftPayUtil.php b/app/Services/Gateway/YftPayUtil.php
new file mode 100644
index 00000000..f1ccdd8c
--- /dev/null
+++ b/app/Services/Gateway/YftPayUtil.php
@@ -0,0 +1,119 @@
+";
+ 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/app/Services/Payment.php b/app/Services/Payment.php
index deccc2c6..68672914 100644
--- a/app/Services/Payment.php
+++ b/app/Services/Payment.php
@@ -9,7 +9,7 @@
namespace App\Services;
use App\Services\Gateway\{
- AopF2F, Codepay, DoiAMPay, PaymentWall, ChenPay, SPay, TrimePay, PAYJS
+ AopF2F, Codepay, DoiAMPay, PaymentWall, ChenPay, SPay, TrimePay, PAYJS, YftPay
};
class Payment
@@ -34,6 +34,8 @@ class Payment
return new TrimePay(Config::get('trimepay_secret'));
case ('payjs'):
return new PAYJS(Config::get('payjs_key'));
+ case ('yftpay'):
+ return new YftPay();
default:
return null;
}
diff --git a/config/.config.example.php b/config/.config.example.php
index 30e610ef..2339ae7f 100644
--- a/config/.config.example.php
+++ b/config/.config.example.php
@@ -177,9 +177,13 @@ $_ENV['enable_checkin_captcha'] = 'false'; //启用签到验证码
//支付系统设置----------------------------------------------------------------------------------------
-#取值 none | codepay | trimepay | f2fpay | chenAlipay | paymentwall | spay |tomatopay | payjs
+#取值 none | codepay | trimepay | f2fpay | chenAlipay | paymentwall | spay |tomatopay | payjs | yftpay
$_ENV['payment_system']='none';
+#yft支付设置
+$_ENV['yft_secret']='';
+$_ENV['yft_accesskey']='';
+
#codepay码支付
#wiki地址:https://goo.gl/dRwRDi http://t.cn/RnsWjtB
$_ENV['codepay_id']=''; //码支付ID
diff --git a/config/routes.php b/config/routes.php
index 5626d92b..773c9eb5 100755
--- a/config/routes.php
+++ b/config/routes.php
@@ -148,6 +148,7 @@ $app->group('/user', function () {
})->add(new Auth());
$app->group('/payment', function () {
+ $this->get('/notify', App\Services\Payment::class . ':notify');
$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');