Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zy_test
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张瑜
zy_test
Commits
c5237299
Commit
c5237299
authored
Sep 25, 2021
by
gk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
淘宝
parent
3ad966b3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
134 additions
and
24 deletions
+134
-24
cmd/app.go
cmd/app.go
+2
-2
go.mod
go.mod
+1
-1
internal/utils/dtk/item_detail.go
internal/utils/dtk/item_detail.go
+1
-1
internal/utils/taobao/item_detail.go
internal/utils/taobao/item_detail.go
+130
-20
No files found.
cmd/app.go
View file @
c5237299
...
...
@@ -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
go.mod
View file @
c5237299
...
...
@@ -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
...
...
internal/utils/dtk/item_detail.go
View file @
c5237299
...
...
@@ -105,7 +105,7 @@ type ItemDetailData struct {
func
ItemDetail
(
itemId
string
,
turnType
int8
)
(
*
ItemDetailData
,
error
)
{
var
err
error
t
:=
time
.
Now
()
.
Unix
Micro
()
/
1
000
t
:=
time
.
Now
()
.
Unix
Nano
()
/
1000
000
nonce
:=
utils
.
RandNum
(
100000
,
999999
)
appKey
:=
"5d00ab04a9f3a"
...
...
internal/utils/taobao/item_detail.go
View file @
c5237299
...
...
@@ -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
r
es
,
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment