lechebang.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package thirdparty
  2. import (
  3. "gd_management/common.in/config"
  4. "gd_management/common.in/httpClient"
  5. "gd_management/common.in/utils"
  6. "encoding/json"
  7. "fmt"
  8. "reflect"
  9. "sort"
  10. "strings"
  11. )
  12. /*
  13. var LeCheAppCode = "3101"
  14. var LeCheSecret = "b9b548a34220f097e6c22ca933f76a8e"
  15. var leCheUrl = "https://m.lechebang.cn/gateway/openapi"
  16. var getTokenRouter = "/user/partnerLogin"
  17. var getTypeRouter = "/car/getBrandTypeByVin"
  18. var getServeInfoRouter = "/mtn/plan/queryFittingAutoMaintenance"
  19. var canOrderRouter = "/car/isBrandTypeCanOrder"
  20. */
  21. /*
  22. func HttpLeChePost(host string, router string, body map[string]interface{}) ([]byte, error) {
  23. urlValue := hurl.Values{}
  24. for k, v := range body {
  25. str := fmt.Sprintf("%v", v)
  26. urlValue.Add(k, str)
  27. }
  28. signText := urlValue.Encode()
  29. signText = fmt.Sprintf("%s%s", signText, config.Conf.ThirdPart.LeCheSecret)
  30. sign := utils.MD5(signText)
  31. body["sign"] = strings.ToUpper(sign)
  32. bytes, _ := json.Marshal(body)
  33. resp, err := httpClient.HttpPostWithHead(host+"/"+router, nil, nil, bytes)
  34. return resp, err
  35. }
  36. */
  37. func HttpLeChePost(host string, router string, body map[string]interface{}) ([]byte, error) {
  38. names := []string{}
  39. for k, _ := range body {
  40. names = append(names, k)
  41. }
  42. sort.Strings(names)
  43. value := ""
  44. signText := ""
  45. for _, v := range names {
  46. if reflect.TypeOf(body[v]).Kind() == reflect.Struct ||
  47. reflect.TypeOf(body[v]).Kind() == reflect.Slice {
  48. bytes, _ := json.Marshal(body[v])
  49. value = string(bytes)
  50. } else {
  51. value = fmt.Sprintf("%v", body[v])
  52. }
  53. if signText == "" {
  54. signText = fmt.Sprintf("%s=%s", v, value)
  55. continue
  56. }
  57. signText = fmt.Sprintf("%s&%s=%s", signText, v, value)
  58. }
  59. signText = fmt.Sprintf("%s%s", signText, config.Conf.ThirdPart.LeCheSecret)
  60. sign := utils.MD5(signText)
  61. body["sign"] = strings.ToUpper(sign)
  62. bytes, _ := json.Marshal(body)
  63. resp, err := httpClient.HttpPostWithHead(host+"/"+router, nil, nil, bytes)
  64. return resp, err
  65. }