Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
L
library
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
stbz
library
Commits
a2ae7f16
提交
a2ae7f16
authored
2月 27, 2023
作者:
张立波
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
淘特
上级
5d7cc674
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
45 行增加
和
45 行删除
+45
-45
itao.go
upstream/itao/itao.go
+14
-16
itao_logistics.go
upstream/itao/itao_logistics.go
+31
-29
没有找到文件。
upstream/itao/itao.go
浏览文件 @
a2ae7f16
...
...
@@ -8,9 +8,7 @@ import (
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gctx"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/os/gtimer"
"github.com/gogf/gf/util/gconv"
"net/url"
"sort"
...
...
@@ -32,10 +30,6 @@ const Host = "https://open.huoju6.com/openapi/param2/1/com.huoju6.open/"
func
New
(
req
*
Config
)
{
server
=
req
gtimer
.
Add
(
time
.
Hour
,
func
()
{
var
ctx
=
gctx
.
New
()
_
,
_
=
server
.
accessToken
(
ctx
)
})
return
}
...
...
@@ -78,7 +72,7 @@ func sign(method string, req g.Map) (err error) {
}
func
(
s
*
Config
)
Post
(
ctx
context
.
Context
,
method
string
,
params
g
.
Map
)
(
str
string
,
err
error
)
{
params
[
"access_token"
],
err
=
s
.
Get
AccessToken
(
ctx
)
params
[
"access_token"
],
err
=
AccessToken
(
ctx
)
if
err
!=
nil
{
return
}
...
...
@@ -116,7 +110,7 @@ func Post(ctx context.Context, method string, params g.Map) (str string, err err
}
func
(
s
*
Config
)
Get
(
ctx
context
.
Context
,
method
string
,
params
g
.
Map
)
(
str
string
,
err
error
)
{
params
[
"access_token"
],
err
=
s
.
Get
AccessToken
(
ctx
)
params
[
"access_token"
],
err
=
AccessToken
(
ctx
)
if
err
!=
nil
{
return
}
...
...
@@ -157,7 +151,7 @@ func Get(ctx context.Context, method string, params g.Map) (str string, err erro
}
func
(
s
*
Config
)
Get
AccessToken
(
ctx
context
.
Context
)
(
res
string
,
err
error
)
{
func
AccessToken
(
ctx
context
.
Context
)
(
res
string
,
err
error
)
{
var
conn
=
g
.
Redis
()
.
Conn
()
defer
func
()
{
_
=
conn
.
Close
()
...
...
@@ -165,17 +159,19 @@ func (s *Config) GetAccessToken(ctx context.Context) (res string, err error) {
_
,
_
=
conn
.
DoVar
(
"SELECT"
,
10
)
cache
,
_
:=
conn
.
DoVar
(
"HGETALL"
,
CacheKey
)
if
cache
.
IsEmpty
()
{
err
=
gerror
.
New
(
"获取token 失败"
)
g
.
Log
()
.
Ctx
(
ctx
)
.
Cat
(
PkgName
)
.
Line
(
true
)
.
Info
(
"获取token失败"
)
err
=
gerror
.
New
(
"获取token失败"
)
return
}
var
result
*
AuthTokenRes
_
=
gjson
.
New
(
cache
)
.
Scan
(
&
result
)
if
result
==
nil
||
result
.
AccessToken
==
""
{
err
=
gerror
.
New
(
"获取token 失败"
)
g
.
Log
()
.
Ctx
(
ctx
)
.
Cat
(
PkgName
)
.
Line
(
true
)
.
Info
(
"获取token失败"
)
err
=
gerror
.
New
(
"获取token失败"
)
return
}
if
result
.
AccessTokenExpireTime
<
gtime
.
TimestampMilli
()
{
result
,
err
=
s
.
access
Token
(
ctx
)
result
,
err
=
Refresh
Token
(
ctx
)
if
err
!=
nil
{
return
}
...
...
@@ -184,8 +180,8 @@ func (s *Config) GetAccessToken(ctx context.Context) (res string, err error) {
return
}
//
access
Token 刷新
func
(
s
*
Config
)
access
Token
(
ctx
context
.
Context
)
(
res
*
AuthTokenRes
,
err
error
)
{
//
Refresh
Token 刷新
func
Refresh
Token
(
ctx
context
.
Context
)
(
res
*
AuthTokenRes
,
err
error
)
{
var
conn
=
g
.
Redis
()
.
Conn
()
defer
func
()
{
_
=
conn
.
Close
()
...
...
@@ -193,7 +189,8 @@ func (s *Config) accessToken(ctx context.Context) (res *AuthTokenRes, err error)
_
,
_
=
conn
.
DoVar
(
"SELECT"
,
10
)
cache
,
_
:=
conn
.
DoVar
(
"HGETALL"
,
CacheKey
)
if
cache
.
IsEmpty
()
{
err
=
gerror
.
New
(
"获取token 失败"
)
g
.
Log
()
.
Ctx
(
ctx
)
.
Cat
(
PkgName
)
.
Line
(
true
)
.
Info
(
"获取token失败"
)
err
=
gerror
.
New
(
"获取token失败"
)
return
}
_
=
gjson
.
New
(
cache
)
.
Scan
(
&
res
)
...
...
@@ -205,7 +202,8 @@ func (s *Config) accessToken(ctx context.Context) (res *AuthTokenRes, err error)
return
}
if
res
.
Code
!=
"success"
{
err
=
gerror
.
New
(
"获取token 失败"
)
g
.
Log
()
.
Ctx
(
ctx
)
.
Cat
(
PkgName
)
.
Line
(
true
)
.
Info
(
"获取token失败"
)
err
=
gerror
.
New
(
"获取token失败"
)
return
}
_
,
_
=
conn
.
Do
(
"HMSET"
,
CacheKey
,
"accessToken"
,
res
.
AccessToken
,
"accessTokenExpireTime"
,
res
.
AccessTokenExpireTime
)
...
...
upstream/itao/itao_logistics.go
浏览文件 @
a2ae7f16
...
...
@@ -12,8 +12,14 @@ type logistics struct {
var
Logistics
=
logistics
{}
type
LogisticsTraceRes
struct
{
Result
struct
{
Success
bool
`json:"success"`
ErrMsg
string
`json:"errMsg"`
ErrCode
string
`json:"errCode"`
Result
[]
struct
{
CompanyList
[]
struct
{
BrandCode
string
`json:"brandCode"`
CompanyName
string
`json:"companyName"`
}
`json:"companyList"`
DetailList
[]
struct
{
Action
string
`json:"action"`
GmtCreate
string
`json:"gmtCreate"`
...
...
@@ -38,10 +44,6 @@ type LogisticsTraceRes struct {
StatusDesc
string
`json:"statusDesc"`
}
`json:"status"`
}
`json:"result"`
Success
bool
`json:"success"`
ErrMsg
string
`json:"errMsg"`
ErrCode
string
`json:"errCode"`
}
`json:"result"`
}
//Trace 物流轨迹
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论