diff --git a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs index e917fec..3b93eab 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/SunPalaceBoardSafetyService.cs @@ -98,7 +98,7 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn } //获取单位信息 - HttpClientResult branchs = await _tokenProviderService.GetBranchPermissions(token, loginUsers.Data.Uid); + HttpClientResult branchs = await _tokenProviderService.GetBranchPermissions(token, loginUsers.Data.Ubpid); if (branchs.Code == "Error" || branchs.Data == null || branchs.Data.BranchPermissionIds == null || branchs.Data.BranchPermissionIds.Length == 0) { _logger.LogWarning("GetProductionRiskEchart接口获取单位信息失败"); diff --git a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ThirdPartyProviderService.cs b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ThirdPartyProviderService.cs index 9bc8dd6..39130cf 100644 --- a/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ThirdPartyProviderService.cs +++ b/WeiCloud.Fusion/ThirdPartyServices/ThirdPartyServices.DomainService/ShenZhouShengAn/ThirdPartyProviderService.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using Org.BouncyCastle.Ocsp; using System.Net.Http.Headers; using System.Net.Http.Json; using System.Text.Json; @@ -89,13 +90,28 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn { HttpClientResult result = new HttpClientResult() { Code = "Success", Message = "请求成功" }; - result = await SendAndParseAsync>( - "https://zrh.szdunan.cn/v1/api/branch/index_no_check_branch", - token, - ubpid, - HttpMethod.Post); + try + { + // 构造表单参数(key必须是"ubpid",和Postman一致) + var formData = new Dictionary + { + { "ubpid", ubpid.ToString() } // 转换为字符串,匹配表单提交格式 + }; - return result; + // 调用表单提交方法,而非JSON提交 + result = await SendFormAndParseAsync>( + "https://zrh.szdunan.cn/v1/api/branch/index_no_check_branch", + token, + formData, + HttpMethod.Post); + + return result; + } + catch (Exception ex) + { + _logger.LogError(ex, "获取分支权限失败"); + return new HttpClientResult { Code = "Error", Message = $"请求异常:{ex.Message}" }; + } } /// @@ -110,10 +126,7 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn public async Task SendJsonAsync(string url, string? token, TRequest? payload, HttpMethod method) { using var request = new HttpRequestMessage(method, url); - if (!string.IsNullOrWhiteSpace(token)) - { - request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); - } + request.Headers.TryAddWithoutValidation("Authorization", "Bearer " + token); // 写入 JSON 请求体(POST、PUT、PATCH 等适用) if (payload != null && method != HttpMethod.Get) { @@ -166,5 +179,50 @@ namespace ThirdPartyServices.DomainService.ShenZhouShengAn { return SendAndParseAsync(url, token, null, method); } + + /// + /// 发送表单格式请求(适配 multipart/form-data) + /// + public async Task SendFormDataAsync(string url, string? token, Dictionary formData, HttpMethod method) + { + using var request = new HttpRequestMessage(method, url); + request.Headers.TryAddWithoutValidation("Authorization", "Bearer " + token); + request.Headers.TryAddWithoutValidation("Accept", "*/*"); + + // 构造 multipart/form-data 表单数据 + var formContent = new MultipartFormDataContent(); + foreach (var item in formData) + { + // 添加表单参数(key=ubpid, value=31) + formContent.Add(new StringContent(item.Value), item.Key); + } + request.Content = formContent; + + var response = await _httpClient.SendAsync(request); + + if (!response.IsSuccessStatusCode) + { + var error = await response.Content.ReadAsStringAsync(); + throw new Exception($"请求失败:{response.StatusCode}, 内容:{error}"); + } + + return await response.Content.ReadAsStringAsync(); + } + + /// + /// 表单请求 + 解析结果(适配 BranchResDto) + /// + public async Task SendFormAndParseAsync( + string url, + string? token, + Dictionary formData, + HttpMethod method) + { + var responseContent = await SendFormDataAsync(url, token, formData, method); + return JsonSerializer.Deserialize(responseContent, new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true // 忽略大小写匹配(避免字段名大小写问题) + }) ?? throw new Exception("反序列化返回结果失败"); + } } } \ No newline at end of file