第三方api接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6 月之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package meituan_cps
  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. "crypto/sha256"
  8. "encoding/base64"
  9. "fmt"
  10. "strings"
  11. "time"
  12. )
  13. func Send(method, key, secret string, param map[string]interface{}) {
  14. header := map[string]string{
  15. "S-Ca-App": key,
  16. "S-Ca-Timestamp": zhios_third_party_utils.Int64ToStr(time.Now().Unix() * 1000),
  17. }
  18. url := "https://media.meituan.com/cps_open/common/api/v1/"
  19. paramStr := comm.GetSortJson(param)
  20. paramStr = strings.ReplaceAll(paramStr, "\n", "")
  21. header = GetSign(method, secret, paramStr, header)
  22. fmt.Println(header)
  23. fmt.Println(paramStr)
  24. post, err := zhios_third_party_utils.CurlPost(url+method, paramStr, header)
  25. fmt.Println(string(post))
  26. fmt.Println(err)
  27. }
  28. func GetSign(method, secret string, paramStr string, header map[string]string) map[string]string {
  29. headers := comm.KsortToStr(header)
  30. HTTPMethod := "POST"
  31. h1 := md5.New()
  32. h1.Write([]byte(paramStr))
  33. ContentMd5 := base64.StdEncoding.EncodeToString(h1.Sum(nil))
  34. fmt.Println(ContentMd5)
  35. headerStr := ""
  36. signHeader := ""
  37. for _, v := range headers {
  38. headerStr += v + ":" + header[v] + "\n"
  39. if signHeader == "" {
  40. signHeader += v
  41. } else {
  42. signHeader += "," + v
  43. }
  44. }
  45. Url := "/cps_open/common/api/v1/" + method
  46. sign := HTTPMethod + "\n" + ContentMd5 + "\n" + headerStr + Url
  47. h := hmac.New(sha256.New, []byte(secret))
  48. _, _ = h.Write([]byte(sign))
  49. header["S-Ca-Signature"] = base64.StdEncoding.EncodeToString(h.Sum(nil))
  50. header["Content-MD5"] = ContentMd5
  51. header["S-Ca-Signature-Headers"] = signHeader
  52. header["Content-Type"] = "application/json; charset=utf-8"
  53. return header
  54. }