コード例 #1
0
        /// <summary>
        /// 构造上送请求数据
        /// </summary>
        /// <param name="context">支付上下文</param>
        /// <returns></returns>
        protected virtual string BuildRequestContent(ChargeContext context)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("<form id='chargeForm' name='chargeForm' method='{1}' action='{0}'>",
                                 context.PaymentInfo.PaymentMode.PaymentUrl,
                                 context.PaymentInfo.PaymentMode.RequestType);

            if (context.RequestForm != null && context.RequestForm.Count > 0)
            {
                foreach (string name in context.RequestForm)
                {
                    string value = context.RequestForm[name];
                    builder.AppendFormat("<input type='hidden' name='{0}' value='{1}' />"
                                         , name, value);
                }
            }

            builder.Append("</form>");

            builder.Insert(0, string.Format(@"<html><head><meta http-equiv='pragma' content='no-cache'/><title>{0}</title></head><body>", "在线支付"));
            builder.AppendFormat("<center>正在提交支付数据,请稍候...</center>");
            builder.AppendFormat("<script language='javascript'>");
            builder.AppendFormat("var theForm = document.forms['chargeForm'];");
            builder.AppendFormat("if (!theForm) theForm = document.chargeForm;");
            builder.AppendFormat("theForm.submit();");
            builder.AppendFormat("</script>");
            builder.AppendFormat("</body></html>");

            return(builder.ToString());
        }
コード例 #2
0
ファイル: ChargeTenPay.cs プロジェクト: sanlonezhang/ql
        private string SignData(ChargeContext context)
        {
            string md5SourceValue = "";

            string[] allKeys = context.RequestForm.AllKeys;
            Array.Sort(allKeys);
            foreach (var item in allKeys)
            {
                if (item == "sign")
                {
                    continue;
                }
                string value = context.RequestForm[item];
                if (!string.IsNullOrWhiteSpace(value))
                {
                    md5SourceValue += string.Format("{0}={1}&", item, value);
                }
            }
            md5SourceValue += string.Format("key={0}", context.PaymentInfoMerchant.MerchantCertKey);

            string signStr = GetMD5(md5SourceValue, context.PaymentInfoMerchant.Encoding).ToUpper();

            //Debug模式下记录相关信息至日志
            if (context.PaymentInfo.PaymentMode.Debug.Equals("1"))
            {
                string sourceData = BuildStringFromNameValueCollection(context.RequestForm);
                ECommerce.Utility.Logger.WriteLog(string.Format("原始值:{0},签名明文:{1},签名:{2}", sourceData, md5SourceValue, signStr), "TenPay", "PaySignData");
            }

            return(signStr);
        }
コード例 #3
0
ファイル: ChargeTenPay.cs プロジェクト: sanlonezhang/ql
        public override void SetRequestForm(ChargeContext context)
        {
            context.SOInfo.SellerSysNo             = 1;
            context.RequestForm["sign_type"]       = "MD5";
            context.RequestForm["service_version"] = "1.0";
            context.RequestForm["input_charset"]   = context.PaymentInfoMerchant.Encoding;//编码
            context.RequestForm["sign_key_index"]  = "1";
            context.RequestForm["bank_type"]       = "DEFAULT";
            context.RequestForm["body"]            = "KJT_SO_" + context.SOInfo.SoSysNo.ToString();                                                            //商品标题
            //context.RequestForm["attach"] = "";
            context.RequestForm["return_url"] = BuildActionUrl(context.PaymentInfo.PaymentBase.BaseUrl, context.PaymentInfo.PaymentMode.PaymentCallbackUrl);   //针对该交易支付成功之后的前台通知URL
            context.RequestForm["notify_url"] = BuildActionUrl(context.PaymentInfo.PaymentBase.BaseUrl, context.PaymentInfo.PaymentMode.PaymentBgCallbackUrl); //针对该交易支付成功之后的通知接收URL
            //context.RequestForm["buyer_id"] = "";
            context.RequestForm["partner"]          = context.PaymentInfoMerchant.MerchantNO;                                                                  //境外商户在财付通的用户ID
            context.RequestForm["out_trade_no"]     = context.SOInfo.SoSysNo.ToString();                                                                       //境外商户交易号,订单号
            context.RequestForm["total_fee"]        = ((int)(100 * context.SOInfo.RealPayAmt)).ToString();
            context.RequestForm["fee_type"]         = context.PaymentInfoMerchant.CurCode;                                                                     //币种
            context.RequestForm["spbill_create_ip"] = GetCientIP();                                                                                            //IP
            //风控字段
            context.RequestForm["risk_info"] = HttpUtility.UrlEncode("line_type=on&goods_type=phy&deliver=log&&seller_tag=mer");

            //context.RequestForm["time_start"] = "";
            //context.RequestForm["time_expire"] = "";
            //context.RequestForm["transport_fee"] = "";
            //context.RequestForm["product_fee"] = "";
            //context.RequestForm["goods_tag"] = "";
            context.RequestForm["sign"] = SignData(context).ToUpper();//签名
        }
