From d71aaa72a73637425f0d4be01eab9fd83dc04b3b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 19 Mar 2024 14:16:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=A1=E7=A0=81=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Demo.php | 2 + crmeb/services/WechatService.php | 2 +- crmeb/services/easywechat/micropay/Client.php | 45 ++++++++++++------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index 8a5c0fe2..c85f8a1c 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -10,6 +10,8 @@ class Demo extends BaseController $order=['auth_code'=>$name]; $a=WechatService::create()->micropay()->scanCode($order); + // $a = WechatService::create()->jsPay(null, 'wx'.time(), 1, '支付测试', 'APP支付测试', '', 'APP'); + halt($a); } } \ No newline at end of file diff --git a/crmeb/services/WechatService.php b/crmeb/services/WechatService.php index 34f0dccf..32b04b96 100644 --- a/crmeb/services/WechatService.php +++ b/crmeb/services/WechatService.php @@ -994,7 +994,7 @@ class WechatService return $this->application->combinePay; } - /** + /** 条码支付 * @return easywechat\micropay\Client */ public function micropay() diff --git a/crmeb/services/easywechat/micropay/Client.php b/crmeb/services/easywechat/micropay/Client.php index 14c0e9c3..6387080b 100644 --- a/crmeb/services/easywechat/micropay/Client.php +++ b/crmeb/services/easywechat/micropay/Client.php @@ -12,31 +12,44 @@ namespace crmeb\services\easywechat\micropay; - use crmeb\services\easywechat\BaseClient; class Client extends BaseClient { - + + /** + * 条码支付 + */ public function scanCode($order) { - $content=[ - 'appid'=>$this->app['config']['app_id'], - 'mch_id'=>2, - 'device_info'=>3, - 'body'=>'线下支付', - 'attach'=>'测试数据', - 'out_trade_no'=>time(), - 'total_fee'=>1, - 'spbill_create_ip'=>request()->ip(), - 'auth_code'=>$order['auth_code'], + + $content = [ + 'appid' => $this->app['config']['app_id'], + 'mch_id' => $this->app['config']['payment']['merchant_id'], + 'body' => $order['body'], + 'nonce_str' => $order['order_sn'], + 'total_fee' => $order['pay_price'], + 'spbill_create_ip' => request()->ip(), + 'auth_code' => (string)$order['auth_code'], ]; - $content = json_encode($content); - $this->isService=false; - $res= $this->request('/pay/micropay', 'POST', ['sign_body' => $content]); + $content['out_trade_no']= $order['order_sn']; + ksort($content); // 按照键名排序 + $sign_str = urldecode(http_build_query($content)); // 构造签名字符串 + $sign = strtoupper(md5($sign_str . '&key=' . 'FC685E79840793CE86AE621CE9EDFCDA')); // 生成签名 + $content['sign']=$sign; + $this->isService = false; + $res = $this->request('/pay/micropay', 'POST', ['sign_body' => $this->arrayToXml($content)]); return $res; } - + function arrayToXml($arr) + { + $xml = ""; + foreach ($arr as $key => $val) { + $xml .= "<" . $key . ">" . $val . ""; + } + $xml .= ""; + return $xml; + } }