Commit a2dec19c by 陶然

init

parents
################################################################################
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
################################################################################
/.vs
/obj/Debug
/bin/Debug
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Njzj.Bocoms.Openapis
{
internal static class Configs
{
internal static string APIGW_URL_ADDRESS = "https://open.test.bankcomm.com:9443/uat";//"https://117.184.192.242:9443";
/// <summary>
/// APP_ID:通过内管查看详情,可获取对应的组织机构、接入方式、公钥等信息;APP管理中查看
/// </summary>
internal static string APP_ID = "appozhjz202305110002";
/// <summary>
/// 主机构号
/// </summary>
internal static string ORG_ID = "1000078265";
/// <summary>
/// 子机构号
/// </summary>
internal static string SUB_ORG_ID = "1000078266";
/// <summary>
/// MY_PRIVATE_KEY:RSA私钥,可以通过sdk包下面bin文件夹里面的工具生成一对公私钥
/// </summary>
internal static string MY_PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDEu3hCLeQXcWmi+wXaaM0HSJkRxFb/lQl8GU69UiRmf0zI4Xh7/cPBXdm/CWS5SzzTRCQJh23/USxPuyB//wWHgkqUASj12B4mMdx+/KGFmgrAFCy4CBhE2+O4AaiKWuZ8Gpmv+NUseNhy/kyzdNrmqikffr1vM7q1emJ8Y9OihGIAB8toT6b9I/iL93yLUXNLe0ELIIJ1+mmr7j0GvAMZQKL2IrfJ4MCRqg0Ioj2Ql1ckrkmIjgMKZQ1ryzrzcllq5YeaOM8fM3gff9Ntn06N2fsbpZFnGzokNpZkBX8wsLwOHBLM25RxvMPWH9UwWBXkklNHe57PN9G7qtvMMOnPAgMBAAECggEAMeTNuhMDbwKfZOs+78Z2gStjTsM5wTYeIrAUbSVg//G3Gpc8RE32kJrpt259chTnxzjX3ubO+dqvX0U5F90onNZpbaHhrn/yHYO1xSrzF/waT96N/NpotUYDOc6J3RTysXTZl2yHO/EmC/v8neK8BZYQOeGdz48SAiaYxa1XpjZ0QAUX3rCjf9qjkTKux0TZTBk67PcIb+Gwqk4nRWhc0i3yXW4Xw8Z8UJeABgtsOZ16Nv95K7jA836sF+gf4chLGDl8J9Y7Ciz/FpJPksa6Ysoo6jMW9WkggGsNEOwTK6SfYWqIER+NozWG5F4jOlAmdc3zlteOdM3Z9kiYHdlsmQKBgQD78RpE3AEFIC6dgO5isbBeSRNZJUHOp/H49cJgwtk3DiDuN/hLh8Lw3priFiOSlioFRmv6VkQVRQJ38pCbXacc04d34joNy0zXVWFtaaZlureRz74tTbi9Dp1x123NIJ/i/jiJLBdrXfmkNaQpyzfsrIC1vrFpaA5RWKcooZrgzQKBgQDH5rUX9q6tcB/UE3zNfJsNE/yw1QFSAIzcKE3vxWifjbURdVJXpvNoXWkTivwxEbhBDpyAhtUngpN+Ac/3ZP88hY21v+AHmgq9/65z++Wbptg9JfPpGti7kA132D76OfaGca3C1kt1A4Kl+177P52Nx9uAWbANEw+02Dd147pFCwKBgAbzT9Y2e5C4opCVzf3LCSKQwYfkDzy0RWio3wPsXDG4og/wW1k6FZavjXZPRgv1OJOMrc3qM1ai4L6OYo7mtoWFEGeuRgu7YBNQt69dCsojrIzJPmXhjwcoMA/D8bOHAuIwQT8HiF3d6dUt5amBgbl1yNc6u4o85Kg52eK1EqDBAoGARmbZNpRZVpnbi8xFMvWEgemdIAYUjfXFpi/Hqv8iZrb4oypnkpkotoPXYtubEAkGlFr6AUX7Qgv5t/IZdS6ruXvruavW0baNu/aVUSHQ7q2nEHoSWfFrjTshkyiknWnWiej1Yl4oexB+bciG3gO8kFdn1d9AYoppCK7xcWJ/kpsCgYEA2se5A7Oa6JsWmpil+kRSyijoynEnC4IGVEIzboYcBxlyxfpHtwS2zOdXkhIpjd2cqg08BGFcSxot8CaxCOBcRJsI+N+3lok6VffaZDRjttr+NdY/qc7OCmVCx1lJlJ2+WL0Zitv1DV84WqUY2XpQOHvvcmGfuEXtyfkxD1rSJUE=";
/// <summary>
/// APIGW_PUBLIC_KEY:网关公钥
/// </summary>
internal static string APIGW_PUBLIC_KEY =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxSJrF8T/5rKB4NnwMjIxUer+ELf1PQXO2GSdZ/fvuQCclOR9tBlNWL4jFOftebeL+bvMVOJ+JHm/aSes1AN8YNIDGiFUpF6aDkSCaLynDdjK/mQTWhSNa2fO0GGO+ywOBTdYUjVjVtzJ48bbyG3NSylf1EdnBWnMpFa8qpXJXR4ELpVpMkPDC+93HBAlxEgUjhcIJlP5VdKIiudsmhE2T07qtpIQSuE5hntXP6X6GKJReCk+yek2QJITvIBq3cHPw8KDsHHCs7MaR81KI3onJRWyqFtTfVYTiKsd9EcYSxv+Gx5MOF8B/P4iJCD8uzx0FrqoB3k5OYGcz4tXs+h+9wIDAQAB";
/// <summary>
/// 1.1 账单核销结果查询
/// </summary>
internal static string WriteOffResultRequestV2 = "/api/iifssmartbooking/writeOffResult/v2";
/// <summary>
/// 1.2 账单查询
/// </summary>
internal static string QueryContractOrderRequestV2 = "/api/iifssmartbooking/queryContractOrder/v2";
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{10E1820E-308D-434E-BA2E-6550B28A5446}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Njzj.Bocoms.Openapis</RootNamespace>
<AssemblyName>Njzj.Biz.Bocoms.Openapis.V4.5</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\k5-njzj\appextend\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.8.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<SpecificVersion>False</SpecificVersion>
<HintPath>Sdk\Dll\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="Kivii.Common.V4.5, Version=5.6.2023.4000, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\k5-njzj\packages\Kivii.Common.5.6.2023.4000\lib\net45\Kivii.Common.V4.5.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Kivii.Core.V4.5, Version=5.6.2023.4140, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\k5-njzj\packages\Kivii.Core.5.6.2023.4140\lib\net45\Kivii.Core.V4.5.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Configs.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sdk\BizContent.cs" />
<Compile Include="Sdk\BocomApiException.cs" />
<Compile Include="Sdk\BocomDecryptResponse.cs" />
<Compile Include="Sdk\BocomDownloadEncryptRequest.cs" />
<Compile Include="Sdk\BocomDownloadRequest.cs" />
<Compile Include="Sdk\BocomEncrypt.cs" />
<Compile Include="Sdk\BocomEncryptRequest.cs" />
<Compile Include="Sdk\BocomRequest.cs" />
<Compile Include="Sdk\BocomResponse.cs" />
<Compile Include="Sdk\BocomUploadEncryptRequest.cs" />
<Compile Include="Sdk\BocomUploadRequest.cs" />
<Compile Include="Sdk\DefaultBocomClient.cs" />
<Compile Include="Sdk\request\AddContractOrderRequestV2.cs" />
<Compile Include="Sdk\request\BJPTBlCustAccountQueryRequestV1.cs" />
<Compile Include="Sdk\request\FileUploadRequestV1.cs" />
<Compile Include="Sdk\request\HmdLoanStatusListFileDownloadRequestV1.cs" />
<Compile Include="Sdk\request\IntegralExchangeCheckRequestV1.cs" />
<Compile Include="Sdk\request\IntegralExchangeCreateUrlRequestV1.cs" />
<Compile Include="Sdk\request\QueryContractOrderRequestV2.cs" />
<Compile Include="Sdk\request\ScfCreateUrlRequestV1.cs" />
<Compile Include="Sdk\request\WriteOffResultRequestV2.cs" />
<Compile Include="Sdk\response\AddContractOrderResponseV2.cs" />
<Compile Include="Sdk\response\BJPTBlCustAccountQueryResponseV1.cs" />
<Compile Include="Sdk\response\FileDownloadResponseV1.cs" />
<Compile Include="Sdk\response\FileUploadResponseV1.cs" />
<Compile Include="Sdk\response\IntegralExchangeCheckResponseV1.cs" />
<Compile Include="Sdk\response\IntegralExchangeCreateUrlResponseV1.cs" />
<Compile Include="Sdk\response\IntegralExchangeNotifyResponseV1.cs" />
<Compile Include="Sdk\response\QueryContractOrderResponseV2.cs" />
<Compile Include="Sdk\response\ScfCreateUrlResponseV1.cs" />
<Compile Include="Sdk\response\WriteOffResultResponseV2.cs" />
<Compile Include="Sdk\security\crypt\AESCryptor.cs" />
<Compile Include="Sdk\security\crypt\RSACryptor.cs" />
<Compile Include="Sdk\security\crypt\SM2Cryptor.cs" />
<Compile Include="Sdk\security\crypt\SM4Cryptor.cs" />
<Compile Include="Sdk\security\digest\SHA256Digest.cs" />
<Compile Include="Sdk\security\digest\SM3Digest.cs" />
<Compile Include="Sdk\security\keygen\AESKeyGen.cs" />
<Compile Include="Sdk\security\keygen\SM2KeyGen.cs" />
<Compile Include="Sdk\security\keygen\SM4KeyGen.cs" />
<Compile Include="Sdk\security\sign\RSASignature.cs" />
<Compile Include="Sdk\security\sign\SM2Signature.cs" />
<Compile Include="Sdk\utils\ApiUtils.cs" />
<Compile Include="Sdk\utils\BocomConstants.cs" />
<Compile Include="Sdk\utils\BocomHashMap.cs" />
<Compile Include="Sdk\utils\BocomSignature.cs" />
<Compile Include="Sdk\utils\FileItem.cs" />
<Compile Include="Sdk\utils\HttpRequestParamsUtils.cs" />
<Compile Include="Sdk\utils\KeyGeneratorUtils.cs" />
<Compile Include="Sdk\utils\TrustAllCertificatePolicy.cs" />
<Compile Include="Sdk\utils\WebUtils.cs" />
<Compile Include="Transforms\RestfulTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Sdk\Dll\BouncyCastle.Crypto.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Njzj.Biz.Bocoms.Openapis.V4.5")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Njzj.Biz.Bocoms.Openapis.V4.5")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("10e1820e-308d-434e-ba2e-6550b28a5446")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
namespace Com.Bocom.OpenApi
{
public interface BizContent
{
}
}
\ No newline at end of file
using System;
namespace Com.Bocom.OpenApi
{
public class BocomApiException : Exception
{
private static long serialVersionUID = 1982151499949623380L;
private int errCode;
private string errMsg;
public BocomApiException()
{
}
public BocomApiException(string message)
{
errMsg = message;
}
public BocomApiException(int errCode, string errMsg)
: base(errCode + ":" + errMsg)
{
this.errCode = errCode;
this.errMsg = errMsg;
}
public BocomApiException(string message, Exception e) : base(message, e)
{
errMsg = message;
}
public BocomApiException(int errCode, String errMsg, Exception e) : base(errCode + ":" + errMsg, e)
{
this.errCode = errCode;
this.errMsg = errMsg;
}
public int GetErrCode()
{
return errCode;
}
public string GetErrMsg()
{
return errMsg;
}
}
}
\ No newline at end of file
using System;
using System.Runtime.Serialization;
namespace Com.Bocom.OpenApi
{
[Serializable]
[DataContract]
public class BocomDecryptResponse : BocomResponse
{
private string decryptKey;
/**
* @return the decrptKey
*/
public string getDecryptKey()
{
return decryptKey;
}
/**
* @param decrptKey
* the decrptKey to set
*/
public void setDecryptKey(string decryptKey)
{
this.decryptKey = decryptKey;
}
public string decrypt(string data, string encryptType, string key, string charset)
{
return BocomEncrypt.SymmetricalDecrypt(data, encryptType, key, charset);
}
}
}
\ No newline at end of file
namespace Com.Bocom.OpenApi
{
public abstract class BocomDownloadEncryptRequest<T> : BocomRequest<T> where T : BocomResponse
{
private string downloadPath;
private string hashCode;
public string GetDownloadPath()
{
return downloadPath;
}
/// <summary>
///
/// </summary>
/// <param name="downloadPath">the downloadPath to set</param>
public void SetDownloadPath(string downloadPath)
{
this.downloadPath = downloadPath;
}
public abstract string getEncryptKey();
public abstract string getEncryptPolicy();
public string getHashCode()
{
return hashCode;
}
public abstract string GetEncryptType();
public void SetHashCode(string hashCode)
{
this.hashCode = hashCode;
}
}
}
\ No newline at end of file
namespace Com.Bocom.OpenApi
{
public abstract class BocomDownloadRequest<T> : BocomRequest<T> where T : BocomResponse
{
private string downloadPath;
public string GetDownloadPath()
{
return downloadPath;
}
/// <summary>
///
/// </summary>
/// <param name="downloadPath">the downloadPath to set</param>
public void SetDownloadPath(string downloadPath)
{
this.downloadPath = downloadPath;
}
}
}
\ No newline at end of file
using System.IO;
using Com.Bocom.OpenApi.Security.Crypt;
using Com.Bocom.OpenApi.Utils;
namespace Com.Bocom.OpenApi
{
public class BocomEncrypt
{
private static RSACryptor.RSAFromPkcs8 rsaCryptor =
new RSACryptor.RSAFromPkcs8();
/// <summary>
/// 对称加密,仅支持AES256和SM4。
/// </summary>
/// <param name="plainText"></param>
/// <param name="encryptType"></param>
/// <param name="secretKey"></param>
/// <param name="charset"></param>
/// <returns></returns>
public static string SymmetricalEncrypt(string plainText, string encryptType, string secretKey, string charset)
{
if (BocomConstants.ENCRYPT_TYPE_RSA_AND_AES == encryptType)
{
return AESCryptor.Encrypt(plainText, secretKey, charset);
}
if (BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4 == encryptType)
{
return SM4Cryptor.Encrypt(plainText, secretKey, charset);
}
throw new BocomApiException("对称加密仅支持AES256和SM4!");
}
/// <summary>
/// 对称解密,仅支持AES256和SM4。
/// </summary>
/// <param name="cipherText"></param>
/// <param name="encryptType"></param>
/// <param name="secretKey"></param>
/// <param name="charset"></param>
/// <returns></returns>
/// <exception cref="BocomApiException"></exception>
public static string SymmetricalDecrypt(string cipherText, string encryptType, string secretKey, string charset)
{
if (BocomConstants.ENCRYPT_TYPE_RSA_AND_AES == encryptType)
{
return AESCryptor.Decrypt(cipherText, secretKey, charset);
}
if (BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4 == encryptType)
{
return SM4Cryptor.Decrypt(cipherText, secretKey, charset);
}
throw new BocomApiException("对称解密仅支持AES256和SM4!");
}
/// <summary>
/// 非对称加密,仅支持RSA和SM2。
/// </summary>
/// <param name="plainText"></param>
/// <param name="encryptType"></param>
/// <param name="publicKey"></param>
/// <param name="charset"></param>
/// <returns></returns>
/// <exception cref="BocomApiException"></exception>
public static string AsymmetricalEncrypt(string plainText, string encryptType, string publicKey, string charset)
{
if (BocomConstants.ENCRYPT_TYPE_RSA_AND_AES == encryptType)
{
return rsaCryptor.EncryptData(plainText, publicKey, charset);
}
if (BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4 == encryptType)
{
return SM2Cryptor.Encrypt(plainText, publicKey, charset);
}
throw new BocomApiException("非对称加密仅支持RSA和SM2!");
}
/// <summary>
///
/// </summary>
/// <param name="cipherText"></param>
/// <param name="encryptType"></param>
/// <param name="privateKey"></param>
/// <param name="charset"></param>
/// <returns></returns>
public static string AsymmetricalDecrypt(string cipherText, string encryptType, string privateKey,
string charset)
{
if (BocomConstants.ENCRYPT_TYPE_RSA_AND_AES == encryptType)
{
return rsaCryptor.DecryptData(cipherText, privateKey, charset);
}
if (BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4 == encryptType)
{
return SM2Cryptor.Decrypt(cipherText, privateKey, charset);
}
throw new BocomApiException("非对称解密仅支持RSA和SM2!");
}
public static byte[] EncryptFile(FileStream fi, string cryptKey, string encryptType)
{
if (BocomConstants.ENCRYPT_TYPE_RSA_AND_AES == encryptType)
{
return AESCryptor.EncryptFile(fi, cryptKey);
}
if (BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4 == encryptType)
{
// SM2加密(缺省)
return null;
}
return null;
}
public static byte[] DecryptFile(FileStream fi, string cryptKey, string encryptType)
{
if (BocomConstants.ENCRYPT_TYPE_RSA_AND_AES == encryptType)
{
return AESCryptor.DecryptFile(fi, cryptKey);
}
if (BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4 == encryptType)
{
// SM2加密(缺省)
return null;
}
return null;
}
}
}
\ No newline at end of file
namespace Com.Bocom.OpenApi
{
public abstract class BocomEncryptRequest<T> : BocomRequest<T> where T : BocomResponse
{
public abstract string GetEncryptPolicy();
public abstract string Encrypt(string data, string key, string encryptType);
public abstract string GetEncryptKey();
public abstract string GetEncryptType();
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
namespace Com.Bocom.OpenApi
{
public abstract class BocomRequest<T> where T : BocomResponse
{
private string serviceUrl;
public string GetServiceUrl()
{
return serviceUrl;
}
public void SetServiceUrl(string value)
{
serviceUrl = value;
}
private BizContent bizContent;
public BizContent GetBizContent()
{
return bizContent;
}
public void SetBizContent(BizContent value)
{
bizContent = value;
}
private Dictionary<string, string> extraParams = new Dictionary<string, string>();
public Dictionary<string, string> GetExtraParams()
{
return extraParams;
}
public abstract Type GetResponseClass();
public abstract bool IsNeedEncrypt();
public abstract Type GetBizContentClass();
//abstract public Dictionary<string, string> getExtraParameters();
/**
* @return POST or GET
*/
public abstract string GetMethod();
// abstract public string getEncrpytKey();
// abstract public string getEncrpytPolicy();
// abstract public FileItem getFileItem();
// abstract public void setHashCode(string hashCode);
// abstract public string getDownloadPath();
// abstract public string getEncrpytType();
}
}
\ No newline at end of file
using System;
using System.Runtime.Serialization;
namespace Com.Bocom.OpenApi
{
[Serializable]
[DataContract]
public class BocomResponse
{
[DataMember] private string biz_state = "P";
[DataMember] private string rsp_code = "";
[DataMember] private string rsp_msg = "";
[DataMember] private string ref_msg_id;
public string GetRefMsgId()
{
return ref_msg_id;
}
public void SetRefMsgId(string value)
{
ref_msg_id = value;
}
public string GetRspCode()
{
return rsp_code;
}
public void SetRspCode(string value)
{
rsp_code = value;
}
public string GetRspMsg()
{
return rsp_msg;
}
public void SetRspMsg(string value)
{
rsp_msg = value;
}
/**
* @return 报文成功级别标识;非业务级别成功标识
*/
public bool IsSuccess()
{
return biz_state.Equals("S");
}
public string GetBizState()
{
return biz_state;
}
public void SetBizState(string state)
{
biz_state = state;
}
}
}
\ No newline at end of file
using Com.Bocom.OpenApi.Utils;
namespace Com.Bocom.OpenApi
{
public abstract class BocomUploadEncryptRequest<T> : BocomRequest<T> where T : BocomResponse
{
public abstract FileItem GetFileItem();
public abstract string GetEncryptKey();
public abstract string GetEncryptPolicy();
public abstract string GetEncryptType();
}
}
\ No newline at end of file
using Com.Bocom.OpenApi.Utils;
namespace Com.Bocom.OpenApi
{
public abstract class BocomUploadRequest<T> : BocomRequest<T> where T : BocomResponse
{
public abstract FileItem GetFileItem();
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Web;
//using Newtonsoft.Json;
using Com.Bocom.OpenApi.Security.Digest;
using Com.Bocom.OpenApi.Utils;
using Kivii.Text;
namespace Com.Bocom.OpenApi
{
public class DefaultBocomClient
{
protected string appId;
protected string privateKey;
protected string charset = BocomConstants.CHARSET_UTF8;
protected string format = BocomConstants.FORMAT_JSON;
protected string bocomPublicKey;
protected string password;
protected string encryptType = BocomConstants.ENCRYPT_TYPE_RSA_AND_AES;
public DefaultBocomClient(string appId, string privateKey, string charset, string format,
string bocomPublicKey, string passWord)
{
this.appId = appId;
this.privateKey = privateKey;
this.charset = charset;
this.bocomPublicKey = bocomPublicKey;
this.format = format;
this.password = passWord;
}
public DefaultBocomClient(string appId, string privateKey, string charset, string format,
string bocomPublicKey, string encryptType, string passWord)
{
this.appId = appId;
this.privateKey = privateKey;
this.charset = charset;
this.bocomPublicKey = bocomPublicKey;
this.format = format;
this.encryptType = encryptType;
this.password = passWord;
}
public DefaultBocomClient(string appId, string privateKey, string bocomPulicKey)
: this(appId, privateKey, BocomConstants.CHARSET_UTF8, BocomConstants.FORMAT_JSON,
bocomPulicKey, null)
{
}
public DefaultBocomClient(string appId, string privateKey, string bocomPulicKey, string encryptType)
: this(appId, privateKey, BocomConstants.CHARSET_UTF8, BocomConstants.FORMAT_JSON,
bocomPulicKey, encryptType, null)
{
}
public BocomResponse Execute<T>(BocomRequest<T> request) where T : BocomResponse
{
string uuid = Guid.NewGuid().ToString();
string msgId = uuid.Replace("-", "");
return Execute(request, msgId);
}
public BocomResponse Execute<T>(BocomRequest<T> request, string msgId) where T : BocomResponse
{
return Execute(request, msgId, "");
}
public BocomResponse Execute<T>(BocomRequest<T> request, string msgId, string appAuthToken)
where T : BocomResponse
{
string encryptKey = null;
string encryptType = this.encryptType;
string encryptPolicy = null;
if (request.IsNeedEncrypt())
{
if (request is BocomEncryptRequest<T>)
{
encryptKey = ((BocomEncryptRequest<T>) request).GetEncryptKey();
encryptPolicy = ((BocomEncryptRequest<T>) request).GetEncryptPolicy();
}
else if (request is BocomUploadEncryptRequest<T>)
{
encryptKey = ((BocomUploadEncryptRequest<T>) request).GetEncryptKey();
encryptPolicy = ((BocomUploadEncryptRequest<T>) request).GetEncryptPolicy();
}
else if (request is BocomDownloadEncryptRequest<T>)
{
encryptKey = ((BocomDownloadEncryptRequest<T>) request).getEncryptKey();
encryptPolicy = ((BocomDownloadEncryptRequest<T>) request).getEncryptPolicy();
}
}
Dictionary<string, string> param =
PrepareParams(request, msgId, appAuthToken, encryptType, encryptKey, encryptPolicy);
string respStr;
if (request.GetMethod().Equals("POST"))
{
try
{
if (request is BocomUploadRequest<T>)
{
Dictionary<string, FileItem> map = new Dictionary<string, FileItem>();
map.Add(BocomConstants.FILE_CONTENT, ((BocomUploadRequest<T>) request).GetFileItem());
respStr = WebUtils.GetResponseJson(request.GetServiceUrl(), param, charset,
((BocomUploadRequest<T>) request).GetFileItem());
}
else if (request is BocomUploadEncryptRequest<T>)
{
Dictionary<string, FileItem> map = new Dictionary<string, FileItem>();
map.Add(BocomConstants.FILE_CONTENT, ((BocomUploadEncryptRequest<T>) request).GetFileItem());
respStr = WebUtils.GetResponseJson(request.GetServiceUrl(), param, charset,
((BocomUploadEncryptRequest<T>) request).GetFileItem());
}
else if (request is BocomDownloadRequest<T>)
{
respStr = WebUtils.GetResponseJson(request.GetServiceUrl(), param, charset,
((BocomDownloadRequest<T>) request).GetDownloadPath());
}
else if (request is BocomDownloadEncryptRequest<T>)
{
respStr = WebUtils.GetResponseJson(request.GetServiceUrl(), param, charset,
((BocomDownloadEncryptRequest<T>) request).GetDownloadPath(), encryptKey, encryptType);
}
else
{
respStr = WebUtils.GetResponseJson(request.GetServiceUrl(), param, charset);
}
}
catch (IOException e)
{
throw new BocomApiException(500, "api connect host err", e);
}
}
else
{
throw new BocomApiException("only support POST, method: " + request.GetMethod());
}
BocomResponse response = ParseJsonWithBocomSign(request, respStr, encryptType, encryptKey);
if (response == null)
{
throw new Exception("response is null.");
}
if (response is BocomDecryptResponse)
{
((BocomDecryptResponse) response).setDecryptKey(((BocomEncryptRequest<T>) request).GetEncryptKey());
}
return response;
}
protected Dictionary<string, string> PrepareParams<T>(BocomRequest<T> request, string msgId,
string appAuthToken, string encryptType, string encryptKey, string encryptPolicy) where T : BocomResponse
{
Console.WriteLine("PrepareParams---" + encryptKey);
string bizContentStr = BuildBizContentStr(request);
string path = string.Empty;
try
{
path = new Uri(request.GetServiceUrl()).LocalPath;
path = path.Replace("/uat/", "/");
}
catch (UriFormatException e)
{
Console.WriteLine(e.Message);
}
Dictionary<string, string> param = new Dictionary<string, string>();
Dictionary<string, string> extraParams = request.GetExtraParams();
if (extraParams != null)
{
param = param.Union(extraParams).ToDictionary(k => k.Key, v => v.Value);
}
param.Add(BocomConstants.APP_ID, appId);
Console.WriteLine("appId:" + appId);
param.Add(BocomConstants.CHARSET, charset);
param.Add(BocomConstants.FMT_TYPE, BocomConstants.FORMAT_JSON);
param.Add(BocomConstants.APP_AUTH_TOKEN, appAuthToken);
param.Add(BocomConstants.MSG_ID, msgId);
param.Add(BocomConstants.TIMESTAMP, DateTime.Now.ToString(BocomConstants.DATE_TIME_FORMAT));
Console.WriteLine("请求是否要加密:" + request.IsNeedEncrypt());
if (request.IsNeedEncrypt())
{
if (encryptType == null || encryptKey == null || encryptPolicy == null)
{
throw new ArgumentNullException(
"request need be encrypted, encrypt type, encrypt policy and encrypt key can not be null.");
}
string is_Encrypt = "true";
/* if (request.isNeedEncrypt())
{
is_Encrypt = "true";
}*/
param.Add(BocomConstants.IS_ENCRYPT, is_Encrypt);
}
else
{
param.Add(BocomConstants.BIZ_CONTENT_KEY, bizContentStr);
}
if (request is BocomEncryptRequest<T>)
{
//这里分报文和字段加密
/*if(BocomConstants.ENCRYPT_POLICY_TYPE_CONTENT.Equals(encryptPolicy)&&bizContentStr != null) { //报文加密
Console.WriteLine("报文加密bizcontent:" + bizContentStr);
param.Add(BocomConstants.BIZ_CONTENT,
BocomEncrypt.encryptContent(bizContentStr, encryptType, encryptKey, charset));
}*/
if (BocomConstants.ENCRYPT_POLICY_TYPE_FIELD.Equals(encryptPolicy) && bizContentStr != null)
{
//字段加密
param.Add(BocomConstants.BIZ_CONTENT, bizContentStr);
}
param.Add(BocomConstants.ENCRYPT_POLICY, encryptPolicy);
// 用公钥对对称密钥进行加密
param.Add(BocomConstants.ENCRYPT_KEY,
BocomEncrypt.AsymmetricalEncrypt(encryptKey, this.encryptType, bocomPublicKey, charset));
}
if (request is BocomUploadRequest<T>)
{
//如果是上传文件请求但不需要加密的话,就只需提取文件的哈希码,不需要进行其他操作
FileItem f = ((BocomUploadRequest<T>) request).GetFileItem();
Console.WriteLine("文件没有加密");
string fileName = f.GetFileName();
param.Add(BocomConstants.FILE_HASHCODE,
SHA256Digest.Digest(fileName));
}
if (request is BocomUploadEncryptRequest<T>)
{
//如果是上传文件请求 并且需要加密的话,先提取文件哈希码 存储到params,然后将文件内容加密,然后用密文替换fileItem的content
FileItem f = ((BocomUploadEncryptRequest<T>) request).GetFileItem();
string fileName = f.GetFileName();
//params.put(BocomConstants.ENCRYPT_TYPE, encryptType);
param.Add(BocomConstants.BIZ_CONTENT, bizContentStr);
param.Add(BocomConstants.FILE_HASHCODE,
SHA256Digest.Digest(fileName));
param.Add(BocomConstants.ENCRYPT_POLICY, encryptPolicy);
// 用公钥对对称密钥进行加密
param.Add(BocomConstants.ENCRYPT_KEY,
BocomEncrypt.AsymmetricalEncrypt(encryptKey, BocomConstants.ENCRYPT_TYPE_RSA_AND_AES, bocomPublicKey, charset));
try
{
//提取fileItem的file 然后转为InputStream,然后用encryptFile加密,然后将加密的流转为字节数组保存
FileStream i = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] encryptContent = BocomEncrypt.EncryptFile(i, encryptKey, encryptType);
f.SetContent(encryptContent);
}
catch (IOException e)
{
throw new BocomApiException("上传文件加密失败", e);
}
}
if (request is BocomDownloadEncryptRequest<T>)
{
param.Add(BocomConstants.BIZ_CONTENT, bizContentStr);
param.Add(BocomConstants.ENCRYPT_POLICY, encryptPolicy);
// 用公钥对对称密钥进行加密
param.Add(BocomConstants.ENCRYPT_KEY,
BocomEncrypt.AsymmetricalEncrypt(encryptKey, BocomConstants.ENCRYPT_TYPE_RSA_AND_AES, bocomPublicKey, charset));
}
string strToSign = WebUtils.BuildOrderedSignStr(path, param);
Console.WriteLine("strToSign:" + strToSign);
string signedStr = BocomSignature.Sign(encryptType, strToSign, privateKey, charset);
if (signedStr.Length < 3)
throw new Exception("sign Exception!");
param.Add(BocomConstants.SIGN, signedStr);
return param;
}
protected string BuildBizContentStr<T>(BocomRequest<T> request) where T : BocomResponse
{
if (request.GetBizContent() == null)
{
return null;
}
if (string.Equals(BocomConstants.FORMAT_JSON, format))
{
string json;
//JsonSerializerSettings jsonSetting = new JsonSerializerSettings
//{ NullValueHandling = NullValueHandling.Ignore };
//json = JsonConvert.SerializeObject(request.GetBizContent(), Formatting.None, jsonSetting);
json = Kivii.Text.JsonSerializer.SerializeToString(request.GetBizContent());
return json;
}
throw new Exception("only support json format, current format is not supported. format: " + format);
}
private BocomResponse ParseJsonWithBocomSign<T>(BocomRequest<T> request, string respStr, string encryptType,
string encryptKey) where T : BocomResponse
{
if (request is BocomDownloadRequest<T> || request is BocomDownloadEncryptRequest<T>)
{
respStr = HttpUtility.UrlDecode(respStr);
}
string respBizContentStr = string.Empty;
string sign = string.Empty;
int indexOfRootStart = respStr.IndexOf(BocomConstants.RESPONSE_BIZ_CONTENT)
+ BocomConstants.RESPONSE_BIZ_CONTENT.Length + 2;
int indexOfRootEnd = respStr.LastIndexOf(",");
int indexOfSignStart = respStr.LastIndexOf(BocomConstants.SIGN + "\"") + BocomConstants.SIGN.Length + 3;
int indexOfSignEnd = respStr.LastIndexOf("\"");
respBizContentStr = respStr.Substring(indexOfRootStart, indexOfRootEnd - indexOfRootStart);
sign = respStr.Substring(indexOfSignStart, indexOfSignEnd - indexOfSignStart);
if (request is BocomDownloadEncryptRequest<T>)
{
int indexOfHashCodeStart = respBizContentStr.IndexOf(BocomConstants.FILE_HASHCODE) +
BocomConstants.FILE_HASHCODE.Length + 3;
int indexOfHashCodeEnd = respBizContentStr.LastIndexOf("\"");
string hashCode =
respBizContentStr.Substring(indexOfHashCodeStart, indexOfHashCodeEnd - indexOfHashCodeStart);
((BocomDownloadEncryptRequest<T>) request).SetHashCode(hashCode);
}
bool passed = BocomSignature.Verify(encryptType, respBizContentStr, bocomPublicKey, charset, sign);
if (!passed)
{
throw new Exception("bocom sign verify not passed.");
}
if (request.IsNeedEncrypt() && request is BocomEncryptRequest<BocomDecryptResponse>)
{
string encryptPolicy = ((BocomEncryptRequest<T>) request).GetEncryptPolicy();
// 全报文加密需要使用对称密钥解密response报文
if (BocomConstants.ENCRYPT_POLICY_TYPE_CONTENT.Equals(encryptPolicy) && respBizContentStr != null)
{
try
{
// body = "{\"rsp_biz_content\":" + body + ",\"sign\":\"" + signContent + "\"}";
respBizContentStr = BocomEncrypt.SymmetricalDecrypt(
respBizContentStr.Substring(1, respBizContentStr.Length - 1), encryptType, encryptKey,
charset);
}
catch (Exception e)
{
throw new Exception("response can not decrypt. response: " + respStr, e);
}
}
}
//反序列化并返回
BocomResponse response;
using (MemoryStream ms = new MemoryStream(Encoding.GetEncoding(charset).GetBytes(respBizContentStr)))
{
try
{
DataContractJsonSerializer deseralizer = new DataContractJsonSerializer(request.GetResponseClass());
response = deseralizer.ReadObject(ms) as BocomResponse;
}
catch (Exception e)
{
throw new Exception("---------- respBizContentStr: " + respBizContentStr, e);
}
}
return response;
}
public void IgnoreSslHostnameVerifier()
{
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Njzj.Bocoms.Openapis.Sdk.request
{
internal class AddContractOrderRequestV2
{
}
}
using System;
using System.Runtime.Serialization;
using Com.Bocom.OpenApi.Response;
using Com.Bocom.OpenApi.Security.KeyGen;
using Com.Bocom.OpenApi.Utils;
namespace Com.Bocom.OpenApi
{
namespace Request
{
public class BJPTBlCustAccountQueryRequestV1 : BocomEncryptRequest<BJPTBlCustAccountQueryResponseV1>
{
private string encryptType = BocomConstants.ENCRYPT_TYPE_RSA_AND_AES;
private string encryptKey = AESKeyGen.GenAES256Key();
public override Type GetResponseClass()
{
return typeof(BJPTBlCustAccountQueryResponseV1);
}
public override bool IsNeedEncrypt()
{
return true;
}
public override string GetMethod()
{
return "POST";
}
public override Type GetBizContentClass()
{
return typeof(BlCustAccountQueryRequestV1Biz);
}
[DataContract]
public class BlCustAccountQueryRequestV1Biz : BizContent
{
[DataMember]
public string req_usercode { get; set; }
[DataMember]
public string field1 { get; set; }
[DataMember]
public string cust_idno { get; set; }
[DataMember]
public string balance_account { get; set; }
[DataMember]
public string cust_erpid { get; set; }
[DataMember]
public string field2 { get; set; }
}
public override string GetEncryptPolicy()
{
return BocomConstants.ENCRYPT_POLICY_TYPE_CONTENT;
}
public override string GetEncryptType()
{
return encryptType;
}
public void setEncryptType(string encryptType)
{
if (encryptType.Equals(BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4))
{
this.encryptType = encryptType;
encryptKey = SM4KeyGen.GenSM4Key();
}
}
public override string Encrypt(string data, string key, string encryptType)
{
string cipher;
try
{
cipher = BocomEncrypt.SymmetricalEncrypt(data, encryptType, key, BocomConstants.CHARSET_UTF8);
}
catch (Exception e)
{
throw new Exception("加密字符串[" + data + "]时遇到异常", e);
}
return cipher;
}
public override string GetEncryptKey()
{
return encryptKey;
}
}
}
}
\ No newline at end of file
using System;
using Com.Bocom.OpenApi.Response;
using Com.Bocom.OpenApi.Security.KeyGen;
using Com.Bocom.OpenApi.Utils;
namespace Com.Bocom.OpenApi
{
namespace Request
{
public class FileUploadRequestV1 : BocomUploadEncryptRequest<FileUploadResponseV1>
{
/// <summary>
/// 获取响应类
/// </summary>
/// <returns>返回IntegralExchangeCheckResponseV1类对应的响应类类型</returns>
public override Type GetResponseClass()
{
return typeof(FileUploadResponseV1);
}
/// <summary>
/// 是否支持加密(目前sdk只支持对字段进行AES加解密)
/// </summary>
/// <returns>一般返回false</returns>
public override bool IsNeedEncrypt()
{
return true;
}
/// <summary>
/// http发起请求方式(支持GET、POST两种方式)
/// </summary>
/// <returns>一般返回POST</returns>
public override string GetMethod()
{
return "POST";
}
private FileItem fileItem;
public void setFileItem(FileItem f)
{
fileItem = f;
}
public override string GetEncryptType()
{
return BocomConstants.ENCRYPT_TYPE_RSA_AND_AES;
}
public override string GetEncryptPolicy()
{
return BocomConstants.ENCRYPT_POLICY_TYPE_FILE;
}
private string encryptKey = AESKeyGen.GenAES256Key();
public override string GetEncryptKey()
{
return encryptKey;
}
public override FileItem GetFileItem()
{
return fileItem;
}
/// <summary>
/// 获取业务类类型
/// </summary>
/// <returns>返回request类内部定义的BizContent类的类型</returns>
public override Type GetBizContentClass()
{
return null;
}
/* [DataMember]
private FileItem fileItem;
public FileItem FileItem
{
get { return fileItem; }
// set { protocol_no = value; }
}*/
}
}
}
\ No newline at end of file
using System;
using System.Runtime.Serialization;
using Com.Bocom.OpenApi.Response;
using Com.Bocom.OpenApi.Security.KeyGen;
using Com.Bocom.OpenApi.Utils;
namespace Com.Bocom.OpenApi
{
namespace Request
{
public class HmdLoanStatusListFileDownloadRequestV1 : BocomDownloadEncryptRequest<FileDownloadResponseV1>
{
private string encryptKey = AESKeyGen.GenAES256Key();
private string encryptPolicy = "FILE";
private string hashCode;
private string encryptType = "AES";
public override bool IsNeedEncrypt()
{
return true;
}
public override string GetMethod()
{
return "POST";
}
public override Type GetResponseClass()
{
return typeof(FileDownloadResponseV1);
}
public override Type GetBizContentClass()
{
return typeof(HmdLoanStatusListFileDownloadRequestV1Biz);
}
[DataContract]
public class HmdLoanStatusListFileDownloadRequestV1Biz : BizContent
{
//(desc = "联盟商标识")
//@JsonProperty("bv_ode_no")
[DataMember]
public string bv_ode_no { get; set; }
[DataMember]
public string clc_no { get; set; }
//(desc = "备用字段1")
//@JsonProperty("query_date")
[DataMember]
public string query_date { get; set; }
//(desc = "备用字段2")
//@JsonProperty("notify_url")
[DataMember]
public string notify_url { get; set; }
}
public override string getEncryptKey()
{
// TODO Auto-generated method stub
return encryptKey;
}
public override string getEncryptPolicy()
{
// TODO Auto-generated method stub
return encryptPolicy;
}
public string getHashCode()
{
// TODO Auto-generated method stub
return hashCode;
}
public void setHashCode(string hashCode)
{
// TODO Auto-generated method stub
this.hashCode = hashCode;
}
public void setEncryptType(string encryptType)
{
if (encryptType.Equals(BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4))
{
this.encryptType = encryptType;
encryptKey = SM4KeyGen.GenSM4Key();
}
}
public override string GetEncryptType()
{
return encryptType;
}
}
}
}
\ No newline at end of file
using System;
using System.Runtime.Serialization;
using Com.Bocom.OpenApi.Response;
using Org.BouncyCastle.Bcpg.OpenPgp;
namespace Com.Bocom.OpenApi
{
namespace Request
{
public class IntegralExchangeCheckRequestV1 : BocomRequest<IntegralExchangeCheckResponseV1>
{
/// <summary>
/// 获取响应类
/// </summary>
/// <returns>返回IntegralExchangeCheckResponseV1类对应的响应类类型</returns>
public override Type GetResponseClass()
{
return typeof(IntegralExchangeCheckResponseV1);
}
/// <summary>
/// 是否支持加密(目前sdk只支持对字段进行AES加解密)
/// </summary>
/// <returns>一般返回false</returns>
public override bool IsNeedEncrypt()
{
return false;
}
/// <summary>
/// http发起请求方式(支持GET、POST两种方式)
/// </summary>
/// <returns>一般返回POST</returns>
public override string GetMethod()
{
return "POST";
}
/// <summary>
/// 获取业务类类型
/// </summary>
/// <returns>返回request类内部定义的BizContent类的类型</returns>
public override Type GetBizContentClass()
{
return typeof(IntegralExchangeCheckRequestV1Biz);
}
/// <summary>
/// 内部业务类,封装需要发送给服务端的业务字段
/// </summary>
[DataContract]
public class IntegralExchangeCheckRequestV1Biz : BizContent
{
[DataMember] public string req_usercode { get; set; }
[DataMember] public string doc_id { get; set; }
[DataMember] public string file_name { get; set; }
}
}
}
}
\ No newline at end of file
using System;
using System.Runtime.Serialization;
using Com.Bocom.OpenApi.Response;
namespace Com.Bocom.OpenApi
{
namespace Request
{
public class IntegralExchangeCreateUrlRequestV1 : BocomRequest<IntegralExchangeCreateUrlResponseV1>
{
/// <summary>
/// 获取响应类
/// </summary>
/// <returns>返回IntegralExchangeCreateUrlRequestV1类对应的响应类类型</returns>
public override Type GetResponseClass()
{
return typeof(IntegralExchangeCreateUrlResponseV1);
}
/// <summary>
/// 是否支持加密(目前sdk只支持对字段进行AES加解密)
/// </summary>
/// <returns>一般返回false</returns>
public override Boolean IsNeedEncrypt()
{
return false;
}
/// <summary>
/// http发起请求方式(支持GET、POST两种方式)
/// </summary>
/// <returns>一般返回POST</returns>
public override string GetMethod()
{
return "POST";
}
/// <summary>
/// 获取业务类类型
/// </summary>
/// <returns>返回request类内部定义的BizContent类的类型</returns>
public override Type GetBizContentClass()
{
return typeof(IntegralExchangeCreateUrlRequestV1Biz);
}
/// <summary>
/// 内部业务类,封装需要发送给服务端的业务字段
/// </summary>
[DataContract]
public class IntegralExchangeCreateUrlRequestV1Biz : BizContent
{
//回调地址url
[DataMember]
public string notify_url { get; set; }
//页面UAL
[DataMember]
public string return_url { get; set; }
//订单编号
[DataMember]
public string order_no { get; set; }
//兑换规则
[DataMember]
public string exchange_rules { get; set; }
//协议编号
[DataMember]
public string protocol_no { get; set; }
}
}
}
}
\ No newline at end of file
using Com.Bocom.OpenApi.Response;
using Com.Bocom.OpenApi.Security.KeyGen;
using Com.Bocom.OpenApi.Utils;
using Kivii.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Com.Bocom.OpenApi
{
public class QueryContractOrderRequestV2 : BocomRequest<QueryContractOrderResponseV2>
{
/// <summary>
/// 获取响应类
/// </summary>
/// <returns>返回QueryContractOrderResponseV2类对应的响应类类型</returns>
public override Type GetResponseClass()
{
return typeof(QueryContractOrderResponseV2);
}
/// <summary>
/// 是否支持加密(目前sdk只支持对字段进行AES加解密)
/// </summary>
/// <returns>一般返回false</returns>
public override bool IsNeedEncrypt()
{
return false;
}
/// <summary>
/// http发起请求方式(支持GET、POST两种方式)
/// </summary>
/// <returns>一般返回POST</returns>
public override string GetMethod()
{
return "POST";
}
public override Type GetBizContentClass()
{
return typeof(QueryContractOrderRequestV2Biz);
}
[DataContract]
public class QueryContractOrderRequestV2Biz : BizContent
{
/// <summary>
/// 机构编号 </summary>
[DataMember]
internal string org_id;
/// <summary>
/// 账单编号 </summary>
[DataMember]
internal string bill_id;
public string getOrgId()
{
return org_id;
}
public void setOrgId(string orgId)
{
this.org_id = orgId;
}
public string getBillId()
{
return bill_id;
}
public void setBillId(string billId)
{
this.bill_id = billId;
}
}
}
}
using System;
using System.Runtime.Serialization;
using Com.Bocom.OpenApi.Response;
using Com.Bocom.OpenApi.Security.KeyGen;
using Com.Bocom.OpenApi.Utils;
namespace Com.Bocom.OpenApi
{
namespace Request
{
public class ScfCreateUrlRequestV1 : BocomEncryptRequest<ScfCreateUrlResponseV1>
{
private string encryptType = BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4;
private string encryptKey = SM4KeyGen.GenSM4Key();
public override Type GetResponseClass()
{
return typeof(ScfCreateUrlResponseV1);
}
public override bool IsNeedEncrypt()
{
return true;
}
public override string GetMethod()
{
return "POST";
}
public override Type GetBizContentClass()
{
return typeof(ScfCreateUrlRequestV1Biz);
}
[DataContract]
public class ScfCreateUrlRequestV1Biz : BizContent
{
[DataMember]
public string com_no { get; set; }
}
public override string GetEncryptPolicy()
{
// TODO Auto-generated method stub
return "FIELD";
}
public override string GetEncryptType()
{
// TODO Auto-generated method stub
return encryptType;
}
public override string Encrypt(string data, string key, string encryptType)
{
string cipher;
try
{
cipher = BocomEncrypt.SymmetricalEncrypt(data, encryptType, key, BocomConstants.CHARSET_UTF8);
}
catch (Exception e)
{
throw new Exception("加密字符串[" + data + "]时遇到异常", e);
}
return cipher;
}
public override string GetEncryptKey()
{
return encryptKey;
}
}
}
}
\ No newline at end of file
using Com.Bocom.OpenApi;
using Kivii.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Com.Bocom.OpenApi.QueryContractOrderRequestV2;
namespace Com.Bocom.OpenApi
{
public class WriteOffResultRequestV2 : BocomRequest<WriteOffResultResponseV2>
{
/// <summary>
/// 获取响应类
/// </summary>
/// <returns>返回WriteOffResultResponseV2类对应的响应类类型</returns>
public override Type GetResponseClass()
{
return typeof(WriteOffResultResponseV2);
}
/// <summary>
/// 是否支持加密(目前sdk只支持对字段进行AES加解密)
/// </summary>
/// <returns>一般返回false</returns>
public override bool IsNeedEncrypt()
{
return false;
}
/// <summary>
/// http发起请求方式(支持GET、POST两种方式)
/// </summary>
/// <returns>一般返回POST</returns>
public override string GetMethod()
{
return "POST";
}
public override Type GetBizContentClass()
{
return typeof(WriteOffResultRequestV2Biz);
}
public class WriteOffResultRequestV2Biz : BizContent
{
/// <summary>
/// 机构编号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("org_id") private String orgId;
[Alias("org_id")]
public string orgId { get; set; }
/// <summary>
/// 子机构编号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("sub_org_id") private String subOrgId;
//internal string subOrgId;
[Alias("sub_org_id")]
public string subOrgId { get; set; }
/// <summary>
/// 核销日期 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_dte") private String writeOffDte;
//internal string writeOffDte;
[Alias("write_off_dte")]
public string writeOffDte { get; set; }
/// <summary>
/// 核销编号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_no") private String writeOffNo;
//internal string writeOffNo;
[Alias("write_off_no")]
public string writeOffNo { get; set; }
/// <summary>
/// 页数 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("pageablerequest_pagenum") private String pageablerequestPagenum;
//internal string pageablerequestPagenum;
[Alias("pageablerequest_pagenum")]
public string pageablerequestPagenum { get; set; }
/// <summary>
/// 每页显示数据数 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("pageablerequest_pagesize") private String pageablerequestPagesize;
//internal string pageablerequestPagesize;
[Alias("pageablerequest_pagesize")]
public string pageablerequestPagesize { get; set; }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Njzj.Bocoms.Openapis.Sdk.response
{
internal class AddContractOrderResponseV2
{
}
}
using System.Runtime.Serialization;
namespace Com.Bocom.OpenApi
{
namespace Response
{
[DataContract]
public class BJPTBlCustAccountQueryResponseV1 : BocomDecryptResponse
{
//(desc="备用1")
[DataMember]
public string field1 { get; set; }
//(desc="客户组织机构代码")
[DataMember]
public string cust_id_no { get; set; }
//(desc="客户平台编号")
[DataMember]
public string cust_erp_id { get; set; }
//(desc="借款人结算账户状态")
[DataMember]
public string balance_account_state { get; set; }
//(desc="备用2")
[DataMember]
public string field2 { get; set; }
public string ToString()
{
return "BJPTBlCustAccountQueryResponseV1 [field1=" + field1 + ", custIdno=" + cust_id_no +
", custErpid="
+ cust_erp_id + ", balanceAccountState=" + balance_account_state + ", field2=" + field2 + "]";
}
}
}
}
\ No newline at end of file
using System;
using System.Runtime.Serialization;
using System.IO;
using Com.Bocom.OpenApi.Security.Digest;
using Com.Bocom.OpenApi.Utils;
namespace Com.Bocom.OpenApi
{
namespace Response
{
[Serializable]
[DataContract]
public class FileDownloadResponseV1 : BocomResponse
{
private string filePath;
[DataMember]
public string file_name { get; set; }
[DataMember]
public string file_hashcode { get; set; }
public string GetFilePath()
{
return filePath;
}
public void SetFilePath(string filePath)
{
this.filePath = filePath;
}
public bool isSuccess()
{
if (!IsSuccess())
{
return false;
}
if (!filePath.EndsWith("/") || !filePath.EndsWith("\\"))
{
filePath = filePath + "/";
}
string tempFileName = file_name + ".TMP";
FileItem file = new FileItem(filePath + tempFileName);
try
{
string fileHashcode = SHA256Digest.Digest(filePath + this.file_name);
if (!fileHashcode.Equals(file_hashcode))
{
File.Delete(filePath + file_name);
throw new Exception("Bocom fileHashCode digest not passed.");
}
File.Delete(filePath + tempFileName);
return true;
}
catch (Exception e)
{
throw new Exception("文件重命名失败", e);
}
}
}
}
}
\ No newline at end of file
using System;
using System.Runtime.Serialization;
namespace Com.Bocom.OpenApi
{
namespace Response
{
[Serializable]
[DataContract]
public class FileUploadResponseV1 : BocomResponse
{
[DataMember]
public string document_id { get; set; }
}
}
}
\ No newline at end of file
using System;
using System.Runtime.Serialization;
namespace Com.Bocom.OpenApi
{
namespace Response
{
[Serializable]
[DataContract]
public class IntegralExchangeCheckResponseV1 : BocomResponse
{
//订单编号
[DataMember]
public string order_no { get; set; }
//兑换规则 =兑换金额:信用卡积分
[DataMember]
public string exchange_rules { get; set; }
//所用积分
[DataMember]
public string credit_card_points { get; set; }
//换领ISA积分
[DataMember]
public string isa_points { get; set; }
//交易时间
[DataMember]
public string date { get; set; }
//信用卡号
[DataMember]
public string card_no { get; set; }
//交行交易编号
[DataMember]
public string trade_no { get; set; }
//成功标志
[DataMember]
public string flag { get; set; }
public override string ToString()
{
return "order_no: " + order_no + " " + "exchange_rules: " + exchange_rules + " "
+ "credit_card_points: " + credit_card_points + " " + "isa_points: " + isa_points + " "
+ "card_no: " + card_no + " " + "date: " + date + " " + "trade_no: " + trade_no + " "
+ "flag: " + flag + " ";
}
}
}
}
\ No newline at end of file
using System;
using System.Runtime.Serialization;
namespace Com.Bocom.OpenApi
{
namespace Response
{
[Serializable]
[DataContract]
public class IntegralExchangeCreateUrlResponseV1 : BocomResponse
{
private string decryptKey;
/**
* @return the decrptKey
*/
public string GetDecryptKey()
{
return decryptKey;
}
/**
* @param decrptKey
* the decrptKey to set
*/
public void SetDecryptKey(string decryptKey)
{
this.decryptKey = decryptKey;
}
public string Decrypt(string data, string encryptType, string key, string charset)
{
return BocomEncrypt.SymmetricalDecrypt(data, encryptType, key, charset);
}
//H5页面地址
[DataMember]
public string url { get; set; }
public override string ToString()
{
return "url: " + url + " ";
}
}
}
}
\ No newline at end of file
using System;
using System.Runtime.Serialization;
namespace Com.Bocom.OpenApi
{
namespace Response
{
[Serializable]
[DataContract]
public class IntegralExchangeNotifyResponseV1 : BocomResponse
{
//订单编号
[DataMember]
public string order_no { get; set; }
//兑换规则 =兑换金额:信用卡积分
[DataMember]
public string exchange_rules { get; set; }
//所用积分
[DataMember]
public string credit_card_points { get; set; }
//换领ISA积分
[DataMember]
public string isa_points { get; set; }
//交易时间
[DataMember]
public string date { get; set; }
//成功标志
[DataMember]
public string flag { get; set; }
//信用卡号
[DataMember]
public string card_no { get; set; }
//交行交易编号
[DataMember]
public string trade_no { get; set; }
//回调地址url
[DataMember]
public string notify_url { get; set; }
//回调地址url
[DataMember]
public string protocol_no { get; set; }
public override string ToString()
{
return "order_no: " + order_no + " " + "exchange_rules: " + exchange_rules + " "
+ "credit_card_points: " + credit_card_points + " " + "isa_points: " + isa_points + " "
+ "card_no: " + card_no + " " + "date: " + date + " " + "flag: " + flag + " "
+ "trade_no: " + trade_no + " " + "notify_url: " + notify_url + " "
+ "protocol_no: " + protocol_no + " ";
}
}
}
}
\ No newline at end of file
using Kivii.DataAnnotations;
namespace Com.Bocom.OpenApi
{
public class QueryContractOrderResponseV2 : BocomResponse
{
/// <summary>
/// 账单编号 </summary>
[Alias("contorderdetaillist_billid")]
public string contorderdetaillist_billid { get; set; }
/// <summary>
/// 批次号 </summary>
[Alias("contorderdetaillist_batid")]
public string contorderdetaillist_batid { get; set; }
/// <summary>
/// 合同号 </summary>
[Alias("contorderdetaillist_contid")]
public string contorderdetaillist_contid;
/// <summary>
/// 机构编号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_orgid") private String contorderdetaillistOrgid;
//private string contorderdetaillistOrgid;
[Alias("contorderdetaillist_orgid")]
public string contorderdetaillist_orgid;
/// <summary>
/// 应付款人 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_oripayer") private String contorderdetaillistOripayer;
//private string contorderdetaillistOripayer;
[Alias("contorderdetaillist_oripayer")]
public string contorderdetaillist_oripayer;
/// <summary>
/// 应付款人账号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_oriac") private String contorderdetaillistOriac;
//private string contorderdetaillistOriac;
[Alias("contorderdetaillist_oriac")]
public string contorderdetaillist_oriac;
/// <summary>
/// 应付款人地址 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_oriaddr") private String contorderdetaillistOriaddr;
//private string contorderdetaillistOriaddr;
[Alias("contorderdetaillist_oriaddr")]
public string contorderdetaillist_oriaddr;
/// <summary>
/// 应付款人联系电话 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_oritelno") private String contorderdetaillistOritelno;
//private string contorderdetaillistOritelno;
[Alias("contorderdetaillist_oritelno")]
public string contorderdetaillist_oritelno;
/// <summary>
/// 应付款人其他信息1 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_oriotherinfo1") private String contorderdetaillistOriotherinfo1;
//private string contorderdetaillistOriotherinfo1;
[Alias("contorderdetaillist_oriotherinfo1")]
public string contorderdetaillist_oriotherinfo1;
/// <summary>
/// 应付款人其他信息2 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_oriotherinfo2") private String contorderdetaillistOriotherinfo2;
//private string contorderdetaillistOriotherinfo2;
[Alias("contorderdetaillist_oriotherinfo2")]
public string contorderdetaillist_oriotherinfo2;
/// <summary>
/// 应付款人其他信息3 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_oriotherinfo3") private String contorderdetaillistOriotherinfo3;
//private string contorderdetaillistOriotherinfo3;
[Alias("contorderdetaillist_oriotherinfo3")]
public string contorderdetaillist_oriotherinfo3;
/// <summary>
/// 费项名称 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_oriitmnme") private String contorderdetaillistOriitmnme;
//private string contorderdetaillistOriitmnme;
[Alias("contorderdetaillist_oriitmnme")]
public string contorderdetaillist_oriitmnme;
/// <summary>
/// 费项类型 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_oriitmtype") private String contorderdetaillistOriitmtype;
//private string contorderdetaillistOriitmtype;
[Alias("contorderdetaillist_oriitmtype")]
public string contorderdetaillist_oriitmtype;
/// <summary>
/// 应付金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_oriamt") private String contorderdetaillistOriamt;
//private string contorderdetaillistOriamt;
[Alias("contorderdetaillist_oriamt")]
public string contorderdetaillist_oriamt;
/// <summary>
/// 减免金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_orioffsetamt") private String contorderdetaillistOrioffsetamt;
//private string contorderdetaillistOrioffsetamt;
[Alias("contorderdetaillist_orioffsetamt")]
public string contorderdetaillist_orioffsetamt;
/// <summary>
/// 实际应付金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_oriactamt") private String contorderdetaillistOriactamt;
//private string contorderdetaillistOriactamt;
[Alias("contorderdetaillist_oriactamt")]
public string contorderdetaillist_oriactamt;
/// <summary>
/// 已付金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_paidamt") private String contorderdetaillistPaidamt;
//private string contorderdetaillistPaidamt;
[Alias("contorderdetaillist_paidamt")]
public string contorderdetaillist_paidamt;
/// <summary>
/// 附言码 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_attachcode") private String contorderdetaillistAttachcode;
//private string contorderdetaillistAttachcode;
[Alias("contorderdetaillist_attachcode")]
public string contorderdetaillist_attachcode;
/// <summary>
/// 补录方式
/// 01-现金;
/// 02-微信;
/// 03-支付宝;
/// 04-转账;
/// 05-支票;
/// 06-银承;
/// 07-商承;
/// 08-其他
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_addttype") private String contorderdetaillistAddttype;
//private string contorderdetaillistAddttype;
[Alias("contorderdetaillist_addttype")]
public string contorderdetaillist_addttype;
/// <summary>
/// 补录金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_addtamt") private String contorderdetaillistAddtamt;
//private string contorderdetaillistAddtamt;
[Alias("contorderdetaillist_addtamt")]
public string contorderdetaillist_addtamt;
/// <summary>
/// 补录日期 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_addtdat") private String contorderdetaillistAddtdat;
//private string contorderdetaillistAddtdat;
[Alias("contorderdetaillist_addtdat")]
public string contorderdetaillist_addtdat;
/// <summary>
/// 补录人 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_addtstaff") private String contorderdetaillistAddtstaff;
//private string contorderdetaillistAddtstaff;
[Alias("contorderdetaillist_addtstaff")]
public string contorderdetaillist_addtstaff;
/// <summary>
/// 创建日期 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_credte") private String contorderdetaillistCredte;
//private string contorderdetaillistCredte;
[Alias("contorderdetaillist_credte")]
public string contorderdetaillist_credte;
/// <summary>
/// 创建人 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_creusr") private String contorderdetaillistCreusr;
//private string contorderdetaillistCreusr;
[Alias("contorderdetaillist_creusr")]
public string contorderdetaillist_creusr;
/// <summary>
/// 备注 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_remark") private String contorderdetaillistRemark;
//private string contorderdetaillistRemark;
[Alias("contorderdetaillist_remark")]
public string contorderdetaillist_remark;
/// <summary>
/// 减免金额备注 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_offsetremark") private String contorderdetaillistOffsetremark;
//private string contorderdetaillistOffsetremark;
[Alias("contorderdetaillist_offsetremark")]
public string contorderdetaillist_offsetremark;
/// <summary>
/// 部门名称 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_dept") private String contorderdetaillistDept;
//private string contorderdetaillistDept;
[Alias("contorderdetaillist_dept")]
public string contorderdetaillist_dept;
/// <summary>
/// 核销状态
/// 01-已核销;
/// 02-核销待确认
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_writeoffstate") private String contorderdetaillistWriteoffstate;
//private string contorderdetaillistWriteoffstate;
[Alias("contorderdetaillist_writeoffstate")]
public string contorderdetaillist_writeoffstate;
/// <summary>
/// 核销方式
/// 01-现金;
/// 02-微信;
/// 03-支付宝;
/// 04-转账;
/// 05-支票;
/// 06-银承;
/// 07-商承;
/// 08-其他
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_writeofftype") private String contorderdetaillistWriteofftype;
//private string contorderdetaillistWriteofftype;
[Alias("contorderdetaillist_writeofftype")]
public string contorderdetaillist_writeofftype;
/// <summary>
/// 核销日期 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_writeoffdte") private String contorderdetaillistWriteoffdte;
//private string contorderdetaillistWriteoffdte;
[Alias("contorderdetaillist_writeoffdte")]
public string contorderdetaillist_writeoffdte;
/// <summary>
/// 核销金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_writeoffamt") private String contorderdetaillistWriteoffamt;
//private string contorderdetaillistWriteoffamt;
[Alias("contorderdetaillist_writeoffamt")]
public string contorderdetaillist_writeoffamt;
/// <summary>
/// 账期 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_paymentperiod") private String contorderdetaillistPaymentperiod;
//private string contorderdetaillistPaymentperiod;
[Alias("contorderdetaillist_paymentperiod")]
public string contorderdetaillist_paymentperiod;
/// <summary>
/// 核销提醒手机号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_phonenum") private String contorderdetaillistPhonenum;
//private string contorderdetaillistPhonenum;
[Alias("contorderdetaillist_phonenum")]
public string contorderdetaillist_phonenum;
/// <summary>
/// 框架性协议类型
/// -1: 非框架性协议;
/// 1: 非足额自动部分核销协议
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_agreementtype") private String contorderdetaillistAgreementtype;
//private string contorderdetaillistAgreementtype;
[Alias("contorderdetaillist_agreementtype")]
public string contorderdetaillist_agreementtype;
/// <summary>
/// 账单核销状态
/// 01-未核销;
/// 02-部分核销;
/// 03-全额核销;
/// 04-失效
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_billwostate") private String contorderdetaillistBillwostate;
//private string contorderdetaillistBillwostate;
[Alias("contorderdetaillist_billwostate")]
public string contorderdetaillist_billwostate;
/// <summary>
/// 操作结果
/// F-失败;
/// S-成功
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_oprresult") private String contorderdetaillistOprresult;
//private string contorderdetaillistOprresult;
[Alias("contorderdetaillist_oprresult")]
public string contorderdetaillist_oprresult;
/// <summary>
/// 失败原因 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("contorderdetaillist_failreason") private String contorderdetaillistFailreason;
//private string contorderdetaillistFailreason;
[Alias("contorderdetaillist_failreason")]
public string contorderdetaillist_failreason;
}
}
using System;
using System.Runtime.Serialization;
namespace Com.Bocom.OpenApi
{
namespace Response
{
[Serializable]
[DataContract]
public class ScfCreateUrlResponseV1 : BocomDecryptResponse
{
/** 二维码 **/
[DataMember]
public string url { get; set; }
public string ToString()
{
return "ScfCreateUrlResponseV1 [url=" + url + "]";
}
}
}
}
\ No newline at end of file
using Com.Bocom.OpenApi;
using Kivii.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Com.Bocom.OpenApi
{
public class WriteOffResultResponseV2 : BocomResponse
{
/// <summary>
/// 总记录数 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("pageableresponse_totalelements") private String pageableresponseTotalelements;
//private string pageableresponseTotalelements;
[Alias("pageableresponse_totalelements")]
public string pageableresponseTotalelements { get; set; }
/// <summary>
/// 总页数 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("pageableresponse_totalpages") private String pageableresponseTotalpages;
//private string pageableresponseTotalpages;
[Alias("pageableresponse_totalpages")]
public string pageableresponseTotalpages { get; set; }
/// <summary>
/// "" </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_record_list") private java.util.List<WriteOffRecord> writeOffRecordList;
//private IList<WriteOffRecord> writeOffRecordList;
[Alias("write_off_record_list")]
public List<WriteOffRecord> writeOffRecordList { get; set; }
public class WriteOffRecord
{
/// <summary>
/// 核销编号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_id") private String writeOffId;
//internal string writeOffId;
[Alias("write_off_id")]
public string writeOffId { get; set; }
/// <summary>
/// 核销订单号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_ode_no") private String writeOffOdeNo;
//internal string writeOffOdeNo;
[Alias("write_off_ode_no")]
public string writeOffOdeNo { get; set; }
/// <summary>
/// 核销订单流水编号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_bill_jnl_id") private String writeOffBillJnlId;
//internal string writeOffBillJnlId;
[Alias("write_off_bill_jnl_id")]
public string writeOffBillJnlId { get; set; }
/// <summary>
/// 账单流水类型
/// 00-都已核销;
/// 01订单已核销;
/// 02-流水已核销
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("bill_jnl_typ") private String billJnlTyp;
//internal string billJnlTyp;
[Alias("bill_jnl_typ")]
public string billJnlTyp { get; set; }
/// <summary>
/// 核销金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_amt") private String writeOffAmt;
//internal string writeOffAmt;
[Alias("write_off_amt")]
public string writeOffAmt { get; set; }
/// <summary>
/// 核销状态
/// 01-已核销;
/// 02-核销待确认
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_state") private String writeOffState;
//internal string writeOffState;
[Alias("write_off_state")]
public string writeOffState { get; set; }
/// <summary>
/// 核销方式
/// 01-自动核销;
/// 02-手动核销;
/// 03-半自动核销;
/// 04-补录核销
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_type") private String writeOffType;
//internal string writeOffType;
[Alias("write_off_type")]
public string writeOffType { get; set; }
/// <summary>
/// 核销日期 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_dte") private String writeOffDte;
//internal string writeOffDte;
[Alias("write_off_dte")]
public string writeOffDte { get; set; }
/// <summary>
/// 核销人员 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_staff") private String writeOffStaff;
//internal string writeOffStaff;
[Alias("write_off_staff")]
public string writeOffStaff { get; set; }
/// <summary>
/// 核销编号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_no") private String writeOffNo;
//internal string writeOffNo;
[Alias("write_off_no")]
public string writeOffNo { get; set; }
/// <summary>
/// 核销种类
/// 01-流水核销;
/// 02-补录核销
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_kind") private String writeOffKind;
//internal string writeOffKind;
[Alias("write_off_kind")]
public string writeOffKind { get; set; }
/// <summary>
/// 补录ID </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_addt_id") private String writeOffAddtId;
//internal string writeOffAddtId;
[Alias("write_off_addt_id")]
public string writeOffAddtId { get; set; }
/// <summary>
/// "" </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("cont_order_detail_list") private java.util.List<ContOrderDetail> contOrderDetailList;
//internal IList<ContOrderDetail> contOrderDetailList;
[Alias("cont_order_detail_list")]
public List<ContOrderDetail> contOrderDetailList { get; set; }
public class ContOrderDetail
{
/// <summary>
/// 账单编号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("bill_id") private String billId;
//internal string billId;
[Alias("bill_id")]
public string billId { get; set; }
/// <summary>
/// 批次号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("bat_id") private String batId;
//internal string batId;
[Alias("bat_id")]
public string batId { get; set; }
/// <summary>
/// 合同号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("cont_id") private String contId;
//internal string contId;
[Alias("cont_id")]
public string contId { get; set; }
/// <summary>
/// 机构编号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("org_id") private String orgId;
//internal string orgId;
[Alias("org_id")]
public string orgId { get; set; }
/// <summary>
/// 应付款人 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ori_payer") private String oriPayer;
//internal string oriPayer;
[Alias("ori_payer")]
public string oriPayer { get; set; }
/// <summary>
/// 应付款人账号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ori_ac") private String oriAc;
//internal string oriAc;
[Alias("ori_ac")]
public string oriAc { get; set; }
/// <summary>
/// 应付款人地址 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ori_addr") private String oriAddr;
//internal string oriAddr;
[Alias("ori_addr")]
public string oriAddr { get; set; }
/// <summary>
/// 应付款人联系电话 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ori_tel_no") private String oriTelNo;
//internal string oriTelNo;
[Alias("ori_tel_no")]
public string oriTelNo { get; set; }
/// <summary>
/// 应付款人其他信息1 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ori_other_info1") private String oriOtherInfo1;
//internal string oriOtherInfo1;
[Alias("ori_other_info1")]
public string oriOtherInfo1 { get; set; }
/// <summary>
/// 应付款人其他信息2 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ori_other_info2") private String oriOtherInfo2;
//internal string oriOtherInfo2;
[Alias("ori_other_info2")]
public string oriOtherInfo2 { get; set; }
/// <summary>
/// 应付款人其他信息3 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ori_other_info3") private String oriOtherInfo3;
//internal string oriOtherInfo3;
[Alias("ori_other_info3")]
public string oriOtherInfo3 { get; set; }
/// <summary>
/// 费项名称 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ori_itm_nme") private String oriItmNme;
//internal string oriItmNme;
[Alias("ori_itm_nme")]
public string oriItmNme { get; set; }
/// <summary>
/// 费项类型 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ori_itm_type") private String oriItmType;
//internal string oriItmType;
[Alias("ori_itm_type")]
public string oriItmType { get; set; }
/// <summary>
/// 应付金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ori_amt") private String oriAmt;
//internal string oriAmt;
[Alias("ori_amt")]
public string oriAmt { get; set; }
/// <summary>
/// 减免金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ori_offset_amt") private String oriOffsetAmt;
//internal string oriOffsetAmt;
[Alias("ori_offset_amt")]
public string oriOffsetAmt { get; set; }
/// <summary>
/// 实际应付金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ori_act_amt") private String oriActAmt;
//internal string oriActAmt;
[Alias("ori_act_amt")]
public string oriActAmt { get; set; }
/// <summary>
/// 已付金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("paid_amt") private String paidAmt;
//internal string paidAmt;
[Alias("paid_amt")]
public string paidAmt { get; set; }
/// <summary>
/// 附言码 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("attach_code") private String attachCode;
[Alias("attach_code")]
public string attachCode { get; set; }
/// <summary>
/// 补录方式
/// 01-现金;
/// 02-微信;
/// 03-支付宝;
/// 04-转账;
/// 05-支票;
/// 06-银承;
/// 07-商承;
/// 08-其他
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("addt_type") private String addtType;
//internal string addtType;
[Alias("addt_type")]
public string addtType { get; set; }
/// <summary>
/// 补录金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("addt_amt") private String addtAmt;
//internal string addtAmt;
[Alias("addt_amt")]
public string addtAmt { get; set; }
/// <summary>
/// 补录日期 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("addt_dat") private String addtDat;
//internal string addtDat;
[Alias("addt_dat")]
public string addtDat { get; set; }
/// <summary>
/// 补录人 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("addt_staff") private String addtStaff;
//internal string addtStaff;
[Alias("addt_staff")]
public string addtStaff { get; set; }
/// <summary>
/// 创建日期 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("cre_dte") private String creDte;
//internal string creDte;
[Alias("cre_dte")]
public string creDte { get; set; }
/// <summary>
/// 创建人 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("cre_usr") private String creUsr;
//internal string creUsr;
[Alias("cre_usr")]
public string creUsr { get; set; }
/// <summary>
/// 备注 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("remark") private String remark;
//internal string remark;
[Alias("remark")]
public string remark { get; set; }
/// <summary>
/// 减免金额备注 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("offset_remark") private String offsetRemark;
//internal string offsetRemark;
[Alias("offset_remark")]
public string offsetRemark { get; set; }
/// <summary>
/// 部门名称 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("dept") private String dept;
//internal string dept;
[Alias("dept")]
public string dept { get; set; }
/// <summary>
/// 核销状态
/// 01-已核销;
/// 02-核销待确认
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_state") private String writeOffState;
//internal string writeOffState;
[Alias("write_off_state")]
public string writeOffState { get; set; }
/// <summary>
/// 核销方式
/// 01-自动核销;
/// 02-手动核销;
/// 03-半自动核销;
/// 04-补录核销
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_type") private String writeOffType;
//internal string writeOffType;
[Alias("write_off_type")]
public string writeOffType { get; set; }
/// <summary>
/// 核销日期 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_dte") private String writeOffDte;
//internal string writeOffDte;
[Alias("write_off_dte")]
public string writeOffDte { get; set; }
/// <summary>
/// 核销金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("write_off_amt") private String writeOffAmt;
//internal string writeOffAmt;
[Alias("write_off_amt")]
public string writeOffAmt { get; set; }
/// <summary>
/// 账期 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("payment_period") private String paymentPeriod;
//internal string paymentPeriod;
[Alias("payment_period")]
public string paymentPeriod { get; set; }
/// <summary>
/// 核销提醒手机号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("phone_num") private String phoneNum;
//internal string phoneNum;
[Alias("phone_num")]
public string phoneNum { get; set; }
/// <summary>
/// 框架性协议类型
/// -1: 非框架性协议;
/// 1: 非足额自动部分核销协议
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("agreement_type") private String agreementType;
//internal string agreementType;
[Alias("agreement_type")]
public string agreementType { get; set; }
/// <summary>
/// 账单核销状态
/// 01-未核销;
/// 02-部分核销;
/// 03-全额核销;
/// 04-失效
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("bill_wo_state") private String billWoState;
//internal string billWoState;
[Alias("bill_wo_state")]
public string billWoState { get; set; }
/// <summary>
/// 操作结果
/// F-失败;
/// S-成功
/// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("opr_result") private String oprResult;
//internal string oprResult;
[Alias("opr_result")]
public string oprResult { get; set; }
/// <summary>
/// 失败原因 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("fail_reason") private String failReason;
//internal string failReason;
[Alias("fail_reason")]
public string failReason { get; set; }
} //* ""
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("pay_detail_list") private java.util.List<PayDetail> payDetailList;
//internal IList<PayDetail> payDetailList;
[Alias("pay_detail_list")]
public List<PayDetail> payDetailList { get; set; }
public class PayDetail
{
/// <summary>
/// 客户账号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("cus_ac") private String cusAc;
//internal string cusAc;
[Alias("cus_ac")]
public string cusAc { get; set; }
/// <summary>
/// 账户名称 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ac_nme") private String acNme;
//internal string acNme;
[Alias("ac_nme")]
public string acNme { get; set; }
/// <summary>
/// 会计日期 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ac_dte") private String acDte;
//internal string acDte;
[Alias("ac_dte")]
public string acDte { get; set; }
/// <summary>
/// 交易时间 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("tr_time") private String trTime;
//internal string trTime;
[Alias("tr_time")]
public string trTime { get; set; }
/// <summary>
/// 交易码 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("tr_code") private String trCode;
//internal string trCode;
[Alias("tr_code")]
public string trCode
{ get; set; }
/// <summary>
/// 交易金额 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("txn_amt") private String txnAmt;
//internal string txnAmt;
[Alias("txn_amt")]
public string txnAmt
{ get; set; }
/// <summary>
/// 币种 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("ccy") private String ccy;
//internal string ccy;
[Alias("ccy")]
public string ccy
{ get; set; }
/// <summary>
/// 借贷标志 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("dc_flg") private String dcFlg;
//internal string dcFlg;
[Alias("dc_flg")]
public string dcFlg
{ get; set; }
/// <summary>
/// 对方户名 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("opp_ac_nme") private String oppAcNme;
//internal string oppAcNme;
[Alias("opp_ac_nme")]
public string oppAcNme
{ get; set; }
/// <summary>
/// 会计传票号 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("vch_no") private String vchNo;
//internal string vchNo;
[Alias("vch_no")]
public string vchNo
{ get; set; }
/// <summary>
/// 业务摘要码 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("rmk_cde") private String rmkCde;
//internal string rmkCde;
[Alias("rmk_cde")]
public string rmkCde
{ get; set; }
/// <summary>
/// 传票业务摘要区 </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @JsonProperty("vch_bus_rmk") private String vchBusRmk;
//internal string vchBusRmk;
[Alias("vch_bus_rmk")]
public string vchBusRmk
{ get; set; }
}
}
}
}
using System;
using System.Linq;
using System.IO;
using System.Text;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Crypto.Paddings;
using Org.BouncyCastle.Crypto.Modes;
using Org.BouncyCastle.Crypto.Engines;
namespace Com.Bocom.OpenApi
{
namespace Security
{
namespace Crypt
{
public class AESCryptor
{
/**
* @param sourceContent
* @param cryptKey
* @param charset
* @return
*/
public static string Encrypt(string sourceContent, string cryptKey, string charset)
{
Console.WriteLine(cryptKey);
Console.WriteLine(cryptKey.Length);
KeyParameter kp = new KeyParameter(Convert.FromBase64String(cryptKey));
byte[] bytes;
bytes = Encoding.GetEncoding(charset).GetBytes(sourceContent);
CbcBlockCipher aes = new CbcBlockCipher(new AesEngine());
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(aes, new Pkcs7Padding());
cipher.Init(true, kp);
byte[] output = new byte[cipher.GetOutputSize(bytes.Length)];
int len = cipher.ProcessBytes(bytes, 0, bytes.Length, output, 0);
cipher.DoFinal(output, len);
return Convert.ToBase64String(output);
}
/**
* @param content
* @param aesKey
* @return
*/
public static byte[] Encrypt(byte[] content, string aesKey, string charset)
{
KeyParameter kp = new KeyParameter(Convert.FromBase64String(aesKey));
CbcBlockCipher aes = new CbcBlockCipher(new AesEngine());
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(aes, new Pkcs7Padding());
cipher.Init(true, kp);
byte[] output = new byte[cipher.GetOutputSize(content.Length)];
int len = cipher.ProcessBytes(content, 0, content.Length, output, 0);
cipher.DoFinal(output, len);
return Encoding.GetEncoding(charset).GetBytes(Convert.ToBase64String(output));
}
/**
* @param encryptContent
* @param cryptKey
* @param charset
* @return
*/
public static string Decrypt(string encryptContent, string cryptKey, string charset)
{
try
{
KeyParameter kp = new KeyParameter(Convert.FromBase64String(cryptKey));
Console.WriteLine("encryptContent : " + encryptContent);
byte[] bytes = Convert.FromBase64String(encryptContent);
CbcBlockCipher aes = new CbcBlockCipher(new AesEngine());
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(aes, new Pkcs7Padding());
cipher.Init(false, kp);
byte[] output = new byte[cipher.GetOutputSize(bytes.Length)];
int len = cipher.ProcessBytes(bytes, 0, bytes.Length, output, 0);
int len2;
len2 = cipher.DoFinal(output, len);
byte[] rawData = new byte[len + len2];
Array.Copy(output, 0, rawData, 0, rawData.Length);
string plainData = Encoding.UTF8.GetString(rawData, 0, rawData.Length);
return plainData;
}
catch (Exception e)
{
throw e;
}
}
/**
* @param content
* @param aesKey
* @param charset
* @return
*/
public static byte[] Decrypt(byte[] content, string aesKey, string charset)
{
try
{
KeyParameter kp = new KeyParameter(Convert.FromBase64String(aesKey));
CbcBlockCipher aes = new CbcBlockCipher(new AesEngine());
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(aes, new Pkcs7Padding());
cipher.Init(false, kp);
byte[] output = new byte[cipher.GetOutputSize(content.Length)];
int len = cipher.ProcessBytes(content, 0, content.Length, output, 0);
int len2;
len2 = cipher.DoFinal(output, len);
byte[] rawData = new byte[len + len2];
rawData = (byte[]) output.Take(rawData.Length);
string plainData = Encoding.UTF8.GetString(rawData, 0, rawData.Length);
return Encoding.GetEncoding(charset).GetBytes(plainData);
}
catch (Exception e)
{
Console.WriteLine("解密错误,错误信息为:" + e.Message);
}
return null;
}
/**
* @param in
* @param cryptKey
* @return
*/
public static byte[] EncryptFile(Stream fi, string cryptKey)
{
KeyParameter kp = new KeyParameter(Convert.FromBase64String(cryptKey));
byte[] bytes = ToByteArray(fi);
CbcBlockCipher aes = new CbcBlockCipher(new AesEngine());
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(aes, new Pkcs7Padding());
cipher.Init(true, kp);
byte[] output = new byte[cipher.GetOutputSize(bytes.Length)];
int len = cipher.ProcessBytes(bytes, 0, bytes.Length, output, 0);
cipher.DoFinal(output, len);
fi.Close();
return output;
}
public static byte[] DecryptFile(Stream fi, string cryptKey)
{
KeyParameter kp = new KeyParameter(Convert.FromBase64String(cryptKey));
byte[] bytes = ToByteArray(fi);
CbcBlockCipher aes = new CbcBlockCipher(new AesEngine());
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(aes, new Pkcs7Padding());
cipher.Init(false, kp);
byte[] output = new byte[cipher.GetOutputSize(bytes.Length)];
int len = cipher.ProcessBytes(bytes, 0, bytes.Length, output, 0);
int len2 = cipher.DoFinal(output, len);
byte[] rawData = new byte[len + len2];
Array.Copy(output, 0, rawData, 0, rawData.Length);
return rawData;
}
private static byte[] ToByteArray(Stream stream)
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
stream.Seek(0, SeekOrigin.Begin);
stream.Close();
return bytes;
}
}
}
}
}
\ No newline at end of file
using System;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using Com.Bocom.OpenApi.Security.Sign;
namespace Com.Bocom.OpenApi
{
namespace Security
{
namespace Crypt
{
public class RSACryptor
{
/// <summary>
/// 类名:RSAFromPkcs8
/// 功能:RSA加密、解密、签名、验签
/// 详细:该类对Java生成的密钥进行解密和签名以及验签专用类,不需要修改
/// 版本:3.0
/// 日期:2013-07-08
/// 说明:
/// 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
/// </summary>
public sealed class RSAFromPkcs8
{
/// <summary>
/// 签名(SHA256)
/// </summary>
/// <param name="content">待签名字符串</param>
/// <param name="privateKey">私钥</param>
/// <param name="charset">编码格式</param>
/// <returns>签名后字符串</returns>
public static string SignWithRSASHA256(string content, string privateKey, string charset)
{
byte[] Data = Encoding.GetEncoding(charset).GetBytes(content);
RSACryptoServiceProvider rsa = DecodePemPrivateKey(privateKey);
SHA256CryptoServiceProvider sh = new SHA256CryptoServiceProvider();
byte[] signData = rsa.SignData(Data, "SHA256");
return Convert.ToBase64String(signData);
}
/// <summary>
/// 验签
/// </summary>
/// <param name="content">待验签字符串</param>
/// <param name="signedString">签名</param>
/// <param name="publicKey">公钥</param>
/// <param name="input_charset">编码格式</param>
/// <returns>true(通过),false(不通过)</returns>
public static bool VerifySHA256(string content, string signedString, string publicKey,
string input_charset)
{
bool result;
byte[] Data = Encoding.GetEncoding(input_charset).GetBytes(content);
byte[] data = Convert.FromBase64String(signedString);
RSACryptoServiceProvider rsaPub = DecodePemPublicKey(publicKey);
//RSACryptoServiceProvider rsaPub = new RSACryptoServiceProvider();
//RSAParameters paraPub = ConvertFromPublicKey(publicKey);
//rsaPub.ImportParameters(paraPub);
SHA256CryptoServiceProvider sh = new SHA256CryptoServiceProvider();
result = rsaPub.VerifyData(Data, "SHA256", data);
return result;
}
/// <summary>
/// 加密
/// </summary>
/// <param name="resData">需要加密的字符串</param>
/// <param name="publicKey">公钥</param>
/// <param name="input_charset">编码格式</param>
/// <returns>明文</returns>
public string EncryptData(string content, string encryptKey, string charset)
{
RSACryptoServiceProvider rsa = DecodePemPublicKey(encryptKey);
byte[] cipherBytes = rsa.Encrypt(Encoding.GetEncoding(charset).GetBytes(content), false);
return Convert.ToBase64String(cipherBytes);
}
/// <summary>
/// 解密
/// </summary>
/// <param name="resData">加密字符串</param>
/// <param name="privateKey">私钥</param>
/// <param name="input_charset">编码格式</param>
/// <returns>明文</returns>//content, encryptKey, charset
public string DecryptData(string content, string encryptKey, string charset)
{
RSACryptoServiceProvider rsa = DecodePemPrivateKey(encryptKey);
byte[] cipherBytes = rsa.Decrypt(Convert.FromBase64String(content), false);
return Encoding.GetEncoding(charset).GetString(cipherBytes);
}
#region 内部方法
private static string encrypt(byte[] data, string publicKey, string input_charset)
{
RSACryptoServiceProvider rsa = DecodePemPublicKey(publicKey);
SHA1 sh = new SHA1CryptoServiceProvider();
byte[] result = rsa.Encrypt(data, false);
return Convert.ToBase64String(result);
}
private static string decrypt(byte[] data, string privateKey, string input_charset)
{
string result = "";
RSACryptoServiceProvider rsa = DecodePemPrivateKey(privateKey);
SHA1 sh = new SHA1CryptoServiceProvider();
byte[] source = rsa.Decrypt(data, false);
char[] asciiChars =
new char[Encoding.GetEncoding(input_charset).GetCharCount(source, 0, source.Length)];
Encoding.GetEncoding(input_charset).GetChars(source, 0, source.Length, asciiChars, 0);
result = new string(asciiChars);
//result = ASCIIEncoding.ASCII.GetString(source);
return result;
}
private static RSACryptoServiceProvider DecodePemPublicKey(string pemstr)
{
byte[] pkcs8publickkey;
pkcs8publickkey = Convert.FromBase64String(pemstr);
if (pkcs8publickkey != null)
{
RSACryptoServiceProvider rsa = DecodeRSAPublicKey(pkcs8publickkey);
return rsa;
}
return null;
}
private static RSACryptoServiceProvider DecodePemPrivateKey(string pemstr)
{
byte[] pkcs8privatekey;
pkcs8privatekey = Convert.FromBase64String(pemstr);
if (pkcs8privatekey != null)
{
RSACryptoServiceProvider rsa = DecodePrivateKeyInfo(pkcs8privatekey);
return rsa;
}
return null;
}
private static RSACryptoServiceProvider DecodePrivateKeyInfo(byte[] pkcs8)
{
byte[] SeqOID =
{0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00};
byte[] seq = new byte[15];
MemoryStream mem = new MemoryStream(pkcs8);
int lenstream = (int) mem.Length;
BinaryReader
binr = new BinaryReader(mem); //wrap Memory Stream with BinaryReader for easy reading
byte bt;
ushort twobytes;
try
{
twobytes = binr.ReadUInt16();
if (twobytes == 0x8130
) //data read as little endian order (actual data order for Sequence is 30 81)
binr.ReadByte(); //advance 1 byte
else if (twobytes == 0x8230)
binr.ReadInt16(); //advance 2 bytes
else
return null;
bt = binr.ReadByte();
if (bt != 0x02)
return null;
twobytes = binr.ReadUInt16();
if (twobytes != 0x0001)
return null;
seq = binr.ReadBytes(15); //read the Sequence OID
if (!CompareBytearrays(seq, SeqOID)) //make sure Sequence for OID is correct
return null;
bt = binr.ReadByte();
if (bt != 0x04) //expect an Octet string
return null;
bt = binr
.ReadByte(); //read next byte, or next 2 bytes is 0x81 or 0x82; otherwise bt is the byte count
if (bt == 0x81)
binr.ReadByte();
else if (bt == 0x82)
binr.ReadUInt16();
//------ at this stage, the remaining sequence should be the RSA private key
byte[] rsaprivkey = binr.ReadBytes((int) (lenstream - mem.Position));
RSACryptoServiceProvider rsacsp = DecodeRSAPrivateKey(rsaprivkey);
return rsacsp;
}
catch (Exception)
{
return null;
}
finally
{
binr.Close();
}
}
private static bool CompareBytearrays(byte[] a, byte[] b)
{
if (a.Length != b.Length)
return false;
int i = 0;
foreach (byte c in a)
{
if (c != b[i])
return false;
i++;
}
return true;
}
private static RSACryptoServiceProvider DecodeRSAPublicKey(byte[] publickey)
{
// encoded OID sequence for PKCS #1 rsaEncryption szOID_RSA_RSA = "1.2.840.113549.1.1.1"
byte[] SeqOID =
{0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00};
byte[] seq = new byte[15];
// --------- Set up stream to read the asn.1 encoded SubjectPublicKeyInfo blob ------
MemoryStream mem = new MemoryStream(publickey);
BinaryReader
binr = new BinaryReader(mem); //wrap Memory Stream with BinaryReader for easy reading
byte bt;
ushort twobytes;
try
{
twobytes = binr.ReadUInt16();
if (twobytes == 0x8130
) //data read as little endian order (actual data order for Sequence is 30 81)
binr.ReadByte(); //advance 1 byte
else if (twobytes == 0x8230)
binr.ReadInt16(); //advance 2 bytes
else
return null;
seq = binr.ReadBytes(15); //read the Sequence OID
if (!CompareBytearrays(seq, SeqOID)) //make sure Sequence for OID is correct
return null;
twobytes = binr.ReadUInt16();
if (twobytes == 0x8103
) //data read as little endian order (actual data order for Bit string is 03 81)
binr.ReadByte(); //advance 1 byte
else if (twobytes == 0x8203)
binr.ReadInt16(); //advance 2 bytes
else
return null;
bt = binr.ReadByte();
if (bt != 0x00) //expect null byte next
return null;
twobytes = binr.ReadUInt16();
if (twobytes == 0x8130
) //data read as little endian order (actual data order for Sequence is 30 81)
binr.ReadByte(); //advance 1 byte
else if (twobytes == 0x8230)
binr.ReadInt16(); //advance 2 bytes
else
return null;
twobytes = binr.ReadUInt16();
byte lowbyte = 0x00;
byte highbyte = 0x00;
if (twobytes == 0x8102
) //data read as little endian order (actual data order for Integer is 02 81)
lowbyte = binr.ReadByte(); // read next bytes which is bytes in modulus
else if (twobytes == 0x8202)
{
highbyte = binr.ReadByte(); //advance 2 bytes
lowbyte = binr.ReadByte();
}
else
return null;
byte[] modint =
{
lowbyte, highbyte, 0x00, 0x00
}; //reverse byte order since asn.1 key uses big endian order
int modsize = BitConverter.ToInt32(modint, 0);
byte firstbyte = binr.ReadByte();
binr.BaseStream.Seek(-1, SeekOrigin.Current);
if (firstbyte == 0x00)
{
//if first byte (highest order) of modulus is zero, don't include it
binr.ReadByte(); //skip this null byte
modsize -= 1; //reduce modulus buffer size by 1
}
byte[] modulus = binr.ReadBytes(modsize); //read the modulus bytes
if (binr.ReadByte() != 0x02) //expect an Integer for the exponent data
return null;
int expbytes =
(int) binr
.ReadByte(); // should only need one byte for actual exponent data (for all useful values)
byte[] exponent = binr.ReadBytes(expbytes);
// ------- create RSACryptoServiceProvider instance and initialize with public key -----
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters RSAKeyInfo = new RSAParameters();
RSAKeyInfo.Modulus = modulus;
RSAKeyInfo.Exponent = exponent;
RSA.ImportParameters(RSAKeyInfo);
return RSA;
}
catch (Exception)
{
return null;
}
finally
{
binr.Close();
}
}
private static RSACryptoServiceProvider DecodeRSAPrivateKey(byte[] privkey)
{
byte[] MODULUS, E, D, P, Q, DP, DQ, IQ;
// --------- Set up stream to decode the asn.1 encoded RSA private key ------
MemoryStream mem = new MemoryStream(privkey);
BinaryReader
binr = new BinaryReader(mem); //wrap Memory Stream with BinaryReader for easy reading
byte bt;
ushort twobytes;
int elems;
try
{
twobytes = binr.ReadUInt16();
if (twobytes == 0x8130
) //data read as little endian order (actual data order for Sequence is 30 81)
binr.ReadByte(); //advance 1 byte
else if (twobytes == 0x8230)
binr.ReadInt16(); //advance 2 bytes
else
return null;
twobytes = binr.ReadUInt16();
if (twobytes != 0x0102) //version number
return null;
bt = binr.ReadByte();
if (bt != 0x00)
return null;
//------ all private key components are Integer sequences ----
elems = GetIntegerSize(binr);
MODULUS = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
E = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
D = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
P = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
Q = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
DP = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
DQ = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
IQ = binr.ReadBytes(elems);
// ------- create RSACryptoServiceProvider instance and initialize with public key -----
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters RSAparams = new RSAParameters();
RSAparams.Modulus = MODULUS;
RSAparams.Exponent = E;
RSAparams.D = D;
RSAparams.P = P;
RSAparams.Q = Q;
RSAparams.DP = DP;
RSAparams.DQ = DQ;
RSAparams.InverseQ = IQ;
RSA.ImportParameters(RSAparams);
return RSA;
}
catch (Exception)
{
return null;
}
finally
{
binr.Close();
}
}
private static int GetIntegerSize(BinaryReader binr)
{
byte bt;
byte lowbyte;
byte highbyte;
int count;
bt = binr.ReadByte();
if (bt != 0x02) //expect integer
return 0;
bt = binr.ReadByte();
if (bt == 0x81)
count = binr.ReadByte(); // data size in next byte
else if (bt == 0x82)
{
highbyte = binr.ReadByte(); // data size in next 2 bytes
lowbyte = binr.ReadByte();
byte[] modint = {lowbyte, highbyte, 0x00, 0x00};
count = BitConverter.ToInt32(modint, 0);
}
else
{
count = bt; // we already have the data size
}
while (binr.ReadByte() == 0x00)
{
//remove high order zeros in data
count -= 1;
}
binr.BaseStream.Seek(-1,
SeekOrigin.Current); //last ReadByte wasn't a removed zero, so back up a byte
return count;
}
#endregion
#region 解析.net 生成的Pem
private static RSAParameters ConvertFromPublicKey(string pemFileConent)
{
byte[] keyData = Convert.FromBase64String(pemFileConent);
if (keyData.Length < 162)
{
throw new ArgumentException("pem file content is incorrect.");
}
byte[] pemModulus = new byte[128];
byte[] pemPublicExponent = new byte[3];
Array.Copy(keyData, 29, pemModulus, 0, 128);
Array.Copy(keyData, 159, pemPublicExponent, 0, 3);
RSAParameters para = new RSAParameters();
para.Modulus = pemModulus;
para.Exponent = pemPublicExponent;
return para;
}
private static RSAParameters ConvertFromPrivateKey(string pemFileConent)
{
byte[] keyData = Convert.FromBase64String(pemFileConent);
if (keyData.Length < 609)
{
throw new ArgumentException("pem file content is incorrect.");
}
int index = 11;
byte[] pemModulus = new byte[128];
Array.Copy(keyData, index, pemModulus, 0, 128);
index += 128;
index += 2; //141
byte[] pemPublicExponent = new byte[3];
Array.Copy(keyData, index, pemPublicExponent, 0, 3);
index += 3;
index += 4; //148
byte[] pemPrivateExponent = new byte[128];
Array.Copy(keyData, index, pemPrivateExponent, 0, 128);
index += 128;
index += ((int) keyData[index + 1] == 64 ? 2 : 3); //279
byte[] pemPrime1 = new byte[64];
Array.Copy(keyData, index, pemPrime1, 0, 64);
index += 64;
index += ((int) keyData[index + 1] == 64 ? 2 : 3); //346
byte[] pemPrime2 = new byte[64];
Array.Copy(keyData, index, pemPrime2, 0, 64);
index += 64;
index += ((int) keyData[index + 1] == 64 ? 2 : 3); //412/413
byte[] pemExponent1 = new byte[64];
Array.Copy(keyData, index, pemExponent1, 0, 64);
index += 64;
index += ((int) keyData[index + 1] == 64 ? 2 : 3); //479/480
byte[] pemExponent2 = new byte[64];
Array.Copy(keyData, index, pemExponent2, 0, 64);
index += 64;
index += ((int) keyData[index + 1] == 64 ? 2 : 3); //545/546
byte[] pemCoefficient = new byte[64];
Array.Copy(keyData, index, pemCoefficient, 0, 64);
RSAParameters para = new RSAParameters();
para.Modulus = pemModulus;
para.Exponent = pemPublicExponent;
para.D = pemPrivateExponent;
para.P = pemPrime1;
para.Q = pemPrime2;
para.DP = pemExponent1;
para.DQ = pemExponent2;
para.InverseQ = pemCoefficient;
return para;
}
#endregion
}
public static void ProKey(string path)
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
using (StreamWriter writer = new StreamWriter(path + "yourname.pri"))
{
string privateKey = rsa.ToXmlString(true);
writer.WriteLine(RSASignature.RSAPrivateKeyDotNet2Java(privateKey));
}
using (StreamWriter writer = new StreamWriter(path + "yourname.pub"))
{
string publicKey = rsa.ToXmlString(false);
writer.WriteLine(RSASignature.RSAPublicKeyDotNet2Java(publicKey));
}
}
/* static void Main(string[] args)
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
string privateKey = rsa.ToXmlString(true);
string publicKey = rsa.ToXmlString(false);
//string pr = BocomSignature.RSAPrivateKeyDotNet2Java(privateKey);
//string pu = BocomSignature.RSAPublicKeyDotNet2Java(publicKey);
string pr = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDkcFdmrJ/cwLE3u3dreROlM0/YbAi0g7m6o5YCfISOVqVPE6/WKRS0SVCFonFSb3BbddCv8fWUxQOyPkhccsxZN4tR4xEAVj6YOqb0JGMgEg3qdyGqdPlFK2FtsWvqhx23PAbfuruJNWWF+S27Ek0BV9/PgF5Hqg5NLAPawHkK8Vo4vaHntPBCLxrfidqWFMUR4nNc/zXoQxQtxTsoYLdTUjWglU9Ce5AcS0UvYbD0d7FrdaQ0XHwbNCWhFrX68c1eMxMNoSs+YaMgPb7dFwtLcO3uHGLzTOlX21eDokfBMvcc8+KJtqdpsYrQ8s4pb7OIO06oq/XH+wNeTHaFnVLnAgMBAAECggEBAMKzhar7Yt3SVrm7zJMLhVT+oQVDP0AsLbcICqlf29M9wnPdwbb1GLJ48mqUA6ZRWSB7ED2GKtx79ySKtT4mkklQcCyBLlJtL7ir9PSNtvb0rGu00jrorDTqPoYx/FrOguNUBD/YdlMB8d/4e6PAe2Wzsgy3yqOmK75Wz4o5FnHdm73Aa8IhO8TpKLeIQVYtxMizRVIyMWHfvPSTYS4cyQQyUUUSlCRjv9oa6lEpIvCZ0t5ZJ+PP4Mh2JWErf710mKNFGJTIkTYkM95kNtWeUPnpOAUN+MNZ5OjYFjIAzRiRURH3EnGVLriyYeJTOAELMZkyNu5zbLKgewwsi15kvcECgYEA9/+CRYvQi8VkHrTuKUrgfdKQyh6lQnXoI2jVDfMvziPOP6ibym68jqoYMPsEWLEBsiZixvldg16iHn8YdXXbUmzoWsm+IQjNHGminBjh5vs+GtdIDZ2qP54L27NuLA454wihVh1uC/Vb+kzYxhloGJ7dWlFCI0pD8LdCpOPBYdECgYEA689FYa6TMx5COCfH0saJxnh82gcqHXIJ2B7GCojlYt7IlKer0kkQQxN24O3VgLJGi/NI0uxeyDphSt0+T0qPi7CLNDgJ/JXRV98vFuD3LSFJGTe+s8HyvKHRd8n5pqRJd3+JpOJhoRnu38DzS0bDoFq+THrIoY/sOoNK3RXpHzcCgYAYZWM8Ui+2wDlEKApRt5Lz7bXenDsnmY+3hAWJdMXcInuUmZKRzGjyI9tzXg4kZ21CSDJpXniLhtCt7VTLoUdtCVemLrhsaYA77kxXzL7USRzn6Qumgz8POQ3zk+gfn1qkceHlJcoAlSdyLQMaIb+yxFYEH4BBFnougOimbd1FMQKBgQDB706FfrkLIoidfIIH5EbtVqx/98J4QxC7kNuZUGsvPEBEmf1izbo1IC314URlOrlwYh5zcfilvfXER172gUC7Ru/Fe40jEegA18n3i/9dO3HN7p3FYu4Kmx8V4KOUnKrbP6XpWFGo2BYwKZUuRL2hBOBbL+QPk7lZih8o4ts+UwKBgFW40/4QRJ/aw20eXSjdN4aIUtFiDM/LRQhYsW3evbXqxkBpK4MsTaROFmgb0VsiJpA1gDLRuRy6i2tEbgyl7zyFakWF+JZTP2ASxw8nBMpG4fC4IHIodjoCGIt9gFto6qCknS9YE88T1v/bhhRuzRswl/00aTZIXL+HMfwxwvWm";
string pu = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5HBXZqyf3MCxN7t3a3kTpTNP2GwItIO5uqOWAnyEjlalTxOv1ikUtElQhaJxUm9wW3XQr/H1lMUDsj5IXHLMWTeLUeMRAFY+mDqm9CRjIBIN6nchqnT5RSthbbFr6ocdtzwG37q7iTVlhfktuxJNAVffz4BeR6oOTSwD2sB5CvFaOL2h57TwQi8a34nalhTFEeJzXP816EMULcU7KGC3U1I1oJVPQnuQHEtFL2Gw9Hexa3WkNFx8GzQloRa1+vHNXjMTDaErPmGjID2+3RcLS3Dt7hxi80zpV9tXg6JHwTL3HPPiibanabGK0PLOKW+ziDtOqKv1x/sDXkx2hZ1S5wIDAQAB";
Console.WriteLine("pr: " + pr);
Console.WriteLine("pu: " + pu);
string content = "aaawwwwgsagas42352346";
string sign = RSACryptor.RSAFromPkcs8.signWithRSASHA256(content, pr, "UTF-8");
Console.WriteLine("sign: " + sign);
Boolean b = RSACryptor.RSAFromPkcs8.verifySHA256(content, sign, pu, "UTF-8");
Console.WriteLine("verifySHA256: " + b);
}*/
}
}
}
}
\ No newline at end of file
using System;
using System.Text;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using Com.Bocom.OpenApi.Security.KeyGen;
namespace Com.Bocom.OpenApi
{
namespace Security
{
namespace Crypt
{
public class SM2Cryptor
{
public static string Encrypt(string data, string publicKey, string charset)
{
SM2Engine sm2Engine = new SM2Engine();
sm2Engine.Init(true,
new ParametersWithRandom(SM2KeyGen.GetECPublicKey(publicKey), new SecureRandom()));
byte[] dataByteArray = Encoding.GetEncoding(charset).GetBytes(data);
return Convert.ToBase64String(sm2Engine.ProcessBlock(dataByteArray, 0, dataByteArray.Length));
}
public static string Decrypt(string encryptedData, string privateKey, string charset)
{
SM2Engine sm2Engine = new SM2Engine();
sm2Engine.Init(false, SM2KeyGen.GetECPrivateKey(privateKey));
byte[] encryptedDataByteArray = Convert.FromBase64String(encryptedData);
return Encoding.GetEncoding(charset).GetString(sm2Engine.ProcessBlock(encryptedDataByteArray, 0,
encryptedDataByteArray.Length));
}
public static void Main(string[] args)
{
string data = "bocom-fobp-zhaozheyang";
//AsymmetricCipherKeyPair keyPair = SM2KeyGen.GenSM2KeyPair();
//string pubKey = SM2KeyGen.GetPublicKeyStr(keyPair);
//string priKey = SM2KeyGen.GetPrivateKeyStr(keyPair);
string pubKey = "02e4c86e0a58a130d3d4c82e7771304e4ba05f9d86c91b044b735d57702122bf12";
string priKey = "009001b7caa52bcc67694b9fdd96d06685878457a97db991a787c51ac0c12eebe7";
string encrypted = SM2Cryptor.Encrypt(data, pubKey, "UTF-8");
Console.WriteLine("密文:" + encrypted);
Console.WriteLine("明文:" + SM2Cryptor.Decrypt(encrypted, priKey, "UTF-8"));
}
}
}
}
}
\ No newline at end of file
using System;
using System.Text;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Modes;
using Org.BouncyCastle.Crypto.Paddings;
using Org.BouncyCastle.Crypto.Parameters;
namespace Com.Bocom.OpenApi
{
namespace Security
{
namespace Crypt
{
public class SM4Cryptor
{
public static string Encrypt(string data, string secretKey, string charset)
{
KeyParameter keyParameter = new KeyParameter(Convert.FromBase64String(secretKey));
byte[] dataByteArray = Encoding.GetEncoding(charset).GetBytes(data);
// 生成SM4加密器,CBC模式,PKCS7填充
CbcBlockCipher cbcBlockCipher = new CbcBlockCipher(new SM4Engine());
PaddedBufferedBlockCipher paddedBufferedBlockCipher = new PaddedBufferedBlockCipher(cbcBlockCipher, new Pkcs7Padding());
paddedBufferedBlockCipher.Init(true, keyParameter);
// 根据明文长度获取密文长度
byte[] output = new byte[paddedBufferedBlockCipher.GetOutputSize(dataByteArray.Length)];
// 先处理一部分字节
int len = paddedBufferedBlockCipher.ProcessBytes(dataByteArray, 0, dataByteArray.Length, output, 0);
// 再处理末尾凑不够一个分组的字节
paddedBufferedBlockCipher.DoFinal(output, len);
return Convert.ToBase64String(output);
}
public static string Decrypt(string encryptedData, string secretKey, string charset)
{
KeyParameter keyParameter = new KeyParameter(Convert.FromBase64String(secretKey));
byte[] encryptedDataByteArray = Convert.FromBase64String(encryptedData);
// 生成SM4解密器,CBC模式,PKCS7填充
CbcBlockCipher cbcBlockCipher = new CbcBlockCipher(new SM4Engine());
PaddedBufferedBlockCipher paddedBufferedBlockCipher = new PaddedBufferedBlockCipher(cbcBlockCipher, new Pkcs7Padding());
paddedBufferedBlockCipher.Init(false, keyParameter);
// 填充后的明文
byte[] output = new byte[paddedBufferedBlockCipher.GetOutputSize(encryptedDataByteArray.Length)];
// 获取明文的真实长度
int len1 = paddedBufferedBlockCipher.ProcessBytes(encryptedDataByteArray, 0,
encryptedDataByteArray.Length, output, 0);
int len2 = paddedBufferedBlockCipher.DoFinal(output, len1);
// 填充前的明文
byte[] rawDataByteArray = new byte[len1 + len2];
Array.Copy(output, 0, rawDataByteArray, 0, rawDataByteArray.Length);
return Encoding.GetEncoding(charset).GetString(rawDataByteArray);
}
public static void Main(string[] args)
{
string sm4Key = "teFsqfOOV2NMOZs98AKq9w==";
string data = "Today is not a day!";
string encryptedData = SM4Cryptor.Encrypt(data, sm4Key, "UTF-8");
Console.WriteLine("加密后的密文:" + encryptedData);
Console.WriteLine("解密后的原文:" + SM4Cryptor.Decrypt(encryptedData, sm4Key, "UTF-8"));
}
}
}
}
}
\ No newline at end of file
using System;
using System.Security.Cryptography;
using System.IO;
namespace Com.Bocom.OpenApi
{
namespace Security
{
namespace Digest
{
public class SHA256Digest
{
public static string Digest(string fileName)
{
SHA256 hash = SHA256.Create();
FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] hashByte = hash.ComputeHash(stream);
stream.Close();
Console.WriteLine("上传文件hashh值:" + BitConverter.ToString(hashByte).Replace("-", "").ToLower());
return BitConverter.ToString(hashByte).Replace("-", "").ToLower();
}
}
}
}
}
\ No newline at end of file
using System;
using System.IO;
using System.Text;
using Org.BouncyCastle.Utilities.Encoders;
namespace Com.Bocom.OpenApi
{
namespace Security
{
namespace Digest
{
public class SM3Digest
{
private const int SM3_DIGEST_SIZE = 32;
private const int DEFAULT_BUF_SIZE = 65536;
public static string Digest(string fileName)
{
Org.BouncyCastle.Crypto.Digests.SM3Digest sm3Digest = new Org.BouncyCastle.Crypto.Digests.SM3Digest();
FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
byte[] buf = new byte[DEFAULT_BUF_SIZE];
int num;
while ((num = fileStream.Read(buf, 0, buf.Length)) > 0)
{
sm3Digest.BlockUpdate(buf, 0, num);
}
byte[] dig = new byte[SM3_DIGEST_SIZE];
sm3Digest.DoFinal(dig, 0);
return Encoding.UTF8.GetString(Hex.Encode(dig));
}
public static void Main(string[] args)
{
try
{
string digStr = SM3Digest.Digest("C:/Users/Administrator/Desktop/test.txt");
Console.WriteLine(digStr);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}
}
}
}
}
\ No newline at end of file
using System;
using System.Security.Cryptography;
namespace Com.Bocom.OpenApi
{
namespace Security
{
namespace KeyGen
{
public class AESKeyGen
{
public static string GenAES256Key()
{
AesCryptoServiceProvider key = new AesCryptoServiceProvider();
key.KeySize = 256;
key.GenerateKey();
return Convert.ToBase64String(key.Key);
}
}
}
}
}
\ No newline at end of file
using System;
using System.Text;
using Org.BouncyCastle.Asn1.GM;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Math.EC;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Utilities.Encoders;
using Com.Bocom.OpenApi.Security.Crypt;
namespace Com.Bocom.OpenApi
{
namespace Security
{
namespace KeyGen
{
public class SM2KeyGen
{
public static AsymmetricCipherKeyPair GenSM2KeyPair()
{
// 获取SM2标准中推荐的256bit的质数域的椭圆曲线域参数
X9ECParameters x9ECParameters = GMNamedCurves.GetByOid(GMObjectIdentifiers.sm2p256v1);
ECDomainParameters ecDomainParameters = new ECDomainParameters(x9ECParameters);
// 构造EC密钥生成算法参数
ECKeyGenerationParameters ecKeyGenerationParameters =
new ECKeyGenerationParameters(ecDomainParameters, new SecureRandom());
// 初始化EC密钥生成器
IAsymmetricCipherKeyPairGenerator asymmetricCipherKeyPairGenerator =
GeneratorUtilities.GetKeyPairGenerator("EC");
asymmetricCipherKeyPairGenerator.Init(ecKeyGenerationParameters);
return asymmetricCipherKeyPairGenerator.GenerateKeyPair();
}
/// <summary>
/// 从KeyPair对象中得到字符串表示的公钥(Hex编码)。
/// </summary>
/// <param name="keyPair"></param>
/// <returns></returns>
public static string GetPublicKeyStr(AsymmetricCipherKeyPair keyPair)
{
ECPublicKeyParameters publicKey = (ECPublicKeyParameters) keyPair.Public;
return Encoding.UTF8.GetString(Hex.Encode(publicKey.Q.GetEncoded(false)));
}
/// <summary>
/// 从KeyPair对象中得到字符串表示的私钥(Hex编码)。
/// </summary>
/// <param name="keyPair"></param>
/// <returns></returns>
public static string GetPrivateKeyStr(AsymmetricCipherKeyPair keyPair)
{
ECPrivateKeyParameters privateKey = (ECPrivateKeyParameters) keyPair.Private;
return Encoding.UTF8.GetString(Hex.Encode(privateKey.D.ToByteArray()));
}
/// <summary>
/// 公钥字符串(Hex编码)转成ECPublicKeyParameters对象。
/// </summary>
/// <param name="publicKey"></param>
/// <returns></returns>
public static ECPublicKeyParameters GetECPublicKey(string publicKey)
{
X9ECParameters x9ECParameters = GMNamedCurves.GetByOid(GMObjectIdentifiers.sm2p256v1);
ECDomainParameters ecDomainParameters = new ECDomainParameters(x9ECParameters);
ECPoint q = x9ECParameters.Curve.DecodePoint(Hex.Decode(Encoding.UTF8.GetBytes(publicKey)));
return new ECPublicKeyParameters(q, ecDomainParameters);
}
/// <summary>
/// 私钥字符串(Hex编码)转成ECPrivateKeyParameters对象。
/// </summary>
/// <param name="privateKey"></param>
/// <returns></returns>
public static ECPrivateKeyParameters GetECPrivateKey(string privateKey)
{
X9ECParameters x9ECParameters = GMNamedCurves.GetByOid(GMObjectIdentifiers.sm2p256v1);
ECDomainParameters ecDomainParameters = new ECDomainParameters(x9ECParameters);
BigInteger d = new BigInteger(Hex.Decode(Encoding.UTF8.GetBytes(privateKey)));
return new ECPrivateKeyParameters(d, ecDomainParameters);
}
public static void Main(string[] args)
{
AsymmetricCipherKeyPair keyPair = SM2KeyGen.GenSM2KeyPair();
string pubKey = SM2KeyGen.GetPublicKeyStr(keyPair);
string priKey = SM2KeyGen.GetPrivateKeyStr(keyPair);
Console.WriteLine("公钥:" + pubKey);
Console.WriteLine("公钥位数:" + pubKey.Length);
Console.WriteLine("私钥:" + priKey);
Console.WriteLine("私钥位数:" + priKey.Length);
string plainText = "交通银行软件开发中心";
string encryptedText = SM2Cryptor.Encrypt(plainText, "04d174bced6dab54eae6cb9d4c4794ea77008b4b123663c464084edc04b26da553ec3132b9d44ae5f28522beb0312d178f709d18cf9ad722d8ad0e4431085a2fb0", "UTF-8");
Console.WriteLine("加密后的密文:" + encryptedText);
string decryptedText = SM2Cryptor.Decrypt(encryptedText, "3dea5f72479ef4005e3017e617384d1bf4c66d536204dd44faa4c7075abfb5d5", "UTF-8");
Console.WriteLine("解密后的明文:" + decryptedText);
}
}
}
}
}
\ No newline at end of file
using System;
using System.Security.Cryptography;
namespace Com.Bocom.OpenApi
{
namespace Security
{
namespace KeyGen
{
public class SM4KeyGen
{
public static string GenSM4Key()
{
AesCryptoServiceProvider key = new AesCryptoServiceProvider();
key.KeySize = 128;
key.GenerateKey();
return Convert.ToBase64String(key.Key);
}
}
}
}
}
\ No newline at end of file
using System;
using System.Text;
using System.Security.Cryptography;
using System.Xml;
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Pkcs;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.X509;
using Com.Bocom.OpenApi.Security.Crypt;
using Com.Bocom.OpenApi.Utils;
namespace Com.Bocom.OpenApi
{
namespace Security
{
namespace Sign
{
public class RSASignature
{
//private static infosecapiLib.infosec icbcCA = new infosecapiLib.infosec();
public static string Sign(string content, string privateKey, string charset)
{
return Sign(content, privateKey, charset, null);
}
public static string Sign(string content, string privateKey, string charset, string password)
{
return RSACryptor.RSAFromPkcs8.SignWithRSASHA256(content, privateKey, charset);
}
public static bool Verify(string content, string publicKey, string charset, string sign)
{
try
{
//byte[] contentBytes = Encoding.GetEncoding(charset).GetBytes(content);
return RSACryptor.RSAFromPkcs8.VerifySHA256(content, sign, publicKey, charset);
}
catch (Exception e)
{
throw new Exception(
"get content charset exception. content: " + content + " charset: " + charset,
e);
}
}
public static string RSAPrivateKeyJava2DotNet(string privateKey)
{
RsaPrivateCrtKeyParameters privateKeyParam =
(RsaPrivateCrtKeyParameters) PrivateKeyFactory.CreateKey(Convert.FromBase64String(privateKey));
return string.Format(
"<RSAKeyValue><Modulus>{0}</Modulus><Exponent>{1}</Exponent><P>{2}</P><Q>{3}</Q><DP>{4}</DP><DQ>{5}</DQ><InverseQ>{6}</InverseQ><D>{7}</D></RSAKeyValue>",
Convert.ToBase64String(privateKeyParam.Modulus.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.PublicExponent.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.P.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.Q.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.DP.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.DQ.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.QInv.ToByteArrayUnsigned()),
Convert.ToBase64String(privateKeyParam.Exponent.ToByteArrayUnsigned()));
}
/// <summary>
/// RSA私钥格式转换,.net->java
/// </summary>
/// <param name="privateKey">.net生成的私钥</param>
/// <returns></returns>
public static string RSAPrivateKeyDotNet2Java(string privateKey)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(privateKey);
BigInteger m = new BigInteger(1,
Convert.FromBase64String(doc.DocumentElement.GetElementsByTagName("Modulus")[0].InnerText));
BigInteger exp = new BigInteger(1,
Convert.FromBase64String(doc.DocumentElement.GetElementsByTagName("Exponent")[0].InnerText));
BigInteger d = new BigInteger(1,
Convert.FromBase64String(doc.DocumentElement.GetElementsByTagName("D")[0].InnerText));
BigInteger p = new BigInteger(1,
Convert.FromBase64String(doc.DocumentElement.GetElementsByTagName("P")[0].InnerText));
BigInteger q = new BigInteger(1,
Convert.FromBase64String(doc.DocumentElement.GetElementsByTagName("Q")[0].InnerText));
BigInteger dp = new BigInteger(1,
Convert.FromBase64String(doc.DocumentElement.GetElementsByTagName("DP")[0].InnerText));
BigInteger dq = new BigInteger(1,
Convert.FromBase64String(doc.DocumentElement.GetElementsByTagName("DQ")[0].InnerText));
BigInteger qinv = new BigInteger(1,
Convert.FromBase64String(doc.DocumentElement.GetElementsByTagName("InverseQ")[0].InnerText));
RsaPrivateCrtKeyParameters privateKeyParam =
new RsaPrivateCrtKeyParameters(m, exp, d, p, q, dp, dq, qinv);
PrivateKeyInfo privateKeyInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(privateKeyParam);
byte[] serializedPrivateBytes = privateKeyInfo.ToAsn1Object().GetEncoded();
return Convert.ToBase64String(serializedPrivateBytes);
}
/// <summary>
/// RSA公钥格式转换,.net->java
/// </summary>
/// <param name="publicKey">.net生成的公钥</param>
/// <returns></returns>
public static string RSAPublicKeyDotNet2Java(string publicKey)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(publicKey);
BigInteger m = new BigInteger(1,
Convert.FromBase64String(doc.DocumentElement.GetElementsByTagName("Modulus")[0].InnerText));
BigInteger p = new BigInteger(1,
Convert.FromBase64String(doc.DocumentElement.GetElementsByTagName("Exponent")[0].InnerText));
RsaKeyParameters pub = new RsaKeyParameters(false, m, p);
SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(pub);
byte[] serializedPublicBytes = publicKeyInfo.ToAsn1Object().GetDerEncoded();
return Convert.ToBase64String(serializedPublicBytes);
}
//AES内容解密
public static string DecryptContent(string content, string encryptType, string encryptKey,
string charset)
{
if (encryptType.Equals(BocomConstants.ENCRYPT_TYPE_RSA_AND_AES))
return AesDecrypt(content, encryptKey);
else
throw new Exception("当前不支持该算法类型:encrypeType=" + encryptType);
}
//AES内容加密
public static string EncryptContent(string content, string encryptType, string encryptKey,
string charset)
{
if (encryptType.Equals(BocomConstants.ENCRYPT_TYPE_RSA_AND_AES))
return AesEncrypt(content, encryptKey);
throw new Exception("当前不支持该算法类型:encrypeType=" + encryptType);
}
/// <summary>
///AES加密(加密步骤)
///1,加密字符串得到2进制数组;
///2,将2禁止数组转为16进制;
///3,进行base64编码
/// </summary>
/// <param name="toEncrypt">要加密的字符串</param>
/// <param name="key">密钥</param>
public static string AesEncrypt(string toEncrypt, string key)
{
Byte[] _Key = Convert.FromBase64String(key);
Byte[] _Source = Encoding.UTF8.GetBytes(toEncrypt);
Aes aes = Aes.Create("AES");
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
aes.Key = _Key;
aes.IV = new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
ICryptoTransform cTransform = aes.CreateEncryptor();
Byte[] cryptData = cTransform.TransformFinalBlock(_Source, 0, _Source.Length);
string CryptString = Convert.ToBase64String(cryptData);
return CryptString;
}
/// <summary>
/// AES解密(解密步骤)
/// 1,将BASE64字符串转为16进制数组
/// 2,将16进制数组转为字符串
/// 3,将字符串转为2进制数据
/// 4,用AES解密数据
/// </summary>
/// <param name="encryptedSource">已加密的内容</param>
/// <param name="key">密钥</param>
public static string AesDecrypt(string encryptedSource, string key)
{
Byte[] _Key = Convert.FromBase64String(key);
Aes aes = Aes.Create("AES");
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
aes.Key = _Key;
aes.IV = new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
ICryptoTransform cTransform = aes.CreateDecryptor();
Byte[] encryptedData = Convert.FromBase64String(encryptedSource);
Byte[] originalSourceData = cTransform.TransformFinalBlock(encryptedData, 0, encryptedData.Length);
string originalString = Encoding.UTF8.GetString(originalSourceData);
return originalString;
}
}
}
}
}
\ No newline at end of file
using System;
using System.Text;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Signers;
using Org.BouncyCastle.Utilities.Encoders;
using Com.Bocom.OpenApi.Security.KeyGen;
namespace Com.Bocom.OpenApi
{
namespace Security
{
namespace Sign
{
public class SM2Signature
{
public static string Sign(string data, string privateKey, string charset)
{
ISigner signer = new SM2Signer();
signer.Init(true, SM2KeyGen.GetECPrivateKey(privateKey));
byte[] dataByteArray = Encoding.GetEncoding(charset).GetBytes(data);
signer.BlockUpdate(dataByteArray, 0, dataByteArray.Length);
return Hex.ToHexString(signer.GenerateSignature());
}
public static bool Verify(string data, string publicKey, string charset, string signature)
{
ISigner signer = new SM2Signer();
signer.Init(false, SM2KeyGen.GetECPublicKey(publicKey));
byte[] dataByteArray = Encoding.GetEncoding(charset).GetBytes(data);
signer.BlockUpdate(dataByteArray, 0, dataByteArray.Length);
return signer.VerifySignature(Hex.Decode(signature));
}
}
}
}
}
\ No newline at end of file
using System;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Json;
using Com.Bocom.OpenApi.Security.Sign;
namespace Com.Bocom.OpenApi
{
namespace Utils
{
public class ApiUtils
{
public static Object ParseNotifyJsonWithBocomSign(string notifyStr, string charset, string APIGW_PUBLIC_KEY,
Type T)
{
string bizContentStr;
string sign;
try
{
int indexOfRootStart = notifyStr.IndexOf(BocomConstants.NOTIFY_BIZ_CONTENT)
+ BocomConstants.NOTIFY_BIZ_CONTENT.Length + 2;
int indexOfRootEnd = notifyStr.LastIndexOf(",");
int indexOfSignStart =
notifyStr.LastIndexOf(BocomConstants.SIGN + "\"") + BocomConstants.SIGN.Length + 3;
int indexOfSignEnd = notifyStr.LastIndexOf("\"");
bizContentStr = notifyStr.Substring(indexOfRootStart, indexOfRootEnd - indexOfRootStart);
sign = notifyStr.Substring(indexOfSignStart, indexOfSignEnd - indexOfSignStart);
}
catch (Exception e)
{
throw new Exception("notify_biz_content is not format json. notifyStr :\n" + notifyStr, e);
}
Boolean passed = RSASignature.Verify(bizContentStr, APIGW_PUBLIC_KEY, charset, sign);
if (!passed)
{
throw new Exception("Bocom sign verify not passed.");
}
try
{
//反序列化并返回
BocomResponse response;
MemoryStream ms1 = new MemoryStream(Encoding.GetEncoding(charset).GetBytes(bizContentStr));
using (MemoryStream ms = new MemoryStream(Encoding.GetEncoding(charset).GetBytes(bizContentStr)))
{
DataContractJsonSerializer deseralizer = new DataContractJsonSerializer(T);
response = (BocomResponse) deseralizer.ReadObject(ms) as BocomResponse;
}
return response;
}
catch (Exception e)
{
throw new Exception("notify_biz_content can not transform to defined class. response: " + notifyStr
+ " defined class name: " +
T, e);
}
}
}
}
}
\ No newline at end of file
namespace Com.Bocom.OpenApi
{
namespace Utils
{
public class BocomConstants
{
public static string APP_ID = "app_id";
public static string ENCRYPT_TYPE_SM2_AND_SM4 = "SM2_AND_SM4";
public static string ENCRYPT_TYPE_RSA_AND_AES = "RSA_AND_AES";
public static string FORMAT = "format";
public static string TIMESTAMP = "timestamp";
public static string SIGN = "sign";
public static string APP_AUTH_TOKEN = "app_auth_token";
public static string CHARSET = "charset";
public static string NOTIFY_URL = "notify_url";
public static string RETURN_URL = "return_url";
public static string ENCRYPT_TYPE = "encrypt_type";
public static string IS_ENCRYPT = "is_encrypt";
// -----===-------///
public static string BIZ_CONTENT_KEY = "biz_content";
/** 默认时间格式 **/
public static string DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
/** Date默认时区 **/
public static string DATE_TIMEZONE = "GMT+8";
/** UTF-8字符集 **/
public static string CHARSET_UTF8 = "UTF-8";
/** GBK字符集 **/
public static string CHARSET_GBK = "GBK";
public static string FMT_TYPE = "fmt_type";
/** JSON 应格式 */
public static string FORMAT_JSON = "json";
/** XML 应格式 */
public static string FORMAT_XML = "xml";
public static string PASSWORD = "password";
public static string RESPONSE_BIZ_CONTENT = "rsp_biz_content";
/** 消息唯一编号 **/
public static string MSG_ID = "msg_id";
/** sdk版本号在header中的key */
public static string VERSION_HEADER_NAME = "APIGW-VERSION";
/**
* 通知域
*/
public static string NOTIFY_BIZ_CONTENT = "notify_biz_content";
/// <summary>
/// 字段加密。
/// </summary>
public static string ENCRYPT_POLICY_TYPE_FIELD = "FIELD";
/// <summary>
/// 全报文加密。
/// </summary>
public static string ENCRYPT_POLICY_TYPE_CONTENT = "CONTENT";
/// <summary>
/// 文件加密。
/// </summary>
public static string ENCRYPT_POLICY_TYPE_FILE = "FILE";
public static string ENCRYPT_POLICY = "encrypt_policy";
public static string BIZ_CONTENT = "biz_content";
public static string ENCRYPT_KEY = "encrypt_key";
public static string FILE_HASHCODE = "file_hashcode";
public static string FILE_CONTENT = "file_content";
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
namespace Com.Bocom.OpenApi
{
namespace Utils
{
public class BocomHashMap : Dictionary<string, string>
{
private static long serialVersionUID = 8026336190683519216L;
public BocomHashMap() : base()
{
}
public string Put(string key, Object value)
{
string strValue;
if (value == null)
{
strValue = null;
}
else if (value is string)
{
strValue = (string) value;
}
else if (value is int)
{
strValue = Convert.ToString(value);
}
else if (value is long)
{
strValue = Convert.ToString(value);
}
else if (value is float)
{
strValue = Convert.ToString(value);
}
else if (value is Double)
{
strValue = Convert.ToString(value);
}
else if (value is Boolean)
{
strValue = Convert.ToString(value);
}
else if (value is DateTime)
{
string format = BocomConstants.DATE_TIME_FORMAT;
// format.setTimeZone(TimeZone.getTimeZone(BocomConstants.DATE_TIMEZONE));
strValue = Convert.ToString(value);
}
else
{
strValue = Convert.ToString(value);
}
return Put(key, strValue);
}
public string Put(string key, string value)
{
if (key != string.Empty && value != string.Empty)
{
return Put(key, value);
}
return null;
}
}
}
}
\ No newline at end of file
using System;
using Com.Bocom.OpenApi.Security.Sign;
namespace Com.Bocom.OpenApi
{
namespace Utils
{
public class BocomSignature
{
public static string Sign(string encryptType, string content, string privateKey, string charset)
{
if (BocomConstants.ENCRYPT_TYPE_RSA_AND_AES == encryptType)
{
return RSASignature.Sign(content, privateKey, charset);
}
if (BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4 == encryptType)
{
return SM2Signature.Sign(content, privateKey, charset);
}
throw new BocomApiException("仅支持使用RSA和SM2签名!");
}
public static bool Verify(string encryptType, string content, string publicKey, string charset, string signature)
{
if (BocomConstants.ENCRYPT_TYPE_RSA_AND_AES == encryptType)
{
return RSASignature.Verify(content, publicKey, charset, signature);
}
if (BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4 == encryptType)
{
return SM2Signature.Verify(content, publicKey, charset, signature);
}
throw new BocomApiException("仅支持使用RSA和SM2验签!");
}
}
}
}
\ No newline at end of file
using System.IO;
namespace Com.Bocom.OpenApi
{
namespace Utils
{
public class FileItem
{
private string fileName;
private string mimeType;
private byte[] content;
private FileStream fileStream;
/**
* 基于本地文件的构造器。
*
* @param file
* 本地文件
*/
public FileItem(FileStream fileStream)
{
this.fileStream = fileStream;
content = ToByteArray(fileStream);
fileName = GetFileName();
}
/**
* 基于文件绝对路径的构造器。
*
* @param filePath
* 文件绝对路径
*/
public FileItem(string filePath)
{
FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate);
fileName = filePath;
content = ToByteArray(fileStream);
}
public string GetFileName()
{
if (fileName == null && fileStream != null)
{
fileName = fileStream.Name;
}
return fileName;
}
public string GetMimeType()
{
if (mimeType == null)
{
mimeType = GetMimeType(GetContent());
}
return mimeType;
}
public static byte[] ToByteArray(Stream stream)
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
stream.Seek(0, SeekOrigin.Begin);
stream.Close();
return bytes;
}
/**
* @param filePath
* 文件路径
* @return file bytes
* @throws IOException
* 读取文件错误
*/
public byte[] GetContent()
{
/* if (this.fileName == null && this.fileStream != null )
{
byte[] content = toByteArray(this.fileStream);
this.content = content;
}*/
return content;
}
public static byte[] ToByteArray(FileStream fi)
{
byte[] bytes = new byte[fi.Length];
fi.Read(bytes, 0, bytes.Length);
fi.Close();
return bytes;
}
/**
* 获取文件的真实媒体类型。目前只支持JPG, GIF, PNG, BMP四种图片文件。
*
* @param bytes
* 文件字节流
* @return 媒体类型(MEME-TYPE)
*/
public static string GetMimeType(byte[] bytes)
{
string suffix = GetFileSuffix(bytes);
string mimeType;
if ("JPG".Equals(suffix))
{
mimeType = "image/jpeg";
}
else if ("GIF".Equals(suffix))
{
mimeType = "image/gif";
}
else if ("PNG".Equals(suffix))
{
mimeType = "image/png";
}
else if ("BMP".Equals(suffix))
{
mimeType = "image/bmp";
}
else
{
mimeType = "application/octet-stream";
}
return mimeType;
}
/**
* 获取文件的真实后缀名。目前只支持JPG, GIF, PNG, BMP四种图片文件。
*
* @param bytes
* 文件字节流
* @return JPG, GIF, PNG or null
*/
public static string GetFileSuffix(byte[] bytes)
{
if (bytes == null || bytes.Length < 10)
{
return null;
}
if (bytes[0] == 'G' && bytes[1] == 'I' && bytes[2] == 'F')
{
return "GIF";
}
if (bytes[1] == 'P' && bytes[2] == 'N' && bytes[3] == 'G')
{
return "PNG";
}
if (bytes[6] == 'J' && bytes[7] == 'F' && bytes[8] == 'I' && bytes[9] == 'F')
{
return "JPG";
}
if (bytes[0] == 'B' && bytes[1] == 'M')
{
return "BMP";
}
return null;
}
public FileStream GetFileStream()
{
// TODO Auto-generated method stub
return fileStream;
}
public void SetContent(byte[] encryptContent)
{
content = encryptContent;
}
}
}
}
\ No newline at end of file
using System.Collections.Generic;
namespace Com.Bocom.OpenApi
{
namespace Utils
{
public class HttpRequestParamsUtils
{
static public List<string> apiParamNames = new List<string>()
{
BocomConstants.SIGN, BocomConstants.APP_ID, BocomConstants.CHARSET, BocomConstants.FORMAT,
BocomConstants.ENCRYPT_TYPE, BocomConstants.TIMESTAMP, BocomConstants.MSG_ID
};
}
}
}
\ No newline at end of file
using System.Security.Cryptography;
using System;
namespace Com.Bocom.OpenApi
{
namespace Utils
{
public class KeyGeneratorUtils
{
/// <summary>
/// 随机生成秘钥(对称算法)
/// </summary>
/// <param name="key">秘钥(base64格式)</param>
/// <param name="iv">iv向量(base64格式)</param>
/// <param name="keySize">要生成的KeySize,每8个byte是一个字节,注意每种算法支持的KeySize均有差异,实际可通过输出LegalKeySizes来得到支持的值</param>
public static void CreateSymmetricAlgorithmKey<T>(out string key, out string iv, int keySize)
where T : SymmetricAlgorithm, new()
{
using (T t = new T())
{
t.KeySize = keySize;
t.GenerateIV();
t.GenerateKey();
iv = Convert.ToBase64String(t.IV);
key = Convert.ToBase64String(t.Key);
}
}
}
}
}
\ No newline at end of file
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
namespace Com.Bocom.OpenApi
{
namespace Utils
{
public class TrustAllCertificatePolicy
{
public static void SetCertificatePolicy()
{
System.Net.ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateCalidate;
}
public static bool RemoteCertificateCalidate(object sernder, X509Certificate cert, X509Chain chain,
SslPolicyErrors error)
{
return true;
}
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Web;
using Com.Bocom.OpenApi.Security.Crypt;
namespace Com.Bocom.OpenApi
{
namespace Utils
{
public class WebUtils
{
private static readonly string DefaultUserAgent =
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
public static string GetHttpResponseStr(string url, Dictionary<string, string> parameters, string charset)
{
HttpWebRequest request;
string urlStr = BuildGetUrl(url, parameters, charset);
//HTTPSQ请求:既支持http请求也支持https请求
request = WebRequest.Create(urlStr) as HttpWebRequest;
//HttpVersion.Version10:defines a version instance for http 1.0
//HttpVersion.Version11:defines a version instance for http 1.1,用1.1报网络异常、不通。
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "GET";
request.Timeout = 8000;
request.ReadWriteTimeout = 30000;
var response = request.GetResponse() as HttpWebResponse;
var responseString = string.Empty;
var httpStatusCode = (int) response.StatusCode;
if (httpStatusCode == 200)
{
responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
return responseString;
}
throw new Exception("response status code is not valid. status code: " + httpStatusCode);
}
public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters,
string charset)
{
HttpWebRequest request;
//验证服务器加载回调自动验证
//ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
TrustAllCertificatePolicy.SetCertificatePolicy();
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.Expect100Continue = true;
//HTTPSQ请求:既支持http请求也支持https请求
request = WebRequest.Create(url) as HttpWebRequest;
request.ProtocolVersion = HttpVersion.Version11;
request.Method = "POST";
request.Timeout = 8000;
request.ReadWriteTimeout = 30000;
request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
request.UserAgent = DefaultUserAgent;
Encoding encode = Encoding.GetEncoding(charset);
//如果需要POST数据
if (!(parameters == null || parameters.Count == 0))
{
StringBuilder buffer = new StringBuilder();
int i = 0;
foreach (string key in parameters.Keys)
{
if (parameters[key] == null || parameters[key].Equals(""))
{
continue;
}
if (i > 0)
{
buffer.AppendFormat("&{0}={1}", key,
HttpUtility.UrlEncode(parameters[key], Encoding.GetEncoding(charset)));
}
else
{
buffer.AppendFormat("{0}={1}", key,
HttpUtility.UrlEncode(parameters[key], Encoding.GetEncoding(charset)));
}
i++;
}
//如果用户输入带加号的参数值,需要转义
byte[] data = encode.GetBytes(buffer.ToString()); //.Replace("+","%2B"));
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
return request.GetResponse() as HttpWebResponse;
}
//upload file
public static HttpWebResponse CreatePostUploadFileHttpResponse(string url,
IDictionary<string, string> parameters, string charset, FileItem f)
{
HttpWebRequest request;
//验证服务器加载回调自动验证
//ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
TrustAllCertificatePolicy.SetCertificatePolicy();
System.Net.ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.Expect100Continue = true;
//HTTPSQ请求:既支持http请求也支持https请求
request = WebRequest.Create(url) as HttpWebRequest;
request.ProtocolVersion = HttpVersion.Version11; // http1.1
request.Method = "POST";
request.Timeout = 8000;
request.ReadWriteTimeout = 30000;
// request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
string boundary = "----" + DateTime.Now.Ticks.ToString("x");
request.ContentType = "multipart/form-data;boundary=" + boundary + ";charset=" + charset;
request.UserAgent = DefaultUserAgent;
// string formdataTemplate = "\r\n--" + boundary + "\r\nContent-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: application/octet-stream\r\n\r\n";
Stream stream = request.GetRequestStream();
byte[] entryBoundaryBytes = Encoding.GetEncoding(charset).GetBytes(("\r\n--" + boundary + "\r\n"));
//如果需要POST数据
if (!(parameters == null || parameters.Count == 0))
{
foreach (string key in parameters.Keys)
{
if (parameters[key] == null || parameters[key].Equals(""))
{
continue;
}
byte[] data = GetTextEntry(key, parameters[key], charset);
stream.Write(entryBoundaryBytes, 0, entryBoundaryBytes.Length);
stream.Write(data, 0, data.Length);
}
}
using (var fileStream = FileToStream(f))
{
string fileName = f.GetFileName();
// var formdata = string.Format(formdataTemplate, "", System.IO.Path.GetFileName(fileName) /*Path.GetFileName(fileName)*/);
// var formdataBytes = Encoding.UTF8.GetBytes(stream.Length == 0 ? formdata.Substring(2, formdata.Length - 2) : formdata);//第一行不需要换行
// stream.Write(formdataBytes, 0, formdataBytes.Length);
byte[] fileBytes = GetFileEntry(BocomConstants.FILE_CONTENT, f.GetFileName(), f.GetMimeType(),
charset);
//写入文件
//byte[] buffer = new byte[1024];
// int bytesRead = 0;
// while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
// {
stream.Write(entryBoundaryBytes, 0, entryBoundaryBytes.Length);
stream.Write(fileBytes, 0, fileBytes.Length);
byte[] fileContent = f.GetContent();
stream.Write(fileContent, 0, fileContent.Length);
// }
byte[] endBoundaryBytes = Encoding.GetEncoding(charset).GetBytes(("\r\n--" + boundary + "--\r\n"));
stream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
stream.Close();
}
return request.GetResponse() as HttpWebResponse;
}
private static byte[] GetTextEntry(string fieldName, string fieldValue, string charset)
{
StringBuilder entry = new StringBuilder();
entry.Append("Content-Disposition:form-data;name=\"");
entry.Append(fieldName);
entry.Append("\"\r\nContent-Type:text/plain\r\n\r\n");
entry.Append(fieldValue);
//return entry.toString().getBytes(charset);
return Encoding.GetEncoding(charset).GetBytes(entry.ToString());
}
private static byte[] GetFileEntry(string fieldName, string fileName, string mimeType, string charset)
{
StringBuilder entry = new StringBuilder();
entry.Append("Content-Disposition:form-data;name=\"");
entry.Append(fieldName);
entry.Append("\";filename=\"");
// entry.Append(URLEncoder.encode(fileName, charset));
entry.Append(HttpUtility.UrlEncode(fileName));
entry.Append("\"\r\nContent-Type:");
entry.Append(mimeType);
entry.Append("\r\n\r\n");
//return entry.toString().getBytes(charset);
return Encoding.GetEncoding(charset).GetBytes(Convert.ToString(entry));
}
public static string GetResponseJson(string url, IDictionary<string, string> parameters, string charset)
{
HttpWebResponse response = CreatePostHttpResponse(url, parameters, charset);
var httpStatusCode = (int) response.StatusCode;
if (httpStatusCode == 200)
{
Stream stream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(stream);
string responseStr = streamReader.ReadToEnd();
Console.WriteLine(responseStr);
return responseStr;
}
throw new Exception("response status code is not valid. status code: " + httpStatusCode);
}
//upload file
public static string GetResponseJson(string url, IDictionary<string, string> parameters, string charset,
FileItem f)
{
HttpWebResponse response = CreatePostUploadFileHttpResponse(url, parameters, charset, f);
var httpStatusCode = (int) response.StatusCode;
if (httpStatusCode == 200)
{
Stream stream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(stream);
string responseStr = streamReader.ReadToEnd();
Console.WriteLine(responseStr);
return responseStr;
}
throw new Exception("response status code is not valid. status code: " + httpStatusCode);
}
//download file 加密
public static string GetResponseJson(string url, IDictionary<string, string> parameters, string charset,
string downloadPath, string encryptKey, string encryptType)
{
HttpWebResponse response = CreatePostHttpResponse(url, parameters, charset);
var httpStatusCode = (int) response.StatusCode;
if (httpStatusCode == 200)
{
string responseStr = response.GetResponseHeader(BocomConstants.RESPONSE_BIZ_CONTENT);
string disposition = response.GetResponseHeader("Content-Disposition");
string fileName = HttpUtility.UrlEncode(disposition.Substring(disposition.IndexOf("filename=") + 9),
Encoding.GetEncoding(charset));
string filePath = downloadPath + fileName;
string tmpFilePath = filePath + ".tmp";
Stream stream = response.GetResponseStream();
WriteTmpFile(stream, tmpFilePath);
FileStream tmpStream = new FileStream(tmpFilePath, FileMode.OpenOrCreate);
byte[] text = AESCryptor.DecryptFile(tmpStream, encryptKey);
FileStream stream1 = new FileStream(filePath, FileMode.Create);
BinaryWriter bw = new BinaryWriter(stream1);
bw.Write(text);
bw.Close();
stream1.Close();
File.Delete(tmpFilePath);
return responseStr;
}
throw new Exception("response status code is not valid. status code: " + httpStatusCode);
}
//download file 非加密
public static string GetResponseJson(string url, IDictionary<string, string> parameters, string charset,
string downloadPath)
{
HttpWebResponse response = CreatePostHttpResponse(url, parameters, charset);
var httpStatusCode = (int) response.StatusCode;
if (httpStatusCode == 200)
{
string responseStr = response.GetResponseHeader(BocomConstants.RESPONSE_BIZ_CONTENT);
string disposition = response.GetResponseHeader("Content-Disposition");
string fileName = HttpUtility.UrlEncode(disposition.Substring(disposition.IndexOf("filename=") + 9),
Encoding.GetEncoding(charset));
string filePath = downloadPath + fileName;
Stream stream = response.GetResponseStream();
WriteTmpFile(stream, filePath);
return responseStr;
}
throw new Exception("response status code is not valid. status code: " + httpStatusCode);
}
//将从httpWebResponse中获取的文件流暂存于临时文件
public static void WriteTmpFile(Stream stream, string tmpFilePath)
{
FileStream fs = new FileStream(tmpFilePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
byte[] barr = new byte[1024];
int iTotalSize = 0;
int size = stream.Read(barr, 0, barr.Length);
while (size > 0)
{
iTotalSize += size;
fs.Write(barr, 0, size);
size = stream.Read(barr, 0, barr.Length);
}
fs.Close();
stream.Close();
}
public static Stream GetStream(Stream fi)
{
Stream memortStream = new MemoryStream();
byte[] bArr = new byte[1024];
int size = fi.Read(bArr, 0, bArr.Length);
while (size > 0)
{
memortStream.Write(bArr, 0, size);
size = fi.Read(bArr, 0, bArr.Length);
// Thread.Sleep(1);
}
fi.Close();
return memortStream;
}
public static string BuildOrderedSignStr(string path, Dictionary<string, string> param)
{
Dictionary<string, string> tmp = new Dictionary<string, string>();
tmp = param;
var orderList = tmp.OrderBy(s => s.Key);
StringBuilder sb = new StringBuilder(path);
sb.Append("?");
Boolean hasParam = false;
foreach (var s in orderList)
{
string name = s.Key;
string value = s.Value;
if (value == null || name == null || value.Equals(""))
{
continue;
}
if (hasParam)
{
sb.Append("&");
}
else
{
hasParam = true;
}
sb.Append(name).Append("=").Append(value);
}
return sb.ToString();
}
public static string BuildGetUrl(string strUrl, Dictionary<string, string> param, string charset)
{
if (param == null)
{
return strUrl;
}
StringBuilder sb = new StringBuilder(strUrl);
try
{
if (new Uri(strUrl).Query == null || new Uri(strUrl).Query.Equals(""))
{
if (!strUrl.EndsWith("?"))
{
sb.Append('?');
}
}
}
catch (UriFormatException e)
{
throw new Exception("url exception. url: " + strUrl, e);
}
Dictionary<string, string> tmp = new Dictionary<string, string>();
tmp = param;
Boolean hasParam = false;
Boolean shouldAddAnd = strUrl.Contains("?") ? !strUrl.EndsWith("&") : false;
foreach (var s in tmp)
{
string name = s.Key;
string value = s.Value;
// 忽略参数名或参数值为空的参数
if (value == null || name == null || value.Equals(""))
{
continue;
}
if (hasParam)
{
sb.Append("&");
}
else
{
if (shouldAddAnd)
{
sb.Append("&");
}
hasParam = true;
}
sb.Append(name).Append("=").Append(HttpUtility.UrlEncode(value, Encoding.GetEncoding(charset)));
}
return sb.ToString();
}
public static string BuildForm(string baseUrl, Dictionary<string, string> parameters)
{
StringBuilder sb = new StringBuilder();
sb.Append("<form name=\"auto_submit_form\" method=\"post\" action=\"");
sb.Append(baseUrl);
sb.Append("\">\n");
sb.Append(BuildHiddenFields(parameters));
sb.Append("<input type=\"submit\" value=\"立刻提交\" style=\"display:none\" >\n");
sb.Append("</form>\n");
sb.Append("<script>document.forms[0].submit();</script>");
string form = sb.ToString();
return form;
}
private static string BuildHiddenFields(Dictionary<string, string> parameters)
{
if (parameters == null || parameters.Count == 0)
{
return "";
}
StringBuilder sb = new StringBuilder();
foreach (var s in parameters)
{
string key = s.Key;
string value = s.Value;
// 除去参数中的空值
if (key == null || value == null)
{
continue;
}
sb.Append(BuildHiddenField(key, value));
}
string result = sb.ToString();
return result;
}
private static string BuildHiddenField(string key, string value)
{
StringBuilder sb = new StringBuilder();
sb.Append("<input type=\"hidden\" name=\"");
sb.Append(key);
sb.Append("\" value=\"");
// 转义双引号
string a = value.Replace("\"", "&quot;");
sb.Append(a).Append("\">\n");
return sb.ToString();
}
public bool CheckValidationResult()
{
return true;
}
public static Stream FileToStream(FileItem f)
{
// 把 byte[] 转换成 Stream
Stream stream = new MemoryStream(f.GetContent());
return stream;
}
}
}
}
\ No newline at end of file
using Com.Bocom.OpenApi;
using Com.Bocom.OpenApi.Utils;
using Kivii;
using Kivii.Text;
using Kivii.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Njzj.Bocoms.Openapis.Transforms
{
public class QueryContractOrderResponseV2Test : RestfulExecution<QueryContractOrderResponseV2>
{
public override object OnExecution(IRequest req, IResponse res)
{
DefaultBocomClient client = new DefaultBocomClient(Configs.APP_ID, Configs.MY_PRIVATE_KEY, Configs.APIGW_PUBLIC_KEY, BocomConstants.ENCRYPT_TYPE_RSA_AND_AES);
/**
* 测试环境可以忽略SSL证书告警,生产环境不可忽略
*/
client.IgnoreSslHostnameVerifier();
var request = new QueryContractOrderRequestV2();
request.SetServiceUrl(Configs.APIGW_URL_ADDRESS + Configs.QueryContractOrderRequestV2);
var bizContent = new QueryContractOrderRequestV2.QueryContractOrderRequestV2Biz();
bizContent.setOrgId(Configs.ORG_ID);
bizContent.setBillId("1354000420220402000000001792");
request.SetBizContent(bizContent);
var json = JsonSerializer.SerializeToString(request);
var response = client.Execute(request, Guid.NewGuid().ToString().Replace("-", ""));
var rtns = new RestfulExecutionResponse<string>();
rtns.Results = new List<string>();
if (response.IsSuccess())
{
rtns.Results.Add("success");
rtns.Results.Add($"ReturnCode:{response.GetRspCode()}{Environment.NewLine}ReturnMsg:{response.GetRspMsg()}");
rtns.Results.Add(response.ToString());
}
else
{
rtns.Results.Add("failed");
rtns.Results.Add($"ReturnCode:{response.GetRspCode()}{Environment.NewLine}ReturnMsg:{response.GetRspMsg()}");
}
return rtns;
}
}
public class WriteOffResultResponseV2Test : RestfulExecution<WriteOffResultResponseV2>
{
public override object OnExecution(IRequest req, IResponse res)
{
DefaultBocomClient client = new DefaultBocomClient(Configs.APP_ID, Configs.MY_PRIVATE_KEY, Configs.APIGW_PUBLIC_KEY);
/**
* 测试环境可以忽略SSL证书告警,生产环境不可忽略
*/
client.IgnoreSslHostnameVerifier();
WriteOffResultRequestV2 request = new WriteOffResultRequestV2();
request.SetServiceUrl(Configs.APIGW_URL_ADDRESS + Configs.WriteOffResultRequestV2);
WriteOffResultRequestV2.WriteOffResultRequestV2Biz bizContent = new WriteOffResultRequestV2.WriteOffResultRequestV2Biz();
bizContent.orgId = Configs.ORG_ID;
bizContent.subOrgId = Configs.SUB_ORG_ID;
bizContent.writeOffDte = "2022-05-03";
bizContent.writeOffNo = "2022050500004";
bizContent.pageablerequestPagenum = "1";
bizContent.pageablerequestPagesize = "10";
request.SetBizContent(bizContent);
var response = client.Execute(request, Guid.NewGuid().ToString().Replace("-", ""));
var rtns = new RestfulExecutionResponse<string>();
rtns.Results = new List<string>();
if (response.IsSuccess())
{
rtns.Results.Add("success");
rtns.Results.Add($"ReturnCode:{response.GetRspCode()}{Environment.NewLine}ReturnMsg:{response.GetRspMsg()}");
rtns.Results.Add(response.ToString());
}
else
{
rtns.Results.Add("failed");
rtns.Results.Add($"ReturnCode:{response.GetRspCode()}{Environment.NewLine}ReturnMsg:{response.GetRspMsg()}");
}
return rtns;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Kivii.Common" version="5.6.2023.4000" targetFramework="net45" />
<package id="Kivii.Core" version="5.6.2023.4140" targetFramework="net45" />
</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