コード例 #4
0
ファイル: ChargeAliPay.cs プロジェクト: sanlonezhang/ql
 public override void SetRequestForm(ChargeContext context)
 {
     //不要改变顺序
     context.RequestForm["_input_charset"]     = context.PaymentInfoMerchant.Encoding;
     context.RequestForm["body"]               = "";                                                                                                            //商品描述 可空
     context.RequestForm["buyer_email"]        = "";                                                                                                            //买家支付宝账号 可空
     context.RequestForm["extra_common_param"] = context.PaymentModeId.ToString();
     context.RequestForm["it_b_pay"]           = "";                                                                                                            //超时时间 可空
     context.RequestForm["notify_url"]         = BuildActionUrl(context.PaymentInfo.PaymentBase.BaseUrl, context.PaymentInfo.PaymentMode.PaymentBgCallbackUrl); //服务器异步通知页面路径 可空
     context.RequestForm["out_trade_no"]       = context.SOInfo.SoSysNo.ToString();                                                                             //商户网站唯一订单号 必填
     context.RequestForm["partner"]            = context.PaymentInfoMerchant.MerchantCert;                                                                      //合作者身份ID,以2008开头 必填
     context.RequestForm["payment_type"]       = "1";                                                                                                           //支付类型 必填
     context.RequestForm["paymethod"]          = "";                                                                                                            //默认支付方式,默认识别为余额支付(creditPay、directPay) 可空
     context.RequestForm["price"]              = "";                                                                                                            //商品单价 规则:price、quantity能代替total_fee。即存在total_fee,就不能存在price和quantity;存在price、quantity,就不能存在total_fee 可空
     context.RequestForm["quantity"]           = "";                                                                                                            //可空
     context.RequestForm["return_url"]         = BuildActionUrl(context.PaymentInfo.PaymentBase.BaseUrl, context.PaymentInfo.PaymentMode.PaymentCallbackUrl);   //页面跳转同步通知地址 可空
     context.RequestForm["royalty_parameters"] = "";                                                                                                            //分润账号集 可空
     context.RequestForm["royalty_type"]       = "";                                                                                                            //提成类型10 当传递了参数royalty_parameters时,提成类型参数不能为空 可空
     context.RequestForm["seller_email"]       = context.PaymentInfoMerchant.MerchantNO;                                                                        //卖家支付宝账号
     context.RequestForm["service"]            = "create_direct_pay_by_user";                                                                                   //接口名称 必填
     context.RequestForm["show_url"]           = "";                                                                                                            //商品展示网址 可空
     context.RequestForm["subject"]            = "SJSD_SO_" + context.SOInfo.SoSysNo.ToString();                                                                //商品名称 必填
     context.RequestForm["token"]              = "";                                                                                                            //快捷登录授权令牌 可空
     context.RequestForm["total_fee"]          = context.SOInfo.RealPayAmt.ToString("F2");                                                                      //交易金额 可空
     context.RequestForm["sign"]               = SignData(context);                                                                                             //签名 必填
     context.RequestForm["sign_type"]          = "MD5";                                                                                                         //签名方式DSA、RSA、MD5 必填
 }
コード例 #5
0
        /// <summary>
        /// 同步Check订单(1000订单不存在,2000订单不是待支付状态,3000订单已支付,4000通过Check)
        /// </summary>
        /// <param name="SOSysNo">订单系统编号</param>
        /// <returns>1000订单不存在,2000订单不是待支付状态,3000订单已支付,4000通过Check</returns>
        public int AliPayCheck(int SOSysNo)
        {
            ChargeContext context = new ChargeContext();

            //支付时获取SO详细信息,从CenterDB获取
            context.SOInfo = ShoppingOrderDA.PayGetCenterDBOrderInfoBySOSysNo(SOSysNo);
            if (context.SOInfo == null || context.SOInfo.SOItemList == null || context.SOInfo.SOItemList.Count == 0)
            {
                //throw new BusinessException("订单不存在!");
                return(1000);
            }
            //if (context.SOInfo.Status != Enums.SOStatus.Original)
            //{
            //    //throw new BusinessException("订单不是待支付状态!");
            //    return 2000;
            //}
            //根据订单号查询Netpay
            var netPayInfo = ShoppingOrderDA.GetCenterDBNetpayBySOSysNo(SOSysNo);

            if (netPayInfo != null && netPayInfo.Status > (int)NetPayStatusType.Origin)
            {
                //throw new BusinessException("订单已支付!");
                return(3000);
            }
            return(4000);
        }
コード例 #6
0
ファイル: ChargeIpsPay.cs プロジェクト: sanlonezhang/ql
        /// <summary>
        /// Sets the request form.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void SetRequestForm(ChargeContext context)
        {
            context.RequestForm["Mer_code"]      = context.PaymentInfo.PaymentMode.BankCert;
            context.RequestForm["Billno"]        = context.SOInfo.SoSysNo.ToString();
            context.RequestForm["Amount"]        = context.SOInfo.RealPayAmt.ToString("######0.00");
            context.RequestForm["Date"]          = context.SOInfo.OrderDate.ToString("yyyyMMdd");
            context.RequestForm["Currency_Type"] = "RMB";
            context.RequestForm["Gateway_Type "] = "01";
            context.RequestForm["Lang"]          = "GB";
            context.RequestForm["Attach"]        = context.SOInfo.Payment.PayTypeID.ToString();

            context.RequestForm["Merchanturl"] = BuildActionUrl(context.PaymentInfo.PaymentBase.BaseUrl,
                                                                context.PaymentInfo.PaymentMode.PaymentCallbackUrl);
            context.RequestForm["ServerUrl"] = BuildActionUrl(context.PaymentInfo.PaymentBase.BaseUrl,
                                                              context.PaymentInfo.PaymentMode.PaymentBgCallbackUrl);

            context.RequestForm["OrderEncodeType"] = "5";
            context.RequestForm["RetEncodeType"]   = "17";
            context.RequestForm["Rettype"]         = "1";

            if (context.PaymentInfo.PaymentMode.CustomConfigs != null &&
                context.PaymentInfo.PaymentMode.CustomConfigs["DoCredit"] != null &&
                context.PaymentInfo.PaymentMode.CustomConfigs["DoCredit"] == "1" &&
                context.PaymentInfo.PaymentMode.CustomConfigs["Bankco"] != null)
            {
                context.RequestForm["DoCredit"] = context.PaymentInfo.PaymentMode.CustomConfigs["DoCredit"];
                context.RequestForm["Bankco"]   = context.PaymentInfo.PaymentMode.CustomConfigs["Bankco"];
            }

            context.RequestForm["SignMD5"] = SignData(context);
        }
