Ejemplo n.º 1
0
        public JsonResult AgreeRefund(string refundCode, int isQualityProblem, int refundType, int isReturnDuty, decimal rmbTotalAmount, decimal totalAmount, decimal rmbDutyAmount, decimal dutyAmount, string collectionCode, DateTime tobePickUpTime)
        {
            var order = new RefundOrderInfo();

            order.IsQualityProblem = isQualityProblem;
            order.RefundType       = refundType;
            order.IsReturnDuty     = isReturnDuty;
            order.RmbTotalAmount   = rmbTotalAmount;
            order.TotalAmount      = totalAmount;
            order.RmbDutyAmount    = isReturnDuty == 1 ? rmbDutyAmount : 0;
            order.DutyAmount       = isReturnDuty == 1 ? dutyAmount : 0;
            order.CollectionCode   = collectionCode;
            order.TobePickUpTime   = tobePickUpTime;
            order.AuditTime        = DateTime.Now;
            order.Auditor          = UserName;
            order.RefundStatus     = refundType == 1 ? 2 : 3;
            order.RefundCode       = refundCode;
            var result     = refund.agreeRefund(order);
            var resultJson = new { IsOk = true, Msg = "操作成功" };

            if (result == 0)
            {
                resultJson = new { IsOk = false, Msg = "操作失敗!" }
            }
            ;
            return(Json(resultJson, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 执行同步退款
        /// </summary>
        /// <param name="orderInfo">退款订单</param>
        /// <param name="resultInfo">退款结果记录</param>
        /// <returns></returns>
        public override ExecuteResult <RefundNotifyInfo> ExecuteSyncRefund(RefundOrderInfo orderInfo, RefundResultInfo resultInfo)
        {
            var result = new ExecuteResult <RefundNotifyInfo>();

            try
            {
                resultInfo.OrderId       = orderInfo.OrderId;
                resultInfo.RefundOrderId = orderInfo.RefundOrderId;
                resultInfo.RefundAmt     = Convert.ToDecimal(orderInfo.RefundAmt);
                //获取退款金额
                int refundAmt  = (int)(resultInfo.RefundAmt * 100);//通联退款金额的单位为“分”,所以要乘以100
                var refundData = new AllinpayData(AllinpayDataType.RefundRequest);
                //商户号
                refundData.SetValue("merchantId", AppConfig.Global.AllinpayMerchantId);
                //商户订单号
                refundData.SetValue("orderNo", orderInfo.OrderId);
                //退款金额
                refundData.SetValue("refundAmount", refundAmt.ToString());
                //商户订单提交时间
                refundData.SetValue("orderDatetime", orderInfo.OrderTime);
                //签名字符串
                refundData.SetValue("signMsg", AllinpayCore.RefundSign(refundData));

                var executeResult = AllinpayManager.RefundRequest(refundData);
                if (executeResult.Status != ResultStatus.Success)
                {
                    resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                    resultInfo.ResultDesc    = "通联退款请求失败:" + executeResult.Message;
                    RefundResultDAL.Update(resultInfo);

                    result.Status  = ResultStatus.Error;
                    result.Message = resultInfo.ResultDesc;
                    return(result);
                }

                //退款成功,解析返回参数
                resultInfo.RefundNo      = "";
                resultInfo.ExecuteResult = (int)ResultStatus.Success;

                result.Data   = this.GetRefundNotifyInfo(resultInfo, orderInfo.TradeNo);
                result.Status = ResultStatus.Success;
            }
            catch (Exception ex)
            {
                resultInfo.ExecuteResult = (int)ResultStatus.Error;
                resultInfo.ResultDesc    = ex.Message;
                RefundResultDAL.Update(resultInfo);

                result.Status  = ResultStatus.Error;
                result.Message = ex.Message;
            }
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 执行同步退款
        /// </summary>
        /// <param name="orderInfo">退款订单</param>
        /// <param name="resultInfo">退款结果记录</param>
        /// <returns></returns>
        public override ExecuteResult <RefundNotifyInfo> ExecuteSyncRefund(RefundOrderInfo orderInfo, RefundResultInfo resultInfo)
        {
            var result = new ExecuteResult <RefundNotifyInfo>();

            resultInfo.OrderId       = orderInfo.OrderId;
            resultInfo.RefundOrderId = orderInfo.RefundOrderId;
            resultInfo.RefundAmt     = Convert.ToDecimal(orderInfo.RefundAmt);
            resultInfo.RefundNo      = DateTime.Now.ToString("yyyyMMddHHmmssfff") + RandomHelper.CreateRandomCode(3);
            resultInfo.ExecuteResult = (int)ResultStatus.Success;

            result.Data   = this.GetRefundNotifyInfo(resultInfo, orderInfo.TradeNo);
            result.Status = ResultStatus.Success;
            return(result);
        }
Ejemplo n.º 4
0
        public ResponseInfo <RefundOrderDatamap> Refund(string orderid, string memberid)
        {
            RefundOrderInfo info = new RefundOrderInfo()
            {
                orderId = orderid
            };
            var config   = new ApiSetting(null);
            var response = SecurityHttpClient.Post <RefundOrderInfo, RefundOrderDatamap>(config.JavaOrder_Uri + "orderStatusRefund", info);

            if (response.respCode != "0")
            {
                throw new ApplicationException(response.respMsg);
            }
            return(response);
        }
Ejemplo n.º 5
0
        public ActionResult AllinpayRefund(string appId, string appSecret, string orderId)
        {
            if (appSecret != AppCache.GetAppSecret(appId))
            {
                return(Json(new { msg = "非法appSecret" }));
            }

            var resultInfo = PayResultDAL.GetValidPayResult(orderId, AppEnum.PayType.Allinpay);

            if (resultInfo == null || resultInfo.SysNo <= 0)
            {
                return(Json(new { msg = "订单无支付记录" }));
            }

            var             requestInfo = PayRequestDAL.GetPayRequest(resultInfo.RequestSysNo);
            var             orderTime   = JsonHelper.Deserialize <PayOrderInfo>(requestInfo.RequestData).OrderTime;
            RefundOrderInfo info        = new RefundOrderInfo()
            {
                OrderId       = orderId,
                OrderTime     = orderTime ?? DateTime.Now.ToString("yyyyMMddHHmmss"),
                TradeNo       = resultInfo.TradeNo,
                PaymentAmt    = resultInfo.PaymentAmt.ToString(),
                RefundOrderId = DateTime.Now.ToString("yyyyMMddHHmmssfff"),
                RefundAmt     = resultInfo.PaymentAmt.ToString(),
                NotifyUrl     = string.Format("http://{0}/Test/RefundNotify?type=0", AppConfig.Global.Domain),
            };
            var setting = JsonHelper.GetDefaultSettings();

            setting.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
            string data = JsonHelper.Serialize(info, setting);
            string sign = SignManager.CreateSign(appId, data).Data;

            ViewBag.AppId = appId;
            ViewBag.Sign  = sign;
            ViewBag.Data  = data;
            ViewBag.Title = "通联支付退款(测试)";
            ViewBag.Url   = "/allinpay/syncrefund";
            return(View("Pay"));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 退款审核通过
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public int agreeRefund(RefundOrderInfo order)
        {
            var sql        = @"
UPDATE RefundOrderInfo 
	SET IsQualityProblem  = @IsQualityProblem,
		RefundType = @RefundType,
		IsReturnDuty = @IsReturnDuty,
        RmbTotalAmount = @RmbTotalAmount,
        TotalAmount = @TotalAmount,
        RmbDutyAmount = @RmbDutyAmount,
        DutyAmount = @DutyAmount,
        CollectionCode = @CollectionCode,
        TobePickUpTime = @TobePickUpTime,
        AuditTime = @AuditTime,
        Auditor = @Auditor,
        RefundStatus = @RefundStatus
WHERE	RefundCode = @RefundCode			
		
";
            var db         = DbSFO2OMain;
            var parameters = db.CreateParameterCollection();

            parameters.Append("@IsQualityProblem", order.IsQualityProblem);
            parameters.Append("@RefundType", order.RefundType);
            parameters.Append("@IsReturnDuty", order.IsReturnDuty);
            parameters.Append("@RmbTotalAmount", order.RmbTotalAmount);
            parameters.Append("@TotalAmount", order.TotalAmount);
            parameters.Append("@RmbDutyAmount", order.RmbDutyAmount);
            parameters.Append("@DutyAmount", order.DutyAmount);
            parameters.Append("@CollectionCode", order.CollectionCode);
            parameters.Append("@TobePickUpTime", order.TobePickUpTime);
            parameters.Append("@AuditTime", order.AuditTime);
            parameters.Append("@Auditor", order.Auditor);
            parameters.Append("@RefundStatus", order.RefundStatus);
            parameters.Append("@RefundCode", order.RefundCode);

            return(db.ExecuteSqlNonQuery(sql, parameters));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 在线支付退款
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="sign"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public string SyncRefund(string appId, string sign, string data)
        {
            try
            {
                #region 处理退款请求
                var requestInterface = Builder.BuildRefundRequest();

                //保存退款请求
                var requestInfo = requestInterface.SaveRequest(appId, data, this._payType);

                //校验签名
                var checkResult = requestInterface.CheckSign(appId, sign, data, requestInfo);
                if (checkResult.Status != ResultStatus.Success)
                {
                    return(JsonHelper.Serialize(new { status = 0, msg = checkResult.Message }));
                }

                //校验退款参数
                var checkResult2 = requestInterface.CheckParamaters(data, this._payType, requestInfo);
                if (checkResult2.Status != ResultStatus.Success)
                {
                    return(JsonHelper.Serialize(new { status = 0, msg = checkResult2.Message }));
                }

                RefundOrderInfo orderInfo = checkResult2.Data;

                //解析退款请求
                checkResult = requestInterface.ResolveRequest(data, requestInfo);
                if (checkResult.Status != ResultStatus.Success)
                {
                    return(JsonHelper.Serialize(new { status = 0, msg = checkResult.Message }));
                }

                //退款请求执行成功
                requestInterface.ExecuteSuccess(requestInfo);
                #endregion

                #region 执行退款申请
                var resultInterface = Builder.BuildAllinpayRefundResult();

                //校验模式
                if (requestInterface.CheckModeIsSimulate())
                {
                    resultInterface = Builder.BuildSimulateRefundResult();
                }

                //保存退款结果请求
                var resultInfo = resultInterface.SaveRequest(data, this._payType);

                //执行同步退款
                var executeResult = resultInterface.ExecuteSyncRefund(orderInfo, resultInfo);
                if (executeResult.Status != ResultStatus.Success)
                {
                    return(JsonHelper.Serialize(new { status = 0, msg = executeResult.Message }));
                }

                //更新退款结果记录并关联退款请求记录
                var relateResult = resultInterface.RelateRequestInfo(resultInfo);
                if (relateResult.Status != ResultStatus.Success)
                {
                    return(JsonHelper.Serialize(new { status = 0, msg = relateResult.Message }));
                }

                //异步线程通知业务系统退款结果
                var thread = new System.Threading.Thread(() => resultInterface.NotifyBack(resultInfo, requestInfo));
                thread.Start();

                var notifyInfo = executeResult.Data;
                return(JsonHelper.Serialize(new { status = 1, data = notifyInfo }));

                #endregion
            }
            catch (Exception ex)
            {
                string log = string.Format(@"支付退款发生异常!{0}异常描述:{1}{0}异常堆栈:{2}{0}请求参数:appId={3} sign={4} data={5}",
                                           Environment.NewLine, ex.Message, ex.StackTrace, appId, sign, data);
                LogWriter.WriteLog(log, AppConfig.Global.AllinpayLogFolder, ExceptionHelper.ExceptionLevel.Exception);
                return(JsonHelper.Serialize(new { status = -1, msg = "系统执行时发生异常:" + ex.Message }));
            }
        }
Ejemplo n.º 8
0
        public RefundOrderResponse Refund(string orderid, string memberid)
        {
            RefundOrderInfo info = new RefundOrderInfo()
            {
                orderId = orderid
            };
            string mid = memberid;

            if (string.IsNullOrWhiteSpace(mid))
            {
                mid = DefaultMemberId;
            }
            var password = GetPassword(mid);
            var datetime = DateTime.Now;
            var request  = new RefundOrderRequest
            {
                dataMap = info,
                sign    = "",//此接口不用签名验证
                reqTime = datetime.ToString(DateTimeFormat)
            };

            var jSetting = new JsonSerializerSettings();

            jSetting.NullValueHandling = NullValueHandling.Ignore;
            var content = JsonConvert.SerializeObject(request, jSetting);

            _log.Debug("Post data:" + content);
            var config = new CommonConfig(null);

            var req = (HttpWebRequest)WebRequest.Create(config.JavaOrder_Uri + "orderStatusRefund");

            req.Method      = "POST";
            req.ContentType = "Application/Json";
            req.Credentials = CredentialCache.DefaultCredentials;
            req.Timeout     = 300000;
            // 如果服务器返回错误,他还会继续再去请求,不会使用之前的错误数据,做返回数据
            //req.ServicePoint.Expect100Continue = false;
            WriteRequestData(req, content);
            var response = req.GetResponse();

            if (response == null)
            {
                throw new Exception("请求失败!");
            }
            var stream = response.GetResponseStream();

            if (stream == null)
            {
                throw new Exception("请求Stream为空!");
            }
            var sr     = new StreamReader(stream, Encoding.UTF8);
            var retXml = sr.ReadToEnd();

            sr.Close();
            _log.Debug(retXml);
            var obj = JsonConvert.DeserializeObject <RefundOrderResponse>(retXml);

            if (obj.respCode != "0")
            {
                throw new ApplicationException(obj.respMsg);
            }
            return(obj);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 退款审核通过
 /// </summary>
 /// <param name="order"></param>
 /// <returns></returns>
 public int agreeRefund(RefundOrderInfo order)
 {
     return(dao.agreeRefund(order));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 执行同步退款
 /// </summary>
 /// <param name="orderInfo">退款订单</param>
 /// <param name="resultInfo">退款结果记录</param>
 /// <returns></returns>
 public abstract ExecuteResult <RefundNotifyInfo> ExecuteSyncRefund(RefundOrderInfo orderInfo, RefundResultInfo resultInfo);
Ejemplo n.º 11
0
        /// <summary>
        /// 执行同步退款
        /// </summary>
        /// <param name="orderInfo">退款订单</param>
        /// <param name="resultInfo">退款结果记录</param>
        /// <returns></returns>
        public override ExecuteResult <RefundNotifyInfo> ExecuteSyncRefund(RefundOrderInfo orderInfo, RefundResultInfo resultInfo)
        {
            var result = new ExecuteResult <RefundNotifyInfo>();

            try
            {
                resultInfo.OrderId       = orderInfo.OrderId;
                resultInfo.RefundOrderId = orderInfo.RefundOrderId;
                resultInfo.RefundAmt     = Convert.ToDecimal(orderInfo.RefundAmt);
                int paymentAmt = (int)(Convert.ToDecimal(orderInfo.PaymentAmt) * 100); //微信支付金额的单位为“分”,所以要乘以100
                int refundAmt  = (int)(resultInfo.RefundAmt * 100);                    //微信退款金额的单位为“分”,所以要乘以100

                //提交退款请求
                WxPayData wxData = PayRefund.Run(orderInfo.TradeNo, orderInfo.OrderId, paymentAmt, refundAmt, orderInfo.RefundOrderId);

                //校验返回参数
                if (wxData.GetValue("return_code").ToString() != "SUCCESS")
                {
                    resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                    resultInfo.ResultDesc    = "微信退款请求失败:" + wxData.GetValue("return_msg").ToString();
                    RefundResultDAL.Update(resultInfo);

                    result.Status  = ResultStatus.Failure;
                    result.Message = resultInfo.ResultDesc;
                    return(result);
                }
                else if (wxData.GetValue("result_code").ToString() != "SUCCESS")
                {
                    resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                    resultInfo.ResultDesc    = "微信退款执行失败:" + wxData.GetValue("err_code_des").ToString();
                    RefundResultDAL.Update(resultInfo);

                    result.Status  = ResultStatus.Failure;
                    result.Message = resultInfo.ResultDesc;
                    return(result);
                }

                //退款成功,解析返回参数
                resultInfo.RefundNo      = wxData.GetValue("refund_id").ToString();
                resultInfo.ExecuteResult = (int)ResultStatus.Success;

                result.Data   = this.GetRefundNotifyInfo(resultInfo, orderInfo.TradeNo);
                result.Status = ResultStatus.Success;
            }
            catch (WxPayException wex)
            {
                resultInfo.ExecuteResult = (int)ResultStatus.Error;
                resultInfo.ResultDesc    = wex.Message;
                RefundResultDAL.Update(resultInfo);

                result.Status  = ResultStatus.Error;
                result.Message = wex.Message;
            }
            catch (Exception ex)
            {
                resultInfo.ExecuteResult = (int)ResultStatus.Error;
                resultInfo.ResultDesc    = ex.ToString();
                RefundResultDAL.Update(resultInfo);

                result.Status  = ResultStatus.Error;
                result.Message = ex.Message;
            }
            return(result);
        }