|
|
@@ -0,0 +1,81 @@ |
|
|
|
package meituan_fenxiao |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/comm" |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md" |
|
|
|
zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" |
|
|
|
"crypto/hmac" |
|
|
|
"crypto/md5" |
|
|
|
"encoding/hex" |
|
|
|
"fmt" |
|
|
|
"github.com/syyongx/php2go" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
|
ApiKey = "nsVtNZcmRDuxgBim" |
|
|
|
UtmSource = "511860" |
|
|
|
Url = "https://union.dianping.com/" |
|
|
|
) |
|
|
|
|
|
|
|
func MeituanFenXiaoSend(method string, params map[string]interface{}) (string, error) { |
|
|
|
|
|
|
|
arg := map[string]string{ |
|
|
|
"requestId": zhios_third_party_utils.UUIDString(), |
|
|
|
"utmSource": UtmSource, |
|
|
|
"timestamp": zhios_third_party_utils.Int64ToStr(time.Now().Unix()), |
|
|
|
"version": "1.0", |
|
|
|
"signMethod": "hmac", |
|
|
|
} |
|
|
|
reqParam := make(map[string]interface{}) |
|
|
|
for k, v := range params { |
|
|
|
reqParam[k] = v |
|
|
|
} |
|
|
|
for k, v := range arg { |
|
|
|
reqParam[k] = v |
|
|
|
} |
|
|
|
sign := MeituanFenXiaoGetSign(reqParam) |
|
|
|
arg["sign"] = sign |
|
|
|
url := Url + method |
|
|
|
for k, v := range arg { |
|
|
|
if strings.Contains(url, "?") == false { |
|
|
|
url += "?" + k + "=" + php2go.URLEncode(v) |
|
|
|
} else { |
|
|
|
url += "&" + k + "=" + php2go.URLEncode(v) |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Println(url) |
|
|
|
fmt.Println(zhios_third_party_utils.SerializeStr(params)) |
|
|
|
post, err := zhios_third_party_utils.CurlPost(url, zhios_third_party_utils.SerializeStr(params), map[string]string{}) |
|
|
|
if err != nil { |
|
|
|
return "", err |
|
|
|
} |
|
|
|
fmt.Println(string(post)) |
|
|
|
|
|
|
|
return string(post), nil |
|
|
|
} |
|
|
|
func MeituanFenXiaoGetSign(param map[string]interface{}) string { |
|
|
|
str := "" |
|
|
|
info, ok := param["geo"].(md.MeituanFenXiaoGeoInfo) |
|
|
|
if ok { |
|
|
|
param["cityId"] = info.CityId |
|
|
|
param["lat"] = info.Lat |
|
|
|
param["lng"] = info.Lng |
|
|
|
} |
|
|
|
delete(param, "geo") |
|
|
|
keys := comm.KsortToStrInterface(param) |
|
|
|
for _, k := range keys { |
|
|
|
strs := "" |
|
|
|
if k == "catIds" { |
|
|
|
strs = zhios_third_party_utils.SerializeStr(param[k]) |
|
|
|
} else { |
|
|
|
strs = zhios_third_party_utils.AnyToString(param[k]) |
|
|
|
} |
|
|
|
str += k + strs |
|
|
|
} |
|
|
|
fmt.Println(str) |
|
|
|
h := hmac.New(md5.New, []byte(ApiKey)) |
|
|
|
h.Write([]byte(str)) |
|
|
|
return strings.ToUpper(hex.EncodeToString(h.Sum([]byte("")))) |
|
|
|
} |