コード例 #7
0
ファイル: ChargeIpsPay.cs プロジェクト: sanlonezhang/ql
        /// <summary>
        /// Signs the data.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private string SignData(ChargeContext context)
        {
            string result = string.Empty;

            Dictionary <string, object> signParams = new Dictionary <string, object>();

            signParams.Add("billno", context.RequestForm["Billno"]);
            signParams.Add("currencytype", context.RequestForm["Currency_Type"]);
            signParams.Add("amount", context.RequestForm["Amount"]);
            signParams.Add("date", context.RequestForm["Date"]);
            signParams.Add("orderencodetype", context.RequestForm["OrderEncodeType"]);

            StringBuilder sb = new StringBuilder();

            foreach (KeyValuePair <string, object> item in signParams)
            {
                sb.AppendFormat("{0}{1}", item.Key, item.Value);
            }

            sb.Append(context.PaymentInfo.PaymentMode.BankCertKey);

            result = GetMD5(sb.ToString(), context.PaymentInfo.PaymentMode.CustomConfigs["encoding"]);

            return(result);
        }
コード例 #8
0
ファイル: ChargeChinaPay.cs プロジェクト: sanlonezhang/ql
        /// <summary>
        /// Signs the data.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private void SignData(ChargeContext context)
        {
            string certPath = context.PaymentInfoMerchant.MerchantCert;
            string certPwd  = context.PaymentInfoMerchant.MerchantCertKey;

            context.RequestForm["certId"] = CertUtil.GetSignCertId(certPath, certPwd);

            //将Dictionary信息转换成key1=value1&key2=value2的形式
            string stringData = SDKUtil.CreateLinkString(context.RequestForm, true, false);
            //log.Info("待签名排序串:[" + stringData + "]");

            string stringSign = null;

            byte[] signDigest = SecurityUtil.Sha1X16(stringData, Encoding.UTF8);

            string stringSignDigest = BitConverter.ToString(signDigest).Replace("-", "").ToLower();

            //log.Info("sha1结果:[" + stringSignDigest + "]");

            byte[] byteSign = SecurityUtil.SignBySoft(CertUtil.GetSignProviderFromPfx(certPath, certPwd), Encoding.UTF8.GetBytes(stringSignDigest));

            stringSign = Convert.ToBase64String(byteSign);
            //log.Info("签名结果:[" + stringSign + "]");

            //设置签名域值
            context.RequestForm["signature"] = stringSign;
        }
コード例 #9
0
ファイル: ChargeEasiPay.cs プロジェクト: sanlonezhang/ql
        private string SignData(ChargeContext context)
        {
            StringBuilder builder = new StringBuilder();
            int           index   = 0;

            foreach (var item in context.RequestForm.AllKeys)
            {
                string value = context.RequestForm[item];
                if (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(value.Trim()))
                {
                    builder.Append(item);
                    builder.Append("=");
                    builder.Append(context.RequestForm[item]);
                    if (index != context.RequestForm.AllKeys.Length - 1)
                    {
                        builder.Append("&");
                    }
                }
                index = index + 1;
            }

            string dataStr = string.Format("{0}{1}", builder.ToString().TrimEnd('&'), context.PaymentInfoMerchant.MerchantCertKey);
            string signStr = GetMD5(dataStr, context.PaymentInfoMerchant.Encoding).ToUpper();

            //Debug模式下记录相关信息至日志
            if (context.PaymentInfo.PaymentMode.Debug.Equals("1"))
            {
                string sourceData = BuildStringFromNameValueCollection(context.RequestForm);
                Nesoft.Utility.Logger.WriteLog(string.Format("原始值:{0},签名明文:{1},签名:{2}", sourceData, dataStr, signStr), "EasiPay", "PaySignData");
            }

            return(signStr);
        }
コード例 #10
0
 public void BaseSetup()
 {
     _factory        = new MockWebApplicationFactory <TStartup>(_connection);
     Client          = _factory.CreateClient();
     DatabaseContext = new ChargeContext(_builder.Options);
     DatabaseContext.Database.EnsureCreated();
     _transaction = DatabaseContext.Database.BeginTransaction();
 }
コード例 #11
0
ファイル: DatabaseTests.cs プロジェクト: hjolany/charges-api
        public void RunBeforeAnyTests()
        {
            var builder = new DbContextOptionsBuilder();

            builder.UseNpgsql(ConnectionString.TestDatabase());
            DatabaseContext = new ChargeContext(builder.Options);

            DatabaseContext.Database.EnsureCreated();
            _transaction = DatabaseContext.Database.BeginTransaction();
        }
