Hw_VoiceNotice.go 2.8 KB

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