ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

跨境通申报助手V1.0

2021-10-07 07:33:08  阅读:171  来源: 互联网

标签:Exception string V1.0 助手 result 跨境 new byte throw


一、跨境通申报助手 介绍

经过多年的开发与修改对接了一部分口岸海关的申报对接,为了帮助进出口跨境电商企业,跨境通申报助手解决订单,支付,运单申报的问题,专注来做业务,推出跨境通申报助手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

标签:Exception,string,V1.0,助手,result,跨境,new,byte,throw
来源: https://www.cnblogs.com/kuangood2018/p/15374899.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有