VoiceTemplate.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package submail
  2. import (
  3. "FollowUp_Notice/conf"
  4. "FollowUp_Notice/lib"
  5. "FollowUp_Notice/logs"
  6. "encoding/json"
  7. "github.com/go-resty/resty/v2"
  8. )
  9. type VoiceXSendRes struct {
  10. Status string `json:"status"`
  11. Send_id string `json:"send_id"`
  12. Fee float64 `json:"fee"`
  13. Msg string `json:"msg"`
  14. Code string `json:"code"`
  15. }
  16. // 语音模板发送
  17. func VoiceXSend(to, hospital, name, date string) (VoiceXSendRes, error) {
  18. type Vars struct {
  19. Hospital string `json:"hospital"`
  20. Name string `json:"name"`
  21. Date string `json:"date"`
  22. }
  23. vars := Vars{Hospital: hospital, Name: name, Date: date}
  24. b, _ := json.Marshal(vars)
  25. client := resty.New()
  26. resp, err := client.R().
  27. SetHeader("Content-Type", "application/x-www-form-urlencoded").
  28. SetFormData(map[string]string{
  29. "appid": conf.SUBMAIL_Voice_Appid,
  30. "signature": conf.SUBMAIL_Voice_Signature,
  31. "to": to,
  32. "project": conf.SUBMAIL_Voice_Project,
  33. "vars": string(b),
  34. }).
  35. SetResult(&VoiceXSendRes{}).
  36. Post("https://api-v4.mysubmail.com/voice/xsend.json")
  37. if err != nil {
  38. return VoiceXSendRes{}, err
  39. }
  40. temp := VoiceXSendRes{}
  41. if err = json.Unmarshal(resp.Body(), &temp); err != nil {
  42. logs.Error(lib.FuncName(), err)
  43. return VoiceXSendRes{}, err
  44. }
  45. return temp, nil
  46. }
  47. func VoiceSend(to, content string) (VoiceXSendRes, error) {
  48. client := resty.New()
  49. resp, err := client.R().
  50. SetHeader("Content-Type", "application/x-www-form-urlencoded").
  51. SetFormData(map[string]string{
  52. "appid": conf.SUBMAIL_Voice_Appid,
  53. "signature": conf.SUBMAIL_Voice_Signature,
  54. "to": to,
  55. "content": content,
  56. }).
  57. SetResult(&VoiceXSendRes{}).
  58. Post("https://api-v4.mysubmail.com/voice/send.json")
  59. if err != nil {
  60. return VoiceXSendRes{}, err
  61. }
  62. temp := VoiceXSendRes{}
  63. if err = json.Unmarshal(resp.Body(), &temp); err != nil {
  64. logs.Error(lib.FuncName(), err)
  65. return VoiceXSendRes{}, err
  66. }
  67. return temp, nil
  68. }