common.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2019 utimes.cc. All rights reserved.
  2. // Use of this source code is governed by utimes.cc.
  3. package data_api_check
  4. import (
  5. "gd_auth_check/common.in/config"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/astaxie/beego/orm"
  9. "io/ioutil"
  10. "net/http"
  11. "strings"
  12. "strconv"
  13. )
  14. type Text struct {
  15. Content string `json:"content"`
  16. }
  17. type At struct {
  18. AtMobiles []string `json:"atMobiles"`
  19. IsAtAll bool `json:"isAtAll"`
  20. }
  21. type TextMsg struct {
  22. MsgType string `json:"msgtype"`
  23. Text Text `json:"text"`
  24. At At `json:"at"`
  25. }
  26. func SendToDingTalk(content string) {
  27. textMsg := TextMsg{}
  28. textMsg.MsgType = "text"
  29. textMsg.Text = Text{}
  30. textMsg.Text.Content = content
  31. webHook := config.Conf.ThirdPart.DingTalkWebhook
  32. contentByte, _ := json.Marshal(textMsg)
  33. req, err := http.NewRequest("POST", webHook, strings.NewReader(string(contentByte)))
  34. client := &http.Client{}
  35. req.Header.Set("Content-Type", "application/json")
  36. resp, err := client.Do(req)
  37. defer resp.Body.Close()
  38. if err != nil {
  39. fmt.Println("send error:", err)
  40. return
  41. }
  42. fmt.Println(resp.StatusCode)
  43. body, _ := ioutil.ReadAll(resp.Body)
  44. fmt.Println(string(body))
  45. }
  46. func ormStringToInt(m orm.Params, key string) int64 {
  47. if m[key] == nil {
  48. return 0
  49. }
  50. str, ok := m[key].(string)
  51. if ok == false {
  52. return 0
  53. }
  54. ret, err := strconv.ParseInt(str, 10, 64)
  55. if err != nil {
  56. return 0
  57. }
  58. return ret
  59. }
  60. func ormStringToFloat(m orm.Params, key string) float64 {
  61. if m[key] == nil {
  62. return 0
  63. }
  64. str, ok := m[key].(string)
  65. if ok == false {
  66. return 0
  67. }
  68. ret, err := strconv.ParseFloat(str, 64)
  69. if err != nil {
  70. return 0
  71. }
  72. return ret
  73. }