WIN-2308041133\Administrator 2 週間 前
コミット
e2d3dce1f3
1 ファイル変更55 行追加6 行削除
  1. 55 6
      vendor/overtrue/wechat/src/Payment/API.php

+ 55 - 6
vendor/overtrue/wechat/src/Payment/API.php

@@ -482,18 +482,67 @@ class API extends AbstractAPI
         $params['nonce_str'] = uniqid();
         $params = array_filter($params);
         @file_put_contents('quanju2.txt',  json_encode($this->getSignkey($api))."-微信支付失败9\r\n", 8);
-        $params2 = [
+        $params = [
             'appid' => 'wxc249a20cfeed19cd',
+            'body' => 'test',
             'mch_id' => '1731458899',
             'nonce_str' => 'test123456',
-            'body' => 'test',
+            'notify_url' => 'http://gcshop.qiniu1314.com/api/wechat/notify',
+            'openid' => 'o4h8g2NHKRUxkKw3ZKcDjZq0RojA',
             'out_trade_no' => 'test' . time(),
-            'total_fee' => 1,
             'spbill_create_ip' => '127.0.0.1',
-            'notify_url' => 'http://gcshop.qiniu1314.com/api/wechat/notify',
-            'trade_type' => 'JSAPI',
-            'openid' => 'o4h8g2NHKRUxkKw3ZKcDjZq0RojA'
+            'total_fee' => 1,
+            'trade_type' => 'JSAPI'
         ];
+
+// 排序并生成签名
+        ksort($params);
+        $apiKey = '8BwxEDhWF3BmUDbYpasb4c5kBchnEFfB';
+        $stringA = '';
+        foreach ($params as $k => $v) {
+            $stringA .= $k . '=' . $v . '&';
+        }
+        $stringA = rtrim($stringA, '&');
+        $stringSignTemp = $stringA . '&key=' . $apiKey;
+        $params['sign'] = strtoupper(md5($stringSignTemp));
+
+// 生成XML
+        $xml = '<xml>';
+        foreach ($params as $key => $val) {
+            if (is_numeric($val)) {
+                $xml .= "<{$key}>{$val}</{$key}>";
+            } else {
+                $xml .= "<{$key}><![CDATA[{$val}]]></{$key}>";
+            }
+        }
+        $xml .= '</xml>';
+
+// 发送请求
+        $ch = curl_init();
+        curl_setopt_array($ch, [
+            CURLOPT_URL => 'https://api.mch.weixin.qq.com/pay/unifiedorder',
+            CURLOPT_POST => true,
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_POSTFIELDS => $xml,
+            CURLOPT_HTTPHEADER => ['Content-Type: application/xml'],
+            CURLOPT_TIMEOUT => 10,
+            CURLOPT_SSL_VERIFYPEER => false,
+            CURLOPT_SSL_VERIFYHOST => false,
+        ]);
+
+        $response = curl_exec($ch);
+        @file_put_contents('quanju2.txt',  json_encode($response)."-自己测试2\r\n", 8);
+
+        $error = curl_error($ch);
+        curl_close($ch);
+
+        echo "Request XML:\n$xml\n\n";
+        echo "Response:\n$response\n";
+        if ($error) {
+            @file_put_contents('quanju2.txt',  json_encode($error)."-自己测试1\r\n", 8);
+            echo "cURL Error: $error\n";
+        }
+        die();
         ksort($params2);
 //        ksort($params);
         foreach ($params2 as $key => $value) {