123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package thirdparty
- import (
- "gd_management/common.in/config"
- "gd_management/common.in/httpClient"
- "gd_management/common.in/utils"
- "fmt"
- hurl "net/url"
- "sort"
- )
- func HttpBiHuGet(api string, query map[string]string) ([]byte, error) {
- agent := config.Conf.ThirdPart.BiHuAgent
- secret := config.Conf.ThirdPart.BiHuSecret
- names := []string{}
- query["Agent"] = agent
- for k, _ := range query {
- names = append(names, k)
- }
- sort.Strings(names)
- value := ""
- signText := ""
- for _, v := range names {
- value = fmt.Sprintf("%v", query[v])
- if signText == "" {
- signText = fmt.Sprintf("%s=%s", v, value)
- continue
- }
- signText = fmt.Sprintf("%s&%s=%s", signText, v, value)
- }
- urlValue := hurl.Values{}
- for k, v := range query {
- urlValue.Add(k, v)
- }
- querystring := urlValue.Encode()
- signText = fmt.Sprintf("%s%s", signText, secret)
- sign := utils.MD5(signText)
- query["SecCode"] = sign
- querystring = fmt.Sprintf("%s&%s=%s", querystring, "SecCode", sign)
- url := fmt.Sprintf("%s?%s", api, querystring)
- resp, err := httpClient.HttpGetWithHead(url, nil, nil)
- return resp, err
- }
- /*
- func HttpBiHuPost(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
- }
- */
|