fix Authorization

This commit is contained in:
2025-11-11 17:47:08 +08:00
parent 64c0a10193
commit c40be9daf8
10 changed files with 326 additions and 29 deletions

View File

@@ -2,17 +2,19 @@ package queue
import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"net/url"
"os"
"path"
"regexp"
"strings"
"tydata-server/app/main/api/internal/svc"
"tydata-server/app/main/api/internal/types"
"tydata-server/app/main/model"
"tydata-server/pkg/lzkit/crypto"
"tydata-server/pkg/lzkit/lzUtils"
"encoding/hex"
"encoding/json"
"fmt"
"os"
"regexp"
"strings"
"github.com/hibiken/asynq"
"github.com/zeromicro/go-zero/core/logx"
@@ -112,9 +114,9 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
// 将授权书URL添加到解密数据中
if authDoc != nil {
// 生成完整的授权书访问URL
fullAuthDocURL := l.svcCtx.AuthorizationService.GetFullFileURL(authDoc.FileUrl)
userInfo["authorization_url"] = fullAuthDocURL
// 生成授权书下载接口URL
downloadURL := l.buildAuthorizationDownloadURL(authDoc.FileName)
userInfo["authorization_url"] = downloadURL
// 重新序列化用户信息
updatedDecryptData, marshalErr := json.Marshal(userInfo)
@@ -132,7 +134,7 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
if updateParamsErr != nil {
logx.Errorf("更新查询参数失败: %v", updateParamsErr)
} else {
logx.Infof("成功更新查询参数包含授权书URL: %s", fullAuthDocURL)
logx.Infof("成功更新查询参数包含授权书URL: %s", downloadURL)
}
}
decryptData = updatedDecryptData
@@ -177,6 +179,18 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
return nil
}
func (l *PaySuccessNotifyUserHandler) buildAuthorizationDownloadURL(fileName string) string {
escapedFileName := url.PathEscape(fileName)
base := l.svcCtx.Config.Authorization.FileBaseURL
if parsed, err := url.Parse(base); err == nil && parsed.Scheme != "" && parsed.Host != "" {
parsed.Path = path.Join("/api/v1/authorization/download/file", escapedFileName)
parsed.RawQuery = ""
parsed.Fragment = ""
return parsed.String()
}
return fmt.Sprintf("/api/v1/authorization/download/file/%s", escapedFileName)
}
// 定义一个中间件函数
func (l *PaySuccessNotifyUserHandler) handleError(ctx context.Context, err error, order *model.Order, query *model.Query) error {
logx.Errorf("处理任务失败,原因: %v", err)