acarbang.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package thirdparty
  2. import (
  3. "bytes"
  4. "gd_management/common.in/config"
  5. "gd_management/common.in/utils"
  6. "encoding/json"
  7. "go.uber.org/zap"
  8. "io/ioutil"
  9. "net/http"
  10. "strconv"
  11. "time"
  12. )
  13. /*const (
  14. //acarbangProductionHost = "http://api.acarbang.com/api"
  15. //acarbangAppId = "369907822114111489"
  16. //acarbangAppKey = "d494773a04dc44139a17d40a5c4d9445"
  17. acarbangAppId = "476795160986910721"
  18. acarbangAppKey = "897c86f2779341e88e38b3eb9acb384f"
  19. )
  20. */
  21. func AcarbangHttpPost(api string, data map[string]string) (result []byte, err error) {
  22. return []byte(`{"code":1 "data":"test"}`), nil
  23. defer func() {
  24. l.Info("thirdparty",
  25. zap.String("api", api),
  26. zap.String("request", utils.MarshalJsonString(data)),
  27. zap.String("response", utils.MarshalJsonString(result)))
  28. }()
  29. jsonData, err := json.Marshal(data)
  30. if err != nil {
  31. return nil, err
  32. }
  33. client := &http.Client{}
  34. client.Timeout = 60 * time.Second
  35. req, err := http.NewRequest("POST", api, bytes.NewBuffer(jsonData))
  36. if err != nil {
  37. return nil, err
  38. }
  39. timeNow := time.Now()
  40. requestsn := timeNow.Format("20060102150405000")
  41. timestamp := strconv.FormatInt(timeNow.UnixNano()/1000000, 10)
  42. req.Header.Set("appId", config.Conf.ThirdPart.ArcbangAppId)
  43. req.Header.Set("apiKey", config.Conf.ThirdPart.ArcbangAppKey)
  44. req.Header.Set("requestsn", requestsn)
  45. req.Header.Set("timestamp", timestamp)
  46. req.Header.Set("sign", utils.MD5(config.Conf.ThirdPart.ArcbangAppId+config.Conf.ThirdPart.ArcbangAppKey+requestsn+timestamp))
  47. req.Header.Set("Content-Type", "application/json")
  48. resp, err := client.Do(req)
  49. if err != nil {
  50. return nil, err
  51. }
  52. defer resp.Body.Close()
  53. result, err = ioutil.ReadAll(resp.Body)
  54. return
  55. }
  56. /*(func acarbangFullUrl(api string, host string) string {
  57. return host + "/" + api
  58. }*/