From 417f43aba7c1533add5cde46bba5e86c4b91d6c5 Mon Sep 17 00:00:00 2001 From: mmw1984 <103017331+mmwong1984@users.noreply.github.com> Date: Fri, 26 Jan 2024 11:13:18 +0800 Subject: [PATCH] Create EpayWxPay --- app/Payments/EpayWxPay | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 app/Payments/EpayWxPay diff --git a/app/Payments/EpayWxPay b/app/Payments/EpayWxPay new file mode 100644 index 0000000..cc3bb5b --- /dev/null +++ b/app/Payments/EpayWxPay @@ -0,0 +1,70 @@ +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'], + 'type' => 'wxpay', + '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'] + ]; + } +}