12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package thirdparty
- import (
- "gd_management/common.in/config"
- "gd_management/common.in/httpClient"
- "gd_management/common.in/utils"
- "encoding/json"
- "fmt"
- "reflect"
- "sort"
- "strings"
- )
- /*
- var LeCheAppCode = "3101"
- var LeCheSecret = "b9b548a34220f097e6c22ca933f76a8e"
- var leCheUrl = "https://m.lechebang.cn/gateway/openapi"
- var getTokenRouter = "/user/partnerLogin"
- var getTypeRouter = "/car/getBrandTypeByVin"
- var getServeInfoRouter = "/mtn/plan/queryFittingAutoMaintenance"
- var canOrderRouter = "/car/isBrandTypeCanOrder"
- */
- /*
- func HttpLeChePost(host string, router string, body map[string]interface{}) ([]byte, error) {
- urlValue := hurl.Values{}
- for k, v := range body {
- str := fmt.Sprintf("%v", v)
- urlValue.Add(k, str)
- }
- signText := urlValue.Encode()
- signText = fmt.Sprintf("%s%s", signText, config.Conf.ThirdPart.LeCheSecret)
- sign := utils.MD5(signText)
- body["sign"] = strings.ToUpper(sign)
- bytes, _ := json.Marshal(body)
- resp, err := httpClient.HttpPostWithHead(host+"/"+router, nil, nil, bytes)
- return resp, err
- }
- */
- func HttpLeChePost(host string, router string, body map[string]interface{}) ([]byte, error) {
- names := []string{}
- for k, _ := range body {
- names = append(names, k)
- }
- sort.Strings(names)
- value := ""
- signText := ""
- for _, v := range names {
- if reflect.TypeOf(body[v]).Kind() == reflect.Struct ||
- reflect.TypeOf(body[v]).Kind() == reflect.Slice {
- bytes, _ := json.Marshal(body[v])
- value = string(bytes)
- } else {
- value = fmt.Sprintf("%v", body[v])
- }
- if signText == "" {
- signText = fmt.Sprintf("%s=%s", v, value)
- continue
- }
- signText = fmt.Sprintf("%s&%s=%s", signText, v, value)
- }
- signText = fmt.Sprintf("%s%s", signText, config.Conf.ThirdPart.LeCheSecret)
- sign := utils.MD5(signText)
- body["sign"] = strings.ToUpper(sign)
- bytes, _ := json.Marshal(body)
- resp, err := httpClient.HttpPostWithHead(host+"/"+router, nil, nil, bytes)
- return resp, err
- }
|