Commit 1bc98960 by 陶然

优化

parent 7d84f33a
...@@ -27,13 +27,13 @@ namespace Com.Bocom.OpenApi ...@@ -27,13 +27,13 @@ namespace Com.Bocom.OpenApi
client.IgnoreSslHostnameVerifier(); client.IgnoreSslHostnameVerifier();
var bizKvid = settlement.Kvid.ToString(); var bizKvid = settlement.Kvid.ToString();
var bizId = settlement.BizId;
var request = new AddContractOrderRequestV2(); var request = new AddContractOrderRequestV2();
request.SetServiceUrl(Configs.APIGW_URL_ADDRESS + Configs.AddContractOrderRequestV2); request.SetServiceUrl(Configs.APIGW_URL_ADDRESS + Configs.AddContractOrderRequestV2);
var bizContent = new AddContractOrderRequestV2.AddContractOrderRequestV2Biz(); var bizContent = new AddContractOrderRequestV2.AddContractOrderRequestV2Biz();
bizContent.org_id = Configs.ORG_ID; bizContent.org_id = Configs.ORG_ID;
bizContent.bat_id = bizKvid; bizContent.bat_id = bizId;
bizContent.cont_order_list = new List<ContOrder>(); bizContent.cont_order_list = new List<ContOrder>();
var contorder = new ContOrder(); var contorder = new ContOrder();
contorder.cont_id = bizKvid; contorder.cont_id = bizKvid;
......
...@@ -35,17 +35,14 @@ ...@@ -35,17 +35,14 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>Sdk\Dll\BouncyCastle.Crypto.dll</HintPath> <HintPath>Sdk\Dll\BouncyCastle.Crypto.dll</HintPath>
</Reference> </Reference>
<Reference Include="Kivii.Common.V4.5, Version=5.6.2023.4000, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Kivii.Common.V4.5, Version=5.6.2023.6000, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\k5-njzj\packages\Kivii.Common.5.6.2023.4000\lib\net45\Kivii.Common.V4.5.dll</HintPath> <HintPath>..\local-njzj\packages\Kivii.Common.5.6.2023.6000\lib\net45\Kivii.Common.V4.5.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="Kivii.Core.V4.5, Version=5.6.2023.4140, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Kivii.Core.V4.5, Version=5.6.2023.6000, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\k5-njzj\packages\Kivii.Core.5.6.2023.4140\lib\net45\Kivii.Core.V4.5.dll</HintPath> <HintPath>..\local-njzj\packages\Kivii.Core.5.6.2023.6000\lib\net45\Kivii.Core.V4.5.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="Kivii.Linq.V4.5, Version=5.6.2023.4200, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Kivii.Linq.V4.5, Version=5.6.2023.4200, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\k5-njzj\packages\Kivii.Linq.5.6.2023.4200\lib\net45\Kivii.Linq.V4.5.dll</HintPath> <HintPath>..\local-njzj\packages\Kivii.Linq.5.6.2023.4200\lib\net45\Kivii.Linq.V4.5.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
......
...@@ -600,9 +600,30 @@ namespace Com.Bocom.OpenApi ...@@ -600,9 +600,30 @@ namespace Com.Bocom.OpenApi
} }
} }
public class WriteOffBizContentObj
{
public string biz_content { get; set; }
public string msg_id { get; set; }
public string timestamp { get; set; }
public string encrypt_key { get; set; }
}
[Alias("BCOM_WriteOffResultNotifys")] [Alias("BCOM_WriteOffResultNotifys")]
public class WriteOffResultNotify:EntityWithMetadata public class WriteOffResultNotify:EntityWithMetadata
{ {
public string BillId { get; set; }
[DefaultEmptyGuid]
public Guid BizKvid { get; set; }
[ApiMember(Description = "业务流水号")]
[StringLength(200)]
public string BizId { get; set; }
[ApiMember(Description = "业务类型")]
[StringLength(100)]
public string BizType { get; set; }
public WriteOffBizContent biz_content { get; set; } public WriteOffBizContent biz_content { get; set; }
[StringLength(2000)] [StringLength(2000)]
public string encrypt_key { get; set; } public string encrypt_key { get; set; }
...@@ -618,50 +639,141 @@ namespace Com.Bocom.OpenApi ...@@ -618,50 +639,141 @@ namespace Com.Bocom.OpenApi
public class WriteOffBizContent public class WriteOffBizContent
{ {
public string transcode { get; set; }
/// <summary> /// <summary>
/// /// appid@http://notify.com
/// </summary>
public string communication_url { get; set; }
/// <summary>
/// 机构编号
/// </summary>
public string org_id { get; set; }
/// <summary>
/// 账单编号
/// </summary>
public string bill_id { get; set; }
/// <summary>
/// 应付款人
/// </summary> /// </summary>
public string term_trans_time { get; set; } public string ori_payer { get; set; }
/// <summary> /// <summary>
/// /// 实际应付金额
/// </summary> /// </summary>
public string requester_type { get; set; } public string ori_act_amt { get; set; }
/// <summary> /// <summary>
/// /// 此次账单核销总金额
/// </summary> /// </summary>
public string trace_no { get; set; } public string bill_write_off_amt { get; set; }
/// <summary> /// <summary>
/// /// 合同号
/// </summary> /// </summary>
public string version { get; set; } public string cont_id { get; set; }
/// <summary> /// <summary>
/// /// 费项名称
/// </summary> /// </summary>
public string mer_ptc_id { get; set; } public string ori_itm_nme { get; set; }
/// <summary> /// <summary>
/// /// 账期
/// </summary> /// </summary>
public string mobile_no { get; set; } public string payment_period { get; set; }
/// <summary> /// <summary>
/// /// 账单已核销金额
/// </summary> /// </summary>
public string cert_type { get; set; } public string write_off_amt { get; set; }
/// <summary> /// <summary>
/// /// 账单核销状态 01-未核销; 02-部分核销; 03-全额核销; 04-失效
/// </summary> /// </summary>
public string cert_no { get; set; } public string bill_wo_state { get; set; }
/// <summary> /// <summary>
/// /// 核销编号
/// </summary> /// </summary>
public string cus_name { get; set; } public string write_off_no { get; set; }
/// <summary> /// <summary>
/// /// 核销日期
/// </summary> /// </summary>
public string reserved { get; set; } public string write_off_dte { get; set; }
/// <summary> /// <summary>
/// /// 核销状态 01-已核销;02-核销待确认
/// </summary> /// </summary>
public string communication_url { get; set; } public string write_off_state { get; set; }
/// <summary>
/// 备注
/// </summary>
public string remark { get; set; }
/// <summary>
/// 流水列表
/// </summary>
public List<PayDetail> pay_detail_list { get; set; }
}
public class PayDetail
{
/// <summary>
/// 会计传票号
/// </summary>
public string vch_no { get; set; }
/// <summary>
/// 对方户名
/// </summary>
public string opp_ac_nme { get; set; }
/// <summary>
/// 交易金额
/// </summary>
public string txn_amt { get; set; }
/// <summary>
/// 交易时间
/// </summary>
public string tr_time { get; set; }
/// <summary>
/// 交易渠道
/// </summary>
public string chnl { get; set; }
/// <summary>
/// 流水核销金额
/// </summary>
public string jnl_write_off_amt { get; set; }
/// <summary>
/// 流水已核销金额
/// </summary>
public string write_off_amt { get; set; }
/// <summary>
/// 流水核销状态 01-未核销; 02-部分核销; 03-全额核销; 04-失效
/// </summary>
public string jnl_wo_state { get; set; }
/// <summary>
/// 备注
/// </summary>
public string remark { get; set; }
} }
} }
...@@ -4,6 +4,8 @@ using System.IO; ...@@ -4,6 +4,8 @@ using System.IO;
using System.Runtime.Serialization.Json; using System.Runtime.Serialization.Json;
using Com.Bocom.OpenApi.Security.Sign; using Com.Bocom.OpenApi.Security.Sign;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Org.BouncyCastle.Asn1.Crmf;
namespace Com.Bocom.OpenApi namespace Com.Bocom.OpenApi
{ {
...@@ -46,7 +48,7 @@ namespace Com.Bocom.OpenApi ...@@ -46,7 +48,7 @@ namespace Com.Bocom.OpenApi
using (MemoryStream ms = new MemoryStream(Encoding.GetEncoding(charset).GetBytes(bizContentStr))) using (MemoryStream ms = new MemoryStream(Encoding.GetEncoding(charset).GetBytes(bizContentStr)))
{ {
DataContractJsonSerializer deseralizer = new DataContractJsonSerializer(T); DataContractJsonSerializer deseralizer = new DataContractJsonSerializer(T);
response = (BocomResponse) deseralizer.ReadObject(ms) as BocomResponse; response = (BocomResponse)deseralizer.ReadObject(ms) as BocomResponse;
} }
return response; return response;
...@@ -59,13 +61,13 @@ namespace Com.Bocom.OpenApi ...@@ -59,13 +61,13 @@ namespace Com.Bocom.OpenApi
} }
} }
public static Object ParseCommunicationJsonWithBocomSign(string respStr, string charset, string MY_PRIVATE_KEY, string APIGW_PUBLIC_KEY) public static WriteOffResultNotify ParseCommunicationJsonWithBocomSign(string respStr, string charset, string MY_PRIVATE_KEY, string APIGW_PUBLIC_KEY)
{ {
string bizContentStr; string bizContentStr;
string sign; string sign;
try try
{ {
//int indexOfRootStart = respStr.IndexOf(BocomConstants.BIZ_CONTENT) + BocomConstants.BIZ_CONTENT.Length + 2; int indexOfRootStart = respStr.IndexOf(BocomConstants.BIZ_CONTENT) + BocomConstants.BIZ_CONTENT.Length + 2;
int indexOfRootEnd = respStr.LastIndexOf(","); int indexOfRootEnd = respStr.LastIndexOf(",");
int indexOfSignStart = respStr.LastIndexOf(BocomConstants.SIGN + "\"") + BocomConstants.SIGN.Length + 3; int indexOfSignStart = respStr.LastIndexOf(BocomConstants.SIGN + "\"") + BocomConstants.SIGN.Length + 3;
int indexOfSignEnd = respStr.LastIndexOf("\""); int indexOfSignEnd = respStr.LastIndexOf("\"");
...@@ -90,16 +92,87 @@ namespace Com.Bocom.OpenApi ...@@ -90,16 +92,87 @@ namespace Com.Bocom.OpenApi
var reqBizContentEncrypt = jsonDic["biz_content"]; var reqBizContentEncrypt = jsonDic["biz_content"];
var encryptKey = BocomEncrypt.AsymmetricalDecrypt(encryptKeyEncrypt, BocomConstants.ENCRYPT_TYPE_RSA_AND_AES, MY_PRIVATE_KEY, charset); var encryptKey = BocomEncrypt.AsymmetricalDecrypt(encryptKeyEncrypt, BocomConstants.ENCRYPT_TYPE_RSA_AND_AES, MY_PRIVATE_KEY, charset);
var reqBizContent = BocomEncrypt.SymmetricalDecrypt(reqBizContentEncrypt, BocomConstants.ENCRYPT_TYPE_RSA_AND_AES, encryptKey, charset); var reqBizContent = BocomEncrypt.SymmetricalDecrypt(reqBizContentEncrypt, BocomConstants.ENCRYPT_TYPE_RSA_AND_AES, encryptKey, charset);
jsonDic["encrypt_key"] = encryptKey; var rtns = new WriteOffResultNotify();
jsonDic["biz_content"] = reqBizContent; rtns.encrypt_key = encryptKey;
//var rtns=Kivii.Text.JsonSerializer.SerializeToString(jsonDic); rtns.msg_id = jsonDic["msg_id"];
return jsonDic; rtns.timestamp = jsonDic["timestamp"];
rtns.sign = sign;
rtns.biz_content = Kivii.Text.JsonSerializer.DeserializeFromString<WriteOffBizContent>(reqBizContent);
rtns["encrypt_key"] = encryptKey;
rtns["biz_content"] = reqBizContent;
rtns["msg_id"] = jsonDic["msg_id"];
rtns["timestamp"] = jsonDic["timestamp"];
rtns["sign"] = sign;
return rtns;
} }
catch (Exception e) catch (Exception e)
{ {
throw new Exception("Bocom decrypt not success.", e); throw new Exception("Bocom decrypt not success.", e);
} }
} }
public static WriteOffResultNotify ParseCommunicationJsonWithBocomSign(Dictionary<string, string> respStr, string charset, string MY_PRIVATE_KEY, string APIGW_PUBLIC_KEY)
{
string biz_content = respStr["biz_content"];
string msg_id = respStr["msg_id"];
string timestamp = respStr["timestamp"];
string encrypt_key = respStr["encrypt_key"];
string sign = respStr["sign"];
var notify = new WriteOffBizContentObj();
notify.biz_content = biz_content;
notify.msg_id = msg_id;
notify.timestamp = timestamp;
notify.encrypt_key = encrypt_key;
var biz_contentStr = Kivii.Text.JsonSerializer.SerializeToString(notify);
biz_contentStr = biz_contentStr.Replace("{", "");
biz_contentStr = biz_contentStr.Replace("}", "");
Boolean passed = BocomSignature.Verify(BocomConstants.ENCRYPT_TYPE_RSA_AND_AES, biz_contentStr, APIGW_PUBLIC_KEY, charset, sign);
if (!passed)
{
throw new Exception("Bocom sign verify not passed.");
}
try
{
//var jsonDic = Kivii.Text.JsonSerializer.DeserializeFromString<Dictionary<string, string>>(respStr);
var encryptKeyEncrypt = encrypt_key;
var reqBizContentEncrypt = biz_content;
var encryptKey = BocomEncrypt.AsymmetricalDecrypt(encryptKeyEncrypt, BocomConstants.ENCRYPT_TYPE_RSA_AND_AES, MY_PRIVATE_KEY, charset);
var reqBizContent = BocomEncrypt.SymmetricalDecrypt(reqBizContentEncrypt, BocomConstants.ENCRYPT_TYPE_RSA_AND_AES, encryptKey, charset);
var rtns = new WriteOffResultNotify();
rtns.encrypt_key = encryptKey;
rtns.msg_id = msg_id;
rtns.timestamp = timestamp;
rtns.sign = sign;
rtns.biz_content = Kivii.Text.JsonSerializer.DeserializeFromString<WriteOffBizContent>(reqBizContent);
rtns["encrypt_key"] = encryptKey;
rtns["biz_content"] = reqBizContent;
rtns["msg_id"] = msg_id;
rtns["timestamp"] = timestamp;
rtns["sign"] = sign;
return rtns;
}
catch (Exception e)
{
throw new Exception("Bocom decrypt not success.", e);
}
}
public static object SignRspBizContent(string rspBizContent, string encrypt_key, string mY_PRIVATE_KEY)
{
var rspContent = BocomEncrypt.SymmetricalEncrypt(rspBizContent, BocomConstants.ENCRYPT_TYPE_RSA_AND_AES, encrypt_key, "UTF-8");
string signContent;
try
{
signContent = BocomSignature.Sign(BocomConstants.ENCRYPT_TYPE_RSA_AND_AES, rspContent, mY_PRIVATE_KEY, "UTF-8");
}
catch (Exception ex)
{
throw new BocomApiException($"Bocom sign not success.{ex.Message}");
}
string newBody = "{\"rsp_biz_content\":\"" + rspContent + "\",\"sign\":\"" + signContent + "\"}";
return newBody;
}
} }
} }
} }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Kivii.Common" version="5.6.2023.4000" targetFramework="net45" /> <package id="Kivii.Common" version="5.6.2023.6000" targetFramework="net45" />
<package id="Kivii.Core" version="5.6.2023.4140" targetFramework="net45" /> <package id="Kivii.Core" version="5.6.2023.6000" targetFramework="net45" />
<package id="Kivii.Linq" version="5.6.2023.4200" targetFramework="net45" /> <package id="Kivii.Linq" version="5.6.2023.4200" targetFramework="net45" />
</packages> </packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment