golang 的 rabbitmq 消费项目
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

86 linhas
2.2 KiB

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