浏览代码

更新

master
huangjiajun 1年前
父节点
当前提交
026f95bb45
共有 3 个文件被更改,包括 90 次插入3 次删除
  1. +3
    -3
      md/meituan_fenxiao.go
  2. +81
    -0
      meituan_fenxiao/api.go
  3. +6
    -0
      meituan_fenxiao/meituan_fenxiao.go

+ 3
- 3
md/meituan_fenxiao.go 查看文件

@@ -1,7 +1,7 @@
package md

type MeituanFenXiaoGeoInfo struct {
CityId int `json:"cityId"`
Lng string `json:"lng"`
Lat string `json:"lat"`
CityId int `json:"cityId"`
Lng float64 `json:"lng"`
Lat float64 `json:"lat"`
}

+ 81
- 0
meituan_fenxiao/api.go 查看文件

@@ -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(""))))
}

+ 6
- 0
meituan_fenxiao/meituan_fenxiao.go 查看文件

@@ -0,0 +1,6 @@
package meituan_fenxiao

func MeituanFenXiaoGoods(param map[string]interface{}) (string, error) {
send, err := MeituanFenXiaoSend("api/search/open/odp/products", param)
return send, err
}

正在加载...
取消
保存