fix: 优化登录配置和API调用

This commit is contained in:
renzhiyuan 2026-01-05 15:52:16 +08:00
parent aa3151baa5
commit 5831eefd4f
13 changed files with 104 additions and 67 deletions

View File

@ -21,7 +21,19 @@ vllm:
coze:
base_url: "https://api.coze.cn"
api_secret: "sat_AqvFcdNgesP8megy1ItTscWFXRcsHRzmM4NJ1KNavfcdT0EPwYuCPkDqGhItpx13"
redis:
host: 47.97.27.195:6379
type: node
pass:
lansexiongdi@666i_secret: "sat_AqvFcdNgesP8megy1ItTscWFXRcsHRzmM4NJ1KNavfcdT0EPwYuCPkDqGhItpx13"
lsxd:
# 统一登录
login_url: "http://api.test.user.1688sup.com/v1/login/phone"
phone: "0zmINhJBwsDJYTmeaxXK4A=="
password: "LSSGoWhc63NpZc1rq3LT8g=="
check_token_url: "http://api.test.user.1688sup.com/v1/user/welcome"
sys:
@ -30,10 +42,6 @@ sys:
channel_pool_size: 32
llm_pool_len: 5
heartbeat_interval: 30
redis:
host: 47.97.27.195:6379
type: node
pass: lansexiongdi@666
key: report-api
pollSize: 5 #连接池大小不配置或配置为0表示不启用连接池
minIdleConns: 2 #最小空闲连接数
@ -128,7 +136,7 @@ eino_tools:
# 我们的商品统计
rechargeStatisticsOursProduct:
base_url: "http://admin.lanseds.cn/admin/statistics/oursProduct"
api_key: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzY3MTc5ODgzLCJuYmYiOjE3NjcxNjkwODMsImp0aSI6IjEiLCJQaG9uZSI6IjE4MjAwMTYwMTQzIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MiwiR3JvdXBDb2RlcyI6IkxTWEREU19TWVNURU0sU1RBVElTVElDQUxTWVNURU1fQURNSU4sUEhZU0lDQUxHT09EU19BRE1JTiIsIkRpbmdVc2VySWQiOiIifQ.ELNF1Iv6yEwA12nCbXGKwXCw-F5Gq4GI2t2nqo1PlSkFdQ5Oz5s5NwV0RUXA66LxCggI-9IjBtFI1MvBHpvTHq9QRlm-HKzVTMcOBkEtKEfCCI6SPKVTAZyntTJlWPKG3u-CJUotT5YW0j2rU1VcpA7uGEiY7gs5VPUOZ80R1uGJ7HBSqVI2DRqar6STa1xryygdCjK7qamUM2d6aJ6r9VPTBt-JO6dkDdw3KHs3wl-PGM3wcbXHZ2aC18WFd_PxLmtjqErpxTEkdUBCnUHOSKDePG0henDJq71Nh3yRdRmY9VvszHMyIxJA2BVGPIPUT_Y5aewaaEMQVEjhiBnn-Q"
excel2pic:
base_url: "http://192.168.6.109:8010/api/v1/convert"

View File

