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

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package tpdaren
  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. "github.com/syyongx/php2go"
  6. "github.com/tidwall/gjson"
  7. "time"
  8. )
  9. /***
  10. appid:nqrsce
  11. appSecret:KZOl46YF6zposQUFQbIXyXCm2pR0nX5dhkyVCk1EDXE=
  12. 7200s
  13. */
  14. func TpdarenToken(appid, appSecret string) string {
  15. url := "http://tpdaren.jzjxwh.cn/api/v1/get/token?appid=" + php2go.URLEncode(appid) + "&app_secret=" + php2go.URLEncode(appSecret)
  16. get, _ := zhios_third_party_utils.CurlGet(url, map[string]string{})
  17. token := gjson.Get(string(get), "data.token").String()
  18. return token
  19. }
  20. func TpdarenSend(method, token string, param map[string]interface{}) (string, error) {
  21. url := "http://tpdaren.jzjxwh.cn/api/v1/" + method
  22. header := map[string]string{
  23. "token": token,
  24. }
  25. param["timestamp"] = time.Now().Unix()
  26. param["signature"] = getSign(param)
  27. post, err := zhios_third_party_utils.CurlPost(url, zhios_third_party_utils.SerializeStr(param), header)
  28. return string(post), err
  29. }
  30. func getSign(param map[string]interface{}) string {
  31. str := ""
  32. keys := comm.KsortToStrInterface(param)
  33. for _, k := range keys {
  34. if str == "" {
  35. str += k + "=" + zhios_third_party_utils.AnyToString(param[k])
  36. } else {
  37. str += "&" + k + "=" + zhios_third_party_utils.AnyToString(param[k])
  38. }
  39. }
  40. return php2go.Md5(str)
  41. }