From 30ff71bd111a8e9a5dadeae4d07abbd62fc7cecf Mon Sep 17 00:00:00 2001 From: tokumeikoi Date: Sun, 9 May 2021 00:46:21 +0900 Subject: [PATCH] payment: support epay --- app/Payments/EPay.php | 69 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 app/Payments/EPay.php diff --git a/app/Payments/EPay.php b/app/Payments/EPay.php new file mode 100644 index 00000000..a87b97a8 --- /dev/null +++ b/app/Payments/EPay.php @@ -0,0 +1,69 @@ +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'] + ]; + } +}