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',''),