Ver código fonte

payment: support epay

tokumeikoi 4 anos atrás
pai
commit
30ff71bd11
1 arquivos alterados com 69 adições e 0 exclusões
  1. 69 0
      app/Payments/EPay.php

+ 69 - 0
app/Payments/EPay.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace App\Payments;
+
+class EPay {
+    public function __construct($config)
+    {
+        $this->config = $config;
+    }
+
+    public function form()
+    {
+        return [
+            'url' => [
+                'label' => 'URL',
+                'description' => '',
+                'type' => 'input',
+            ],
+            'pid' => [
+                'label' => 'PID',
+                'description' => '',
+                'type' => 'input',
+            ],
+            'key' => [
+                'label' => 'KEY',
+                'description' => '',
+                'type' => 'input',
+            ]
+        ];
+    }
+
+    public function pay($order)
+    {
+        $params = [
+            'money' => $order['total_amount'] / 100,
+            'name' => $order['trade_no'],
+            'notify_url' => $order['notify_url'],
+            'return_url' => $order['return_url'],
+            'out_trade_no' => $order['trade_no'],
+            'pid' => $this->config['pid']
+        ];
+        ksort($params);
+        reset($params);
+        $str = stripslashes(urldecode(http_build_query($params))) . $this->config['key'];
+        $params['sign'] = md5($str);
+        $params['sign_type'] = 'MD5';
+        return [
+            'type' => 1, // 0:qrcode 1:url
+            'data' => $this->config['url'] . '/submit.php?' . http_build_query($params)
+        ];
+    }
+
+    public function notify($params)
+    {
+        $sign = $params['sign'];
+        unset($params['sign']);
+        unset($params['sign_type']);
+        ksort($params);
+        reset($params);
+        $str = stripslashes(urldecode(http_build_query($params))) . $this->config['key'];
+        if ($sign !== md5($str)) {
+            return false;
+        }
+        return [
+            'trade_no' => $params['out_trade_no'],
+            'callback_no' => $params['trade_no']
+        ];
+    }
+}