public async Task ProcessAccountStopout(AccountStopoutBackendContract stopout) { var queueName = QueueHelper.BuildQueueName(_settings.MarginTradingFront.RabbitMqQueues.AccountStopout.ExchangeName, _settings.MarginTradingFront.Env); _consoleWriter.WriteLine($"Get account stopout from {queueName} queue for clientId = {stopout.ClientId}"); var notificationId = await _clientNotificationService.GetNotificationId(stopout.ClientId); var userTopic = _realm.Services.GetSubject <NotifyResponse <AccountStopoutClientContract> >($"user.{notificationId}"); var response = new NotifyResponse <AccountStopoutClientContract> { Entity = stopout.ToClientContract(), Type = NotifyEntityType.AccountStopout }; userTopic.OnNext(response); _operationsLog.AddLog($"topic user.{notificationId} (account stopout)", stopout.ClientId, response.Entity.AccountId, null, response.ToJson()); _consoleWriter.WriteLine($"topic user.{notificationId} (account stopout) for clientId = {stopout.ClientId}"); var userUpdateTopic = _realm.Services.GetSubject <NotifyResponse>($"user.updates.{notificationId}"); var userUpdateTopicResponse = new NotifyResponse { Account = null, Order = null, AccountStopout = response.Entity }; userUpdateTopic.OnNext(userUpdateTopicResponse); _operationsLog.AddLog($"topic user.updates.{notificationId} (account stopout)", stopout.ClientId, response.Entity.AccountId, null, userUpdateTopicResponse.ToJson()); _consoleWriter.WriteLine($"topic user.updates.{notificationId} (account stopout) for clientId = {stopout.ClientId}"); }
public NotifyResponse Post(NotifyUsersRequest request) { NotifyResponse res = new NotifyResponse(); try { foreach (KeyValuePair <int, string> user_details in request.UsersDetails) { this.Post(new NotifyUserIdRequest { Msg = request.Msg, Selector = request.Selector, ToUserAuthId = user_details.Value, NotificationId = request.NotificationId, NotifyUserId = user_details.Key, SolnId = request.SolnId }); } } catch (Exception e) { Console.WriteLine(e.ToJson()); res.ResponseStatus.Message = e.Message; } return(res); }
public async Task ProcessOrderChanged(OrderContract order) { var queueName = QueueHelper.BuildQueueName(_settings.MarginTradingFront.RabbitMqQueues.OrderChanged.ExchangeName, _settings.MarginTradingFront.Env); _consoleWriter.WriteLine($"Get order change from {queueName} queue for clientId = {order.ClientId}"); var notificationId = await _clientNotificationService.GetNotificationId(order.ClientId); var userTopic = _realm.Services.GetSubject <NotifyResponse <OrderClientContract> >($"user.{notificationId}"); var notifyResponse = new NotifyResponse <OrderClientContract> { Entity = order.ToClientContract(), Type = NotifyEntityType.Order }; userTopic.OnNext(notifyResponse); _operationsLog.AddLog($"topic user.{notificationId} (position changed)", order.ClientId, order.AccountId, null, notifyResponse.ToJson()); _consoleWriter.WriteLine($"topic user.{notificationId} (order changed) for clientId = {order.ClientId}"); var userUpdateTopic = _realm.Services.GetSubject <NotifyResponse>($"user.updates.{notificationId}"); var userUpdateTopicResponse = new NotifyResponse { Account = null, Order = notifyResponse.Entity }; userUpdateTopic.OnNext(userUpdateTopicResponse); _operationsLog.AddLog($"topic user.updates.{notificationId} (position changed)", order.ClientId, notifyResponse.Entity.AccountId, null, userUpdateTopicResponse.ToJson()); _consoleWriter.WriteLine($"topic user.updates.{notificationId} (order changed) for clientId = {order.ClientId}"); }
public NotifyResponse Notify(NotifyType type, NotifyRequest request) { NotifyResponse result = null; switch (type) { case NotifyType.Email: result = NotifyMail(request as EmailNotifyRequest); break; case NotifyType.SMS: result = NotifySms(request as SmsNotifyRequest); break; case NotifyType.WebMessage: result = NotifyWebMessage(request as WebMessageNotifyRequest); break; case NotifyType.AppMessage: result = NotifyAppMessage(request as AppMessageNotifyRequest); break; case NotifyType.AppNotify: result = NotifyApp(request as AppNotifyRequest); break; default: // for other notification types we do nothing and deliver this to sub-classses to do it at their will break; } return(result); }
public NotifyResult ParseNotifyResponse(string responseValue) { NotifyResponse response = XmlSerializerHelper.FromXmlString <NotifyResponse>(responseValue); if (!response.IsSuccess) { NotifyResult result1 = new NotifyResult(); result1.ErrorCode = response.ErrCode; result1.ErrorMessage = this.GetErrorMessage(response, "ParseNotifyResponse"); return(result1); } if (!this.ValidateResponse <NotifyResponse>(response)) { NotifyResult result2 = new NotifyResult(); result2.ErrorMessage = "返回结果响应结果不正确"; return(result2); } NotifyResult result3 = new NotifyResult(); result3.IsSuccess = true; result3.Attach = response.Attach; result3.OutTradeNo = response.OutTradeNo; result3.TimeEnd = response.TimeEnd; result3.TotalFee = ((double)response.TotalFee.GetValueOrDefault()) / 100.0; result3.TransactionId = response.TransactionId; result3.Bank = WeChatBankTypes.GetBank(response.BankType); return(result3); }
public NotifyResponse Post(NotifyChannelRequest request) { NotifyResponse res = new NotifyResponse(); try { //var subscriptionInfos = ServerEvents.GetSubscriptionsDetails(request.ToChannel); //if (subscriptionInfos != null) //{ foreach (string channel in request.ToChannel) { ServerEvents.NotifyChannel(channel, request.Selector, request.Msg); } //} // else // { // Console.WriteLine("No one listening in the Channel: " + request.ToChannel.ToJson()); //} } catch (Exception e) { Console.WriteLine(e.ToJson()); res.ResponseStatus.Message = e.Message; } return(res); }
public NotifyResponse Post(NotifyUserAuthIdRequest request) { NotifyResponse res = new NotifyResponse(); try { Console.WriteLine("Reached in NotifyUserAuthIdRequest"); if (!String.IsNullOrEmpty(request.To_UserAuthId)) { if (request.ToChannel == null) { ServerEvents.NotifyUserId(request.To_UserAuthId, request.Selector, request.Msg); } else { foreach (string channel in request.ToChannel) { ServerEvents.NotifyUserId(request.To_UserAuthId, request.Selector, request.Msg); } } } else { Console.WriteLine("UserAuthId doesn't Exist"); res.ResponseStatus.Message = "UserAuthId doesn't Exist"; } } catch (Exception e) { Console.WriteLine(e.Message + e.StackTrace); res.ResponseStatus.Message = e.Message; } return(res); }
public async Task ProcessUserUpdates(UserUpdateEntityBackendContract userUpdate) { var queueName = QueueHelper.BuildQueueName(_settings.MarginTradingFront.RabbitMqQueues.UserUpdates.ExchangeName, _settings.MarginTradingFront.Env); _consoleWriter.WriteLine($"Get user update from {queueName} queue for {userUpdate.ClientIds.Length} clients"); foreach (var clientId in userUpdate.ClientIds) { try { var notificationId = await _clientNotificationService.GetNotificationId(clientId); var userTopic = _realm.Services.GetSubject <NotifyResponse <UserUpdateEntityClientContract> >( $"user.{notificationId}"); var response = new NotifyResponse <UserUpdateEntityClientContract> { Entity = userUpdate.ToClientContract(), Type = NotifyEntityType.UserUpdate }; userTopic.OnNext(response); var eventType = string.Empty; if (userUpdate.UpdateAccountAssetPairs) { eventType = "account assets"; } if (userUpdate.UpdateAccounts) { eventType = "accounts"; } _operationsLog.AddLog($"topic user.{notificationId} ({eventType} changed)", clientId, null, null, response.ToJson()); _consoleWriter.WriteLine( $"topic user.{notificationId} ({eventType} changed) for clientId = {clientId}"); var userUpdateTopic = _realm.Services.GetSubject <NotifyResponse>($"user.updates.{notificationId}"); var userUpdateTopicResponse = new NotifyResponse { UserUpdate = response.Entity }; userUpdateTopic.OnNext(userUpdateTopicResponse); _operationsLog.AddLog($"topic user.updates.{notificationId} ({eventType} changed)", clientId, null, null, userUpdateTopicResponse.ToJson()); _consoleWriter.WriteLine( $"topic user.updates.{notificationId} (account assets changed) for clientId = {clientId}"); } catch (Exception ex) { await _log.WriteErrorAsync(nameof(RabbitMqHandler), nameof(ProcessUserUpdates), clientId, ex); } } }
protected void Page_Load(object sender, EventArgs e) { System.IO.Stream s = Request.InputStream; int count = 0; byte[] buffer = new byte[1024]; StringBuilder builder = new StringBuilder(); while ((count = s.Read(buffer, 0, 1024)) > 0) { builder.Append(Encoding.UTF8.GetString(buffer, 0, count)); } s.Flush(); s.Close(); s.Dispose(); PayLogHelper.WriteEvent(builder.ToString(), "扫呗支付"); //string testresponse = "{\"attach\":\"\",\"channel_trade_no\":\"4009262001201708186903067327\",\"end_time\":\"20170818160418\",\"key_sign\":\"b503c7c76e4df6379c6d43c5103595b9\",\"merchant_name\":\"45对接专用1号\",\"merchant_no\":\"852100210000005\",\"out_trade_no\":\"300508950021217081816035700005\",\"pay_type\":\"010\",\"receipt_fee\":\"10\",\"result_code\":\"01\",\"return_code\":\"01\",\"return_msg\":\"支付成功\",\"terminal_id\":\"30050895\",\"terminal_time\":\"20170818160255\",\"terminal_trace\":\"b609bfed0a8f4badaa5373d20b30a52c\",\"total_fee\":\"10\",\"user_id\":\"on9DrwJ7GgmOaxHBN_yIkSCeBZVo\"}"; JavaScriptSerializer jsonSerialize = new JavaScriptSerializer(); NotifyResponse ack = jsonSerialize.Deserialize <NotifyResponse>(builder.ToString()); //NotifyResponse ack = jsonSerialize.Deserialize<NotifyResponse>(testresponse); Response.ContentType = "application/json"; Response.HeaderEncoding = Encoding.UTF8; try { if (ack.CheckSign()) { if (ack.return_code == "01") { if (ack.result_code == "01") { string out_trade_no = ack.out_trade_no; decimal total_fee = Convert.ToDecimal(ack.total_fee); decimal payAmount = total_fee / 100; Flw_OrderBusiness.OrderPay(out_trade_no, payAmount, SelttleType.LcswPay); } } Response.Write("{\"return_code\":\"01\",\"return_msg\":\"success\"}"); } else { Response.Write("{\"return_code\":\"02\",\"return_msg\":\"签名失败\"}"); } } catch (Exception ex) { Response.Write("{\"return_code\":\"02\",\"return_msg\":\"签名失败\"}"); PayLogHelper.WriteError(ex); } }
public async Task <IActionResult> SendEmail([FromForm] SendEmailRequest sendEmailRequest) { var correlationId = Guid.NewGuid(); try { var sessionId = await TryGetSessionId(Request); if (string.IsNullOrEmpty(sessionId)) { return(Redirect("/")); } var model = new SaveProgressViewModel { BackLink = "/save-my-progress" }; if (!sendEmailRequest.ValidEmail) { if (string.IsNullOrWhiteSpace(sendEmailRequest.Email)) { return(Redirect("/save-my-progress/email?e=1")); } return(Redirect("/save-my-progress/email?e=2")); } NotifyResponse notifyResponse = null; try { notifyResponse = await _apiServices.SendEmail($"https://{Request.Host.Value}", sendEmailRequest.Email?.ToLower(), _appSettings.NotifyEmailTemplateId, sessionId, correlationId); if (!notifyResponse.IsSuccess) { throw new Exception(notifyResponse?.Message); } model.SentTo = sendEmailRequest.Email?.ToLower(); AppendCookie(sessionId); TempData["SentEmail"] = model.SentTo; return(RedirectToAction("EmailSent")); } catch (Exception ex) { _log.LogError(ex, $"Correlation Id: {correlationId} - Sending email in action {nameof(SendEmail)}"); return(Redirect("/save-my-progress/email?e=3")); } } catch (Exception ex) { _log.LogError(ex, $"Correlation Id: {correlationId} - An error occurred rendering action {nameof(SendEmail)}"); return(RedirectToAction("Error500", "Error")); } }
public async Task <IActionResult> SendSms([FromForm] SendSmsRequest sendSmsRequest) { var correlationId = Guid.NewGuid(); try { var sessionId = await TryGetSessionId(Request); if (string.IsNullOrEmpty(sessionId)) { return(Redirect("/")); } if (!sendSmsRequest.ValidMobileNumber) { if (String.IsNullOrWhiteSpace(sendSmsRequest.MobileNumber)) { return(Redirect("/save-my-progress/reference?e=1")); } return(Redirect("/save-my-progress/reference?e=2")); } var model = new SaveProgressViewModel { BackLink = "/save-my-progress" }; await UpdateSessionVarsOnViewModel(model, sessionId, correlationId); NotifyResponse notifyResponse = null; try { notifyResponse = await _apiServices.SendSms($"https://{Request.Host.Value}", sendSmsRequest.MobileNumber, _appSettings.NotifySmsTemplateId, sessionId, correlationId); if (!notifyResponse.IsSuccess) { throw new Exception(notifyResponse?.Message); } model.SentTo = sendSmsRequest.MobileNumber; AppendCookie(sessionId); TempData["SentSms"] = model.SentTo; return(RedirectToAction("SmsSent")); } catch (Exception ex) { _log.LogError(ex, $"Correlation Id: {correlationId} - An error occurred sending an SMS in action {nameof(SendSms)}"); return(Redirect("/save-my-progress/reference?e=3")); } } catch (Exception ex) { _log.LogError(ex, $"Correlation Id: {correlationId} - An error occurred rendering action {nameof(SendSms)}"); return(RedirectToAction("Error500", "Error")); } }
public async Task SendSms_ShouldCall_CorrectUrl() { var guid = Guid.NewGuid(); var sessionId = "Abc123"; var url = $"{ApiRoot}/assessment/notify/sms"; var response = new NotifyResponse() { IsSuccess = true }; _httpService.PostData(url, Arg.Any <object>(), guid).Returns(Task.FromResult(JsonConvert.SerializeObject(response))); var result = await _api.SendSms("disco", "0790002200", "0", sessionId, guid); Assert.Equal(response.IsSuccess, result.IsSuccess); }
public NotifyResponse Post(NotifyUserIdRequest request) { Console.WriteLine("---------------------->Inside notifyUserIdReq \nUserId: " + request.ToUserAuthId); NotifyResponse res = new NotifyResponse(); try { if (request.Selector == "cmd.onNotification") { this.MessageProducer3.Publish(new NotificationToDBRequest() { SolnId = request.SolnId, UserId = request.UserId, NotifyUserId = request.NotifyUserId, Notification = request.Msg, NotificationId = request.NotificationId }); Console.WriteLine("---------------------->After NotificationToDBRequest UserId: " + request.ToUserAuthId); } Console.WriteLine("request.Selector" + request.Selector + "------------No NotificationToDBRequest----------> UserId: " + request.ToUserAuthId); List <SubscriptionInfo> subscriptionInfos = ServerEvents.GetSubscriptionInfosByUserId(request.ToUserAuthId); foreach (SubscriptionInfo sub in subscriptionInfos) { if (request.ToChannel == null) { ServerEvents.NotifySubscription(sub.SubscriptionId, request.Selector, request.Msg); } else { foreach (string channel in request.ToChannel) { ServerEvents.NotifySubscription(sub.SubscriptionId, request.Selector, request.Msg, channel); } } } } catch (Exception e) { Console.WriteLine(e.Message + e.StackTrace); res.ResponseStatus.Message = e.Message; } return(res); }
public NotifyResponse Post(NotifySubscriptionRequest request) { NotifyResponse res = new NotifyResponse(); try { Console.WriteLine("Reached in NotifySubscriptionRequest"); SubscriptionInfo subscriptionInfos = ServerEvents.GetSubscriptionInfo(request.ToSubscriptionId); if (subscriptionInfos != null) { if (!String.IsNullOrEmpty(subscriptionInfos.SubscriptionId)) { Console.WriteLine("SubscriptionId :" + subscriptionInfos.SubscriptionId); if (request.ToChannel == null) { ServerEvents.NotifySubscription(subscriptionInfos.SubscriptionId, request.Selector, request.Msg); } else { foreach (string channel in request.ToChannel) { ServerEvents.NotifySubscription(subscriptionInfos.SubscriptionId, request.Selector, request.Msg, channel); } } } else { Console.WriteLine("SubscriptionId doesn't Exist"); res.ResponseStatus.Message = "SubscriptionId doesn't Exist"; } } else { Console.WriteLine("subscriptionInfos Is Null"); res.ResponseStatus.Message = "subscriptionInfos Is Null"; } } catch (Exception e) { Console.WriteLine(e.Message + e.StackTrace); res.ResponseStatus.Message = e.Message; } return(res); }
private void NotificationReceived(NotifyResponse info) { if (info.Account != null) { LogInfo($"Notification received: Account changed={info.Account.Id} Balance:{info.Account.Balance}"); } if (info.Order != null) { LogInfo($"Notification received: Order changed={info.Order.Id} Open:{info.Order.OpenDate} Close:{info.Order.CloseDate} Fpl:{info.Order.Fpl}"); } if (info.AccountStopout != null) { LogInfo($"Notification received: Account stopout={info.AccountStopout.AccountId}"); } if (info.UserUpdate != null) { LogInfo($"Notification received: User update={info.UserUpdate.UpdateAccountAssetPairs}, accounts = {info.UserUpdate.UpdateAccounts}"); } }
public async Task ProcessAccountChanged(AccountChangedMessage accountChangedMessage) { if (accountChangedMessage.EventType != AccountEventTypeEnum.Updated) { return; } var account = accountChangedMessage.Account; var queueName = QueueHelper.BuildQueueName(_settings.MarginTradingFront.RabbitMqQueues.AccountChanged.ExchangeName, _settings.MarginTradingFront.Env); _consoleWriter.WriteLine($"Get account change from {queueName} queue for clientId = {account.ClientId}"); var notificationId = await _clientNotificationService.GetNotificationId(account.ClientId); var userTopic = _realm.Services.GetSubject <NotifyResponse <MarginTradingAccountClientContract> >($"user.{notificationId}"); var notifyResponse = new NotifyResponse <MarginTradingAccountClientContract> { Entity = account.ToClientContract(), Type = NotifyEntityType.Account }; userTopic.OnNext(notifyResponse); _operationsLog.AddLog($"topic user.{notificationId} (account changed)", account.ClientId, account.Id, null, notifyResponse.ToJson()); _consoleWriter.WriteLine($"topic user.{notificationId} (account changed) for clientId = {account.ClientId}"); var userUpdateTopic = _realm.Services.GetSubject <NotifyResponse>($"user.updates.{notificationId}"); var userUpdateTopicResponse = new NotifyResponse { Account = notifyResponse.Entity, Order = null }; userUpdateTopic.OnNext(userUpdateTopicResponse); _operationsLog.AddLog($"topic user.updates.{notificationId} (account changed)", account.ClientId, account.Id, null, userUpdateTopicResponse.ToJson()); _consoleWriter.WriteLine($"topic user.updates.{notificationId} (account changed) for clientId = {account.ClientId}"); }
public ReplyInfo HandleMessageAll(MessageInfo message) { ReplyInfo info = new ReplyInfo(); switch (message.msg_type_id) { case 1: case 4: // msg from contact //info.toUserId = message.user.senderId; if (message.content.type == 0) { string msg_content = message.content.data; string user_id = message.user.senderId; string user_name = message.user.senderName; log.Info("[Contact Message]: From (" + user_name + "), Context: " + msg_content); if ((user_name == "YJL SOEVPM") && (msg_content.StartsWith("##"))) { string[] tmps = msg_content.Split('@'); string notifier = user_name; if (tmps.Length > 1) { notifier = tmps[0].Replace("##", ""); } string content = tmps[tmps.Length - 1]; NotifyResponse resp = controller.NotificationStore(notifier, content); if (resp.success) { info.reply = "好的,我记住老师的话了"; } else { info.reply = "我的程序有点问题,没记住老师的话555"; } } else { if (!string.IsNullOrWhiteSpace(msg_content)) { info.reply = controller.AnswerOneOneQuestion(user_id, msg_content); } } } else if (message.content.type == 4) { string msg_content = message.content.data; string user_id = message.user.senderId; string user_name = message.user.senderName; info.reply = controller.AnswerOneOneQuestion(user_id, msg_content); log.Info("[Contact Message]: From (" + user_name + "), Context: [Voice Message]"); } else { log.Warn("[Warning]: Received non-text messsage from contact: " + message.user.senderName); info.reply = "对不起,我现在只认识文字。"; } break; case 3: //Group text message //info.toUserId = message.user.groupId; if (!string.IsNullOrWhiteSpace(message.content.detail)) { if (message.user.isAtMe) { if (message.content.type == 0) { string msg_content = message.content.desc; string src_user_id = message.user.senderId; string src_user_name = message.user.senderName; string gid = message.user.groupId; log.Info("[Group AtMe Message]: In Group(" + gid + "), From (" + src_user_name + "), Context: " + msg_content); if (!string.IsNullOrWhiteSpace(msg_content)) { string reply = controller.AnswerQuestion(src_user_id, msg_content); info.reply = "@" + src_user_name + " " + reply; } } else { log.Warn("[Warning]: Received non-text messsage in group: " + message.user.groupId); info.reply = "对不起,我现在只认识文字。"; } } } break; /* case 100: * if (message.content.type == 0) * { * string msg_content = message.content.data; * string user_id = message.user.senderId; * string user_name = message.user.senderName; * * log.Info("[Unknown Contact Message]: From (" + user_name + "), Context: " + msg_content); * * if (!string.IsNullOrWhiteSpace(msg_content)) * { * info.reply = controller.AnswerOneOneQuestion(user_id, msg_content); * * } * } * else * { * log.Warn("[Warning]: Received non-text messsage from contact: " + message.user.senderName); * info.reply = "对不起,我现在只认识文字。"; * } * break;*/ default: break; } return(info); }
public HttpResponseMessage PostNotification(NotifyRequest request) { HttpResponseMessage responseMessage; var commandHandler = new CommandHandler(); try { var tempString = Parser.SplitOnFirstWord(request.Item.message.message).Item2; if (string.IsNullOrEmpty(tempString)) { throw new Exception("no email distribution alias provided"); } // parse message var parsedMessage = Parser.SplitOnFirstWord(tempString); //get command var commandString = parsedMessage.Item1.Trim(); Command command; var commandResult = Enum.TryParse(commandString, true, out command); //get message var message = parsedMessage.Item2; var result = ""; if (commandResult) { switch (command) { case Command.Add: commandHandler.Add(message); result = "Added Successfully"; break; case Command.Update: result = commandHandler.Update(message); break; } } else { var isHtml = false; var parsedbody = Parser.SplitOnFirstWord(message); var regex = new Regex(@"^\^(\d)*"); var match = regex.Match(parsedbody.Item1); if (match.Success) { var regexDigits = new Regex(@"(\d)+"); var matchDigits = regexDigits.Match(parsedbody.Item1); if (matchDigits.Success) { var roomHistory = new RoomHistory(request.Item.room.name); isHtml = false; message = roomHistory.GetRoomMessageHistory(int.Parse(matchDigits.Value) + 1).GetEmailMessage(); } } var senderName = request.Item.message.from.name; var senderMention = request.Item.message.from.mention_name; result = commandHandler.Email(senderName, senderMention, commandString, message, isHtml); } if (result == null) { throw new Exception("error"); } // Notify Hipchat var responseBody = new NotifyResponse { color = "green", message = result, message_format = "text", notify = "false" }; responseMessage = this.Request.CreateResponse(HttpStatusCode.OK, responseBody); } catch (Exception ex) { commandHandler.Dispose(); var responseBody = new NotifyResponse { color = "green", message = ex.Message, message_format = "text", notify = "false" }; responseMessage = this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, JsonConvert.SerializeObject(responseBody)); } return(responseMessage); }