|
|
@@ -600,109 +600,109 @@ class WechatService
|
|
|
$timestamp=time();
|
|
|
$version = '1.0';
|
|
|
// 微信支付配置参数
|
|
|
-// $mch_id = "1623907696";
|
|
|
-// $key = "1wm55KpF5tgZFW1TYs6TBX9MWBpI5FmT";
|
|
|
-//
|
|
|
-//// 使用动态时间戳
|
|
|
-// $current_timestamp = time();
|
|
|
-//
|
|
|
-// $params = [
|
|
|
-// 'appid' => 'wx5681205d1ef4d9d3',
|
|
|
-// 'mch_id' => $mch_id,
|
|
|
-// 'plan_id' => '189172',
|
|
|
-// 'contract_code' => 'qy175029625306023753',
|
|
|
-// '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编码的参数值进行编码(签名前)
|
|
|
+ $mch_id = "1623907696";
|
|
|
+ $key = "1wm55KpF5tgZFW1TYs6TBX9MWBpI5FmT";
|
|
|
+
|
|
|
+// 使用动态时间戳
|
|
|
+ $current_timestamp = time();
|
|
|
+
|
|
|
+ $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']);
|
|
|
-// $params['notify_url'] = urlencode($params['notify_url']);
|
|
|
-//
|
|
|
-//// 步骤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, '')); // 注意:第三个参数为空字符串
|
|
|
-// $params['sign'] = $sign;
|
|
|
-//
|
|
|
-//// 构建最终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
|
|
|
- );
|
|
|
+
|
|
|
+
|
|
|
+// 步骤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, '')); // 注意:第三个参数为空字符串
|
|
|
+ $params['sign'] = $sign;
|
|
|
+ $params['notify_url'] = urlencode($params['notify_url']);
|
|
|
+// 构建最终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;
|
|
|
+ @file_put_contents("quanju3.txt", json_encode($response) . "-签约返回结果测试\r\n", 8);
|
|
|
+ return $response;
|
|
|
}
|
|
|
/**
|
|
|
* 签约申请扣款
|