From 36cdb8df88cd245d003f55247e8b0cb2bf548968 Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 13 Aug 2020 12:34:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=8F=82=E6=95=B0=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=EF=BC=8C=E9=87=8D=E6=96=B0=E5=8A=A0=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PaymentController.php | 38 +++++++++++++++++++++++++--- app/Service/OrderService.php | 1 - config/config.php | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/Controller/PaymentController.php b/app/Controller/PaymentController.php index e0c850c..a411185 100644 --- a/app/Controller/PaymentController.php +++ b/app/Controller/PaymentController.php @@ -39,10 +39,42 @@ class PaymentController extends BaseController 'openid' => $data['openid'], ]); - $result['sign_type'] = 'MD5'; - $result['timestamp'] = time(); + $parameters = [ + 'appId' => $result['appid'], + 'timeStamp' => '' . time() . '', + 'nonceStr' => uniqid(), + 'package' => 'prepay_id=' . $result['prepay_id'], + 'signType' => 'MD5' + ]; + + //签名步骤一:按字典序排序参数 + ksort($parameters); + $string = $this->formatBizQueryParaMap($parameters, false); + //签名步骤二:在string后加入KEY + $string = $string . "&key=" . $config['key']; + //签名步骤三:MD5加密 + $string = md5($string); + //签名步骤四:所有字符转为大写 + $parameters['paySign'] = strtoupper($string); + + return $this->success($parameters); + } - return $this->success($result); + ///作用:格式化参数,签名过程需要使用 + private function formatBizQueryParaMap($paraMap, $urlencode) { + $buff = ""; + ksort($paraMap); + foreach ($paraMap as $k => $v) { + if ($urlencode) { + $v = urlencode($v); + } + $buff .= $k . "=" . $v . "&"; + } + $reqPar = null; + if (strlen($buff) > 0) { + $reqPar = substr($buff, 0, strlen($buff) - 1); + } + return $reqPar; } public function wxminiPayOffline(WxminiPayRequest $request){ diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index de1c925..54468a9 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -92,7 +92,6 @@ class OrderService implements OrderServiceInterface $storeOrderCounts = []; foreach ($countsArr as $key => &$row) { - var_dump('row', $row); $storeOrderCounts[$row['id']] = $row['count']; } diff --git a/config/config.php b/config/config.php index c67f910..7e8d490 100644 --- a/config/config.php +++ b/config/config.php @@ -32,7 +32,7 @@ return [ 'wxpay' => [ 'app_id' => env('APP_ID',''), 'mch_id' => env('MCH_ID',''), - 'key' => env('APP_SECRET',''), + 'key' => env('MCH_KEY',''), 'cert_path' => env('CERT_PATH',''), 'key_path' => env('KEY_PATH',''), 'notify_url' => env('NOTIFY_URL',''),