public HttpResponseMessage Get(string no, string from, string type) { var response = new RetDTO(); JObject requestHeader = new JObject(); try { if (string.IsNullOrEmpty(no) || string.IsNullOrEmpty(from) || string.IsNullOrEmpty(type)) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.ParamError, "参数不正确"); return(Request.CreateResponse(HttpStatusCode.OK, response, "application/json")); } JObject result; if (type == "1") { result = TradeBusiness.GetTrade(no, from); } else if (type == "2") { result = TradeBusiness.GetByActualTradeNo(no, from); } else { result = TradeBusiness.GetByTradeFromNo(no, from); } response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.Success, string.Empty); response.Body = result; return(Request.CreateResponse(HttpStatusCode.OK, response, "application/json")); } catch (Exception ex) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.CatchError, ex.Message); return(Request.CreateResponse(HttpStatusCode.OK, response, "application/json")); } }
public HttpResponseMessage Get(string startTime, string endTime) { var response = new RetDTO(); JObject requestHeader = new JObject(); try { if (string.IsNullOrEmpty(startTime) || string.IsNullOrEmpty(endTime)) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.ParamError, "参数不正确"); return(Request.CreateResponse(HttpStatusCode.OK, response, "application/json")); } var result = TradeBusiness.GetTradeList(startTime, endTime); response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.Success, string.Empty); response.Body = result; return(Request.CreateResponse(HttpStatusCode.OK, response, "application/json")); } catch (Exception ex) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.CatchError, ex.Message); return(Request.CreateResponse(HttpStatusCode.OK, response, "application/json")); } }
// POST api/<controller> public HttpResponseMessage Post() { var response = new RetDTO(); JObject requestHeader = null; JObject requestBody = null; var token = string.Empty; var timeStamp = string.Empty; var type = string.Empty; var fee = string.Empty; var from = string.Empty; var subject = string.Empty; var fromNo = string.Empty; var installmentTimes = string.Empty; try { var httpCurrent = HttpContext.Current; var request = HttpHelper.GetRequestJObjectFromStream(HttpContext.Current); requestHeader = (JObject)request.GetValue("Header"); token = requestHeader.GetValue("Token").ToString(); timeStamp = requestHeader.GetValue("TimeStamp").ToString(); requestBody = (JObject)request.GetValue("Body"); type = requestBody.GetValue("Type").ToString(); fee = requestBody.GetValue("Fee").ToString(); from = requestBody.GetValue("From").ToString(); subject = requestBody.GetValue("Subject") != null?requestBody.GetValue("Subject").ToString() : string.Empty; fromNo = requestBody.GetValue("FromNo") != null?requestBody.GetValue("FromNo").ToString() : string.Empty; installmentTimes = requestBody.GetValue("InstallmentTimes") != null?requestBody.GetValue("InstallmentTimes").ToString() : ConfigurationManager.AppSettings["icbc.InstallmentTimes"]; WebApiConfig.log.Error("Pay controller:" + request.ToString()); } catch (Exception ex) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.CatchError, "参数错误:" + ex.Message); return(Request.CreateResponse(HttpStatusCode.OK, response)); } try { if (string.IsNullOrEmpty(token)) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.NoLogin, "令牌为空"); return(Request.CreateResponse(HttpStatusCode.OK, response)); } double temp; PaymentType paymentType; if (string.IsNullOrEmpty(type) || !double.TryParse(fee, out temp) || !System.Enum.TryParse(type, out paymentType) || string.IsNullOrEmpty(from) || paymentType != PaymentType.ICBC) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.ParamError, "参数不正确"); return(Request.CreateResponse(HttpStatusCode.OK, response)); } var isPC = (requestBody.GetValue("isPC") != null && requestBody.GetValue("isPC").ToString() == "1") ? true : false; var responseForm = ICBC.Pay.createForm(paymentType, from, fromNo, fee, subject, installmentTimes, isPC); response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.Success, string.Empty); response.Body = responseForm; return(Request.CreateResponse(HttpStatusCode.OK, response)); } catch (Exception ex) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.CatchError, ex.Message); return(Request.CreateResponse(HttpStatusCode.OK, response)); } }
// POST api/<controller> public HttpResponseMessage Post() { var response = new RetDTO(); JObject requestHeader = null; JObject requestBody = null; var token = string.Empty; var timeStamp = string.Empty; var tradeNo = string.Empty; var fee = string.Empty; var from = string.Empty; var sign = string.Empty; try { var httpCurrent = HttpContext.Current; var request = HttpHelper.GetRequestJObjectFromStream(HttpContext.Current); requestHeader = (JObject)request.GetValue("Header"); token = requestHeader.GetValue("Token").ToString(); timeStamp = requestHeader.GetValue("TimeStamp").ToString(); requestBody = (JObject)request.GetValue("Body"); tradeNo = requestBody.GetValue("TradeNo").ToString(); fee = requestBody.GetValue("Fee").ToString(); from = requestBody.GetValue("From").ToString(); sign = requestBody.GetValue("sign").ToString(); WebApiConfig.log.Info("Refund controller:" + request.ToString()); } catch (Exception ex) { WebApiConfig.log.Error("参数错误"); response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.CatchError, "参数错误:" + ex.Message); return(Request.CreateResponse(HttpStatusCode.BadRequest, response)); } try { if (string.IsNullOrEmpty(token)) { WebApiConfig.log.Error("令牌为空"); response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.NoLogin, "令牌为空"); return(Request.CreateResponse(HttpStatusCode.BadRequest, response)); } double temp; if (string.IsNullOrEmpty(tradeNo) || !double.TryParse(fee, out temp) || string.IsNullOrEmpty(from) || string.IsNullOrEmpty(sign)) { WebApiConfig.log.Error("参数不正确"); response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.ParamError, "参数不正确"); return(Request.CreateResponse(HttpStatusCode.BadRequest, response)); } //sign = EncryptDES(tradeNo + "," + from); var signValue = Decode(sign); var splits = signValue.Split(','); if (splits.Length != 2 || splits[0] != tradeNo || splits[1] != from) { WebApiConfig.log.Error("验证签名不过"); response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.ParamError, "验证签名不过"); return(Request.CreateResponse(HttpStatusCode.BadRequest, response)); } var result = TradeBusiness.GetByActualTradeNo(tradeNo, from); if (result == null) { WebApiConfig.log.Error("传入的订单号不存在"); throw new Exception("传入的订单号不存在"); } object responseForm; var paymentType = result.GetValue("Type").ToString(); //if (paymentType == ((int)PaymentType.Alipay).ToString() || paymentType == ((int)PaymentType.AlipayWap).ToString()) //{ // responseForm = Alipay.Refund.execute(from, tradeNo, string.Empty, fee, result); //} //else if (paymentType == ((int)PaymentType.WechatPay).ToString()) //{ // responseForm = WxPay.Refund.execute(from, tradeNo, string.Empty, fee, result); //} if (paymentType == ((int)PaymentType.ICBC).ToString()) { WebApiConfig.log.Info("开始退款流程"); responseForm = ICBC.Refund.execute(from, result.GetValue("TradeNo").ToString(), string.Empty, fee, result); } else { WebApiConfig.log.Error("该模式不支持退款"); throw new Exception("该模式不支持退款"); } response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.Success, string.Empty); response.Body = responseForm; return(Request.CreateResponse(HttpStatusCode.OK, response)); } catch (Exception ex) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.CatchError, ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, response)); } }
// POST api/<controller> public HttpResponseMessage Post() { var response = new RetDTO(); JObject requestHeader = null; JObject requestBody = null; var token = string.Empty; var timeStamp = string.Empty; var no = string.Empty; var from = string.Empty; var type = string.Empty; try { var httpCurrent = HttpContext.Current; var request = HttpHelper.GetRequestJObjectFromStream(HttpContext.Current); requestHeader = (JObject)request.GetValue("Header"); token = requestHeader.GetValue("Token").ToString(); timeStamp = requestHeader.GetValue("TimeStamp").ToString(); requestBody = (JObject)request.GetValue("Body"); no = requestBody.GetValue("No").ToString(); from = requestBody.GetValue("From").ToString(); type = requestBody.GetValue("Type").ToString(); } catch (Exception ex) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.CatchError, "参数错误:" + ex.Message); return(Request.CreateResponse(HttpStatusCode.OK, response)); } try { if (string.IsNullOrEmpty(token)) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.NoLogin, "令牌为空"); return(Request.CreateResponse(HttpStatusCode.OK, response)); } double temp; if (string.IsNullOrEmpty(no) || string.IsNullOrEmpty(from) || string.IsNullOrEmpty(type)) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.ParamError, "参数不正确"); return(Request.CreateResponse(HttpStatusCode.OK, response)); } JObject result; if (type == "1") { result = TradeBusiness.GetTrade(no, from); } else if (type == "2") { result = TradeBusiness.GetByActualTradeNo(no, from); } else { result = TradeBusiness.GetByTradeFromNo(no, from); } response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.Success, string.Empty); response.Body = result; return(Request.CreateResponse(HttpStatusCode.OK, response)); } catch (Exception ex) { response.Header = CommonBusiness.SetHeader(requestHeader, CustomizeStatus.CatchError, ex.Message); return(Request.CreateResponse(HttpStatusCode.OK, response)); } }