Exemple #1
0
 public override object Query(RefundQueryRequest reqModel)
 {
     try
     {
         var canObj = CanAccess();
         if (!canObj.Successed)
         {
             return(canObj);
         }
         var sxfReq = new SxfRefundQueryRequest(reqModel, MerchStoreModel);
         //sxf签名并请求
         var sxfResult = PayHelper.SendPost(MerchStoreModel.ApiUrl, PaySignHelper.ToDicAndSign(sxfReq, MerchModel.SecretKey3, "signature"));
         if (sxfResult.Successed)
         {
             //处理返回结果
             var sxfResultObj = JsonConvert.DeserializeObject <SxfRefundQueryResponse>(sxfResult.Data.ToString());
             var result       = sxfResultObj.ToRefundQueryResponse(MerchStoreModel);
             //Qct签名
             var rstRsp = PaySignHelper.ToDicAndSign(result, MerchModel.SecretKey, "sign");
             return(rstRsp);
         }
         else
         {
             return(sxfResult);
         }
     }
     catch (Exception ex)
     {
         LogEngine.WriteError(string.Format("退款订单查询请求异常:{0},请求参数:{1}", ex.Message, reqModel.ToJson()), null, LogModule.支付交易);
         return(QctPayReturn.Fail());
     }
 }
        /// <summary>
        /// 支付订单分页查询
        /// </summary>
        /// <param name="reqModel"></param>
        /// <returns></returns>
        public override object Query(PayBatchQueryRequest reqModel)
        {
            try
            {
                var canObj = CanAccess();
                if (!canObj.Successed)
                {
                    return(canObj);
                }
                var sxfReq = new SxfPayBatchQueryRequest(reqModel, MerchStoreModel);
                //sxf签名并请求
                var sxfResult = PayHelper.SendPost(MerchStoreModel.ApiUrl, PaySignHelper.ToDicAndSign(sxfReq, MerchModel.SecretKey3, "signature"));
                if (sxfResult.Successed)
                {
                    //处理返回结果
                    var sxfJObj      = JObject.Parse(HttpUtility.UrlDecode(sxfResult.Data.ToString()));
                    var sxfResultRsp = sxfJObj.ToObject <SxfPayBatchQueryResponse>();

                    if (sxfResultRsp.IsSuccess())
                    {
                        var result = sxfResultRsp.ToPayBatchQueryRsp(MerchStoreModel);
                        //Qct签名
                        var resultDic = PaySignHelper.ToDicAndSign(result, MerchModel.SecretKey, "sign");
                        return(resultDic);
                    }
                    else
                    {
                        LogEngine.WriteError(string.Format("支付订单分页查询请求错误:请求参数:{0},返回参数:{1}", sxfResultRsp.ToJson(), sxfResult.ToJson()), null, LogModule.支付交易);
                        var rst = QctPayReturn.Fail(PayConst.FAIL_CODE_40004, sxfResultRsp.RspMsg);
                        return(rst);
                    }
                }
                else
                {
                    return(sxfResult);
                }
            }
            catch (Exception ex)
            {
                LogEngine.WriteError(string.Format("支付订单分页查询请求异常:{0},请求参数:{1}", ex.Message, reqModel.ToJson()), null, LogModule.支付交易);
                var rst = QctPayReturn.Fail();
                return(rst);
            }
        }
Exemple #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, ""));
                }
            }
        }
 /// <summary>
 /// 发送请求
 /// </summary>
 /// <returns></returns>
 public QctPayReturn SendPost <TSxfReqModel, TSxfRspModel>(string url, TSxfReqModel sxfReqModel)
     where TSxfReqModel : SxfBaseTradeRequest
     where TSxfRspModel : SxfBaseTradeResponse
 {
     //var resultStr = string.Empty;
     try
     {
         var postResult = PayHelper.SendPost(url, PaySignHelper.ToDicAndSign(sxfReqModel, MerchModel.SecretKey3, "signature"));
         if (postResult.Successed)
         {
             var resultObj = JsonConvert.DeserializeObject <TSxfRspModel>(postResult.Data.ToString());
             if (resultObj.IsSuccess())
             {
                 return(QctPayReturn.Success(data: resultObj));
             }
             else
             {
                 //处理返回失败结果
                 LogEngine.WriteError(string.Format("发送交易请求成功但返回交易错误信息:请求参数:{0},返回参数:{1}]", sxfReqModel.ToJson(), postResult), null, LogModule.支付交易);
                 if (string.IsNullOrWhiteSpace(resultObj.RspMsg))
                 {
                     resultObj.RspMsg = "服务器请求失败";
                 }
                 return(QctPayReturn.Fail(PayTradeHelper.TransCodeBySxf(resultObj.RspCod), resultObj.RspMsg));
             }
         }
         else
         {
             return(postResult);
         }
     }
     catch (Exception ex)
     {
         return(ResultFail(msg: "订单请求失败", logMsg: string.Format("发送交易请求异常:服务器异常,请求参数:{0},异常信息:{1}]", sxfReqModel.ToJson(), ex.Message)));
     }
 }
Exemple #5
0
        /// <summary>
        /// 发送Post支付请求
        /// </summary>
        /// <param name="request"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static QctPayReturn SendPost(this string url, Dictionary <string, object> reqParams)
        {
            var result = PayHelper.SendPost(url, reqParams.ToSignString());

            return(result);
        }