Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
L
library
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
stbz
library
Commits
1cbef05d
提交
1cbef05d
authored
7月 01, 2025
作者:
张立波
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
上级
aac2fed1
8f089672
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
11 行删除
+20
-11
hcw.go
upstream/hcw/hcw.go
+5
-4
hcw_callback.go
upstream/hcw/hcw_callback.go
+15
-7
没有找到文件。
upstream/hcw/hcw.go
浏览文件 @
1cbef05d
...
...
@@ -26,6 +26,7 @@ import (
const
pkgName
=
"hcw"
type
Config
struct
{
AppId
string
SecretKey
string
ApiUrl
string
}
...
...
@@ -165,9 +166,9 @@ func (s *HcwClient) post(ctx context.Context, method string, req interface{}) (r
Url
:=
s
.
Config
.
ApiUrl
+
method
Request
:=
g
.
Client
()
Request
.
SetHeader
(
"Content-Type"
,
"application/json"
)
Request
.
SetHeader
(
"Format"
,
"json"
)
Request
.
SetHeader
(
"Content-Type"
,
"application/json;charset=UTF-8"
)
Request
.
SetHeader
(
"signature"
,
signature
)
Request
.
SetHeader
(
"appid"
,
s
.
Config
.
AppId
)
resp
,
err
:=
Request
.
Timeout
(
time
.
Second
*
10
)
.
Post
(
Url
,
param
.
MustToJsonString
())
defer
func
()
{
...
...
@@ -196,9 +197,9 @@ func (s *HcwClient) get(ctx context.Context, method string, req interface{}) (re
query
:=
mapToSortedQuery
(
queryParams
)
Url
:=
s
.
Config
.
ApiUrl
+
method
+
"?"
+
query
Request
:=
g
.
Client
()
Request
.
SetHeader
(
"Content-Type"
,
"text/xml; charset=utf-8"
)
Request
.
SetHeader
(
"Format"
,
"json"
)
Request
.
SetHeader
(
"Content-Type"
,
"application/json;charset=UTF-8"
)
Request
.
SetHeader
(
"signature"
,
signature
)
Request
.
SetHeader
(
"appid"
,
s
.
Config
.
AppId
)
resp
,
err
:=
Request
.
Timeout
(
time
.
Second
*
10
)
.
Get
(
Url
)
defer
func
()
{
...
...
upstream/hcw/hcw_callback.go
浏览文件 @
1cbef05d
...
...
@@ -2,7 +2,9 @@ package hcw
import
(
"encoding/json"
"errors"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/util/gconv"
)
//notify_id string 唯一请求ID(用于幂等校验)示例:20240320140000_123456
...
...
@@ -32,19 +34,25 @@ type OrderNotifyData struct {
// 回调
func
(
s
*
HcwClient
)
CallBack
(
r
*
ghttp
.
Request
)
(
res
*
OrderNotifyRes
,
err
error
)
{
body
,
err
:=
CheckSign
(
r
)
if
nil
!=
err
{
return
}
body
:=
r
.
GetBodyString
()
if
body
==
""
{
return
}
err
=
json
.
Unmarshal
([]
byte
(
body
),
&
res
)
if
nil
!=
err
{
return
}
err
=
s
.
CheckSign
(
res
)
return
}
func
CheckSign
(
r
*
ghttp
.
Request
)
(
body
string
,
err
error
)
{
body
=
r
.
GetBodyString
()
func
(
s
*
HcwClient
)
CheckSign
(
req
*
OrderNotifyRes
)
(
err
error
)
{
reqMap
:=
gconv
.
Map
(
req
.
Data
)
signature
,
err
:=
s
.
EncryptWithSignature
(
reqMap
)
if
req
.
Signature
!=
signature
{
err
=
errors
.
New
(
"incorrect signature"
)
}
return
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论