Esempio n. 1
0
        /// <summary>
        /// 生成海关报关连接代码
        /// </summary>
        /// <returns></returns>
        /// <remarks>2016-06-06 杨云奕 添加</remarks>
        public static string GetAlipayAcquireCustoms(AlipayCustomsMdl mdl)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("service", mdl.service);
            dic.Add("partner", mdl.partner);
            dic.Add("_input_charset", mdl._input_charset);
            dic.Add("sign_type", mdl.sign_type);
            dic.Add("sign", mdl.sign);
            dic.Add("out_request_no", mdl.out_request_no);
            dic.Add("trade_no", mdl.trade_no);
            dic.Add("merchant_customs_code", mdl.merchant_customs_code);
            dic.Add("merchant_customs_name", mdl.merchant_customs_name);
            dic.Add("amount", mdl.amount.ToString());
            dic.Add("customs_place", mdl.customs_place);
            //dic.Add("order_fee", mdl.order_fee);
            //dic.Add("product_fee", mdl.product_fee);
            //dic.Add("service_version", mdl.service_version);
            //dic.Add("transport_fee", mdl.transport_fee);
            //dic.Add("merchant_customs_name", mdl.merchant_customs_name);
            //dic.Add("is_split", mdl.is_split);
            //dic.Add("sub_out_biz_no", mdl.sub_out_biz_no);

            string htmlUrl = "";

            foreach (string key in dic.Keys)
            {
                if (!string.IsNullOrEmpty(htmlUrl))
                {
                    htmlUrl += "&";
                }
                htmlUrl += key + "=" + dic[key];
            }
            return("https://mapi.alipay.com/gateway.do?" + htmlUrl);
        }
Esempio n. 2
0
        /// <summary>
        /// 生成支付宝报关签名
        /// </summary>
        /// <param name="mdl"></param>
        /// <returns></returns>
        /// <remarks>2016-06-06 杨云奕 添加</remarks>
        public static void CreateAlipayCustomsSign(AlipayCustomsMdl mdl)
        {
            string sign = "";
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("_input_charset", mdl._input_charset);
            dic.Add("amount", mdl.amount.ToString());
            dic.Add("customs_place", mdl.customs_place);
            dic.Add("merchant_customs_code", mdl.merchant_customs_code);
            dic.Add("merchant_customs_name", mdl.merchant_customs_name);
            dic.Add("out_request_no", mdl.out_request_no);
            dic.Add("partner", mdl.partner);
            dic.Add("service", mdl.service);
            dic.Add("trade_no", mdl.trade_no);
            foreach (string key in dic.Keys)
            {
                if (!string.IsNullOrEmpty(sign))
                {
                    sign += "&";
                }
                sign += key + "=" + dic[key];
            }
            Hyt.Model.Common.PayConfig modelConfig = Hyt.BLL.Config.Config.Instance.GetPayConfig();
            sign += modelConfig.AliPaykey;
            //Game.Utils.FileManager.WriteFile(Hyt.Util.WebUtil.GetMapPath("/AliAcquireCustoms011.txt"), sign);
            if (mdl.sign_type == "MD5")
            {
                StringBuilder sb  = new StringBuilder(32);
                MD5           md5 = new MD5CryptoServiceProvider();
                byte[]        t   = md5.ComputeHash(Encoding.GetEncoding(mdl._input_charset).GetBytes(sign));
                for (int i = 0; i < t.Length; i++)
                {
                    sb.Append(t[i].ToString("x").PadLeft(2, '0'));
                }
                sign = sb.ToString();
            }
            //Game.Utils.FileManager.WriteFile(Hyt.Util.WebUtil.GetMapPath("/AliAcquireCustoms012.txt"), sign);
            mdl.sign = sign;
        }