コード例 #12
0
        public static Charges GetInstance(ChargeContext context)
        {
            if (context != null && context.PaymentModeId > 0)
            {
                context.PaymentInfo = GetPaymentInfo(context.PaymentModeId);
                if (context.PaymentInfo != null && context.PaymentInfo.PaymentMode != null)
                {
                    return(GetInstance(context.PaymentInfo.PaymentMode.ChargeProcessor));
                }
            }

            return(null);
        }
コード例 #13
0
        /// <summary>
        /// 根据支付上下文获取一个支付上送请求数据
        /// </summary>
        /// <param name="context">支付上下文</param>
        /// <returns></returns>
        public string GetRequestContent(ChargeContext context)
        {
            if (context != null && context.PaymentModeId > 0)
            {
                if (context.RequestForm == null)
                {
                    context.RequestForm = new NameValueCollection();
                }
                SetRequestForm(context);

                return(BuildRequestContent(context));
            }

            return(string.Empty);
        }
コード例 #14
0
ファイル: ChargeZJTLCB.cs プロジェクト: sanlonezhang/ql
        /// <summary>
        /// Signs the data.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private string SignData(ChargeContext context)
        {
            string result = string.Empty;

            string strPfxFile  = string.Empty;
            string strPfxPwd   = context.PaymentInfo.PaymentMode.CustomConfigs["PfxPwd"];
            string pOriginData = string.Empty;

            if (!Path.IsPathRooted(context.PaymentInfo.PaymentMode.BankCertKey))
            {
                strPfxFile = HttpContext.Current.Server.MapPath(@"~/bin/" + context.PaymentInfo.PaymentMode.BankCertKey.TrimStart('/').TrimStart('\\'));
            }
            else
            {
                strPfxFile = context.PaymentInfo.PaymentMode.BankCertKey;
            }

            StringBuilder sb = new StringBuilder();

            sb.Append(context.RequestForm["merchantNo"]);
            sb.Append("|");
            sb.Append(context.RequestForm["orderNo"]);
            sb.Append("|");
            sb.Append(context.RequestForm["orderAmt"]);
            sb.Append("|");
            sb.Append(context.RequestForm["orderDate"]);
            sb.Append("|");
            sb.Append(context.RequestForm["orderTime"]);
            sb.Append("|");
            sb.Append(context.RequestForm["currencyType"]);

            pOriginData = sb.ToString();

            Logger.WriteLog(string.Format("中间日志,strPfxFile:{0},strPfxPwd:{1},pOriginData:{2}", strPfxFile, strPfxPwd, pOriginData), "ChargeZJTLCB", "SignData");
            string code = TryToSignData(strPfxFile, strPfxPwd, pOriginData);


            if (!string.IsNullOrWhiteSpace(code))
            {
                return(code);
            }
            else
            {
                Logger.WriteLog(string.Format("签名失败,错误代码:{0},", code), "ChargeZJTLCB", "SignData");

                return(string.Empty);
            }
        }
コード例 #15
0
ファイル: ChargeEasiPay.cs プロジェクト: sanlonezhang/ql
        /// <summary>
        /// 支付签名
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string SignData(ChargeContext context)
        {
            string sourceSignValue = "{0}^{2}^{3}^{1}";
            string prefixCertKey   = context.PaymentInfoMerchant.MerchantCertKey.Substring(0, 64);
            string suffixCertKey   = context.PaymentInfoMerchant.MerchantCertKey.Substring(64, 64);

            sourceSignValue = string.Format(sourceSignValue, prefixCertKey, suffixCertKey, context.RequestForm["SENDER_CODE"], context.RequestForm["TRX_CONTENT"]);
            string signValue = GetMD5(sourceSignValue, context.PaymentInfoMerchant.Encoding).ToUpper();

            //Debug模式下记录相关信息至日志
            if (context.PaymentInfo.PaymentMode.Debug.Equals("1"))
            {
                Nesoft.Utility.Logger.WriteLog(string.Format("签名明文:{0},签名:{1}", sourceSignValue, signValue)
                                               , "EasiPay", "PaySignData");
            }
            return(signValue);
        }
コード例 #16
0
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.ConfigureAppConfiguration(b => b.AddEnvironmentVariables())
            .UseStartup <Startup>();
            builder.ConfigureServices(services =>
            {
                var dbBuilder = new DbContextOptionsBuilder();
                dbBuilder.UseNpgsql(_connection);
                var context = new ChargeContext(dbBuilder.Options);
                services.AddSingleton(context);

                var serviceProvider = services.BuildServiceProvider();
                var dbContext       = serviceProvider.GetRequiredService <ChargeContext>();

                dbContext.Database.EnsureCreated();
            });
        }
