Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
L
library
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
stbz
library
Commits
7ad8686c
提交
7ad8686c
authored
8月 23, 2022
作者:
zhanglibo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
快递鸟
上级
7a87507d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
136 行增加
和
0 行删除
+136
-0
kdniao.go
kdniao/kdniao.go
+69
-0
kdniao_deliver.go
kdniao/kdniao_deliver.go
+67
-0
没有找到文件。
kdniao/kdniao.go
0 → 100644
浏览文件 @
7ad8686c
package
kdniao
import
(
"context"
"github.com/gogf/gf/crypto/gmd5"
"github.com/gogf/gf/encoding/gbase64"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/text/gregex"
"time"
)
type
Config
struct
{
AppKey
string
API
string
EBusinessID
string
}
var
server
*
Config
const
PkgName
=
"kdniao"
const
CacheKey
=
"kdniao:token"
func
New
(
req
*
Config
)
{
server
=
req
return
}
type
CommonReq
struct
{
RequestType
string
`json:"RequestType"`
EBusinessID
string
`json:"EBusinessID"`
DataType
string
`json:"DataType"`
//请求、返回数据类型:2-json;
RequestData
interface
{}
`json:"RequestData"`
DataSign
string
`json:"DataSign"`
}
func
post
(
ctx
context
.
Context
,
method
string
,
RequestType
string
,
req
interface
{})
(
res
string
,
err
error
)
{
Start
:=
gtime
.
TimestampMilli
()
var
params
=
CommonReq
{
RequestType
:
RequestType
,
EBusinessID
:
server
.
EBusinessID
,
DataType
:
"2"
,
RequestData
:
gjson
.
New
(
req
)
.
MustToJsonString
(),
DataSign
:
sign
(
req
),
}
Request
:=
g
.
Client
()
.
ContentType
(
"application/x-www-form-urlencoded; charset=utf-8"
)
Request
.
Timeout
(
3
*
time
.
Second
)
resp
,
err
:=
Request
.
Post
(
server
.
API
+
method
,
params
)
defer
func
()
{
_
=
resp
.
Close
()
ctx
=
context
.
WithValue
(
ctx
,
"Method"
,
"POST"
)
ctx
=
context
.
WithValue
(
ctx
,
"URI"
,
method
)
if
err
!=
nil
{
g
.
Log
()
.
Ctx
(
ctx
)
.
Infof
(
"参数【%v】错误【%v】响应时间【%v】"
,
gjson
.
New
(
params
)
.
MustToJsonString
(),
err
.
Error
(),
gtime
.
TimestampMilli
()
-
Start
)
}
else
{
g
.
Log
()
.
Ctx
(
ctx
)
.
Cat
(
PkgName
)
.
Infof
(
"参数【%v】响应【%v】响应时间【%v】"
,
gjson
.
New
(
params
)
.
MustToJsonString
(),
res
,
gtime
.
TimestampMilli
()
-
Start
)
}
}()
res
=
resp
.
ReadAllString
()
res
,
_
=
gregex
.
ReplaceString
(
`\s`
,
""
,
res
)
return
}
func
sign
(
req
interface
{})
string
{
return
gbase64
.
EncodeString
(
gmd5
.
MustEncryptString
(
gjson
.
New
(
req
)
.
MustToJsonString
()
+
server
.
AppKey
))
}
kdniao/kdniao_deliver.go
0 → 100644
浏览文件 @
7ad8686c
package
kdniao
import
(
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type
deliverKdniao
struct
{
}
var
Deliver
=
deliverKdniao
{}
type
TrackReq
struct
{
CustomerName
string
`json:"CustomerName"`
DeliverNo
string
`json:"LogisticCode"`
Code
string
`json:"ShipperCode"`
}
type
DeliverTrackRes
struct
{
EBusinessID
string
`json:"EBusinessID"`
ShipperCode
string
`json:"ShipperCode"`
LogisticCode
string
`json:"LogisticCode"`
State
string
`json:"State"`
StateEx
string
`json:"StateEx"`
Location
string
`json:"Location"`
Traces
[]
struct
{
Action
string
`json:"Action"`
AcceptStation
string
`json:"AcceptStation"`
AcceptTime
string
`json:"AcceptTime"`
Location
string
`json:"Location"`
}
`json:"Traces"`
DeliveryMan
string
`json:"DeliveryMan"`
DeliveryManTel
string
`json:"DeliveryManTel"`
Success
bool
`json:"Success"`
}
//Track 物流轨迹
func
(
*
deliverKdniao
)
Track
(
ctx
context
.
Context
,
req
TrackReq
)
(
res
*
DeliverTrackRes
,
err
error
)
{
const
requestType
string
=
"8001"
url
:=
"Ebusiness/EbusinessOrderHandle.aspx"
result
,
err
:=
post
(
ctx
,
url
,
requestType
,
req
)
_
=
gjson
.
New
(
result
)
.
Scan
(
&
res
)
return
}
type
DeliverParseRes
struct
{
LogisticCode
string
`json:"LogisticCode"`
Shippers
[]
struct
{
ShipperName
string
`json:"ShipperName"`
ShipperCode
string
`json:"ShipperCode"`
}
`json:"Shippers"`
EBusinessID
string
`json:"EBusinessID"`
Code
string
`json:"Code"`
Success
bool
`json:"Success"`
}
//Parse 单号识别
func
(
*
deliverKdniao
)
Parse
(
ctx
context
.
Context
,
req
string
)
(
res
*
DeliverParseRes
,
err
error
)
{
const
requestType
string
=
"2002"
url
:=
"Ebusiness/EbusinessOrderHandle.aspx"
result
,
err
:=
post
(
ctx
,
url
,
requestType
,
g
.
Map
{
"LogisticCode"
:
req
,
})
_
=
gjson
.
New
(
result
)
.
Scan
(
&
res
)
return
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论