1557492053 1 year ago
parent
commit
64c91c9bb8
1 changed files with 10 additions and 12 deletions
  1. 10 12
      application/api/service/WxService.php

+ 10 - 12
application/api/service/WxService.php

@@ -311,7 +311,7 @@ class WxService extends BaseService
     {
         try {
             $config = WxService::wxAppConfig();
-            $resp = $this->instance("app")
+            $resp = $this->instance('app')
                 ->chain('v3/pay/transactions/app')
                 ->post(['json' => [
                     'appid' => $config["appid"],
@@ -323,21 +323,18 @@ class WxService extends BaseService
                         'total' => fixed2Float($amount * 100),
                         'currency' => 'CNY'
                     ],
-//                    'payer' => [
-//                        "openid" => $openid
-//                    ]
                 ]]);
             if (200 === $resp->getStatusCode()) {
                 $resp_data = json_decode($resp->getBody()->__toString(), true);
                 $res = [
-                    'appId' => $config['appid'],
-                    'timeStamp' => time(),
-                    'nonceStr' => Formatter::nonce(),
-                    'package' => 'prepay_id=' . $resp_data['prepay_id'],
-                    'signType' => 'RSA'
+                    'appid' => $config['appid'],
+                    "partnerid" => $config['mch_id'],
+                    "prepayid" => $resp_data['prepay_id'],
+                    'package' => "Sign=WXPay",
+                    'noncestr' => Formatter::nonce(),
+                    'timestamp' => time(),
                 ];
-                $sign = $this->sign($res['appId'] . "\n" . $res["timeStamp"] . "\n" . $res["nonceStr"] . "\n" . $res["package"] . "\n", $config["mch_private_key_file_path"]);
-                $res["paySign"] = $sign;
+                $res['sign'] = $this->sign($res['appid'] . "\n" . $res["timestamp"] . "\n" . $res["noncestr"] . "\n" . $res["prepayid"] . "\n", $config["mch_private_key_file_path"]);
                 return $this->ok($res);
             }
             return $this->fail("发起支付失败!");
@@ -345,7 +342,8 @@ class WxService extends BaseService
             // 进行错误处理
             if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
                 $r = $e->getResponse();
-                return $this->fail($r->getBody()->__toString());
+                $body = json_decode($r->getBody()->__toString(), true);
+                return $this->fail($body['message']);
             }
             return $this->fail($e->getMessage());
         }