Exemple #1
0
        public override PaymentInfo EnterprisePay(EnterprisePayPara para)
        {
            RequestHandler requestHandler = new RequestHandler();
            PaymentInfo    paymentInfo    = new PaymentInfo();
            string         empty          = string.Empty;
            Config         config         = Utility <Config> .GetConfig(base.WorkDirectory);

            if (string.IsNullOrEmpty(config.AppId))
            {
                throw new PluginException("未设置AppId");
            }
            if (string.IsNullOrEmpty(config.MCHID))
            {
                throw new PluginException("未设置MCHID");
            }
            if (string.IsNullOrWhiteSpace(config.pkcs12))
            {
                throw new PluginConfigException("未设置商户证书");
            }
            requestHandler.SetKey(config.Key);
            string noncestr = TenPayUtil.GetNoncestr();

            requestHandler.SetParameter("partner_trade_no", para.out_trade_no);
            int num = Convert.ToInt32(para.amount * new decimal(100));

            requestHandler.SetParameter("amount", num.ToString());
            requestHandler.SetParameter("openid", para.openid);
            requestHandler.SetParameter("mch_appid", config.AppId);
            requestHandler.SetParameter("mchid", config.MCHID);
            requestHandler.SetParameter("nonce_str", noncestr);
            string str = "NO_CHECK";

            if (para.check_name)
            {
                str = "OPTION_CHECK";
            }
            requestHandler.SetParameter("check_name", str);
            requestHandler.SetParameter("desc", para.desc);
            requestHandler.SetParameter("spbill_create_ip", (string.IsNullOrWhiteSpace(para.spbill_create_ip) ? "222.240.184.122" : para.spbill_create_ip));
            string str1 = requestHandler.CreateMd5Sign("key", config.Key);

            requestHandler.SetParameter("sign", str1);
            string str2 = string.Concat(base.WorkDirectory, "\\", config.pkcs12);

            if (!File.Exists(str2))
            {
                throw new PluginException("未找到商户证书文件");
            }
            string str3   = requestHandler.ParseXML();
            string empty1 = string.Empty;

            try
            {
                empty1 = TenPayV3.transfers(str3, str2, config.MCHID);
            }
            catch (Exception exception)
            {
                throw new PluginException(string.Concat("企业付款时出错:", exception.Message));
            }
            XDocument xDocument = XDocument.Parse(empty1);

            if (xDocument == null)
            {
                throw new PluginException(string.Concat("企业付款时出错:", str3));
            }
            XElement xElement  = xDocument.Element("xml").Element("return_code");
            XElement xElement1 = xDocument.Element("xml").Element("return_msg");

            if (xElement == null)
            {
                throw new PluginException("企业付款时,返回参数异常");
            }
            if (!(xElement.Value == "SUCCESS"))
            {
                throw new PluginException(string.Concat("企业付款时,接口返回异常:", xElement1.Value));
            }
            xElement1 = xDocument.Element("xml").Element("result_code");
            XElement xElement2 = xDocument.Element("xml").Element("err_code_des");

            if (!(xElement1.Value == "SUCCESS"))
            {
                throw new PluginException(string.Concat("企业付款时,接口返回异常:", xElement2.Value));
            }
            string value  = xDocument.Element("xml").Element("payment_no").Value;
            string value1 = xDocument.Element("xml").Element("partner_trade_no").Value;
            string value2 = xDocument.Element("xml").Element("payment_time").Value;

            paymentInfo.OrderIds = new List <long>()
            {
                long.Parse(value1)
            };
            paymentInfo.TradNo    = value;
            paymentInfo.TradeTime = new DateTime?(DateTime.Parse(value2));
            return(paymentInfo);
        }
Exemple #2
0
        public override PaymentInfo ProcessRefundFee(PaymentPara para)
        {
            RequestHandler requestHandler = new RequestHandler();
            PaymentInfo    paymentInfo    = new PaymentInfo();
            string         empty          = string.Empty;
            Config         config         = Utility <Config> .GetConfig(base.WorkDirectory);

            if (string.IsNullOrEmpty(config.AppId))
            {
                throw new PluginException("未设置AppId");
            }
            if (string.IsNullOrEmpty(config.MCHID))
            {
                throw new PluginException("未设置MCHID");
            }
            if (string.IsNullOrWhiteSpace(config.pkcs12))
            {
                throw new PluginConfigException("未设置商户证书");
            }
            requestHandler.SetKey(config.Key);
            string noncestr = TenPayUtil.GetNoncestr();

            requestHandler.SetParameter("out_trade_no", para.out_trade_no);
            requestHandler.SetParameter("out_refund_no", para.out_refund_no);
            int num = Convert.ToInt32(para.total_fee * new decimal(100));

            requestHandler.SetParameter("total_fee", num.ToString());
            num = Convert.ToInt32(para.refund_fee * new decimal(100));
            requestHandler.SetParameter("refund_fee", num.ToString());
            requestHandler.SetParameter("op_user_id", config.MCHID);
            requestHandler.SetParameter("appid", config.AppId);
            requestHandler.SetParameter("mch_id", config.MCHID);
            requestHandler.SetParameter("nonce_str", noncestr);
            string str = requestHandler.CreateMd5Sign("key", config.Key);

            requestHandler.SetParameter("sign", str);
            string str1 = string.Concat(base.WorkDirectory, "\\", config.pkcs12);

            if (!File.Exists(str1))
            {
                throw new PluginException("未找到商户证书文件");
            }
            string str2   = requestHandler.ParseXML();
            string empty1 = string.Empty;

            try
            {
                empty1 = TenPayV3.Refund(str2, str1, config.MCHID);
            }
            catch (Exception exception)
            {
                throw new PluginException(string.Concat("原路返回退款时出错:", exception.Message));
            }
            XDocument xDocument = XDocument.Parse(empty1);

            if (xDocument == null)
            {
                throw new PluginException(string.Concat("原路返回退款时出错:", str2));
            }
            XElement xElement  = xDocument.Element("xml").Element("return_code");
            XElement xElement1 = xDocument.Element("xml").Element("return_msg");

            if (xElement == null)
            {
                throw new PluginException("原路返回退款时,返回参数异常");
            }
            if (!(xElement.Value == "SUCCESS"))
            {
                throw new PluginException(string.Concat("原路返回退款时,接口返回异常:", xElement1.Value));
            }
            xElement1 = xDocument.Element("xml").Element("result_code");
            XElement xElement2 = xDocument.Element("xml").Element("err_code_des");

            if (!(xElement1.Value == "SUCCESS"))
            {
                throw new PluginException(string.Concat("原路返回退款时,接口返回异常:", xElement2.Value));
            }
            string value  = xDocument.Element("xml").Element("refund_id").Value;
            string value1 = xDocument.Element("xml").Element("out_refund_no").Value;

            paymentInfo.OrderIds = new List <long>()
            {
                long.Parse(value1)
            };
            paymentInfo.TradNo    = value;
            paymentInfo.TradeTime = new DateTime?(DateTime.Now);
            return(paymentInfo);
        }