跨境通申报助手V1.0
Posted kuangood
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了跨境通申报助手V1.0相关的知识,希望对你有一定的参考价值。
一、跨境通申报助手 介绍
经过多年的开发与修改对接了一部分口岸海关的申报对接,为了帮助进出口跨境电商企业,跨境通申报助手解决订单,支付,运单申报的问题,专注来做业务,推出跨境通申报助手V1.0
帮助进出口跨境电商对接各地申报海关对接的一个申报助手。免费提供学习,提供有偿服务,申报按票数计费,减轻企业成本.
二、加签方法如下
/// <summary>
/// 签名报文
/// </summary>
/// <param name="strMsgXml"></param>
/// <returns></returns>
private string EncryptToSHA1(string strMsgXml)
{
string result;
try
{
SHA1CryptoServiceProvider sha1CryptoServiceProvider = new SHA1CryptoServiceProvider();
byte[] bytes = Encoding.UTF8.GetBytes(strMsgXml);
byte[] inArray = sha1CryptoServiceProvider.ComputeHash(bytes);
sha1CryptoServiceProvider.Clear();
((IDisposable)sha1CryptoServiceProvider).Dispose();
result = Convert.ToBase64String(inArray);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return result;
}
/// <summary>
/// 读取设备
/// </summary>
/// <param name="centiNoOut"></param>
/// <returns></returns>
public bool IsICOrUKeyOk(out string centiNoOut)
{
centiNoOut = "";
bool result;
try
{
byte[] array = new byte[100];
int num = array.Length;
byte[] array2 = new byte[10000];
int num2 = array2.Length;
int cardID = ICHepler.GetCardID(array, out num);
if (cardID == 0)
{
int certNo = ICHepler.GetCertNo(array2, out num2);
if (certNo == 0)
{
byte[] array3 = new byte[num2];
Array.Copy(array2, array3, num2);
centiNoOut = Encoding.UTF8.GetString(array3);
return true;
}
if (certNo == -1)
{
throw new Exception("卡初始化出错");
}
if (certNo == -2)
{
throw new Exception("读取证书号失败");
}
}
else
{
if (cardID == -1)
{
throw new Exception("卡初始化出错");
}
if (cardID == -2)
{
throw new Exception("读取卡号失败");
}
}
result = false;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return result;
}
/// <summary>
/// 组织签各后的报文
/// </summary>
/// <param name="strMsgXml"></param>
/// <param name="digestMsg"></param>
/// <param name="signResult"></param>
/// <param name="centiNo"></param>
/// <param name="signInfo"></param>
/// <returns></returns>
private string RebuildXmlMsg(string strMsgXml, string digestMsg, string signResult, string centiNo, string signInfo)
{
string result;
try
{
string str = string.Format("<ds:Signature xmlns:ds=\\"http://www.w3.org/2000/09/xmldsig#\\"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm=\\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\\"/><ds:SignatureMethod Algorithm=\\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\\"/><ds:Reference URI=\\"\\"><ds:Transforms><ds:Transform Algorithm=\\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\\"/></ds:Transforms><ds:DigestMethod Algorithm=\\"http://www.w3.org/2000/09/xmldsig#sha1\\"/><ds:DigestValue>{0}</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>{1}</ds:SignatureValue><ds:KeyInfo><ds:KeyName>{2}</ds:KeyName><ds:X509Data><ds:X509Certificate>{3}</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature>", new object[]
{
digestMsg,
signResult,
centiNo,
signInfo
});
string text = strMsgXml.Substring(strMsgXml.LastIndexOf(\'<\'));
strMsgXml = strMsgXml.Replace(text, str + text);
result = strMsgXml;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return result;
}
/// <summary>
/// 签名报文
/// </summary>
/// <param name="digestMsg"></param>
/// <returns></returns>
private string OnlySignXml(string digestMsg)
{
string result;
try
{
byte[] bytes = Encoding.UTF8.GetBytes(digestMsg);
IntPtr intPtr = Marshal.AllocHGlobal(bytes.Length);
Marshal.Copy(bytes, 0, intPtr, bytes.Length);
byte[] array = new byte[200];
IntPtr intPtr2 = Marshal.AllocHGlobal(array.Length);
Marshal.Copy(array, 0, intPtr2, array.Length);
int num = array.Length;
string password = this.Password;
int num2 = ICHepler.Sign(intPtr, bytes.Length, intPtr2, ref num, password);
array = new byte[num];
Marshal.Copy(intPtr2, array, 0, num);
Marshal.FreeHGlobal(intPtr);
Marshal.FreeHGlobal(intPtr2);
if (num2 == 0)
{
result = Encoding.UTF8.GetString(array);
}
else
{
if (num2 == -1)
{
throw new Exception("卡初始化出错");
}
if (num2 == -2)
{
throw new Exception("卡口令不正确");
}
if (num2 == -3)
{
throw new Exception("签名失败");
}
if (num2 == -4)
{
throw new Exception("编码失败");
}
result = "";
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return result;
}
下载地址:
链接:https://pan.baidu.com/s/1813-eDsw3NiuUINH4wbEaQ
提取码:pbrm
以上是关于跨境通申报助手V1.0的主要内容,如果未能解决你的问题,请参考以下文章