/// <summary> /// 页面-支付宝支付通知 /// </summary> public ActionResult AlipayNotify(RequestModel request) { //支付宝通知日志 Log4netHelper.Get(KeyModel.Log.PayNotification).AsyncWriter(request.JsonString); string tradStatus = JsonHelper.GetValue(request.Obj, "trade_status"); if (!(tradStatus.ToLower() == "trade_success")) { return(Content("fail")); } string tradeNo = JsonHelper.GetValue(request.Obj, "out_trade_no"); decimal moneyValue = DecimalHelper.Get(JsonHelper.GetValue(request.Obj, "total_fee")); string rechrageRecordId = JsonHelper.GetValue(request.Obj, "trade_no"); if (VerifyHelper.IsEmpty(tradeNo) || VerifyHelper.IsEmpty(moneyValue)) { throw new MessageException(EnumMessageCode.信息错误); } try { rechargeRecordService.RechargeSuccess(tradeNo, moneyValue, rechrageRecordId); } catch (Exception ex) { throw ex; } return(Content("success")); }
private void Snapshot(dynamic data) { var currencyPair = _currencyMapper.GetCurrency((string)data.product_id); var orderBook = new OrderBook { CurrencyPair = currencyPair }; foreach (var bid in data.bids) { var bookItem = new OrderBookItem() { Price = DecimalHelper.Get((string)bid[0]), Volume = DecimalHelper.Get((string)bid[1]), }; orderBook.Bids.Add(bookItem); } foreach (var ask in data.asks) { var bookItem = new OrderBookItem() { Price = DecimalHelper.Get((string)ask[0]), Volume = DecimalHelper.Get((string)ask[1]), }; orderBook.Asks.Add(bookItem); } SortBids(orderBook); SortAsks(orderBook); _orderBookDict[currencyPair] = orderBook; OrderBookChanged?.Invoke(orderBook.CurrencyPair, orderBook); }
/// <summary> /// 页面-支付宝支付跳转 /// </summary> public ActionResult AlipayReturn(RequestModel request) { //异步记录日志 Log4netHelper.Get(KeyModel.Log.PayNotification).AsyncWriter(request.JsonString); var result = WebHelper.GetResult(request); if (result.Code == EnumHelper.GetValue(EnumResultCode.操作成功)) { //支付失败 string returnSuccess = JsonHelper.GetValue(request.Obj, "is_success"); string tradStatus = JsonHelper.GetValue(request.Obj, "trade_status"); if (!(returnSuccess.ToLower() == "t" && tradStatus.ToLower() == "trade_success")) { throw new MessageException(EnumMessageCode.支付失败); } string tradeNo = JsonHelper.GetValue(request.Obj, "out_trade_no"); decimal moneyValue = DecimalHelper.Get(JsonHelper.GetValue(request.Obj, "total_fee")); string rechrageRecordId = JsonHelper.GetValue(request.Obj, "trade_no"); if (VerifyHelper.IsEmpty(tradeNo) || VerifyHelper.IsEmpty(moneyValue)) { throw new MessageException(EnumMessageCode.信息错误); } try { rechargeRecordService.RechargeSuccess(tradeNo, moneyValue, rechrageRecordId); } catch (Exception ex) { throw ex; } } return(new RedirectResult(WebHelper.GetMemberUrl("/trade/rechargerecord"))); }
//通知信息 public override void ProcessNotify() { WxPayData notifyData = GetNotifyData(); Log4netHelper.Get(KeyModel.Log.PayNotification).AsyncWriter(notifyData.ToJson()); //检查支付结果中transaction_id是否存在 if (!notifyData.IsSet("transaction_id")) { //若transaction_id不存在,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "支付结果中微信订单号不存在"); context.Response.Write(res.ToXml()); context.Response.End(); } string transaction_id = notifyData.GetValue("transaction_id").ToString(); string tradeNo = StringHelper.Get(notifyData.GetValue("out_trade_no")); decimal moneyValue = DecimalHelper.Get(notifyData.GetValue("total_fee")) / 100; string rechrageRecordId = ""; bool isFunction = false; if (QueryOrder(transaction_id)) { //执执判断是否执行成功 isFunction = fun(tradeNo, moneyValue, rechrageRecordId); } if (!isFunction) { WxPayData res = new WxPayData(); res.SetValue("return_code", "SUCCESS"); res.SetValue("return_msg", "OK"); context.Response.Write(res.ToXml()); context.Response.End(); } else { WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "订单查询失败"); context.Response.Write(res.ToXml()); context.Response.End(); } }
private void L2Update(dynamic data) { try { var currencyPair = _currencyMapper.GetCurrency((string)data.product_id); var orderBook = _orderBookDict[currencyPair]; foreach (var change in data.changes) { var tradeType = (string)change[0]; var price = DecimalHelper.Get((string)change[1]); var volume = DecimalHelper.Get((string)change[2]); if (tradeType == "buy") { var bid = orderBook.Bids.FirstOrDefault(it => it.Price == price); if (volume == 0) { if (bid != null) { orderBook.Bids.Remove(bid); SortBids(orderBook); } } else { if (bid != null) { bid.Volume = volume; } else { bid = new OrderBookItem() { Price = price, Volume = volume }; orderBook.Bids.Add(bid); SortBids(orderBook); } } } else { var ask = orderBook.Asks.FirstOrDefault(it => it.Price == price); if (volume == 0) { if (ask != null) { orderBook.Asks.Remove(ask); SortAsks(orderBook); } } if (ask != null) { ask.Volume = volume; } else { ask = new OrderBookItem() { Price = price, Volume = volume }; orderBook.Asks.Add(ask); SortAsks(orderBook); } } OrderBookChanged?.Invoke(currencyPair, orderBook); } } catch (Exception) { //Todo:log data format error } }