public async Task <ActionResult> Test([FromBody] AdminRequest model) { if (model.Key != _adminSettings.Key) { ModelState.AddModelError("key", "認證錯誤"); } if (string.IsNullOrEmpty(model.Cmd)) { ModelState.AddModelError("cmd", "指令錯誤"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (model.Cmd.EqualTo("remove-bill")) { var billView = JsonConvert.DeserializeObject <BillViewModel>(model.Data); _testsService.RemoveBill(billView.Id); return(Ok()); } else if (model.Cmd.EqualTo("remove-subsrcibes")) { await _testsService.RemoveSubsrcibesFromUserAsync(); await _testsService.RemoveBillsFromUserAsync(); return(Ok()); } else if (model.Cmd.EqualTo("fake-pay")) { var tradeResultModel = JsonConvert.DeserializeObject <TradeResultModel>(model.Data); var subscribe = await _subscribesService.StorePayAsync(tradeResultModel); if (subscribe != null) { //付款訂閱完成 BackgroundJob.Enqueue(() => NotifyUserAsync(subscribe.UserId)); } return(Ok("1|OK")); } else if (model.Cmd.EqualTo("login")) { var responseView = await _testsService.LoginAsync(RemoteIpAddress); return(Ok(responseView)); } else { ModelState.AddModelError("cmd", "指令錯誤"); return(BadRequest(ModelState)); } }
public async Task <ActionResult> Store() { TradeResultModel tradeResultModel = null; try { tradeResultModel = _subscribesService.ResolveTradeResult(Request); } catch (Exception ex) { _logger.LogException(ex); if (ex is EcPayTradeFeedBackFailed) { // rtnCode 不是 1 也不是 2 _logger.LogInfo("ResolveTradeResult: 1|OK"); return(Ok("1|OK")); } else if (ex is EcPayTradeFeedBackError) { _logger.LogInfo($"ResolveTradeResult: 0|{ex.Message}"); return(Ok($"0|{ex.Message}")); } else { throw ex; } } var subscribe = await _subscribesService.StorePayAsync(tradeResultModel); if (subscribe != null) { //付款訂閱完成 BackgroundJob.Enqueue(() => NotifyUserAsync(subscribe.UserId)); } return(Ok("1|OK")); }