コード例 #17
0
        /// <summary>
        /// 支付
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public string Payment(int SOSysNo)
        {
            ChargeContext context = new ChargeContext();

            context.SOInfo = ShoppingOrderDA.PayGetCenterDBOrderInfoBySOSysNo(SOSysNo);
            if (context.SOInfo == null || context.SOInfo.SOItemList == null ||
                context.SOInfo.SOItemList.Count == 0)
            {
                throw new BusinessException("订单不存在!");
            }
            if (context.SOInfo.Status != Enums.SOStatus.Original)
            {
                throw new BusinessException("订单不是待支付状态!");
            }
            var netPayInfo = ShoppingOrderDA.GetCenterDBNetpayBySOSysNo(SOSysNo);

            if (netPayInfo != null && netPayInfo.Status > (int)NetPayStatusType.Origin)
            {
                throw new BusinessException("订单已支付!");
            }

            if (context.SOInfo.Payment != null)
            {
                context.PaymentModeId = context.SOInfo.Payment.PayTypeID;
                CustomerFacade.UpdateCustomerLastOrderPayTypeID(context.SOInfo.CustomerSysNo, context.SOInfo.Payment.PayTypeID);
            }

            Charges charge = Charges.GetInstance(context);

            if (charge != null)
            {
                charge.UpdateChargePayment(context);
            }

            return(charge != null?charge.GetRequestContent(context) : string.Empty);
        }
コード例 #18
0
ファイル: ChargeEasiPay.cs プロジェクト: sanlonezhang/ql
 public override void UpdateChargePayment(ChargeContext context)
 {
     UpdatePayment(context.SOInfo.SoSysNo, context.PaymentInfo.PaymentMode.MerchantList);
 }