Esempio n. 3
0
        /// <summary>
        /// 支付宝报关实体
        /// </summary>
        /// <param name="payment"></param>
        /// <param name="soorder"></param>
        /// <returns></returns>
        public Result AliAcquireCustomsBackData(FnOnlinePayment payment, SoOrder soorder)
        {
            Result result = new Result();

            try
            {
                // Hyt.Model.Common.PayConfig modelConfig = Hyt.BLL.Config.Config.Instance.GetPayConfig();

                ///支付宝报关实体
                AlipayCustomsMdl mdl = new AlipayCustomsMdl();
                mdl.service               = customsConfig.service;
                mdl.partner               = customsConfig.partner;
                mdl._input_charset        = customsConfig.input_charset;
                mdl.sign_type             = customsConfig.sign_type;
                mdl.out_request_no        = payment.BusinessOrderSysNo;
                mdl.trade_no              = payment.VoucherNo;
                mdl.merchant_customs_code = customsConfig.merchant_customs_code;
                mdl.merchant_customs_name = customsConfig.merchant_customs_name;
                mdl.amount        = payment.Amount;
                mdl.customs_place = customsConfig.customs_place;

                string pushResult = "";

                string pushData      = "";
                string outReportData = "";

                #region 海关报关

                ///创建支付宝报关签名
                CreateAlipayCustomsSign(mdl);
                ///生成支付宝连接
                string uriPath = GetAlipayAcquireCustoms(mdl);
                //Game.Utils.FileManager.WriteFile(Hyt.Util.WebUtil.GetMapPath("/AliAcquireCustoms.txt"), uriPath);
                ///执行http连接获取返回的xml内容

                pushData = uriPath;
                string xml = Hyt.Util.MyHttp.GetResponse(uriPath);
                outReportData = xml;

                //Game.Utils.FileManager.WriteFile(Hyt.Util.WebUtil.GetMapPath("/AliAcquireCustomsBack.txt"), xml);
                ///返回实体内容
                AliAcquireCustomsBack backMod = SaveAlipayAcquireCustomsBackData(xml);
                backMod.OutRequestNo = mdl.out_request_no;
                backMod.OrderSysNo   = payment.SourceSysNo;
                backMod.Success      = "海关:" + backMod.Success;
                //AliAcquireCustomsBackBo.Instance.InnerAcquireCustoms(backMod);
                //pushResult = "海关:" + backMod.Success;
                if (backMod.Success != "海关:T")
                {
                    pushResult = "海关支付报关失败-" + xml;
                }
                #endregion

                #region 商检
                if (!string.IsNullOrEmpty(customsConfig.merchant_commodity_code))
                {
                    mdl.out_request_no        = "S" + soorder.OrderNo;
                    mdl.merchant_customs_code = customsConfig.merchant_commodity_code;
                    mdl.merchant_customs_name = customsConfig.merchant_commodity_name;
                    mdl.customs_place         = customsConfig.commodity_place;
                    CreateAlipayCustomsSign(mdl);
                    ///生成支付宝连接
                    uriPath = GetAlipayAcquireCustoms(mdl);
                    //Game.Utils.FileManager.WriteFile(Hyt.Util.WebUtil.GetMapPath("/AliAcquireSJ.txt"), uriPath);
                    ///执行http连接获取返回的xml内容

                    pushData      += "\r\n" + uriPath;
                    xml            = Hyt.Util.MyHttp.GetResponse(uriPath);
                    outReportData += "\r\n" + xml;

                    //Game.Utils.FileManager.WriteFile(Hyt.Util.WebUtil.GetMapPath("/AliAcquireSJBack.txt"), xml);
                    ///返回实体内容
                    backMod = SaveAlipayAcquireCustomsBackData(xml);
                    backMod.OutRequestNo = mdl.out_request_no;
                    backMod.OrderSysNo   = payment.SourceSysNo;
                    backMod.Success      = "商检:" + backMod.Success;
                    if (backMod.Success != "商检:T")
                    {
                        pushResult += "商检支付报关失败-" + xml;
                    }
                }
                //AcquireCustomsBo.Instance.InnerAcquireCustoms(backMod);
                //pushResult = "商检:" + backMod.Success;
                #endregion

                #region 将支付宝保税报关反馈信息返回到订单中
                SoOrder sorder = SoOrderBo.Instance.GetEntity(backMod.OrderSysNo);
                //sorder.CustomsResult = pushResult;
                //SoOrderBo.Instance.UpdateOrder(sorder);
                //Game.Utils.FileManager.WriteFile(Hyt.Util.WebUtil.GetMapPath("/CustomsResult.txt"), sorder.CustomsResult);

                if (string.IsNullOrEmpty(pushResult))
                {
                    result.Message = "提交成功!";
                    result.Status  = true;
                    //更新订单支付报关状态为处理中
                    Hyt.BLL.Order.SoOrderBo.Instance.UpdateOrderApiStatus((int)OrderStatus.支付报关状态.成功, 0, sorder.SysNo);
                    BLL.Log.SysLog.Instance.Info(LogStatus.系统日志来源.前台, "订单编号:" + sorder.SysNo + ",支付信息报关提交成功!" + "回执:" + outReportData, LogStatus.系统日志目标类型.订单支付报关, sorder.SysNo, 0);
                }
                else
                {
                    result.Message = pushResult;
                    result.Status  = false;
                    BLL.Log.LocalLogBo.Instance.Write("提交失败!" + pushResult, "EhkingCustomsLog");
                }


                result.Status = true;
            }
            catch (Exception e)
            {
                result.Status  = false;
                result.Message = e.Message;
            }
            #endregion

            return(result);
        }