This commit is contained in:
2026-01-16 18:43:50 +08:00
parent 9e10b5f2e9
commit 83bd8d9c5c

View File

@@ -48,11 +48,28 @@ type GetAccessTokenRequest struct {
// GetAccessTokenResponse 获取token响应
type GetAccessTokenResponse struct {
Code int `json:"code"`
Code interface{} `json:"code"` // 可能是字符串"200"或数字200
Msg string `json:"msg"`
Data *AccessTokenData `json:"data,omitempty"`
}
// GetCodeInt 获取 code 的 int 值
func (r *GetAccessTokenResponse) GetCodeInt() int {
switch v := r.Code.(type) {
case int:
return v
case float64:
return int(v)
case string:
if v == "200" {
return 200
}
return 0
default:
return 0
}
}
// AccessTokenData token数据
type AccessTokenData struct {
AccessToken string `json:"accessToken"`
@@ -121,7 +138,9 @@ func (y *YunYinSignPayService) GetAccessToken(ctx context.Context) (string, erro
logx.Infof("[云印签API] GetAccessToken: 响应解析成功Code: %v, Msg: %s", tokenResp.Code, tokenResp.Msg)
if tokenResp.Code != 0 {
// 检查响应码(可能是字符串"200"或数字200
codeInt := tokenResp.GetCodeInt()
if codeInt != 200 {
logx.Errorf("[云印签API] GetAccessToken: API返回错误Code: %v, Msg: %s", tokenResp.Code, tokenResp.Msg)
return "", fmt.Errorf("获取token失败: %s", tokenResp.Msg)
}
@@ -154,11 +173,28 @@ type GetUserIdRequest struct {
// GetUserIdResponse 获取操作ID响应
type GetUserIdResponse struct {
Code int `json:"code"`
Code interface{} `json:"code"` // 可能是字符串"200"或数字200
Msg string `json:"msg"`
Data *UserIdData `json:"data,omitempty"`
}
// GetCodeInt 获取 code 的 int 值
func (r *GetUserIdResponse) GetCodeInt() int {
switch v := r.Code.(type) {
case int:
return v
case float64:
return int(v)
case string:
if v == "200" {
return 200
}
return 0
default:
return 0
}
}
// UserIdData 操作ID数据
type UserIdData struct {
UserId string `json:"userId"`
@@ -227,7 +263,9 @@ func (y *YunYinSignPayService) GetUserId(ctx context.Context, accessToken string
logx.Infof("[云印签API] GetUserId: 响应解析成功Code: %v, Msg: %s", userIdResp.Code, userIdResp.Msg)
if userIdResp.Code != 0 {
// 检查响应码(可能是字符串"200"或数字200
codeInt := userIdResp.GetCodeInt()
if codeInt != 200 {
logx.Errorf("[云印签API] GetUserId: API返回错误Code: %v, Msg: %s", userIdResp.Code, userIdResp.Msg)
return "", fmt.Errorf("获取操作ID失败: %s", userIdResp.Msg)
}
@@ -454,11 +492,28 @@ type GetPaymentURLRequest struct {
// GetPaymentURLResponse 获取支付链接响应
type GetPaymentURLResponse struct {
Code int `json:"code"`
Code interface{} `json:"code"` // 可能是字符串"200"或数字200
Msg string `json:"msg"`
Data *PaymentURLData `json:"data,omitempty"`
}
// GetCodeInt 获取 code 的 int 值
func (r *GetPaymentURLResponse) GetCodeInt() int {
switch v := r.Code.(type) {
case int:
return v
case float64:
return int(v)
case string:
if v == "200" {
return 200
}
return 0
default:
return 0
}
}
// PaymentURLData 支付链接数据
type PaymentURLData struct {
PayURL string `json:"payUrl,omitempty"`
@@ -519,10 +574,12 @@ func (y *YunYinSignPayService) GetPaymentURL(ctx context.Context, accessToken, u
return "", fmt.Errorf("解析响应失败: %v, 响应内容: %s", err, string(body))
}
logx.Infof("[云印签API] GetPaymentURL: 响应解析成功Code: %d, Msg: %s", paymentURLResp.Code, paymentURLResp.Msg)
logx.Infof("[云印签API] GetPaymentURL: 响应解析成功Code: %v, Msg: %s", paymentURLResp.Code, paymentURLResp.Msg)
if paymentURLResp.Code != 0 {
logx.Errorf("[云印签API] GetPaymentURL: API返回错误Code: %d, Msg: %s", paymentURLResp.Code, paymentURLResp.Msg)
// 检查响应码(可能是字符串"200"或数字200
codeInt := paymentURLResp.GetCodeInt()
if codeInt != 200 {
logx.Errorf("[云印签API] GetPaymentURL: API返回错误Code: %v, Msg: %s", paymentURLResp.Code, paymentURLResp.Msg)
return "", fmt.Errorf("获取支付链接失败: %s", paymentURLResp.Msg)
}