コード例 #19
0
ファイル: ChargeEasiPay.cs プロジェクト: sanlonezhang/ql
        public override void SetRequestForm(ChargeContext context)
        {
            List <Dictionary <string, string> > detailList = new List <Dictionary <string, string> >();

            #region 1.单笔值计算
            decimal allCargoTotalPrice = 0m;
            decimal totalTariffAmount  = 0m;
            decimal otherPrice         = Math.Abs(context.SOInfo.Amount.PrepayAmt) * -1;
            foreach (var item in context.SOInfo.SOItemList)
            {
                totalTariffAmount += item.TariffAmt * item.Quantity;
                item.ProductName   = item.ProductName.Replace("#", "").Replace("%", "").Replace("&", "").Replace("+", "");
                //折扣除不尽时,把多余的作为OtherPrice上送
                decimal currOtherPrice = Math.Abs(item.DiscountAmt) % item.Quantity;
                otherPrice += currOtherPrice * -1;
                //Item上是商品本身的价格,需要排除折扣
                decimal unitPrice = item.OriginalPrice - ((Math.Abs(item.DiscountAmt) - currOtherPrice) / item.Quantity);
                unitPrice           = decimal.Parse(unitPrice.ToString("F2"));
                otherPrice         += Math.Abs(item.PromotionDiscount * item.Quantity) * -1;
                allCargoTotalPrice += unitPrice * item.Quantity;
            }
            //积分支付作为其他金额报关
            otherPrice += Math.Abs(context.SOInfo.Amount.PointPay * 1.00m / decimal.Parse(Nesoft.ECWeb.Entity.ConstValue.PointExhangeRate)) * -1;
            #endregion

            #region 2.基本信息
            Dictionary <string, string> baseList = new Dictionary <string, string>();
            //订单号
            baseList["BILLNO"] = context.SOInfo.SoSysNo.ToString();
            //线上回调地址
            baseList["CALLBACKURL"] = BuildActionUrl(context.PaymentInfo.PaymentBase.BaseUrl, context.PaymentInfo.PaymentMode.PaymentCallbackUrl);
            //线下后台通知商户地址
            baseList["BGURL"] = BuildActionUrl(context.PaymentInfo.PaymentBase.BaseUrl, context.PaymentInfo.PaymentMode.PaymentBgCallbackUrl);
            //请求时间
            baseList["REQ_TIME"] = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss");
            //一级商户代码
            baseList["SRC_NCODE"] = context.PaymentInfoMerchant.CBTSRC_NCode;
            //二级商户代码
            baseList["REC_NCODE"] = context.PaymentInfoMerchant.CBTREC_NCode;
            //支付业务
            baseList["PAY_BIZ"] = "30";
            //支付总金额
            baseList["PAY_AMOUNT"] = (allCargoTotalPrice + totalTariffAmount + context.SOInfo.Amount.ShipPrice + otherPrice).ToString("F2");
            //计价币种
            baseList["PAY_CURRENCY"] = "CNY";
            //贸易类型
            baseList["TRADE_TYPE"] = "010204";
            //商品总数
            baseList["CARGO_SUM"] = context.SOInfo.SOItemList.Count.ToString();
            //资金用途
            baseList["TXUSE"] = "10";
            //交易描述
            baseList["TRX_DESC"] = "";
            //订单链接地址
            baseList["BILL_LINK"] = "";
            baseList["SPT1"]      = "";
            baseList["SPT2"]      = "";
            baseList["SPT3"]      = "";
            #endregion

            //其他金额可以抵扣货款和运费,先抵扣货款,再抵扣运费
            decimal productAmt  = 0m;
            decimal shippingAmt = 0m;
            if (Math.Abs(otherPrice) > Math.Abs(allCargoTotalPrice))
            {
                productAmt  = 0m;
                shippingAmt = context.SOInfo.Amount.ShipPrice - (Math.Abs(otherPrice) - Math.Abs(allCargoTotalPrice));
            }
            else
            {
                productAmt  = Math.Abs(allCargoTotalPrice) - Math.Abs(otherPrice);
                shippingAmt = context.SOInfo.Amount.ShipPrice;
            }

            #region 3.货款
            Dictionary <string, string> productFeeList = new Dictionary <string, string>();
            //子交易种类
            productFeeList["BILL_TYPE"] = "10";
            //订单时间
            productFeeList["BILL_DATE"] = context.SOInfo.OrderDate.ToString("yyyy-MM-ddTHH:mm:ss");
            //支付金额
            productFeeList["PAY_AMOUNT"] = productAmt.ToString("F2");
            //支付币种
            productFeeList["PAY_CURRENCY"] = context.PaymentInfoMerchant.PayCurrencyCode;
            //收款币种
            productFeeList["CRT_CURRENCY"] = context.PaymentInfoMerchant.CurCode;
            //是否跨境结算(外汇结算)标志
            productFeeList["BORDER_MARK"] = context.PaymentInfoMerchant.CurCode.Equals("CNY") ? "00" : "01";
            //收款方代码类型
            productFeeList["CRT_CODE_TYPE"] = "10";
            //收款方代码
            productFeeList["CRT_CODE"] = context.PaymentInfoMerchant.MerchantNO;
            //子交易描述
            productFeeList["BILL_DESC"] = "";
            productFeeList["SSPT1"]     = "";
            productFeeList["SSPT2"]     = "";
            detailList.Add(productFeeList);
            #endregion

            #region 4.税费
            Dictionary <string, string> taxFeeList = new Dictionary <string, string>();
            //子交易种类
            taxFeeList["BILL_TYPE"] = "30";
            //订单时间
            taxFeeList["BILL_DATE"] = context.SOInfo.OrderDate.ToString("yyyy-MM-ddTHH:mm:ss");
            //支付金额
            taxFeeList["PAY_AMOUNT"] = totalTariffAmount.ToString("F2");
            //支付币种
            taxFeeList["PAY_CURRENCY"] = context.PaymentInfoMerchant.PayCurrencyCode;
            //收款币种 *海关收款传人民币*
            taxFeeList["CRT_CURRENCY"] = "CNY"; //context.PaymentInfoMerchant.CurCode;
            //是否跨境结算(外汇结算)标志
            taxFeeList["BORDER_MARK"] = "00";   //context.PaymentInfoMerchant.CurCode.Equals("CNY") ? "00" : "01";
            //收款方代码类型
            taxFeeList["CRT_CODE_TYPE"] = "20";
            //收款方代码
            taxFeeList["CRT_CODE"] = context.SOInfo.CustomsCode;
            //子交易描述
            taxFeeList["BILL_DESC"] = "";
            taxFeeList["SSPT1"]     = "";
            taxFeeList["SSPT2"]     = "";
            detailList.Add(taxFeeList);
            #endregion

            #region 5.运费
            Dictionary <string, string> shippingFeeList = new Dictionary <string, string>();
            //子交易种类
            shippingFeeList["BILL_TYPE"] = "20";
            //订单时间
            shippingFeeList["BILL_DATE"] = context.SOInfo.OrderDate.ToString("yyyy-MM-ddTHH:mm:ss");
            //支付金额
            shippingFeeList["PAY_AMOUNT"] = shippingAmt.ToString("F2");
            //支付币种
            shippingFeeList["PAY_CURRENCY"] = context.PaymentInfoMerchant.PayCurrencyCode;
            //收款币种
            shippingFeeList["CRT_CURRENCY"] = context.PaymentInfoMerchant.CurCode;
            //是否跨境结算(外汇结算)标志
            shippingFeeList["BORDER_MARK"] = context.PaymentInfoMerchant.CurCode.Equals("CNY") ? "00" : "01";
            //收款方代码类型
            shippingFeeList["CRT_CODE_TYPE"] = "10";
            //收款方代码
            shippingFeeList["CRT_CODE"] = context.PaymentInfoMerchant.MerchantNO;
            //子交易描述
            shippingFeeList["BILL_DESC"] = "";
            shippingFeeList["SSPT1"]     = "";
            shippingFeeList["SSPT2"]     = "";
            detailList.Add(shippingFeeList);
            #endregion

            StringBuilder reqXml = new StringBuilder();
            reqXml.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><EasipayB2CRequest><CnyPayRequest>");
            foreach (KeyValuePair <string, string> item in baseList)
            {
                reqXml.AppendFormat("<{0}><![CDATA[{1}]]></{0}>", item.Key, item.Value);
            }
            foreach (Dictionary <string, string> itemList in detailList)
            {
                reqXml.Append("<PayDetail>");
                foreach (KeyValuePair <string, string> item in itemList)
                {
                    reqXml.AppendFormat("<{0}><![CDATA[{1}]]></{0}>", item.Key, item.Value);
                }
                reqXml.Append("</PayDetail>");
            }
            reqXml.Append("</CnyPayRequest></EasipayB2CRequest>");
            string trxcontent = Base64Encode(reqXml.ToString());
            context.RequestForm["SENDER_CODE"] = context.PaymentInfoMerchant.MerchantNO;
            context.RequestForm["TRX_CONTENT"] = trxcontent;
            context.RequestForm["SIGNATURE"]   = SignData(context);

            //Debug模式下记录相关信息至日志
            if (context.PaymentInfo.PaymentMode.Debug.Equals("1"))
            {
                Nesoft.Utility.Logger.WriteLog(string.Format("请求xml:{0}", reqXml.ToString())
                                               , "EasiPay", "PayXMLData");
            }
        }
