예제 #1
0
        /// <summary>
        /// 退款
        /// 保证流水号唯一退款前缀添加R
        /// </summary>
        /// <param name="entity">退款实体信息</param>
        /// <returns>退款结果</returns>
        public RefundResult Refund(RefundEntity entity)
        {
            string refundUrl = AppSettingManager.GetSetting("Invoice", "TenPayRefundUrl");

            Dictionary <string, string> reqParams = new Dictionary <string, string>();

            reqParams["input_charset"]   = "UTF-8";
            reqParams["sign_key_index"]  = "1";
            reqParams["service_version"] = "1.1";
            reqParams["partner"]         = AppSettingManager.GetSetting("Invoice", "TenPayParnter");
            reqParams["out_trade_no"]    = entity.SOSysNo.ToString();
            reqParams["out_refund_no"]   = entity.RefundSysNo.ToString();
            reqParams["total_fee"]       = (entity.SOAmt * 100).ToString();
            reqParams["refund_fee"]      = (entity.RefundAmt * 100).ToString();
            reqParams["op_user_id"]      = AppSettingManager.GetSetting("Invoice", "TenPayParnter");
            reqParams["op_user_passwd"]  = GetMD5(AppSettingManager.GetSetting("Invoice", "TenPayParnterPwd"));
            reqParams["sign_type"]       = "MD5";
            //reqParams["notify_url"] = GetMD5(AppSettingManager.GetSetting("Invoice", "TenPayRefundNotifyUrl"));

            string reqData = "";

            string[] allKeys = reqParams.Keys.ToArray();
            Array.Sort(allKeys);
            foreach (var item in allKeys)
            {
                reqData += string.Format("{0}={1}&", item, reqParams[item]);
            }
            string sign = GetMD5(reqData + string.Format("key={0}", AppSettingManager.GetSetting("Invoice", "TenPaySecretKey")));

            reqData += string.Format("sign={0}", sign);

            var resultXml = HttpRequestReturnXml(string.Format("{0}?{1}", refundUrl, reqData), "GET", "");

            var result = new RefundResult();
            var code   = resultXml.SelectSingleNode("root/retcode").InnerText;//请求结果

            if (code == "0")
            {
                result.Result = true;
                var soSysNo = entity.SOSysNo.ToString();                                          //商户订单号
                result.ExternalKey = resultXml.SelectSingleNode("root/transaction_id").InnerText; //退款流水,支付宝国际无
                var refundAmout = entity.RefundAmt.ToString("F2");                                //退款总金额
            }
            else
            {
                result.Message = resultXml.SelectSingleNode("root/retmsg").InnerText;//拒绝原因
            }

            //记录日志
            string resultNote = string.Format("用户[{0}]对订单号:{1} 调用了退款接口.调用结果;{2} 调用返回信息:{3},{4} PostUrl:{5} ", ServiceContext.Current.UserSysNo, entity.SOSysNo, code, result.Message, resultXml.ToXmlString(), refundUrl);

            ExternalDomainBroker.CreateOperationLog(resultNote, BizLogType.RMA_Refund_Refund, entity.RefundSysNo, entity.CompanyCode);
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 退款
        /// 保证流水号唯一退款前缀添加R
        /// </summary>
        /// <param name="entity">退款实体信息</param>
        /// <returns>退款结果</returns>
        public RefundResult Refund(RefundEntity entity)
        {
            string refundUrl = AppSettingManager.GetSetting("Invoice", "RefundUrl");
            string bgUrl     = AppSettingManager.GetSetting("Invoice", "BGURL");

            VendorCustomsInfo customsInfo = ObjectFactory <ISOBizInteract> .Instance.LoadVendorCustomsInfo(entity.SOSysNo);

            Dictionary <string, string> reqParams = new Dictionary <string, string>();

            reqParams["SRC_NCODE"] = customsInfo.CBTSRC_NCode;
            reqParams["BILL_NO"]   = entity.SOSysNo.ToString();

            reqParams["REFUND_AMOUNT"] = entity.RefundAmt.ToString("F2");
            reqParams["CARGO_AMOUNT"]  = entity.ProductAmount.GetValueOrDefault().ToString("F2");

            reqParams["TRANSPORT_AMOUNT"] = entity.ShippingFeeAmount.GetValueOrDefault().ToString("F2");
            reqParams["TAX_AMOUNT"]       = entity.TaxFeeAmount.GetValueOrDefault().ToString("F2");
            reqParams["RDO_TIME"]         = string.Empty;
            reqParams["BGURL"]            = bgUrl;

            StringBuilder reqXml = new StringBuilder();

            reqXml.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><EasipayB2CRequest><ReqData>");
            foreach (KeyValuePair <string, string> kvp in reqParams)
            {
                reqXml.AppendFormat("<{0}><![CDATA[{1}]]></{0}>", kvp.Key, kvp.Value);
            }
            reqXml.Append("</ReqData></EasipayB2CRequest>");
            var resultXml = HttpPostRequestReturnXml(refundUrl, BuildPostReqData(reqXml.ToString(), customsInfo));

            var result = new RefundResult();
            var code   = resultXml.SelectSingleNode("EasipayB2CResponse/ResData/RTN_CODE").InnerText;     //请求结果

            result.Message = resultXml.SelectSingleNode("EasipayB2CResponse/ResData/RTN_INFO").InnerText; //拒绝原因

            if (code == "000000")
            {
                result.Result = true;
                var soSysNo = resultXml.SelectSingleNode("EasipayB2CResponse/ResData/BILL_NO").InnerText;                                   //商户订单号
                result.ExternalKey = string.Format("R" + resultXml.SelectSingleNode("/EasipayB2CResponse/ResData/REFTRX_SERNO").InnerText); //退款流水
                var refundAmout = resultXml.SelectSingleNode("EasipayB2CResponse/ResData/REFUND_AMOUNT").InnerText;                         //退款总金额
            }

            //记录日志
            string resultNote = string.Format("用户[{0}]对订单号:{1} 调用了退款接口.调用结果;{2} 调用返回信息:{3},{4} PostUrl:{5} ", ServiceContext.Current.UserSysNo, entity.SOSysNo, code, result.Message, resultXml.ToXmlString(), refundUrl);

            ExternalDomainBroker.CreateOperationLog(resultNote, BizLogType.RMA_Refund_Refund, entity.RefundSysNo, entity.CompanyCode);
            return(result);
        }
예제 #3
0
 private void CreateOperationLog(PriceChangeMaster item, string action, BizLogType logType)
 {
     ExternalDomainBroker.CreateOperationLog(string.Format("用户:\"{0}\"{1}了编号为\"{2}\"类型为\"{3}\"的变价单", (string.IsNullOrEmpty(ServiceContext.Current.UserDisplayName) ? "Job" : ServiceContext.Current.UserDisplayName), action, item.SysNo, item.PriceType.ToDisplayText())
                                             , logType, item.SysNo, "8601");
 }
예제 #4
0
        public RefundResult Refund(RefundEntity entity)
        {
            BizLogType RefoundLogType = BizLogType.RMA_Refund_Refund;

            if (entity.OrderType.GetValueOrDefault() == SOIncomeOrderType.AO)
            {
                RefoundLogType = BizLogType.AO_Refund_Refund;
            }
            BizLogType RefountType = BizLogType.AO_Refund_Refund;

            ExternalDomainBroker.CreateOperationLog("支付宝退款开始构建请求参数", RefoundLogType, entity.RefundSysNo, entity.CompanyCode);
            RefundResult responseResult = null;

            #region 无密退款
            ////////////////////////////////////////////请求参数////////////////////////////////////////////

            //服务器异步通知页面路径
            string notify_url = string.Empty;
            //需http://格式的完整路径,不允许加?id=123这类自定义参数

            //退款批次号
            string batch_no = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            //必填,每进行一次即时到账批量退款,都需要提供一个批次号,必须保证唯一性

            //退款请求时间
            string refund_date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            //必填,格式为:yyyy-MM-dd hh:mm:ss

            //退款总笔数
            string batch_num = "1";
            //必填,即参数detail_data的值中,“#”字符出现的数量加1,最大支持1000笔(即“#”字符出现的最大数量999个)

            //单笔数据集
            string     detail_data = "";
            NetPayInfo netpayInfo  = ObjectFactory <NetPayProcessor> .Instance.GetValidBySOSysNo(entity.SOSysNo);

            if (netpayInfo != null && !string.IsNullOrWhiteSpace(netpayInfo.ExternalKey))
            {
                //退款详细数据
                detail_data += BuildDetailDataString(netpayInfo.ExternalKey.TrimEnd(), entity.RefundAmt.ToString("f2"), "支付宝无线支付退款");
            }
            //必填,格式详见“4.3 单笔数据集参数说明”


            ////////////////////////////////////////////////////////////////////////////////////////////////
            #endregion

            #region 请求参数 :
            //////////////////////////////////////////////请求参数////////////////////////////////////////////
            ////服务器异步通知页面路径
            //string notify_url = string.Empty;
            ////需http://格式的完整路径,不允许加?id=123这类自定义参数

            ////卖家支付宝帐户
            //string seller_email = "*****@*****.**";

            ////卖家UserID:
            //string seller_user_id = Config.Partner;

            ////退款当天日期
            //string refund_date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            ////必填,格式:年[4位]-月[2位]-日[2位] 小时[2位 24小时制]:分[2位]:秒[2位],如:2007-10-01 13:13:13

            ////批次号
            //string batch_no = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            ////必填,格式:当天日期[8位]+序列号[3至24位],如:201008010000001

            ////退款笔数
            //string batch_num = entity.Count.ToString() ;
            ////必填,参数detail_data的值中,“#”字符出现的数量加1,最大支持1000笔(即“#”字符出现的数量999个)
            //string detail_data = "";
            //foreach (var item in entity)
            //{
            //    NetPayInfo netpayInfo = ObjectFactory<NetPayProcessor>.Instance.GetValidBySOSysNo(item.SOSysNo);
            //    if (netpayInfo!=null&&!string.IsNullOrWhiteSpace(netpayInfo.ExternalKey))
            //    {
            //        //退款详细数据
            //        detail_data += BuildDetailDataString(netpayInfo.ExternalKey.TrimEnd(), item.RefundAmt.ToString("f2"), "支付宝无线支付退款");
            //    }
            //}

            ////必填,具体格式请参见接口技术文档
            //if (string.IsNullOrWhiteSpace(detail_data))
            //{
            //    return responseResult = new RefundResult()
            //    {
            //        Result = false,
            //        Message = "报错:无有效退款订单"
            //    };

            //}
            //else
            //{
            //    detail_data=detail_data.Remove(detail_data.Length - 1);
            //}

            //////////////////////////////////////////////////////////////////////////////////////////////////
            #endregion

            //把请求参数打包成数组
            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();
            sParaTemp.Add("partner", Config.Partner);
            sParaTemp.Add("_input_charset", Config.Input_charset.ToLower());
            sParaTemp.Add("service", "refund_fastpay_by_platform_nopwd");
            sParaTemp.Add("notify_url", notify_url);
            sParaTemp.Add("batch_no", batch_no);
            sParaTemp.Add("refund_date", refund_date);
            sParaTemp.Add("batch_num", batch_num);
            sParaTemp.Add("detail_data", detail_data);
            ExternalDomainBroker.CreateOperationLog("开支请求支付宝退款。", RefoundLogType, entity.RefundSysNo, entity.CompanyCode);
            //建立请求
            string sHtmlText = Submit.BuildRequest(sParaTemp);

            ExternalDomainBroker.CreateOperationLog(sHtmlText, RefoundLogType, entity.RefundSysNo, entity.CompanyCode);
            //请在这里加上商户的业务逻辑程序代码

            //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——

            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.LoadXml(sHtmlText);
                string strXmlResponse = xmlDoc.SelectSingleNode("/alipay").InnerText;
                string result         = xmlDoc.SelectSingleNode("/alipay/is_success").InnerText;
                if (result == "F")
                {
                    string resultNote = string.Format("用户[{0}]对订单号:{1} 调用了退款接口.调用结果;{2} 调用返回信息:{3} PostUrl:{4} 退款金额:{5}", ServiceContext.Current.UserSysNo, entity.SOSysNo, "False", strXmlResponse, Submit.GATEWAY_NEW, entity.RefundAmt.ToString());
                    ExternalDomainBroker.CreateOperationLog(resultNote, RefoundLogType, entity.RefundSysNo, entity.CompanyCode);
                    Exception refundException = new Exception(strXmlResponse);
                    return(responseResult = new RefundResult()
                    {
                        Result = false,
                        Message = strXmlResponse
                    });
                }
                else
                {
                    string resultNote = string.Format("用户[{0}]对订单号:{1} 调用了退款接口.调用结果;{2} 调用返回信息:{3} PostUrl:{4} 退款金额:{5}", ServiceContext.Current.UserSysNo, entity.SOSysNo, "True", strXmlResponse, Submit.GATEWAY_NEW, entity.RefundAmt.ToString());
                    ExternalDomainBroker.CreateOperationLog(resultNote, RefoundLogType, entity.RefundSysNo, entity.CompanyCode);
                    return(responseResult = new RefundResult()
                    {
                        Result = true,
                        ExternalKey = strXmlResponse
                    });
                }
            }
            catch (Exception exp)
            {
                string resultNote = string.Format("用户[{0}]对订单号:{1} 调用了退款接口.调用结果;{2} 调用返回信息:{3} PostUrl:{4} 退款金额:{5}", ServiceContext.Current.UserSysNo, entity.SOSysNo, "False", exp.Message, Submit.GATEWAY_NEW, entity.RefundAmt.ToString());
                ExternalDomainBroker.CreateOperationLog(resultNote, RefoundLogType, entity.RefundSysNo, entity.CompanyCode);
                return(responseResult = new RefundResult()
                {
                    Result = false,
                    Message = exp.Message
                });
            }

            //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——
        }