Ejemplo n.º 1
0
        /// <summary>
        /// 创建生成支付通知
        /// </summary>
        /// <param name="reqModel"></param>
        /// <returns></returns>
        public override SxfPayReturn Build(SxfPayNotifyRequest reqModel)
        {
            TradeOrder tradeOrder  = null;
            var        tradeResult = new TradeResult(reqModel);
            //保存通知结果并更改TradeOrder状态
            var isSucc = PaySvc.SaveMchTradeResult(tradeResult, out tradeOrder);

            if (!isSucc)
            {
                return(SxfPayReturn.Fail(msg: "数据接收失败"));
            }
            else
            {
                try
                {
                    var payNotify    = new NotifyPayRequest(tradeOrder, tradeResult);
                    var payNotifyDic = PaySignHelper.ToASCIIDictionary(payNotify);
                    return(SendPost(PayConst.QCTTRADE_NOTIFY_PAY, payNotifyDic, tradeOrder.CID, tradeOrder.PayNotifyUrl));
                }
                catch (Exception ex)
                {
                    LogEngine.WriteError(string.Format("发起支付后台通知请求异常:商户ID:{0},门店ID:{1},返回参数:{2}", reqModel.MerchantId, reqModel.ShopId, reqModel.ToJson()), null, LogModule.支付交易);
                    return(SxfPayReturn.Fail(msg: "数据接收失败"));
                }
            }
        }
        /// <summary>
        /// 创建生成退款通知
        /// </summary>
        /// <param name="reqModel"></param>
        /// <returns></returns>
        public override SxfPayReturn Build(SxfRefundNotifyRequest reqModel)
        {
            TradeOrder tradeOrder     = null;
            var        rfdTradeResult = new TradeResult(reqModel);
            //保存通知结果并更改TradeOrder状态
            var success = PaySvc.SaveMchTradeResult(rfdTradeResult, out tradeOrder);

            if (!success)
            {
                return(SxfPayReturn.Fail(msg: "数据接收失败"));
            }
            else
            {
                var rfdNotify    = new NotifyRefundRequest(tradeOrder, rfdTradeResult);
                var rfdNotifyDic = PaySignHelper.ToASCIIDictionary(rfdNotify);
                return(SendPost(PayConst.QCTTRADE_NOTIFY_REFUND, rfdNotifyDic, tradeOrder.CID, tradeOrder.RfdNotifyUrl));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 回发通知给商家
        /// </summary>
        /// <param name="method"></param>
        /// <param name="dic"></param>
        /// <param name="cid"></param>
        /// <param name="notifyUrl"></param>
        /// <returns></returns>
        public SxfPayReturn SendPost(string method, Dictionary <string, object> dic, int cid, string notifyUrl)
        {
            var secretKey = (new PaySignService()).GetMerchSecretKeyByCID(cid);

            if (secretKey.IsNullOrEmpty())
            {
                LogEngine.WriteError(string.Format("发起后台通知请求错误:找不到SecretKey,接口参数名:{0},通知URL:{1},发送参数:{2}", method, notifyUrl, dic.ToJson()), null, LogModule.支付交易);
                return(SxfPayReturn.Fail(msg: "数据接收失败"));
            }
            else
            {
                //Qct签名
                dic = PaySignHelper.SetSign(dic, secretKey, "sign");
                try
                {
                    //给商家发送结果通知
                    var postResult = PayHelper.SendPost(notifyUrl, dic);
                    if (postResult.Successed)
                    {
                        var resultObj = JsonConvert.DeserializeObject <JObject>(postResult.Data.ToString());

                        if (resultObj.Property("return_code", true) == PayConst.SUCCESS_CODE)
                        {
                            return(SxfPayReturn.Success());
                        }
                        else
                        {
                            return(SxfPayReturn.Fail(msg: "数据接收失败"));
                        }
                    }
                    else
                    {
                        return(SxfPayReturn.Fail(msg: postResult.ReturnMsg));
                    }
                }
                catch (Exception ex)
                {
                    LogEngine.WriteError(string.Format("发起后台通知请求异常:商户通知Url无响应,接口参数名:{0},通知URL:{1}]", method, notifyUrl), ex, LogModule.支付交易);
                    return(SxfPayReturn.Fail(PayConst.FAIL_CODE_40004, ""));
                }
            }
        }
Ejemplo n.º 4
0
 public object SxfPayNotify(SxfPayNotifyRequest reqModel)
 {
     try
     {
         if (reqModel.Type == PayConst.SXF_TYPE_PAYNOTIFY)
         {
             NotifyBuilder <SxfPayNotifyRequest> payNotify = new NotifyBuilderForPay();
             return(payNotify.Build(reqModel));
         }
         else
         {
             return(SxfPayReturn.Fail(msg: "通知参数type值错误"));
         }
     }
     catch (WebException ex)
     {
         LogEngine.WriteError(string.Format("支付通知异常:{0},请求参数:{1}", ex.Message, reqModel.ToJson()), ex, LogModule.支付交易);
         return(SxfPayReturn.Fail(msg: "通知格式错误"));
     }
 }
Ejemplo n.º 5
0
        public object SxfRefundNotify(SxfRefundNotifyRequest reqModel)
        {
            try
            {
                //退款通知日志记录
                PayLogServer.WriteInfo(string.Format("退款通知:{0}", reqModel.ToJson()));

                if (reqModel.Type == PayConst.SXF_TYPE_RFDNOTIFY)
                {
                    NotifyBuilder <SxfRefundNotifyRequest> rfdNotify = new NotifyBuilderForRefund();
                    return(rfdNotify.Build(reqModel));
                }
                else
                {
                    return(SxfPayReturn.Fail(msg: "通知参数type值错误"));
                }
            }
            catch (WebException ex)
            {
                LogEngine.WriteError(string.Format("退款通知异常:{0},请求参数:{1}", ex.Message, reqModel.ToJson()), ex, LogModule.支付交易);
                return(SxfPayReturn.Fail(msg: "通知格式错误"));
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 创建生成退款通知
 /// </summary>
 /// <param name="reqModel"></param>
 /// <returns></returns>
 public virtual SxfPayReturn Build(TReqModel reqModel)
 {
     return(SxfPayReturn.Fail());
 }