广告涉及的mq都放这里
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

83 строки
2.0 KiB

  1. package tool
  2. import (
  3. "applet/app/utils"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "sort"
  8. "time"
  9. )
  10. type CurlResponse struct {
  11. Status string `json:"status"`
  12. Data interface{} `json:"data"`
  13. Msg string `json:"msg"`
  14. }
  15. const (
  16. RequestUrl = "http://router.itaokecms.com/api?app_key=%s&v=1.0&format=json&sign_method=md5&method=%s&timestamp=%s&domain=%s&client=%s&partner_id=%s&sign=%s"
  17. AppKey = "1091808433"
  18. AppSecret = "bed35c10-ecf1-2d06-477b-f821c227198b"
  19. Domain = "hairuyi.com"
  20. PartnerId = "top-sdk-php-20190618"
  21. )
  22. func SendPost(url string, args interface{}) (data CurlResponse, err error) {
  23. post, err := utils.CurlPost(url, utils.Serialize(args), map[string]string{})
  24. utils.FilePutContents("cloud_issuance_send", "resp"+string(post))
  25. err = json.Unmarshal(post, &data)
  26. if err != nil {
  27. return
  28. }
  29. if data.Status != "0000" {
  30. err = errors.New(data.Msg)
  31. return
  32. }
  33. return data, err
  34. }
  35. func HttpBuild(methodName, clientIP string, params map[string]string) (httpUrl string) {
  36. timestamp := utils.AnyToString(time.Now().Unix())
  37. params["app_key"] = AppKey
  38. params["v"] = "1.0"
  39. params["format"] = "json"
  40. params["sign_method"] = "md5"
  41. params["method"] = methodName
  42. params["timestamp"] = timestamp
  43. params["domain"] = Domain
  44. params["client"] = clientIP
  45. params["partner_id"] = PartnerId
  46. sign := httpBuildQuery(params, true)
  47. sign = AppSecret + httpBuildQuery(params, true) + AppSecret
  48. sign = utils.MD5ToUpper32(sign)
  49. httpUrl = fmt.Sprintf(RequestUrl, AppKey, methodName, timestamp, Domain, clientIP, PartnerId, sign)
  50. return
  51. }
  52. func httpBuildQuery(args map[string]string, sortAsc ...bool) string {
  53. str := ""
  54. if len(args) == 0 {
  55. return str
  56. }
  57. if len(sortAsc) > 0 {
  58. keys := make([]string, 0, len(args))
  59. for k := range args {
  60. keys = append(keys, k)
  61. }
  62. if sortAsc[0] {
  63. sort.Strings(keys)
  64. } else {
  65. sort.Sort(sort.Reverse(sort.StringSlice(keys)))
  66. }
  67. for _, k := range keys {
  68. str += k + args[k]
  69. }
  70. } else {
  71. for k, v := range args {
  72. str += k + v
  73. }
  74. }
  75. return str
  76. }