コード例 #20
0
ファイル: ChargeEasiPay.cs プロジェクト: sanlonezhang/ql
        public override void SetRequestForm(ChargeContext context)
        {
            //不要改变顺序,按支付接口文档所给顺序设置值

            #region 单笔值计算
            decimal allCargoTotalPrice = 0m;
            string  cargoDescript      = "";
            decimal totalTariffAmount  = 0m;
            decimal otherPrice         = Math.Abs(context.SOInfo.Amount.PrepayAmt) * -1;
            int     cargoTypeNum       = 0;
            string  cargoName          = "";
            string  cargoCode          = "";
            string  _HSCode            = "";
            string  cargoNum           = "";
            string  cargoUnitPrice     = "";
            string  cargoTotalPrice    = "";
            string  cargoTotalTax      = "";

            foreach (var item in context.SOInfo.SOItemList)
            {
                cargoDescript     += (string.IsNullOrEmpty(cargoDescript) ? "" : ";") + (item.ProductName.Replace("#", "").Replace("%", "").Replace("&", "").Replace("+", "") + "描述");
                totalTariffAmount += item.TariffAmt * item.Quantity;
                cargoTypeNum      += item.Quantity;
                item.ProductName   = item.ProductName.Replace("#", "").Replace("%", "").Replace("&", "").Replace("+", "");
                cargoName         += (string.IsNullOrEmpty(cargoName) ? "" : "^") + item.ProductName;
                cargoCode         += (string.IsNullOrEmpty(cargoCode) ? "" : "^") + item.EntryCode;
                _HSCode           += (string.IsNullOrEmpty(_HSCode) ? "" : "^") + item.TariffCode;
                cargoNum          += (string.IsNullOrEmpty(cargoNum) ? "" : "^") + item.Quantity.ToString();
                //折扣除不尽时,把多余的作为OtherPrice上送
                decimal currOtherPrice = Math.Abs(item.DiscountAmt) % item.Quantity;
                otherPrice += currOtherPrice * -1;
                //Item上是商品本身的价格,需要排除折扣
                decimal unitPrice = item.OriginalPrice - ((Math.Abs(item.DiscountAmt) - currOtherPrice) / item.Quantity);
                unitPrice           = decimal.Parse(unitPrice.ToString("F2"));
                cargoUnitPrice     += (string.IsNullOrEmpty(cargoUnitPrice) ? "" : "^") + unitPrice.ToString("F2");
                cargoTotalPrice    += (string.IsNullOrEmpty(cargoTotalPrice) ? "" : "^") + (unitPrice * item.Quantity).ToString("F2");
                cargoTotalTax      += (string.IsNullOrEmpty(cargoTotalTax) ? "" : "^") + (item.TariffAmt * item.Quantity).ToString("F2");
                otherPrice         += Math.Abs(item.PromotionDiscount * item.Quantity) * -1;
                allCargoTotalPrice += unitPrice * item.Quantity;
            }
            //积分支付作为其他金额报关
            otherPrice += Math.Abs(context.SOInfo.Amount.PointPay * 1.00m / decimal.Parse(Nesoft.ECWeb.Entity.ConstValue.PointExhangeRate)) * -1;
            #endregion

            context.RequestForm["InputCharset"]    = "1";
            context.RequestForm["Version"]         = "v1.2";
            context.RequestForm["Language"]        = "1";
            context.RequestForm["SignType"]        = "1";
            context.RequestForm["PageUrl"]         = BuildActionUrl(context.PaymentInfo.PaymentBase.BaseUrl, context.PaymentInfo.PaymentMode.PaymentCallbackUrl);
            context.RequestForm["BgUrl"]           = BuildActionUrl(context.PaymentInfo.PaymentBase.BaseUrl, context.PaymentInfo.PaymentMode.PaymentBgCallbackUrl);
            context.RequestForm["ShowUrl"]         = BuildActionUrl(context.PaymentInfo.PaymentBase.BaseUrl, context.PaymentInfo.PaymentMode.PaymentCallbackUrl);
            context.RequestForm["MerchantOrderId"] = context.SOInfo.SoSysNo.ToString();
            context.RequestForm["AssBillNo"]       = "";
            context.RequestForm["TradeName"]       = context.PaymentInfoMerchant.MerchantName;
            context.RequestForm["TradeCode"]       = context.PaymentInfoMerchant.CustomConfigs["FirstMerchantCode"];
            context.RequestForm["SrcNcode"]        = context.PaymentInfoMerchant.MerchantNO;
            context.RequestForm["OrderCommitTime"] = context.SOInfo.OrderDate.ToString("yyyyMMddHHmmss");
            //发件信息,从Appsetting配置中取
            //仓库编号
            string warehouseNumber = context.SOInfo.SOItemList != null && context.SOInfo.SOItemList.Count > 0 ? context.SOInfo.SOItemList[0].WarehouseNumber.Trim() : "";
            context.RequestForm["SenderName"]        = AppSettingManager.GetSetting("PaySenderInfo", string.Format("Sender_{0}_SenderName", warehouseNumber));
            context.RequestForm["SenderTel"]         = AppSettingManager.GetSetting("PaySenderInfo", string.Format("Sender_{0}_SenderTel", warehouseNumber));
            context.RequestForm["SenderCompanyName"] = AppSettingManager.GetSetting("PaySenderInfo", string.Format("Sender_{0}_SenderCompanyName", warehouseNumber));
            context.RequestForm["SenderAddr"]        = AppSettingManager.GetSetting("PaySenderInfo", string.Format("Sender_{0}_SenderAddr", warehouseNumber));
            context.RequestForm["SenderZip"]         = AppSettingManager.GetSetting("PaySenderInfo", string.Format("Sender_{0}_SenderZip", warehouseNumber));
            context.RequestForm["SenderCity"]        = AppSettingManager.GetSetting("PaySenderInfo", string.Format("Sender_{0}_SenderCity", warehouseNumber));
            context.RequestForm["SenderProvince"]    = AppSettingManager.GetSetting("PaySenderInfo", string.Format("Sender_{0}_SenderProvince", warehouseNumber));
            //发件地国家
            string countryCode = context.SOInfo.SOItemList[0].CountryCode;
            #region  位国家代码适配
            countryCode = AppSettingManager.GetSetting("CountryCode", string.Format("CountryCode_{0}", countryCode));
            #endregion
            context.RequestForm["SenderCountry"] = countryCode;
            //订单商品信息简述
            cargoDescript = !string.IsNullOrEmpty(cargoDescript) && cargoDescript.Length > 256 ? cargoDescript.Substring(0, 256) : cargoDescript;//限制字符不能大于256
            context.RequestForm["CargoDescript"] = string.IsNullOrEmpty(cargoDescript) ? "无商品信息简述" : cargoDescript;
            //全部购买商品合计总价
            context.RequestForm["AllCargoTotalPrice"] = allCargoTotalPrice.ToString("F2");
            //税费
            context.RequestForm["AllCargoTotalTax"] = totalTariffAmount.ToString("F2");
            //物流运费
            context.RequestForm["ExpressPrice"] = context.SOInfo.Amount.ShipPrice.ToString("F2");
            //其他金额
            context.RequestForm["OtherPrice"] = otherPrice.ToString("F2");
            //支付总金额=全部商品合计总价+税费+物流运费+其他金额(其他金额为负数)-余额支付金额
            context.RequestForm["PayTotalPrice"] = (allCargoTotalPrice + totalTariffAmount + context.SOInfo.Amount.ShipPrice + otherPrice).ToString("F2");
            //付款币种
            context.RequestForm["PayCUR"] = "CNY";
            //收款币种,固定为港币,测试环境支持USD美元
            context.RequestForm["CrtCUR"] = context.PaymentInfoMerchant.CurCode;
            //收货地国家
            context.RequestForm["RecCountry"] = "中国";
            //收货地省/州
            context.RequestForm["RecProvince"] = string.IsNullOrWhiteSpace(context.SOInfo.ReceiveProvinceName) ? "无" : context.SOInfo.ReceiveProvinceName;
            //收货地城市
            context.RequestForm["RecCity"] = string.IsNullOrWhiteSpace(context.SOInfo.ReceiveCityName) ? "无" : context.SOInfo.ReceiveCityName;
            //收货地地址
            context.RequestForm["RecAddress"] = string.IsNullOrWhiteSpace(context.SOInfo.ReceiveAddress) ? "无" : context.SOInfo.ReceiveAddress;
            //收货地邮编
            context.RequestForm["RecZip"] = "";
            //购买商品总数量
            context.RequestForm["CargoTypeNum"] = cargoTypeNum.ToString();
            //单项购买商品名称
            context.RequestForm["CargoName"] = cargoName;
            //单项购买商品编号
            context.RequestForm["CargoCode"] = cargoCode;
            //单项购买商品税则号
            context.RequestForm["HSCode"] = _HSCode;
            //单项购买商品数量
            context.RequestForm["CargoNum"] = cargoNum;
            //单项购买商品单价
            context.RequestForm["CargoUnitPrice"] = cargoUnitPrice;
            //单项购买商品总价
            context.RequestForm["CargoTotalPrice"] = cargoTotalPrice;
            //单项购买商品行邮税总价
            context.RequestForm["CargoTotalTax"] = cargoTotalTax;
            //业务类型
            context.RequestForm["ServerType"] = context.SOInfo.SOItemList[0].CountryCode.ToUpper().Equals("CHN") ? "S02" : "S01";
            //扩展字段1
            context.RequestForm["Spt1"] = "";
            //扩展字段2
            context.RequestForm["Spt2"] = "";
            //签名
            context.RequestForm["SignMsg"] = SignData(context);
        }
コード例 #21
0
 public ConstantService(ChargeContext chargeContext)
 {
     this.chargeContext = chargeContext;
 }
コード例 #22
0
 public ChargeApiGateway(ChargeContext chargeDbContext)
 {
     _chargeDbContext = chargeDbContext;
 }
コード例 #23
0
 public MenuService(ChargeContext chargeContext, ILogger <MenuService> logger)
 {
     this.chargeContext = chargeContext;
     this.logger        = logger;
 }
コード例 #24
0
 /// <summary>
 /// 如果不是平台商家支付信息,则需要根据订单商家系统编号来重新加载支付相关信息
 /// </summary>
 /// <param name="context">支付上下文</param>
 public virtual void UpdateChargePayment(ChargeContext context)
 {
     //如果不是平台商家支付信息,则需要根据商家系统编号来重新加载支付相关信息
 }
コード例 #25
0
 public abstract void SetRequestForm(ChargeContext context);
コード例 #26
0
 public ChargeService(ChargeContext chargeContext)
 {
     this.chargeContext = chargeContext;
 }