Commit c5237299 authored by gk's avatar gk

淘宝

parent 3ad966b3
......@@ -33,9 +33,9 @@ func initApp(){
global.Log = utils.Zap()
// 数据库
global.GORM = utils.GormInit()
//global.GORM = utils.GormInit()
// redis
global.Redis = utils.InitRedis()
//global.Redis = utils.InitRedis()
}
\ No newline at end of file
......@@ -24,7 +24,7 @@ require (
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/spf13/viper v1.8.1
github.com/urfave/cli/v2 v2.3.0 // indirect
github.com/urfave/cli/v2 v2.3.0
github.com/valyala/fasthttp v1.28.0 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
......
......@@ -105,7 +105,7 @@ type ItemDetailData struct {
func ItemDetail(itemId string, turnType int8) (*ItemDetailData, error) {
var err error
t := time.Now().UnixMicro() / 1000
t := time.Now().UnixNano() / 1000000
nonce := utils.RandNum(100000, 999999)
appKey := "5d00ab04a9f3a"
......
......@@ -3,21 +3,21 @@ package taobao
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strconv"
"reflect"
"sort"
"strings"
"time"
"xiaoxiong/internal/global"
"xiaoxiong/internal/utils"
)
const TaobaoUrl = "http://gw.api.taobao.com/router/rest"
type TbkItemInfoGetRequest struct {
CommonRequest
Platform string `json:"platform"`
NumIids string `json:"num_iids"`
}
......@@ -29,34 +29,144 @@ type CommonRequest struct {
SignMethod string `json:"sign_method"`
Method string `json:"method"`
Timestamp string `json:"timestamp"`
PartnerId string `json:"partner_id"`
Sign string `json:"sign"`
//PartnerId string `json:"partner_id"`
Sign string `json:"sign"`
}
func newCommonRequest(appKeyType int8)*CommonRequest{
r := &CommonRequest{}
func getPostData(c interface{}) (url.Values,url.Values) {
t := reflect.TypeOf(c)
v := reflect.ValueOf(c)
if appKeyType {
res := url.Values{}
get := url.Values{}
for k := 0; k < t.NumField(); k++ {
if _, ok := v.Field(k).Interface().(CommonRequest); ok {
tt := reflect.TypeOf(v.Field(k).Interface())
vv := reflect.ValueOf(v.Field(k).Interface())
for kk := 0; kk < tt.NumField(); kk++ {
if value, ok := vv.Field(kk).Interface().(string); ok {
//res.Set(tt.Field(kk).Tag.Get("json"), value)
get.Set(tt.Field(kk).Tag.Get("json"), value)
}
}
} else {
if value, ok := v.Field(k).Interface().(string); ok {
res.Set(t.Field(k).Tag.Get("json"), value)
}
}
}
r.Format = "json"
r.V = "2.0"
r.Method = "sign_method"
return r
return res,get
}
func ItemDetail(itemId string, turnType int8) () {
var err error
func generateSign(c interface{}, appKeyType int8) string {
t := reflect.TypeOf(c)
v := reflect.ValueOf(c)
req := &TbkItemInfoGetRequest{
m := make(map[string]interface{})
for k := 0; k < t.NumField(); k++ {
if _, ok := v.Field(k).Interface().(CommonRequest); ok {
tt := reflect.TypeOf(v.Field(k).Interface())
vv := reflect.ValueOf(v.Field(k).Interface())
for kk := 0; kk < tt.NumField(); kk++ {
m[tt.Field(kk).Tag.Get("json")] = vv.Field(kk).Interface()
}
} else {
m[t.Field(k).Tag.Get("json")] = v.Field(k).Interface()
}
}
var arr []string
for k, _ := range m {
arr = append(arr, k)
}
sort.Strings(arr)
secret := "e835d91edfb5487125f754d831a02fba"
str := secret
for _, k := range arr {
str += fmt.Sprintf("%s%s", k, m[k])
}
str += secret
println(str)
h := md5.New()
h.Write([]byte(str))
return strings.ToTitle(hex.EncodeToString(h.Sum(nil)))
}
func newTbkItemInfoGetRequest(itemId string, appKeyType int8) *TbkItemInfoGetRequest {
c := newCommonRequest(appKeyType)
r := &TbkItemInfoGetRequest{
*c,
"2",
itemId,
}
commonReq :=
commonReq.AppKey
r.Sign = generateSign(*r, appKeyType)
return r
}
func newCommonRequest(appKeyType int8) *CommonRequest {
r := &CommonRequest{}
appKey := "25623446"
r.AppKey = appKey
r.V = "2.0"
r.Format = "json"
r.SignMethod = "md5"
r.Method = "taobao.tbk.item.info.get"
r.Timestamp = time.Now().Format("2006-01-02 15:04:05")
return r
}
type TbkItemInfoGetResponse struct {
}
func ItemDetail(itemId string, appKeyType int8) (*TbkItemInfoGetResponse, error) {
var err error
req := newTbkItemInfoGetRequest(itemId, appKeyType)
a := time.Now().Format("2006-01-02 15:04:05")
println()
println()
sss := fmt.Sprintf("%s%s", "asdsad",a)
println(sss)
println()
println()
v,getV := getPostData(*req)
println(v.Encode())
println(getV.Encode())
urlPath := TaobaoUrl + "?" + getV.Encode()
println(urlPath)
resp, err := http.PostForm(urlPath, v)
defer func() {
err = resp.Body.Close()
if err != nil {
global.Log.Info(fmt.Sprintf("resp close err %s", err.Error()))
}
}()
body, _ := ioutil.ReadAll(resp.Body)
//res := &ItemDetailData{}
//_ = json.Unmarshal(body, res)
fmt.Printf("%s", body)
_ = err
println()
return nil, nil
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment