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

5 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package wph
  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. "fmt"
  6. "github.com/syyongx/php2go"
  7. "strings"
  8. "time"
  9. )
  10. //func SendGet(serviceMethod, method string, serviceParam map[string]string, param string) (string, error) {
  11. // serviceParamNew := map[string]string{
  12. // "service": serviceMethod, //服务名称
  13. // "method": method, //方法名称
  14. // "version": "1.0.0", //版本号
  15. // "timestamp": zhios_third_party_utils.Int64ToStr(time.Now().Unix()),
  16. // "format": "json",
  17. // "appKey": serviceParam["key"],
  18. // }
  19. // if serviceParam["token"] != "" {
  20. // serviceParamNew["accessToken"] = serviceParam["token"]
  21. // }
  22. // sortParam := comm.KsortToStr(serviceParamNew)
  23. // str := ""
  24. // for _, v := range sortParam {
  25. // str += v + serviceParamNew[v]
  26. // }
  27. // str += param
  28. // serviceParamNew["sign"] = strings.ToUpper(comm.HmacMd5(serviceParam["secret"], str))
  29. // url := "https://vop.vipapis.com"
  30. // for k, v := range serviceParamNew {
  31. // if strings.Contains(url, "?") == false {
  32. // url += "?" + k + "=" + php2go.URLEncode(v)
  33. // }
  34. // }
  35. // get, err := zhios_third_party_utils.CurlGet(url, nil)
  36. // fmt.Println(string(get))
  37. // fmt.Println(err)
  38. // return string(get), err
  39. //}
  40. func SendPost(serviceMethod, method string, serviceParam map[string]string, param string) (string, error) {
  41. serviceParamNew := map[string]string{
  42. "service": serviceMethod, //服务名称
  43. "method": method, //方法名称
  44. "version": "1.0.0", //版本号
  45. "timestamp": zhios_third_party_utils.Int64ToStr(time.Now().Unix()),
  46. "format": "json",
  47. "appKey": serviceParam["key"],
  48. }
  49. if serviceParam["token"] != "" {
  50. serviceParamNew["accessToken"] = serviceParam["token"]
  51. }
  52. sortParam := comm.KsortToStr(serviceParamNew)
  53. str := ""
  54. for _, v := range sortParam {
  55. str += v + serviceParamNew[v]
  56. }
  57. str += param
  58. fmt.Println(str)
  59. serviceParamNew["sign"] = strings.ToUpper(comm.HmacMd5(serviceParam["secret"], str))
  60. fmt.Println(serviceParamNew["sign"])
  61. url := "https://vop.vipapis.com"
  62. for k, v := range serviceParamNew {
  63. if strings.Contains(url, "?") == false {
  64. url += "?" + k + "=" + php2go.URLEncode(v)
  65. } else {
  66. url += "&" + k + "=" + php2go.URLEncode(v)
  67. }
  68. }
  69. fmt.Println(url)
  70. // 读取响应体
  71. responseData, err := zhios_third_party_utils.CurlPost(url, param, nil)
  72. fmt.Println(string(responseData))
  73. fmt.Println(err)
  74. return string(responseData), err
  75. }