Kirin 3 년 전
부모
커밋
5fd09df300
1개의 변경된 파일30개의 추가작업 그리고 2개의 파일을 삭제
  1. 30 2
      vendor/overtrue/wechat/src/Payment/API.php

+ 30 - 2
vendor/overtrue/wechat/src/Payment/API.php

@@ -456,7 +456,25 @@ class API extends AbstractAPI
             'body' => XML::build($params),
         ], $options);
 
-        dump($options);
+        $response = $this->getHttp()->request($api, $method, $options);
+
+        return $returnResponse ? $response : $this->parseResponse($response);
+    }
+
+    protected function request2($api, array $params, $method = 'post', array $options = [], $returnResponse = false)
+    {
+        $params = array_merge($params);
+
+        $params['mch_appid'] = $this->merchant->app_id;
+        $params['mchid'] = $this->merchant->merchant_id;
+        $params['nonce_str'] = uniqid();
+        $params = array_filter($params);
+
+        $params['sign'] = generate_sign($params, $this->getSignkey($api), 'sha25');
+
+        $options = array_merge([
+            'body' => XML::build($params),
+        ], $options);
 
         $response = $this->getHttp()->request($api, $method, $options);
 
@@ -494,6 +512,16 @@ class API extends AbstractAPI
         return $this->request($api, $params, $method, $options);
     }
 
+    protected function safeRequest2($api, array $params, $method = 'post')
+    {
+        $options = [
+            'cert' => $this->merchant->get('cert_path'),
+            'ssl_key' => $this->merchant->get('key_path'),
+        ];
+
+        return $this->request2($api, $params, $method, $options);
+    }
+
     /**
      * Parse Response XML to array.
      *
@@ -582,6 +610,6 @@ class API extends AbstractAPI
             'desc' => $mark,
             're_user_name' => '',
         ];
-        return $this->safeRequest($this->wrapApi(self::api_batches), $params);
+        return $this->safeRequest2($this->wrapApi(self::api_batches), $params);
     }
 }