修正west url环境区分
This commit is contained in:
parent
b8d9a72dac
commit
a8e6836731
@ -16,5 +16,6 @@ KqPusherConf:
|
|||||||
- 127.0.0.1:9092
|
- 127.0.0.1:9092
|
||||||
Topic: apirequest
|
Topic: apirequest
|
||||||
WestConfig:
|
WestConfig:
|
||||||
|
Url: "http://proxy.tianyuanapi.com/api/invoke"
|
||||||
Key: "121a1e41fc1690dd6b90afbcacd80cf4"
|
Key: "121a1e41fc1690dd6b90afbcacd80cf4"
|
||||||
SecretId: "449159"
|
SecretId: "449159"
|
@ -16,5 +16,6 @@ KqPusherConf:
|
|||||||
- tyapi_kafka:9092
|
- tyapi_kafka:9092
|
||||||
Topic: apirequest
|
Topic: apirequest
|
||||||
WestConfig:
|
WestConfig:
|
||||||
|
Url: "https://apimaster.westdex.com.cn/api/invoke"
|
||||||
key: "121a1e41fc1690dd6b90afbcacd80cf4"
|
key: "121a1e41fc1690dd6b90afbcacd80cf4"
|
||||||
secretId: "449159"
|
secretId: "449159"
|
@ -19,6 +19,7 @@ type KqPusherConf struct {
|
|||||||
Topic string
|
Topic string
|
||||||
}
|
}
|
||||||
type WestConfig struct {
|
type WestConfig struct {
|
||||||
|
Url string
|
||||||
Key string
|
Key string
|
||||||
SecretId string
|
SecretId string
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,11 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"tianyuan-api/pkg/crypto"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"tianyuan-api/apps/api/internal/config"
|
||||||
|
"tianyuan-api/pkg/crypto"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,15 +26,13 @@ type WestResp struct {
|
|||||||
Reason string `json:"reason"`
|
Reason string `json:"reason"`
|
||||||
}
|
}
|
||||||
type WestDexService struct {
|
type WestDexService struct {
|
||||||
Key string
|
config config.WestConfig
|
||||||
SecretID string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWestDexService 是一个构造函数,用于初始化 WestDexService
|
// NewWestDexService 是一个构造函数,用于初始化 WestDexService
|
||||||
func NewWestDexService(key, secretID string) *WestDexService {
|
func NewWestDexService(config config.WestConfig) *WestDexService {
|
||||||
return &WestDexService{
|
return &WestDexService{
|
||||||
Key: key,
|
config: config,
|
||||||
SecretID: secretID,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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)
|
timestamp := strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10)
|
||||||
|
|
||||||
// 构造请求URL
|
// 构造请求URL
|
||||||
//https://apimaster.westdex.com.cn
|
reqUrl := fmt.Sprintf("%s/%s/%s?timestamp=%s", w.config.Url, w.config.SecretId, code, timestamp)
|
||||||
reqUrl := fmt.Sprintf("http://proxy.tianyuanapi.com/api/invoke/%s/%s?timestamp=%s", w.SecretID, code, timestamp)
|
|
||||||
|
|
||||||
// 将请求参数编码为JSON格式
|
// 将请求参数编码为JSON格式
|
||||||
data := map[string]interface{}{
|
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 {
|
if DecryptErr != nil {
|
||||||
logx.Errorf("【西部数据请求】响应数据解密错误: %v", DecryptErr)
|
logx.Errorf("【西部数据请求】响应数据解密错误: %v", DecryptErr)
|
||||||
return nil, DecryptErr
|
return nil, DecryptErr
|
||||||
|
@ -45,6 +45,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
UserProductRpc: userProductRpc,
|
UserProductRpc: userProductRpc,
|
||||||
ApiAuthInterceptor: middleware.NewApiAuthInterceptorMiddleware(whitelistRpc, secretRpc, userProductRpc, rds).Handle,
|
ApiAuthInterceptor: middleware.NewApiAuthInterceptorMiddleware(whitelistRpc, secretRpc, userProductRpc, rds).Handle,
|
||||||
KqPusherClient: kq.NewPusher(c.KqPusherConf.Brokers, c.KqPusherConf.Topic),
|
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 中
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:e
|
services:
|
||||||
tyapi_etcd:
|
tyapi_etcd:
|
||||||
image: bitnami/etcd
|
image: bitnami/etcd
|
||||||
container_name: tyapi_etcd
|
container_name: tyapi_etcd
|
||||||
@ -183,6 +183,7 @@ services:e
|
|||||||
- tyapi_mysql
|
- tyapi_mysql
|
||||||
- tyapi_redis
|
- tyapi_redis
|
||||||
- tyapi_etcd
|
- tyapi_etcd
|
||||||
|
- tyapi_sentinel
|
||||||
networks:
|
networks:
|
||||||
- tyapi_network
|
- tyapi_network
|
||||||
restart: always
|
restart: always
|
||||||
|
@ -170,6 +170,7 @@ services:
|
|||||||
- tyapi_mysql
|
- tyapi_mysql
|
||||||
- tyapi_redis
|
- tyapi_redis
|
||||||
- tyapi_etcd
|
- tyapi_etcd
|
||||||
|
- tyapi_sentinel
|
||||||
networks:
|
networks:
|
||||||
- tyapi_network
|
- tyapi_network
|
||||||
restart: always
|
restart: always
|
||||||
|
Loading…
Reference in New Issue
Block a user