NatsSbV.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package NatsServer
  2. import (
  3. "Cold_mqtt/lib"
  4. "Cold_mqtt/logs"
  5. "Cold_mqtt/models/Account"
  6. "Cold_mqtt/models/Warning"
  7. "github.com/vmihailenco/msgpack/v5"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. // 赛邮
  13. func Submail_Voice(Company_Charging_r Account.Company, Warning_r *Warning.Warning, PhoneNumbers string, TemplateCode string, TemplateParam string) {
  14. logs.Println("Nats =>", lib.FuncName(), PhoneNumbers, TemplateCode, TemplateParam)
  15. type Ali_Message struct {
  16. PhoneNumbers string
  17. TemplateCode string
  18. TemplateParam string
  19. }
  20. b, err := msgpack.Marshal(&Ali_Message{
  21. PhoneNumbers: PhoneNumbers,
  22. TemplateCode: TemplateCode,
  23. TemplateParam: TemplateParam,
  24. })
  25. if err != nil {
  26. logs.Println("Submail_Voice", err)
  27. return
  28. }
  29. cun_x := 0
  30. Data := ""
  31. breakHere:
  32. cun_x++
  33. // 控制发送
  34. if cun_x > 3 {
  35. // 添加
  36. Warning_r_e := Warning.Warning{}
  37. Warning_r_e.T_pid = 0
  38. Warning_r_e.T_tp = 1014
  39. Warning_r_e.T_D_name = "赛邮语音服务通讯"
  40. Warning_r_e.T_Remark = "语音服务通讯 异常!"
  41. Warning_r_e.T_Log = Data
  42. Warning_r_e.T_State = 3
  43. Warning_r_e.T_Ut = time.Now()
  44. //WarningNotice.WarningToAdminId(&Warning_r_e, []int{1}) // 发送给 绑定公司管理员
  45. // 添加报警
  46. Warning.Add_Warning(Warning_r_e)
  47. logs.PrintlnError("电话通知", "赛邮语音服务通讯 异常!")
  48. // 达到数量上线跳出
  49. return
  50. }
  51. // 请求-响应, 向 test3 发布一个 `help me` 请求数据,设置超时间3秒,如果有多个响应,只接收第一个收到的消息
  52. msg, err := lib.Nats.Request("Submail_Voice", b, 60*time.Second)
  53. if err != nil {
  54. logs.PrintlnError("Submail_Voice %s", err.Error())
  55. Warning.Add_Warning_Log(Warning_r, "---->语音服务发送超时 异常!尝试发送 "+strconv.Itoa(cun_x)+" 次 ["+time.Now().Format("15:04:05")+"]\n")
  56. Data = "语音服务通讯 异常!Nats Err!"
  57. time.Sleep(time.Second * time.Duration(cun_x))
  58. goto breakHere // 跳转到标签
  59. }
  60. Data = string(msg.Data)
  61. logs.Println("Submail_Voice => : %s\n", Data)
  62. if !strings.Contains(Data, "成功") {
  63. Warning.Add_Warning_Log(Warning_r, "---->语音服务发送失败!["+Data+"]!尝试发送 "+strconv.Itoa(cun_x)+" 次 ["+time.Now().Format("15:04:05")+"]\n")
  64. time.Sleep(time.Second * time.Duration(cun_x))
  65. goto breakHere // 跳转到标签
  66. }
  67. Warning.Add_Warning_Log(Warning_r, "->"+Data+"\n")
  68. // ============== 计费 ==============
  69. Warning.Add_WarningSand(Warning.WarningSand{
  70. T_pid: Company_Charging_r.Id,
  71. T_Spid: Warning_r.T_pid,
  72. T_tp: Warning_r.T_tp,
  73. T_Notice: PhoneNumbers,
  74. T_Ntype: 2,
  75. T_Remark: "WID:" + strconv.FormatInt(Warning_r.Id, 10) + "\n" +
  76. "类型:" + Warning.Read_WarningType_Get(Warning_r.T_tp) + "\n" +
  77. "SN:" + Warning_r.T_sn + "\n" +
  78. "主机:" + Warning_r.T_D_name + "\n" +
  79. "设备:" + Warning_r.T_DS_name + "\n" +
  80. "备注:" + Warning_r.T_Remark + "\n" +
  81. "通知方式:语音通知\n" +
  82. "通知对象:" + PhoneNumbers,
  83. })
  84. }