@ -132,7 +132,6 @@ eino_tools:
# 我们的商品统计
rechargeStatisticsOursProduct:
base_url: "http://admin.1688sup.cn:8001/admin/statistics/oursProduct"
api_key: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzY3MDc3NzcwLCJuYmYiOjE3NjcwNzU5NzAsImp0aSI6IjEiLCJQaG9uZSI6IjE4MDAwMDAwMDAwIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MSwiR3JvdXBDb2RlcyI6IlZDTF9DQVNISUVSLFZDTF9PUEVSQVRFLFZDTF9BRE1JTixWQ0xfQUFBLFZDTF9WQ0xfT1BFUkFULFZDTF9JTlZPSUNFLENSTV9BRE1JTixMSUFOTElBTl9BRE1JTixNQVJLRVRNQUcyX0FETUlOLFBIT05FQklMTF9BRE1JTixRSUFOWkhVX1NVUFBFUl9BRE0sTUFSS0VUSU5HU0FBU19TVVBFUkFETUlOLENBUkRfQ09ERSxDQVJEX1BST0NVUkVNRU5ULE1BUktFVElOR1NZU1RFTV9TVVBFUixTVEFUSVNUSUNBTFNZU1RFTV9BRE1JTixaTFRYX0FETUlOLFpMVFhfT1BFUkFURSIsIkRpbmdVc2VySWQiOiIxNjIwMjYxMjMwMjg5MzM4MzQifQ.Nuw_aR6iSPmhhh9E5rhyTxHBsgWtaTZvbnc7SFTnUBJXTQvYahnk0LyZaVpsVw6FB3cU0F5xOdX3rmGyWyaiszWO6yi-o1oxGMXwhf39fMiWT2xUI6pAn9Ync8DmZ4tOMCNUTdEk4CaQFzrTwJs0c-VR4yW6LgoPmNPvUVZ-KwmusUpnPz5j9RsJItzIWE3bpGGsfB54e2UERcZdbo9BXxCZIBbpAYKBKdl73KuI8SNaXgKvGTrJ6hEN4ESpnbisJVwT5pp_kuChJlcfjHTHFsEf4RJDjN9gTrtDbBWZyY3OmO2ukqYAM7tZPs6TXJwvQGJQsFRVZUBGxS1nD_6DzQ"
excel2pic:
base_url: "http://192.168.6.109:8010/api/v1/convert"

View File

@ -24,6 +24,13 @@ coze:
api_secret: "sat_AqvFcdNgesP8megy1ItTscWFXRcsHRzmM4NJ1KNavfcdT0EPwYuCPkDqGhItpx13"
lsxd:
# 统一登录
login_url: "http://api.test.user.1688sup.com/v1/login/phone"
phone: "0zmINhJBwsDJYTmeaxXK4A=="
password: "LSSGoWhc63NpZc1rq3LT8g=="
check_token_url: "http://api.test.user.1688sup.com/v1/user/welcome"
sys:
session_len: 6
channel_pool_len: 100
@ -127,8 +134,7 @@ eino_tools:
# == 电商充值系统 ==
# 我们的商品统计
rechargeStatisticsOursProduct:
base_url: "http://admin.lanseds.cn/admin/statistics/oursProduct"
api_key: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzY3MTc5ODgzLCJuYmYiOjE3NjcxNjkwODMsImp0aSI6IjEiLCJQaG9uZSI6IjE4MjAwMTYwMTQzIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MiwiR3JvdXBDb2RlcyI6IkxTWEREU19TWVNURU0sU1RBVElTVElDQUxTWVNURU1fQURNSU4sUEhZU0lDQUxHT09EU19BRE1JTiIsIkRpbmdVc2VySWQiOiIifQ.ELNF1Iv6yEwA12nCbXGKwXCw-F5Gq4GI2t2nqo1PlSkFdQ5Oz5s5NwV0RUXA66LxCggI-9IjBtFI1MvBHpvTHq9QRlm-HKzVTMcOBkEtKEfCCI6SPKVTAZyntTJlWPKG3u-CJUotT5YW0j2rU1VcpA7uGEiY7gs5VPUOZ80R1uGJ7HBSqVI2DRqar6STa1xryygdCjK7qamUM2d6aJ6r9VPTBt-JO6dkDdw3KHs3wl-PGM3wcbXHZ2aC18WFd_PxLmtjqErpxTEkdUBCnUHOSKDePG0henDJq71Nh3yRdRmY9VvszHMyIxJA2BVGPIPUT_Y5aewaaEMQVEjhiBnn-Q"
base_url: "http://admin.1688sup.cn:8001/admin/statistics/oursProduct"
excel2pic:
base_url: "http://192.168.6.109:8010/api/v1/convert"

View File

@ -633,27 +633,28 @@ func (d *DingTalkBotBiz) HandleStreamRes(ctx context.Context, data *chatbot.BotC
func (d *DingTalkBotBiz) GetReportLists(ctx context.Context, group *model.AiBotGroup) (reports []*bbxt.ReportRes, err error) {
reportList, err := bbxt.NewBbxtTools()
if err != nil {
return
}
var product []string
if group.ProductName != "" {
product = strings.Split(group.ProductName, ",")
}
//[]string{"官方-爱奇艺-星钻季卡", "官方-爱奇艺-星钻半年卡", "官方--腾讯-年卡", "官方--爱奇艺-月卡"}
reports, err = reportList.DailyReport(time.Now(), bbxt.DownWardValue, product, bbxt.SumFilter, d.ossClient)
if err != nil {
//var product []string
//if group.ProductName != "" {
// product = strings.Split(group.ProductName, ",")
//}
//reportList, err := bbxt.NewBbxtTools()
//if err != nil {
// return
//}
//reports, err = reportList.DailyReport(time.Now(), bbxt.DownWardValue, product, bbxt.SumFilter, d.ossClient)
//if err != nil {
// return
//}
//product = []string{"优酷周卡", "优酷季卡", "优酷年卡", "爱奇艺黄金会员天卡"}
//追加电商充值系统统计 - 返回统一使用[]*bbxt.ReportRes
rechargeReports, err := d.rechargeDailyReport(ctx, time.Now(), nil, d.ossClient)
if err != nil || len(rechargeReports) == 0 {
return
}
// 追加电商充值系统统计 - 返回统一使用 []*bbxt.ReportRes
//rechargeReports, err := d.rechargeDailyReport(ctx, time.Now(), product, d.ossClient)
//if err != nil || len(rechargeReports) == 0 {
// return
//}
//
//reports = append(reports, rechargeReports...)
reports = append(reports, rechargeReports...)
return
}

View File

@ -4,18 +4,21 @@ import (
"ai_scheduler/internal/config"
"ai_scheduler/internal/data/impl"
"ai_scheduler/internal/pkg/utils_oss"
"ai_scheduler/utils"
)
// Repos 聚合所有 Repository
type Repos struct {
Session SessionRepo
OssClient *utils_oss.Client
Rdb *utils.Rdb
}
func NewRepos(sessionImpl *impl.SessionImpl, cfg *config.Config) *Repos {
func NewRepos(sessionImpl *impl.SessionImpl, cfg *config.Config, rdb *utils.Rdb) *Repos {
ossClient, _ := utils_oss.NewClient(cfg)
return &Repos{
Session: NewSessionAdapter(sessionImpl),
OssClient: ossClient,
Rdb: rdb,
}
}

View File

@ -3,6 +3,8 @@ package statistics_ours_product
import (
"ai_scheduler/internal/config"
"ai_scheduler/internal/pkg/l_request"
"ai_scheduler/internal/pkg/lsxd"
"ai_scheduler/utils"
"context"
"encoding/json"
"fmt"
@ -14,14 +16,16 @@ type Client struct {
cfg config.ToolConfig
}
// New 是一个客户端构造函数,接收一个 config.ToolConfig 类型的配置参数
// 返回一个初始化后的 Client 指针
func New(cfg config.ToolConfig) *Client {
return &Client{
cfg: cfg,
cfg: cfg, // 将传入的配置参数赋值给 Client 结构体的 cfg 字段
}
}
// Call 调用我们的商品统计接口
func (c *Client) Call(ctx context.Context, req StatisticsOursProductRequest) ([]StatisticsOursProductItem, error) {
func (c *Client) Call(ctx context.Context, req StatisticsOursProductRequest, rdb *utils.Rdb, lsxdcfg *config.LSXDConfig) ([]StatisticsOursProductItem, error) {
// 构建 URL 参数
var queryParams []string
@ -44,9 +48,9 @@ func (c *Client) Call(ctx context.Context, req StatisticsOursProductRequest) ([]
queryString := strings.Join(queryParams, "&")
fullURL := fmt.Sprintf("%s?%s", c.cfg.BaseURL, queryString)
token := lsxd.NewLogin(lsxdcfg, rdb).GetToken(ctx)
headers := map[string]string{
"Authorization": fmt.Sprintf("Bearer %s", c.cfg.APIKey),
"Authorization": fmt.Sprintf("Bearer %s", token),
}
reqObj := l_request.Request{

View File

@ -2,17 +2,33 @@ package statistics_ours_product
import (
"ai_scheduler/internal/config"
"ai_scheduler/utils"
"context"
"testing"
)
func TestClient_Call(t *testing.T) {
cfg := config.ToolConfig{
rdb := utils.NewRdb(&config.Config{
Redis: config.Redis{
Host: "47.97.27.195:6379",
Pass: "lansexiongdi@666",
Key: "report-api-test",
},
})
configEino := config.ToolConfig{
BaseURL: "http://admin.1688sup.cn:8001/admin/statistics/oursProduct",
APIKey: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzY3MDc3NzcwLCJuYmYiOjE3NjcwNzU5NzAsImp0aSI6IjEiLCJQaG9uZSI6IjE4MDAwMDAwMDAwIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MSwiR3JvdXBDb2RlcyI6IlZDTF9DQVNISUVSLFZDTF9PUEVSQVRFLFZDTF9BRE1JTixWQ0xfQUFBLFZDTF9WQ0xfT1BFUkFULFZDTF9JTlZPSUNFLENSTV9BRE1JTixMSUFOTElBTl9BRE1JTixNQVJLRVRNQUcyX0FETUlOLFBIT05FQklMTF9BRE1JTixRSUFOWkhVX1NVUFBFUl9BRE0sTUFSS0VUSU5HU0FBU19TVVBFUkFETUlOLENBUkRfQ09ERSxDQVJEX1BST0NVUkVNRU5ULE1BUktFVElOR1NZU1RFTV9TVVBFUixTVEFUSVNUSUNBTFNZU1RFTV9BRE1JTixaTFRYX0FETUlOLFpMVFhfT1BFUkFURSIsIkRpbmdVc2VySWQiOiIxNjIwMjYxMjMwMjg5MzM4MzQifQ.Nuw_aR6iSPmhhh9E5rhyTxHBsgWtaTZvbnc7SFTnUBJXTQvYahnk0LyZaVpsVw6FB3cU0F5xOdX3rmGyWyaiszWO6yi-o1oxGMXwhf39fMiWT2xUI6pAn9Ync8DmZ4tOMCNUTdEk4CaQFzrTwJs0c-VR4yW6LgoPmNPvUVZ-KwmusUpnPz5j9RsJItzIWE3bpGGsfB54e2UERcZdbo9BXxCZIBbpAYKBKdl73KuI8SNaXgKvGTrJ6hEN4ESpnbisJVwT5pp_kuChJlcfjHTHFsEf4RJDjN9gTrtDbBWZyY3OmO2ukqYAM7tZPs6TXJwvQGJQsFRVZUBGxS1nD_6DzQ",
APIKey: "OFJ8UpqOlI7+w3Qklf36ZA==",
APISecret: "tEbFegH/DRRh6LutFb7o3g==",
}
configLSXD := &config.LSXDConfig{
LoginURL: "http://api.test.user.1688sup.com/v1/login/phone",
Phone: "0zmINhJBwsDJYTmeaxXK4A==",
Password: "LSSGoWhc63NpZc1rq3LT8g==",
CheckTokenURL: "http://api.test.user.1688sup.com/v1/user/welcome",
}
client := New(cfg)
client := New(configEino)
req := StatisticsOursProductRequest{
Page: 1,
@ -24,7 +40,7 @@ func TestClient_Call(t *testing.T) {
// 由于没有真实的后端环境和 Token这里注释掉实际调用
// 在开发环境中,你可以取消注释并填入有效的 Token 进行测试
res, err := client.Call(context.Background(), req)
res, err := client.Call(context.Background(), req, rdb, configLSXD)
if err != nil {
t.Logf("Call failed: %v", err)
} else {

View File

@ -8,6 +8,7 @@ import (
"ai_scheduler/internal/domain/tools/recharge/statistics_ours_product"
"ai_scheduler/internal/domain/workflow/runtime"
"ai_scheduler/internal/pkg/utils_oss"
"ai_scheduler/utils"
"context"
"errors"
"fmt"
@ -24,7 +25,7 @@ const WorkflowIDStatisticsOursProduct = "recharge.statisticsOursProduct"
func init() {
runtime.Register(WorkflowIDStatisticsOursProduct, func(d *runtime.Deps) (runtime.Workflow, error) {
return &statisticsOursProduct{cfg: d.Conf, toolManager: d.ToolManager, ossClient: d.Repos.OssClient}, nil
return &statisticsOursProduct{cfg: d.Conf, toolManager: d.ToolManager, ossClient: d.Repos.OssClient, rdb: d.Repos.Rdb}, nil
})
}
@ -32,6 +33,7 @@ type statisticsOursProduct struct {
cfg *config.Config
toolManager *toolManager.Manager
ossClient *utils_oss.Client
rdb *utils.Rdb
}
type StatisticsOursProductWorkflowInput struct {
@ -103,7 +105,8 @@ func (w *statisticsOursProduct) buildWorkflow(ctx context.Context) (compose.Runn
// formatContext 整理上下文参数
func (w *statisticsOursProduct) formatContext(ctx context.Context, input *StatisticsOursProductWorkflowInput) (*StatisticsOursProductContext, error) {
startTime := input.Time.Format("2006010200")
//startTime := input.Time.Format("2006010200")
startTime := "2025010500"
endTime := input.Time.Format("2006010215")
endTimeStr := input.Time.Format("1.2号15点")
@ -122,7 +125,7 @@ func (w *statisticsOursProduct) callStatisticsTool(ctx context.Context, state *S
Serial: []string{state.StartTime, state.EndTime},
}
dataList, err := w.toolManager.Recharge.StatisticsOursProduct.Call(ctx, req)
dataList, err := w.toolManager.Recharge.StatisticsOursProduct.Call(ctx, req, w.rdb, &w.cfg.LSXD)
if err != nil {
log.Errorf("调用统计我们的商品工具失败: %v", err)
return nil, fmt.Errorf("获取统计我们的商品数据失败")
@ -138,7 +141,7 @@ func (w *statisticsOursProduct) callStatisticsTool(ctx context.Context, state *S
func (w *statisticsOursProduct) generateExcelAndUpload(ctx context.Context, state *StatisticsOursProductContext) (*StatisticsOursProductContext, error) {
// 1. 获取模板路径
cwd, _ := filepath.Abs(".")
cwd, _ := filepath.Abs("../../")
templatePath := filepath.Join(cwd, "tmpl", "excel_temp", "recharge_statistics_ours_product.xlsx")
fileName := fmt.Sprintf("statistics_ours_product_%d%d", time.Now().Unix(), rand.Intn(1000))

View File

@ -19,21 +19,19 @@ import (
)
type Login struct {
config *config.Config
config *config.LSXDConfig
redisCli *redis.Client
mu sync.Mutex
}
func NewLogin(config *config.Config, rdb *utils.Rdb) *Login {
func NewLogin(config *config.LSXDConfig, rdb *utils.Rdb) *Login {
return &Login{
config: config,
redisCli: rdb.Rdb,
}
}
func (l *Login) GetToken() string {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
func (l *Login) GetToken(ctx context.Context) string {
token, err := l.getCachedToken(ctx)
if err != nil {
@ -74,7 +72,7 @@ func (l *Login) GetToken() string {
// 校验token是否有效
func (l *Login) checkTokenValid(ctx context.Context, token string) bool {
// 欢迎页校验token有效
checkTokenURL := l.config.LSXD.CheckTokenURL
checkTokenURL := l.config.CheckTokenURL
if checkTokenURL == "" {
return token != ""
}
@ -96,9 +94,9 @@ func (l *Login) checkTokenValid(ctx context.Context, token string) bool {
// 调用登录接口获取token
func (l *Login) login(ctx context.Context) (string, error) {
// 1.获取配置
loginURL := l.config.LSXD.LoginURL
phone := l.config.LSXD.Phone
password := l.config.LSXD.Password
loginURL := l.config.LoginURL
phone := l.config.Phone
password := l.config.Password
// 2.调用登录接口获取token
if loginURL == "" {
@ -111,7 +109,7 @@ func (l *Login) login(ctx context.Context) (string, error) {
reqBody := map[string]any{
"phone": phone,
"password": password,
"code": "123456",
"code": "456789",
}
bodyBytes, err := json.Marshal(reqBody)
if err != nil {

View File

@ -3,6 +3,7 @@ package lsxd
import (
"ai_scheduler/internal/config"
"ai_scheduler/utils"
"context"
"testing"
)
@ -16,15 +17,13 @@ func TestGetToken(t *testing.T) {
},
})
login := NewLogin(&config.Config{
LSXD: config.LSXDConfig{
login := NewLogin(&config.LSXDConfig{
LoginURL: "http://api.test.user.1688sup.com/v1/login/phone",
Phone: "0zmINhJBwsDJYTmeaxXK4A==",
Password: "LSSGoWhc63NpZc1rq3LT8g==",
Phone: "OFJ8UpqOlI7+w3Qklf36ZA==",
Password: "tEbFegH/DRRh6LutFb7o3g==",
CheckTokenURL: "http://api.test.user.1688sup.com/v1/user/welcome",
},
}, rdb)
token := login.GetToken()
token := login.GetToken(context.Background())
if token == "" {
t.Errorf("token is empty")
}

View File

@ -66,13 +66,13 @@ func (c *CronServer) Run(ctx context.Context) {
}
c.log.Infof("任务[%d]:%s执行结束", jobID, job.Name)
}()
c.log.Infof("任务[%d]:%s执ddd", jobID, job.Name)
// 为每次执行创建新的上下文
ctx := context.Background()
err := job.Func(ctx)
if err != nil {
c.log.Errorf("任务[%d]:%s执行失败: %s", jobID, job.Name, err.Error())
}
//ctx := context.Background()
//err := job.Func(ctx)
//if err != nil {
// c.log.Errorf("任务[%d]:%s执行失败: %s", jobID, job.Name, err.Error())
//}
})
if err != nil {
c.log.Errorf("添加任务失败:%s", err.Error())

View File

@ -22,7 +22,7 @@ func NewCronService(config *config.Config, dingTalkBotBiz *biz.DingTalkBotBiz) *
func (d *CronService) CronReportSend(ctx context.Context) error {
groupId := 29
groupId := 28
groupInfo, err := d.dingTalkBotBiz.GetGroupInfo(ctx, groupId)
if err != nil {
return err

View File

@ -63,7 +63,7 @@ func run() {
// 初始化Redis数据库连接
rdb := utils.NewRdb(configConfig)
// 初始化仓库层
repos := repo.NewRepos(sessionImpl, configConfig)
repos := repo.NewRepos(sessionImpl, configConfig, rdb)
// 初始化包级别的Redis连接
pkgRdb := pkg.NewRdb(configConfig)