diff --git a/apps/api/etc/api-api.dev.yaml b/apps/api/etc/api-api.dev.yaml index 5e3e14a..38f394f 100644 --- a/apps/api/etc/api-api.dev.yaml +++ b/apps/api/etc/api-api.dev.yaml @@ -16,5 +16,6 @@ KqPusherConf: - 127.0.0.1:9092 Topic: apirequest WestConfig: + Url: "http://proxy.tianyuanapi.com/api/invoke" Key: "121a1e41fc1690dd6b90afbcacd80cf4" SecretId: "449159" \ No newline at end of file diff --git a/apps/api/etc/api-api.yaml b/apps/api/etc/api-api.yaml index 97e97ff..5516c94 100644 --- a/apps/api/etc/api-api.yaml +++ b/apps/api/etc/api-api.yaml @@ -16,5 +16,6 @@ KqPusherConf: - tyapi_kafka:9092 Topic: apirequest WestConfig: + Url: "https://apimaster.westdex.com.cn/api/invoke" key: "121a1e41fc1690dd6b90afbcacd80cf4" secretId: "449159" \ No newline at end of file diff --git a/apps/api/internal/config/config.go b/apps/api/internal/config/config.go index 329573b..2e2c01c 100644 --- a/apps/api/internal/config/config.go +++ b/apps/api/internal/config/config.go @@ -19,6 +19,7 @@ type KqPusherConf struct { Topic string } type WestConfig struct { + Url string Key string SecretId string } diff --git a/apps/api/internal/service/west_dex_service.go b/apps/api/internal/service/west_dex_service.go index 3692771..2b568fc 100644 --- a/apps/api/internal/service/west_dex_service.go +++ b/apps/api/internal/service/west_dex_service.go @@ -6,10 +6,11 @@ import ( "errors" "fmt" "github.com/zeromicro/go-zero/core/logx" - "tianyuan-api/pkg/crypto" "io" "net/http" "strconv" + "tianyuan-api/apps/api/internal/config" + "tianyuan-api/pkg/crypto" "time" ) @@ -25,15 +26,13 @@ type WestResp struct { Reason string `json:"reason"` } type WestDexService struct { - Key string - SecretID string + config config.WestConfig } // NewWestDexService 是一个构造函数,用于初始化 WestDexService -func NewWestDexService(key, secretID string) *WestDexService { +func NewWestDexService(config config.WestConfig) *WestDexService { return &WestDexService{ - Key: key, - SecretID: secretID, + config: config, } } @@ -43,8 +42,7 @@ func (w *WestDexService) CallAPI(code string, reqData map[string]interface{}) (r timestamp := strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10) // 构造请求URL - //https://apimaster.westdex.com.cn - reqUrl := fmt.Sprintf("http://proxy.tianyuanapi.com/api/invoke/%s/%s?timestamp=%s", w.SecretID, code, timestamp) + reqUrl := fmt.Sprintf("%s/%s/%s?timestamp=%s", w.config.Url, w.config.SecretId, code, timestamp) // 将请求参数编码为JSON格式 data := map[string]interface{}{ @@ -99,7 +97,7 @@ func (w *WestDexService) CallAPI(code string, reqData map[string]interface{}) (r } // 解密响应数据 - decryptedData, DecryptErr := crypto.WestDexDecrypt(westDexResp.Data, w.Key) + decryptedData, DecryptErr := crypto.WestDexDecrypt(westDexResp.Data, w.config.Key) if DecryptErr != nil { logx.Errorf("【西部数据请求】响应数据解密错误: %v", DecryptErr) return nil, DecryptErr diff --git a/apps/api/internal/svc/servicecontext.go b/apps/api/internal/svc/servicecontext.go index bd9e14e..f6f9e58 100644 --- a/apps/api/internal/svc/servicecontext.go +++ b/apps/api/internal/svc/servicecontext.go @@ -45,6 +45,6 @@ func NewServiceContext(c config.Config) *ServiceContext { UserProductRpc: userProductRpc, ApiAuthInterceptor: middleware.NewApiAuthInterceptorMiddleware(whitelistRpc, secretRpc, userProductRpc, rds).Handle, KqPusherClient: kq.NewPusher(c.KqPusherConf.Brokers, c.KqPusherConf.Topic), - WestDexService: service.NewWestDexService(c.WestConfig.Key, c.WestConfig.SecretId), // 假设你将密钥和 ID 配置在 config 中 + WestDexService: service.NewWestDexService(c.WestConfig), // 假设你将密钥和 ID 配置在 config 中 } } diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 5198a21..4882eb0 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -1,5 +1,5 @@ version: '3' -services:e +services: tyapi_etcd: image: bitnami/etcd container_name: tyapi_etcd @@ -183,6 +183,7 @@ services:e - tyapi_mysql - tyapi_redis - tyapi_etcd + - tyapi_sentinel networks: - tyapi_network restart: always diff --git a/docker-compose.yml b/docker-compose.yml index 0295e0e..6278808 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -170,6 +170,7 @@ services: - tyapi_mysql - tyapi_redis - tyapi_etcd + - tyapi_sentinel networks: - tyapi_network restart: always