Browse Source

人寿

master
wxd 1 year ago
parent
commit
c83eb6b3c8
  1. 150
      src/Shentun.Peis.Application/ThirdBookingPushs/ThirdBookingPushAppService.cs
  2. 33
      src/Shentun.Peis.Domain/AesHelper.cs
  3. 6
      src/Shentun.Peis.Domain/newRsaHelper.cs

150
src/Shentun.Peis.Application/ThirdBookingPushs/ThirdBookingPushAppService.cs

@ -1,24 +1,23 @@
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Converters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Net.Http.Headers;
using Newtonsoft.Json; using Newtonsoft.Json;
using NPOI.HPSF;
using NPOI.SS.Formula.Functions;
using Shentun.Peis.Enums; using Shentun.Peis.Enums;
using Shentun.Peis.Models; using Shentun.Peis.Models;
using Shentun.Peis.PatientRegisters; using Shentun.Peis.PatientRegisters;
using Shentun.Peis.PlugIns.Sms;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Net.Http; using System.Net.Http;
using System.Text;
using System.Net.Http.Headers;
using System.Security.Policy;
using System.Threading.Channels;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NPOI.POIFS.Crypt.Dsig;
using NPOI.SS.Formula.Functions;
namespace Shentun.Peis.ThirdBookingPushs namespace Shentun.Peis.ThirdBookingPushs
{ {
@ -69,6 +68,7 @@ namespace Shentun.Peis.ThirdBookingPushs
var privateKey = interfaceConfig.GetSection("Interface").GetSection("MinZhongPrivateKey").Value; var privateKey = interfaceConfig.GetSection("Interface").GetSection("MinZhongPrivateKey").Value;
var medicalYear = interfaceConfig.GetSection("Interface").GetSection("MedicalYear").Value; var medicalYear = interfaceConfig.GetSection("Interface").GetSection("MedicalYear").Value;
var isActive = interfaceConfig.GetSection("Interface").GetSection("IsActive").Value; var isActive = interfaceConfig.GetSection("Interface").GetSection("IsActive").Value;
var iCode = interfaceConfig.GetSection("Interface").GetSection("ICODE").Value;
if (!string.IsNullOrWhiteSpace(isActive) if (!string.IsNullOrWhiteSpace(isActive)
&& isActive == "Y") && isActive == "Y")
{ {
@ -79,7 +79,12 @@ namespace Shentun.Peis.ThirdBookingPushs
&& !string.IsNullOrWhiteSpace(patientRegisterEnt.ThirdBookingId)) && !string.IsNullOrWhiteSpace(patientRegisterEnt.ThirdBookingId))
{ {
var thirdBookingEnt = await _thirdBookingRepository.FirstOrDefaultAsync(f => f.Id == Guid.Parse(patientRegisterEnt.ThirdBookingId)); var thirdBookingEnt = await _thirdBookingRepository.FirstOrDefaultAsync(f => f.Id == Guid.Parse(patientRegisterEnt.ThirdBookingId));
string iCode = thirdBookingEnt.ICode;
if (thirdBookingEnt != null)
{
if (!string.IsNullOrWhiteSpace(thirdBookingEnt.ICode))
{
iCode = thirdBookingEnt.ICode;
}
if (thirdBookingEnt.MedicalStatus == '0') if (thirdBookingEnt.MedicalStatus == '0')
{ {
@ -109,7 +114,7 @@ namespace Shentun.Peis.ThirdBookingPushs
var inputPara = GetEncryptData(JsonConvert.SerializeObject(pushRegisterInput), iCode, publicKey, privateKey); var inputPara = GetEncryptData(JsonConvert.SerializeObject(pushRegisterInput), iCode, publicKey, privateKey);
var resultPara = await CallBookingAppServiceAsync<EncryDataRequstDto, EncryDataResultDto>(baseApiAddress, registerApiAddress, inputPara, "application/json;charset=utf-8");
var resultPara = await CallBookingAppServiceAsync<EncryDataRequstDto, EncryDataResultDto>(baseApiAddress, registerApiAddress, inputPara, "application/json");
if (resultPara.FLAG) if (resultPara.FLAG)
{ {
var decryptDataPara = GetDecryptData<DecryptBaseDto>(resultPara, publicKey, privateKey); var decryptDataPara = GetDecryptData<DecryptBaseDto>(resultPara, publicKey, privateKey);
@ -121,6 +126,7 @@ namespace Shentun.Peis.ThirdBookingPushs
} }
} }
} }
}
} }
} }
@ -149,6 +155,7 @@ namespace Shentun.Peis.ThirdBookingPushs
var privateKey = interfaceConfig.GetSection("Interface").GetSection("MinZhongPrivateKey").Value; var privateKey = interfaceConfig.GetSection("Interface").GetSection("MinZhongPrivateKey").Value;
var isActive = interfaceConfig.GetSection("Interface").GetSection("IsActive").Value; var isActive = interfaceConfig.GetSection("Interface").GetSection("IsActive").Value;
var medicalYear = interfaceConfig.GetSection("Interface").GetSection("MedicalYear").Value; var medicalYear = interfaceConfig.GetSection("Interface").GetSection("MedicalYear").Value;
var iCode = interfaceConfig.GetSection("Interface").GetSection("ICODE").Value;
if (!string.IsNullOrWhiteSpace(isActive) if (!string.IsNullOrWhiteSpace(isActive)
&& isActive == "Y") && isActive == "Y")
{ {
@ -160,7 +167,13 @@ namespace Shentun.Peis.ThirdBookingPushs
&& !string.IsNullOrWhiteSpace(patientRegisterEnt.ThirdBookingId)) && !string.IsNullOrWhiteSpace(patientRegisterEnt.ThirdBookingId))
{ {
var thirdBookingEnt = await _thirdBookingRepository.FirstOrDefaultAsync(f => f.Id == Guid.Parse(patientRegisterEnt.ThirdBookingId)); var thirdBookingEnt = await _thirdBookingRepository.FirstOrDefaultAsync(f => f.Id == Guid.Parse(patientRegisterEnt.ThirdBookingId));
string iCode = thirdBookingEnt.ICode;
if (thirdBookingEnt != null)
{
if (!string.IsNullOrWhiteSpace(thirdBookingEnt.ICode))
{
iCode = thirdBookingEnt.ICode;
}
if (thirdBookingEnt.MedicalStatus == '1') if (thirdBookingEnt.MedicalStatus == '1')
{ {
var customerOrgGroupEnt = await _customerOrgGroupRepository.GetAsync(g => g.Id == Guid.Parse(thirdBookingEnt.CustomerOrgGroupId)); var customerOrgGroupEnt = await _customerOrgGroupRepository.GetAsync(g => g.Id == Guid.Parse(thirdBookingEnt.CustomerOrgGroupId));
@ -195,7 +208,7 @@ namespace Shentun.Peis.ThirdBookingPushs
var inputPara = GetEncryptData(JsonConvert.SerializeObject(pushCompletePhysicalInput), iCode, publicKey, privateKey); var inputPara = GetEncryptData(JsonConvert.SerializeObject(pushCompletePhysicalInput), iCode, publicKey, privateKey);
var resultPara = await CallBookingAppServiceAsync<EncryDataRequstDto, EncryDataResultDto>(baseApiAddress, completeApiAddress, inputPara, "application/json;charset=utf-8");
var resultPara = await CallBookingAppServiceAsync<EncryDataRequstDto, EncryDataResultDto>(baseApiAddress, completeApiAddress, inputPara, "application/json");
if (resultPara.FLAG) if (resultPara.FLAG)
{ {
@ -208,6 +221,7 @@ namespace Shentun.Peis.ThirdBookingPushs
} }
} }
} }
}
} }
} }
@ -237,6 +251,7 @@ namespace Shentun.Peis.ThirdBookingPushs
var aesKey = interfaceConfig.GetSection("Interface").GetSection("AesKey").Value; var aesKey = interfaceConfig.GetSection("Interface").GetSection("AesKey").Value;
var isActive = interfaceConfig.GetSection("Interface").GetSection("IsActive").Value; var isActive = interfaceConfig.GetSection("Interface").GetSection("IsActive").Value;
var medicalYear = interfaceConfig.GetSection("Interface").GetSection("MedicalYear").Value; var medicalYear = interfaceConfig.GetSection("Interface").GetSection("MedicalYear").Value;
var iCode = interfaceConfig.GetSection("Interface").GetSection("ICODE").Value;
if (!string.IsNullOrWhiteSpace(isActive) if (!string.IsNullOrWhiteSpace(isActive)
&& isActive == "Y") && isActive == "Y")
{ {
@ -248,24 +263,31 @@ namespace Shentun.Peis.ThirdBookingPushs
&& patientRegisterEnt.CompleteFlag == PatientRegisterCompleteFlag.SumCheck) && patientRegisterEnt.CompleteFlag == PatientRegisterCompleteFlag.SumCheck)
{ {
var thirdBookingEnt = await _thirdBookingRepository.FirstOrDefaultAsync(f => f.Id == Guid.Parse(patientRegisterEnt.ThirdBookingId)); var thirdBookingEnt = await _thirdBookingRepository.FirstOrDefaultAsync(f => f.Id == Guid.Parse(patientRegisterEnt.ThirdBookingId));
string iCode = thirdBookingEnt.ICode;
if (thirdBookingEnt != null)
{
if (!string.IsNullOrWhiteSpace(thirdBookingEnt.ICode))
{
iCode = thirdBookingEnt.ICode;
}
if (thirdBookingEnt.MedicalStatus == '2') if (thirdBookingEnt.MedicalStatus == '2')
{ {
var customerOrgGroupEnt = await _customerOrgGroupRepository.GetAsync(g => g.Id == Guid.Parse(thirdBookingEnt.CustomerOrgGroupId)); var customerOrgGroupEnt = await _customerOrgGroupRepository.GetAsync(g => g.Id == Guid.Parse(thirdBookingEnt.CustomerOrgGroupId));
#region 上传文件 #region 上传文件
byte[] filebytes = Convert.FromBase64String(input.ReportBase64);
string fileDataEncrypt = AesHelper.AESEncrypt(filebytes, aesKey);
string fileSign = AesHelper.GetMD5Hash(fileDataEncrypt);
byte[] filebytes = Convert.FromBase64String(input.ReportBase64); //字节数组
byte[] fileDataEncrypt = AesHelper.AESEncrypt(filebytes, aesKey);
string fileSign = AesHelper.GetMD5Hash2(fileDataEncrypt);
var fileInputParm = new EncryDataRequstDto var fileInputParm = new EncryDataRequstDto
{ {
DATA = fileDataEncrypt,
SIGN = fileSign, SIGN = fileSign,
ICODE = thirdBookingEnt.ICode ICODE = thirdBookingEnt.ICode
}; };
var fileResultEncry = await CallBookingAppServiceAsync<EncryDataRequstDto, EncryDataResultDto>(baseApiAddress, completeApiAddress, fileInputParm, "multipart/form-data");
var fileResultEncry = await CallBookingFileAppServiceAsync<EncryDataResultDto>(baseApiAddress, completeApiAddress, fileInputParm, fileDataEncrypt, "006429_民众测试.pdf");
if (fileResultEncry.FLAG) if (fileResultEncry.FLAG)
{ {
@ -323,6 +345,7 @@ namespace Shentun.Peis.ThirdBookingPushs
}
} }
} }
@ -359,7 +382,11 @@ namespace Shentun.Peis.ThirdBookingPushs
var sendData = JsonConvert.SerializeObject(data); var sendData = JsonConvert.SerializeObject(data);
using (HttpContent httpContent = new StringContent(sendData)) using (HttpContent httpContent = new StringContent(sendData))
{ {
httpContent.Headers.ContentType = new MediaTypeHeaderValue(contentType);
var mediaTypeHeaderValue = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
mediaTypeHeaderValue.CharSet = "utf-8";
httpContent.Headers.ContentType = mediaTypeHeaderValue;
HttpResponseMessage response = null; HttpResponseMessage response = null;
if (method == "post") if (method == "post")
{ {
@ -389,6 +416,85 @@ namespace Shentun.Peis.ThirdBookingPushs
/// <summary>
/// 发起请求 上传文件
/// </summary>
/// <typeparam name="TOut"></typeparam>
/// <param name="baseApiAddress"></param>
/// <param name="url"></param>
/// <param name="data"></param>
/// <param name="fileBytes"></param>
/// <param name="fileName"></param>
/// <returns></returns>
private async Task<TOut> CallBookingFileAppServiceAsync<TOut>(string baseApiAddress, string url, EncryDataRequstDto data, byte[] fileBytes, string fileName)
{
using (var httpClientHandler = new HttpClientHandler())
{
using (var httpClient = new HttpClient(httpClientHandler))
{
httpClient.Timeout = TimeSpan.FromMilliseconds(600000);
httpClient.BaseAddress = new Uri(baseApiAddress);
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));//设置accept标头,告诉JSON是可接受的响应类型
using (MultipartFormDataContent multipartContent = new MultipartFormDataContent())
{
// 添加文本字段
var icode = new StringContent(data.ICODE);
icode.Headers.ContentDisposition= new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
{
Name = "ICODE"
};
var sign = new StringContent(data.SIGN);
icode.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
{
Name = "SIGN"
};
//multipartContent.Add(new StringContent(data.ICODE), "ICODE");
//multipartContent.Add(new StringContent(data.SIGN), "SIGN");
// 添加文件
ByteArrayContent fileContent = new ByteArrayContent(fileBytes);
fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
multipartContent.Add(fileContent, "DATA", fileName);
multipartContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("multipart/form-data");
HttpResponseMessage response = null;
response = await httpClient.PostAsync(url, multipartContent);
string result;
if (!response.IsSuccessStatusCode)
{
result = response.Content.ReadAsStringAsync().Result;
//throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
}
result = await response.Content.ReadAsStringAsync();
var resultDto = JsonConvert.DeserializeObject<TOut>(result);
return resultDto;
}
//// 创建MultipartFormDataContent实例
//MultipartFormDataContent multipartContent = new MultipartFormDataContent();
}
}
}
/// <summary> /// <summary>
/// 生成请求密文数据 /// 生成请求密文数据
/// </summary> /// </summary>

33
src/Shentun.Peis.Domain/AesHelper.cs

@ -40,6 +40,29 @@ namespace Shentun.Peis
} }
} }
/// <summary>
/// MD5加密
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static string GetMD5Hash2(byte[] input)
{
using (MD5 md5 = MD5.Create())
{
//byte[] inputBytes = Encoding.UTF8.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(input);
// Convert byte array to a hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
}
}
/// <summary> /// <summary>
/// 解密 /// 解密
/// </summary> /// </summary>
@ -83,7 +106,7 @@ namespace Shentun.Peis
/// <param name="inputArray"></param> /// <param name="inputArray"></param>
/// <param name="strkey"></param> /// <param name="strkey"></param>
/// <returns></returns> /// <returns></returns>
public static string AESEncrypt(byte[] inputArray, string strkey)
public static byte[] AESEncrypt(byte[] inputArray, string strkey)
{ {
try try
{ {
@ -96,12 +119,13 @@ namespace Shentun.Peis
byte[] rv = new byte[cipher.GetOutputSize(inputArray.Length)]; byte[] rv = new byte[cipher.GetOutputSize(inputArray.Length)];
int tam = cipher.ProcessBytes(inputArray, 0, inputArray.Length, rv, 0); int tam = cipher.ProcessBytes(inputArray, 0, inputArray.Length, rv, 0);
cipher.DoFinal(rv, tam); cipher.DoFinal(rv, tam);
return Convert.ToBase64String(rv);
//return Convert.ToBase64String(rv);
return rv;
} }
catch (Exception ex) catch (Exception ex)
{ {
return "";
return null;
} }
} }
@ -115,5 +139,8 @@ namespace Shentun.Peis
} }
return new KeyParameter(bs); return new KeyParameter(bs);
} }
} }
} }

6
src/Shentun.Peis.Domain/newRsaHelper.cs

@ -65,6 +65,7 @@ namespace Shentun.Peis
/// <returns></returns> /// <returns></returns>
public static string RSAEncrypt(string bizContent,string publicKey) public static string RSAEncrypt(string bizContent,string publicKey)
{ {
bizContent = Convert.ToBase64String(Encoding.UTF8.GetBytes(bizContent));
string yuanFuPublicKey_Net = RSAPublicKeyJava2DotNet(publicKey); string yuanFuPublicKey_Net = RSAPublicKeyJava2DotNet(publicKey);
@ -196,7 +197,10 @@ namespace Shentun.Peis
start += _maxDecryptSize; start += _maxDecryptSize;
}; };
} }
return Encoding.UTF8.GetString(encryptedData.ToArray());
string base64str = Encoding.UTF8.GetString(encryptedData.ToArray());
return Encoding.UTF8.GetString(Convert.FromBase64String(base64str));
} }
} }
} }
Loading…
Cancel
Save