|
|
@@ -0,0 +1,60 @@ |
|
|
|
package meituan_cps |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/comm" |
|
|
|
zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" |
|
|
|
"crypto/hmac" |
|
|
|
"crypto/md5" |
|
|
|
"crypto/sha256" |
|
|
|
"encoding/base64" |
|
|
|
"fmt" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
func Send(method, key, secret string, param map[string]interface{}) { |
|
|
|
header := map[string]string{ |
|
|
|
"S-Ca-App": key, |
|
|
|
"S-Ca-Timestamp": zhios_third_party_utils.Int64ToStr(time.Now().Unix() * 1000), |
|
|
|
} |
|
|
|
url := "https://media.meituan.com/cps_open/common/api/v1/" |
|
|
|
paramStr := comm.GetSortJson(param) |
|
|
|
paramStr = strings.ReplaceAll(paramStr, "\n", "") |
|
|
|
header = GetSign(method, secret, paramStr, header) |
|
|
|
fmt.Println(header) |
|
|
|
fmt.Println(paramStr) |
|
|
|
|
|
|
|
post, err := zhios_third_party_utils.CurlPost(url+method, paramStr, header) |
|
|
|
fmt.Println(string(post)) |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
|
|
|
|
func GetSign(method, secret string, paramStr string, header map[string]string) map[string]string { |
|
|
|
headers := comm.KsortToStr(header) |
|
|
|
|
|
|
|
HTTPMethod := "POST" |
|
|
|
h1 := md5.New() |
|
|
|
h1.Write([]byte(paramStr)) |
|
|
|
ContentMd5 := base64.StdEncoding.EncodeToString(h1.Sum(nil)) |
|
|
|
fmt.Println(ContentMd5) |
|
|
|
headerStr := "" |
|
|
|
signHeader := "" |
|
|
|
for _, v := range headers { |
|
|
|
headerStr += v + ":" + header[v] + "\n" |
|
|
|
if signHeader == "" { |
|
|
|
signHeader += v |
|
|
|
} else { |
|
|
|
signHeader += "," + v |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Url := "/cps_open/common/api/v1/" + method |
|
|
|
sign := HTTPMethod + "\n" + ContentMd5 + "\n" + headerStr + Url |
|
|
|
h := hmac.New(sha256.New, []byte(secret)) |
|
|
|
_, _ = h.Write([]byte(sign)) |
|
|
|
header["S-Ca-Signature"] = base64.StdEncoding.EncodeToString(h.Sum(nil)) |
|
|
|
header["Content-MD5"] = ContentMd5 |
|
|
|
header["S-Ca-Signature-Headers"] = signHeader |
|
|
|
header["Content-Type"] = "application/json; charset=utf-8" |
|
|
|
return header |
|
|
|
} |