Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
L
library
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
stbz
library
Commits
b3599bd1
提交
b3599bd1
authored
6月 20, 2025
作者:
屈传平
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hcw
上级
d4d5ed7f
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
35 行增加
和
52 行删除
+35
-52
base.go
upstream/hcw/base.go
+2
-7
hcw.go
upstream/hcw/hcw.go
+17
-14
hcw_goods.go
upstream/hcw/hcw_goods.go
+4
-9
hcw_order.go
upstream/hcw/hcw_order.go
+8
-13
hcw_refund.go
upstream/hcw/hcw_refund.go
+4
-9
没有找到文件。
upstream/hcw/base.go
浏览文件 @
b3599bd1
...
...
@@ -5,11 +5,6 @@ import (
"github.com/gogf/gf/encoding/gjson"
)
var
Base
=
new
(
base
)
type
base
struct
{
}
type
AddressReq
struct
{
Source
string
`json:"source"`
//渠道(aux,midea,suning)
Code
string
`json:"code"`
//地址编码/上级地址编码
...
...
@@ -24,9 +19,9 @@ type AddressRes struct {
SnId
string
`json:"snId"`
}
func
(
s
*
refund
)
Address
(
ctx
context
.
Context
,
req
*
AddressReq
)
(
res
[]
*
AddressRes
,
err
error
)
{
func
(
s
*
hcwClient
)
Address
(
ctx
context
.
Context
,
req
*
AddressReq
)
(
res
[]
*
AddressRes
,
err
error
)
{
var
method
=
"/address"
result
,
err
:=
get
(
ctx
,
method
,
req
)
result
,
err
:=
s
.
get
(
ctx
,
method
,
req
)
if
nil
!=
err
{
return
}
...
...
upstream/hcw/hcw.go
浏览文件 @
b3599bd1
...
...
@@ -23,8 +23,6 @@ import (
"time"
)
var
server
*
Config
const
pkgName
=
"hcw"
type
Config
struct
{
...
...
@@ -32,9 +30,14 @@ type Config struct {
ApiUrl
string
}
func
New
(
req
*
Config
)
{
server
=
req
return
type
hcwClient
struct
{
Config
*
Config
}
func
New
(
req
*
Config
)
*
hcwClient
{
HcwClient
:=
new
(
hcwClient
)
HcwClient
.
Config
=
req
return
HcwClient
}
//const (
...
...
@@ -47,7 +50,7 @@ type EncryptedResponse struct {
Signature
string
`json:"signature"`
}
func
EncryptWithSignature
(
data
interface
{})
(
string
,
error
)
{
func
(
s
*
hcwClient
)
EncryptWithSignature
(
data
interface
{})
(
string
,
error
)
{
// 生成时间戳
timestamp
:=
time
.
Now
()
.
Unix
()
...
...
@@ -61,7 +64,7 @@ func EncryptWithSignature(data interface{}) (string, error) {
signatureString
:=
string
(
jsonData
)
+
strconv
.
FormatInt
(
timestamp
,
10
)
// 计算HMAC-SHA256签名
signature
:=
calculateHMAC
([]
byte
(
s
erver
.
SecretKey
),
signatureString
)
signature
:=
calculateHMAC
([]
byte
(
s
.
Config
.
SecretKey
),
signatureString
)
// 构建加密数据结构
encryptedData
:=
&
EncryptedResponse
{
...
...
@@ -77,7 +80,7 @@ func EncryptWithSignature(data interface{}) (string, error) {
}
// AES加密
block
,
err
:=
aes
.
NewCipher
([]
byte
(
s
erver
.
SecretKey
))
block
,
err
:=
aes
.
NewCipher
([]
byte
(
s
.
Config
.
SecretKey
))
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"创建加密器失败: %v"
,
err
)
}
...
...
@@ -149,18 +152,18 @@ func mapToSortedQuery(params map[string]string) string {
return
builder
.
String
()
}
func
post
(
ctx
context
.
Context
,
method
string
,
req
interface
{})
(
res
string
,
err
error
)
{
func
(
s
*
hcwClient
)
post
(
ctx
context
.
Context
,
method
string
,
req
interface
{})
(
res
string
,
err
error
)
{
Start
:=
gtime
.
TimestampMilli
()
reqMap
:=
gconv
.
Map
(
req
)
param
:=
gjson
.
New
(
reqMap
)
signature
,
err
:=
EncryptWithSignature
(
reqMap
)
signature
,
err
:=
s
.
EncryptWithSignature
(
reqMap
)
if
nil
!=
err
{
return
}
Url
:=
s
erver
.
ApiUrl
+
method
Url
:=
s
.
Config
.
ApiUrl
+
method
Request
:=
g
.
Client
()
Request
.
SetHeader
(
"Content-Type"
,
"text/xml; charset=utf-8"
)
Request
.
SetHeader
(
"Format"
,
"json"
)
...
...
@@ -181,17 +184,17 @@ func post(ctx context.Context, method string, req interface{}) (res string, err
return
}
func
get
(
ctx
context
.
Context
,
method
string
,
req
interface
{})
(
res
string
,
err
error
)
{
func
(
s
*
hcwClient
)
get
(
ctx
context
.
Context
,
method
string
,
req
interface
{})
(
res
string
,
err
error
)
{
Start
:=
gtime
.
TimestampMilli
()
reqMap
:=
gconv
.
Map
(
req
)
param
:=
gjson
.
New
(
reqMap
)
signature
,
err
:=
EncryptWithSignature
(
reqMap
)
signature
,
err
:=
s
.
EncryptWithSignature
(
reqMap
)
if
nil
!=
err
{
return
}
queryParams
:=
getQueryParams
(
reqMap
)
query
:=
mapToSortedQuery
(
queryParams
)
Url
:=
s
erver
.
ApiUrl
+
method
+
"?"
+
query
Url
:=
s
.
Config
.
ApiUrl
+
method
+
"?"
+
query
Request
:=
g
.
Client
()
Request
.
SetHeader
(
"Content-Type"
,
"text/xml; charset=utf-8"
)
Request
.
SetHeader
(
"Format"
,
"json"
)
...
...
upstream/hcw/hcw_goods.go
浏览文件 @
b3599bd1
...
...
@@ -5,11 +5,6 @@ import (
"github.com/gogf/gf/encoding/gjson"
)
var
Goods
=
new
(
goods
)
type
goods
struct
{
}
type
GoodsListReq
struct
{
Page
string
`json:"page"`
//页数
PageSize
string
`json:"page_size"`
//条数
...
...
@@ -43,9 +38,9 @@ type GoodsListRes struct {
}
// 商品列表
func
(
s
*
goods
)
List
(
ctx
context
.
Context
,
req
*
GoodsListReq
)
(
res
*
GoodsListRes
,
err
error
)
{
func
(
s
*
hcwClient
)
Goods
List
(
ctx
context
.
Context
,
req
*
GoodsListReq
)
(
res
*
GoodsListRes
,
err
error
)
{
var
method
=
"/api/v1/product"
result
,
err
:=
get
(
ctx
,
method
,
req
)
result
,
err
:=
s
.
get
(
ctx
,
method
,
req
)
if
nil
!=
err
{
return
}
...
...
@@ -80,11 +75,11 @@ type GoodsDetailRes struct {
}
// 商品详情
func
(
s
*
goods
)
Detail
(
ctx
context
.
Context
,
productSn
,
source
string
)
(
res
*
GoodsDetailRes
,
err
error
)
{
func
(
s
*
hcwClient
)
Goods
Detail
(
ctx
context
.
Context
,
productSn
,
source
string
)
(
res
*
GoodsDetailRes
,
err
error
)
{
var
method
=
"/api/v1/product/"
+
productSn
req
:=
&
GoodsDetailReq
{}
req
.
Source
=
source
result
,
err
:=
get
(
ctx
,
method
,
req
)
result
,
err
:=
s
.
get
(
ctx
,
method
,
req
)
if
nil
!=
err
{
return
}
...
...
upstream/hcw/hcw_order.go
浏览文件 @
b3599bd1
...
...
@@ -6,11 +6,6 @@ import (
"github.com/gogf/gf/frame/g"
)
var
Order
=
new
(
order
)
type
order
struct
{
}
type
OrderCreateReq
struct
{
Order
struct
{
Id
int
`json:"id"`
...
...
@@ -60,9 +55,9 @@ type OrderCreateRes struct {
}
`json:"data"`
}
func
(
s
*
order
)
Create
(
ctx
context
.
Context
,
req
*
OrderCreateReq
)
(
res
*
OrderCreateRes
,
err
error
)
{
func
(
s
*
hcwClient
)
Order
Create
(
ctx
context
.
Context
,
req
*
OrderCreateReq
)
(
res
*
OrderCreateRes
,
err
error
)
{
var
method
=
"/api/v1/order"
result
,
err
:=
post
(
ctx
,
method
,
req
)
result
,
err
:=
s
.
post
(
ctx
,
method
,
req
)
if
nil
!=
err
{
return
}
...
...
@@ -104,9 +99,9 @@ type OrderListRes struct {
}
`json:"data"`
}
func
(
s
*
order
)
List
(
ctx
context
.
Context
,
req
*
OrderCreateReq
)
(
res
*
OrderListRes
,
err
error
)
{
func
(
s
*
hcwClient
)
Order
List
(
ctx
context
.
Context
,
req
*
OrderCreateReq
)
(
res
*
OrderListRes
,
err
error
)
{
var
method
=
"/api/v1/order"
result
,
err
:=
get
(
ctx
,
method
,
req
)
result
,
err
:=
s
.
get
(
ctx
,
method
,
req
)
if
nil
!=
err
{
return
}
...
...
@@ -178,9 +173,9 @@ type OrderDetailRes struct {
}
`json:"data"`
}
func
(
s
*
order
)
Detail
(
ctx
context
.
Context
,
orderSn
string
)
(
res
*
OrderDetailRes
,
err
error
)
{
func
(
s
*
hcwClient
)
Order
Detail
(
ctx
context
.
Context
,
orderSn
string
)
(
res
*
OrderDetailRes
,
err
error
)
{
var
method
=
"/api/v1/order/"
+
orderSn
result
,
err
:=
get
(
ctx
,
method
,
g
.
Map
{})
result
,
err
:=
s
.
get
(
ctx
,
method
,
g
.
Map
{})
if
nil
!=
err
{
return
}
...
...
@@ -202,9 +197,9 @@ type OrderCheckRes struct {
}
`json:"data"`
}
func
(
s
*
order
)
Check
(
ctx
context
.
Context
,
req
*
OrderCheckReq
)
(
res
*
OrderCheckRes
,
err
error
)
{
func
(
s
*
hcwClient
)
Order
Check
(
ctx
context
.
Context
,
req
*
OrderCheckReq
)
(
res
*
OrderCheckRes
,
err
error
)
{
var
method
=
"/api/v1/order/check"
result
,
err
:=
post
(
ctx
,
method
,
req
)
result
,
err
:=
s
.
post
(
ctx
,
method
,
req
)
if
nil
!=
err
{
return
}
...
...
upstream/hcw/hcw_refund.go
浏览文件 @
b3599bd1
...
...
@@ -5,11 +5,6 @@ import (
"github.com/gogf/gf/encoding/gjson"
)
var
Refund
=
new
(
refund
)
type
refund
struct
{
}
type
RefundCreateReq
struct
{
RefundOrderNo
string
`json:"refund_order_no"`
OrderSn
string
`json:"order_sn"`
...
...
@@ -29,9 +24,9 @@ type RefundCreateReq struct {
type
RefundCreateRes
struct
{
}
func
(
s
*
refund
)
Create
(
ctx
context
.
Context
,
req
*
RefundCreateReq
)
(
res
*
RefundCreateRes
,
err
error
)
{
func
(
s
*
hcwClient
)
OrderRefund
Create
(
ctx
context
.
Context
,
req
*
RefundCreateReq
)
(
res
*
RefundCreateRes
,
err
error
)
{
var
method
=
"/api/v1/orderRefund"
result
,
err
:=
post
(
ctx
,
method
,
req
)
result
,
err
:=
s
.
post
(
ctx
,
method
,
req
)
if
nil
!=
err
{
return
}
...
...
@@ -47,9 +42,9 @@ type RefundDetailReq struct {
type
RefundDetailRes
struct
{
}
func
(
s
*
refund
)
Detail
(
ctx
context
.
Context
,
req
*
RefundDetailReq
)
(
res
*
RefundDetailRes
,
err
error
)
{
func
(
s
*
hcwClient
)
OrderRefund
Detail
(
ctx
context
.
Context
,
req
*
RefundDetailReq
)
(
res
*
RefundDetailRes
,
err
error
)
{
var
method
=
"/api/v1/orderRefund"
result
,
err
:=
get
(
ctx
,
method
,
req
)
result
,
err
:=
s
.
get
(
ctx
,
method
,
req
)
if
nil
!=
err
{
return
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论