第三方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.

api.go 1.2 KiB

11 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package pdd
  2. import (
  3. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  4. "encoding/json"
  5. "sort"
  6. "strings"
  7. "time"
  8. )
  9. var (
  10. PDD_HOST = "http://gw-api.pinduoduo.com/api/router"
  11. PDD_AK = "43eed45f20d94fbf828744a77a45e3e2"
  12. PDD_SK = "6ccdd6614f804ed8b0e23c2721be857da3a04b5b"
  13. PDD_CS = "4ee672167e1ee51aa3a9ea864d33629a230a114c"
  14. )
  15. func send(args map[string]interface{}, method string) ([]byte, error) {
  16. args["timestamp"] = zhios_third_party_utils.Int64ToStr(time.Now().UnixNano() / 1e6)
  17. args["data_type"] = "JSON"
  18. args["client_id"] = PDD_AK
  19. args["type"] = method
  20. args["sign"] = sign(args, PDD_CS)
  21. bargs, err := json.Marshal(args)
  22. if err != nil {
  23. return nil, err
  24. }
  25. return zhios_third_party_utils.CurlPost(PDD_HOST, bargs, nil)
  26. }
  27. func sign(m map[string]interface{}, sk string) string {
  28. // key sort
  29. keys := make([]string, 0, len(m))
  30. for k := range m {
  31. keys = append(keys, k)
  32. }
  33. sort.Strings(keys)
  34. str := ""
  35. for _, k := range keys {
  36. switch m[k].(type) {
  37. case int:
  38. str += k + zhios_third_party_utils.IntToStr(m[k].(int))
  39. case string:
  40. str += k + m[k].(string)
  41. }
  42. }
  43. str = sk + str + sk
  44. return strings.ToUpper(zhios_third_party_utils.Md5(str))
  45. }