WIN-2308041133\Administrator 5 月之前
父节点
当前提交
139aa9e5f8
共有 1 个文件被更改,包括 102 次插入102 次删除
  1. 102 102
      extend/liuniu/WechatService.php

+ 102 - 102
extend/liuniu/WechatService.php

@@ -600,108 +600,108 @@ class WechatService
         $timestamp=time();
         $version = '1.0';
         // 微信支付配置参数
-//        $mch_id = "1623907696";
-//        $key = "1wm55KpF5tgZFW1TYs6TBX9MWBpI5FmT";
-//
-//// 使用动态时间戳
-//        $current_timestamp = time();
-////        $contract_code = preg_replace("/[^0-9]/", "", $contract_code);
-//        $params = [
-//            'appid' => 'wx5681205d1ef4d9d3',
-//            'mch_id' => $mch_id,
-//            'plan_id' => '189172',
-//            'contract_code' => $contract_code,
-//            'request_serial' => $current_timestamp, // 使用时间戳作为序列号
-//            'contract_display_account' => '昔拉',
-//            'notify_url' => 'http://red.igxys.com/api/wechat/notify/12',
-//            'timestamp' => $current_timestamp, // 动态时间戳
-//            'version' => '1.0',
-//        ];
-//
-//// 关键步骤1:先对需要编码的参数进行原始值存储
-//        $raw_params = $params;
-//
-//// 关键步骤2:对需要URL编码的参数值进行编码(签名前)
-////        $params['contract_display_account'] = urlencode($params['contract_display_account']);
-//
-//
-//// 步骤3:参数按ASCII排序
-//        ksort($params);
-//
-//// 步骤4:构建待签名字符串(使用编码后的值)
-//        $stringA = "";
-//        foreach ($params as $k => $v) {
-//            $stringA .= $k . '=' . $v . '&';
-//        }
-//        $stringSignTemp = $stringA . 'key=' . $key;
-//
-//// 关键步骤5:正确生成HMAC-SHA256签名
-////        $sign = strtoupper(hash_hmac('sha256', $stringSignTemp, '')); // 注意:第三个参数为空字符串
-//        $sign = self::generateWechatMD5Sign($params, $key);
-//        $params['sign'] = $sign;
-//        $params['notify_url'] = rawurlencode($params['notify_url']);
-////        $params['contract_display_account'] = urlencode($params['contract_display_account']);
-//// 构建最终URL
-//        $queryString = "";
-//        foreach ($params as $k => $v) {
-//            // 已编码的参数不需要再次编码
-//            $queryString .= $k . '=' . $v . '&';
-//        }
-//        $url = 'https://api.mch.weixin.qq.com/papay/entrustweb?' . rtrim($queryString, '&');
-//
-//// 记录请求URL
-//        @file_put_contents("quanju3.txt", "请求URL: " . $url . "\n", FILE_APPEND);
-//
-//// 发送请求(禁止自动重定向)
-//        $ch = curl_init();
-//        curl_setopt($ch, CURLOPT_URL, $url);
-//        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-//        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
-//        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-//        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); // 关键:禁止自动重定向
-//        curl_setopt($ch, CURLOPT_HEADER, true); // 获取响应头
-//
-//        $response = curl_exec($ch);
-//        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-//
-//// 记录完整响应
-//        @file_put_contents("quanju3.txt", "HTTP状态码: " . $http_code . "\n响应内容: " . $response . "\n", FILE_APPEND);
-//
-//// 分析响应
-//        if ($http_code == 302) {
-//            // 解析重定向地址
-//            preg_match('/Location: (.*)/i', $response, $matches);
-//            $redirect_url = trim($matches[1] ?? '');
-//
-//            if ($redirect_url) {
-//                // 成功重定向到微信签约页面
-//                @file_put_contents("quanju3.txt", "签约URL: " . $redirect_url . "\n", FILE_APPEND);
-//            } else {
-//                @file_put_contents("quanju3.txt", "错误:未找到重定向地址\n", FILE_APPEND);
-//            }
-//        } else {
-//            // 提取可能的错误信息
-//            preg_match('/<error_description><!\[CDATA\[(.*?)\]\]><\/error_description>/', $response, $error_matches);
-//            $error_msg = $error_matches[1] ?? '未知错误';
-//
-//            @file_put_contents("quanju3.txt", "错误信息: " . $error_msg . "\n", FILE_APPEND);
-//        }
-//
-//        curl_close($ch);
-//        if (curl_errno($ch)) {
-//            echo 'CURL Error: ' . curl_error($ch);
-//        } else {
-//            echo "Response:\n" . $response;
-//        }
-
-        $request_serial = time();
-        $timestamp = time();
-        $order = array_merge(compact(  'contract_code','plan_id','contract_display_account','timestamp','version','request_serial'), $options);
-//        if ($order['detail'] == '') unset($order['detail']);
-        $order['notify_url']=Request::instance()->domain() . "/api/wechat/notify/" . $cid;
-        $result = self::payment(false, $cid)->contract->web(
-            $order
-        );
+        $mch_id = "1623907696";
+        $key = "1wm55KpF5tgZFW1TYs6TBX9MWBpI5FmT";
+
+// 使用动态时间戳
+        $current_timestamp = time();
+//        $contract_code = preg_replace("/[^0-9]/", "", $contract_code);
+        $params = [
+            'appid' => 'wx5681205d1ef4d9d3',
+            'mch_id' => $mch_id,
+            'plan_id' => '189172',
+            'contract_code' => $contract_code,
+            'request_serial' => $current_timestamp, // 使用时间戳作为序列号
+            'contract_display_account' => 'sera',
+            'notify_url' => 'http://red.igxys.com/api/wechat/notify/12',
+            'timestamp' => $current_timestamp, // 动态时间戳
+            'version' => '1.0',
+        ];
+
+// 关键步骤1:先对需要编码的参数进行原始值存储
+        $raw_params = $params;
+
+// 关键步骤2:对需要URL编码的参数值进行编码(签名前)
+//        $params['contract_display_account'] = urlencode($params['contract_display_account']);
+
+
+// 步骤3:参数按ASCII排序
+        ksort($params);
+
+// 步骤4:构建待签名字符串(使用编码后的值)
+        $stringA = "";
+        foreach ($params as $k => $v) {
+            $stringA .= $k . '=' . $v . '&';
+        }
+        $stringSignTemp = $stringA . 'key=' . $key;
+
+// 关键步骤5:正确生成HMAC-SHA256签名
+//        $sign = strtoupper(hash_hmac('sha256', $stringSignTemp, '')); // 注意:第三个参数为空字符串
+        $sign = self::generateWechatMD5Sign($params, $key);
+        $params['sign'] = $sign;
+        $params['notify_url'] = rawurlencode($params['notify_url']);
+//        $params['contract_display_account'] = urlencode($params['contract_display_account']);
+// 构建最终URL
+        $queryString = "";
+        foreach ($params as $k => $v) {
+            // 已编码的参数不需要再次编码
+            $queryString .= $k . '=' . $v . '&';
+        }
+        $url = 'https://api.mch.weixin.qq.com/papay/entrustweb?' . rtrim($queryString, '&');
+
+// 记录请求URL
+        @file_put_contents("quanju3.txt", "请求URL: " . $url . "\n", FILE_APPEND);
+
+// 发送请求(禁止自动重定向)
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
+        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); // 关键:禁止自动重定向
+        curl_setopt($ch, CURLOPT_HEADER, true); // 获取响应头
+
+        $response = curl_exec($ch);
+        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+// 记录完整响应
+        @file_put_contents("quanju3.txt", "HTTP状态码: " . $http_code . "\n响应内容: " . $response . "\n", FILE_APPEND);
+
+// 分析响应
+        if ($http_code == 302) {
+            // 解析重定向地址
+            preg_match('/Location: (.*)/i', $response, $matches);
+            $redirect_url = trim($matches[1] ?? '');
+
+            if ($redirect_url) {
+                // 成功重定向到微信签约页面
+                @file_put_contents("quanju3.txt", "签约URL: " . $redirect_url . "\n", FILE_APPEND);
+            } else {
+                @file_put_contents("quanju3.txt", "错误:未找到重定向地址\n", FILE_APPEND);
+            }
+        } else {
+            // 提取可能的错误信息
+            preg_match('/<error_description><!\[CDATA\[(.*?)\]\]><\/error_description>/', $response, $error_matches);
+            $error_msg = $error_matches[1] ?? '未知错误';
+
+            @file_put_contents("quanju3.txt", "错误信息: " . $error_msg . "\n", FILE_APPEND);
+        }
+
+        curl_close($ch);
+        if (curl_errno($ch)) {
+            echo 'CURL Error: ' . curl_error($ch);
+        } else {
+            echo "Response:\n" . $response;
+        }
+
+//        $request_serial = time();
+//        $timestamp = time();
+//        $order = array_merge(compact(  'contract_code','plan_id','contract_display_account','timestamp','version','request_serial'), $options);
+////        if ($order['detail'] == '') unset($order['detail']);
+//        $order['notify_url']=Request::instance()->domain() . "/api/wechat/notify/" . $cid;
+//        $result = self::payment(false, $cid)->contract->web(
+//            $order
+//        );
 //        var_dump($result);die();
         @file_put_contents("quanju3.txt", json_encode($result) . "-签约返回结果测试\r\n", 8);
         return $result;