第三方api接口
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

87 líneas
2.1 KiB

  1. package meituan_fenxiao
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/comm"
  4. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  5. "crypto/hmac"
  6. "crypto/md5"
  7. "encoding/hex"
  8. "fmt"
  9. "github.com/syyongx/php2go"
  10. "strings"
  11. "time"
  12. )
  13. const (
  14. ApiKey = "nsVtNZcmRDuxgBim"
  15. UtmSource = "511860"
  16. Url = "https://union.dianping.com/"
  17. )
  18. func MeituanFenXiaoSend(method string, params map[string]interface{}) (string, error) {
  19. arg := map[string]string{
  20. "requestId": zhios_third_party_utils.UUIDString(),
  21. "utmSource": UtmSource,
  22. "timestamp": zhios_third_party_utils.Int64ToStr(time.Now().Unix()),
  23. "version": "1.0",
  24. "signMethod": "hmac",
  25. }
  26. reqParam := make(map[string]interface{})
  27. for k, v := range params {
  28. reqParam[k] = v
  29. }
  30. for k, v := range arg {
  31. reqParam[k] = v
  32. }
  33. sign := MeituanFenXiaoGetSign(reqParam)
  34. arg["sign"] = sign
  35. url := Url + method
  36. for k, v := range arg {
  37. if strings.Contains(url, "?") == false {
  38. url += "?" + k + "=" + php2go.URLEncode(v)
  39. } else {
  40. url += "&" + k + "=" + php2go.URLEncode(v)
  41. }
  42. }
  43. fmt.Println(url)
  44. fmt.Println(zhios_third_party_utils.SerializeStr(params))
  45. post, err := zhios_third_party_utils.CurlPost(url, zhios_third_party_utils.SerializeStr(params), map[string]string{})
  46. if err != nil {
  47. return "", err
  48. }
  49. fmt.Println(string(post))
  50. return string(post), nil
  51. }
  52. func MeituanFenXiaoGetSign(param map[string]interface{}) string {
  53. str := ""
  54. info, ok := param["geo"].(map[string]interface{})
  55. if ok {
  56. if info["cityId"] != "" {
  57. param["cityId"] = info["cityId"]
  58. }
  59. if info["lat"] != "" {
  60. param["lat"] = info["lat"]
  61. }
  62. if info["lng"] != "" {
  63. param["lng"] = info["lng"]
  64. }
  65. }
  66. delete(param, "geo")
  67. keys := comm.KsortToStrInterface(param)
  68. for _, k := range keys {
  69. strs := ""
  70. if k == "catIds" {
  71. strs = zhios_third_party_utils.SerializeStr(param[k])
  72. } else {
  73. strs = zhios_third_party_utils.AnyToString(param[k])
  74. }
  75. str += k + strs
  76. }
  77. fmt.Println(str)
  78. h := hmac.New(md5.New, []byte(ApiKey))
  79. h.Write([]byte(str))
  80. return strings.ToUpper(hex.EncodeToString(h.Sum([]byte(""))))
  81. }