区分环境
This commit is contained in:
@@ -97,9 +97,6 @@ service api-api {
|
||||
|
||||
@handler QYGL6F2D
|
||||
post /QYGL6F2D (request) returns (response)
|
||||
|
||||
@handler QYGL51BC
|
||||
post /QYGL51BC (request) returns (response)
|
||||
}
|
||||
|
||||
@server (
|
||||
@@ -145,10 +142,5 @@ service api-api {
|
||||
@handler JRZQ4AA8
|
||||
post /JRZQ4AA8 (request) returns (response)
|
||||
|
||||
@handler JRZQCEE8
|
||||
post /JRZQCEE8 (request) returns (response)
|
||||
|
||||
@handler JRZQFEF8
|
||||
post /JRZQFEF8 (request) returns (response)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"tianyuan-api/apps/api/internal/config"
|
||||
"tianyuan-api/apps/api/internal/handler"
|
||||
@@ -12,9 +13,23 @@ import (
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/api-api.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
// 读取环境变量 ENV,默认为 "prod"
|
||||
env := os.Getenv("ENV")
|
||||
if env == "" {
|
||||
env = "production"
|
||||
}
|
||||
|
||||
// 根据 ENV 加载不同的配置文件
|
||||
var defaultConfigFile string
|
||||
if env == "development" {
|
||||
defaultConfigFile = "etc/api-api.dev.yaml" // 开发环境配置
|
||||
} else {
|
||||
defaultConfigFile = "etc/api-api.yaml" // 生产环境配置
|
||||
}
|
||||
|
||||
// 允许通过命令行参数覆盖配置文件路径
|
||||
configFile := flag.String("f", defaultConfigFile, "the config file")
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package product;
|
||||
|
||||
option go_package = "./api";
|
||||
|
||||
service ProductService {
|
||||
// 获取产品列表
|
||||
rpc GetProducts(ProductListReq) returns (ProductListResp);
|
||||
|
||||
// 获取用户开通的产品列表
|
||||
rpc GetUserProducts(UserProductListReq) returns (UserProductListResp);
|
||||
}
|
||||
|
||||
// 获取产品列表的请求
|
||||
message ProductListReq {}
|
||||
|
||||
// 获取产品列表的响应
|
||||
message ProductListResp {
|
||||
repeated ProductItem products = 1;
|
||||
}
|
||||
|
||||
// 产品信息
|
||||
message ProductItem {
|
||||
int64 id = 1; // 产品ID
|
||||
string product_name = 2; // 产品名称
|
||||
string product_code = 3; // 产品编号
|
||||
string product_description = 4; // 产品简介
|
||||
string product_content = 5; // 产品内容
|
||||
float product_price = 6; // 产品价格
|
||||
string created_at = 7; // 产品创建时间
|
||||
}
|
||||
|
||||
// 获取用户开通的产品列表的请求
|
||||
message UserProductListReq {
|
||||
int64 user_id = 1; // 用户ID
|
||||
}
|
||||
|
||||
// 获取用户开通的产品列表的响应
|
||||
message UserProductListResp {
|
||||
repeated UserProductItem user_products = 1;
|
||||
}
|
||||
|
||||
// 用户产品信息
|
||||
message UserProductItem {
|
||||
int64 id = 1; // 用户产品ID
|
||||
int64 user_id = 2; // 用户ID
|
||||
int64 product_id = 3; // 产品ID
|
||||
string activation_date = 4; // 激活时间
|
||||
string expiration_date = 5; // 到期时间
|
||||
}
|
||||
20
apps/api/etc/api-api.dev.yaml
Normal file
20
apps/api/etc/api-api.dev.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
Name: api-api
|
||||
Host: 0.0.0.0
|
||||
Port: 10003
|
||||
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
CacheRedis:
|
||||
- Host: "127.0.0.1:6379"
|
||||
Pass: "" # Redis 密码,如果未设置则留空
|
||||
Type: "node" # 单节点模式
|
||||
SentinelRpc:
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 127.0.0.1:2379
|
||||
Key: sentinel.rpc
|
||||
KqPusherConf:
|
||||
Brokers:
|
||||
- 127.0.0.1:9092
|
||||
Topic: apirequest
|
||||
WestConfig:
|
||||
Key: "121a1e41fc1690dd6b90afbcacd80cf4"
|
||||
SecretId: "449159"
|
||||
@@ -1,19 +1,19 @@
|
||||
Name: api-api
|
||||
Host: 0.0.0.0
|
||||
Port: 10003
|
||||
DataSource: "tianyuanapi:g3h98u0291j@tcp(127.0.0.1:3307)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
DataSource: "tianyuanapi:g3h98u0291j@tcp(tyapi_mysql:3306)/tianyuanapi?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
CacheRedis:
|
||||
- Host: "127.0.0.1:6379"
|
||||
- Host: "tyapi_redis:6379"
|
||||
Pass: "" # Redis 密码,如果未设置则留空
|
||||
Type: "node" # 单节点模式
|
||||
SentinelRpc:
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 127.0.0.1:2379
|
||||
- tyapi_etcd:2379
|
||||
Key: sentinel.rpc
|
||||
KqPusherConf:
|
||||
Brokers:
|
||||
- 127.0.0.1:9092
|
||||
- tyapi_kafka:9092
|
||||
Topic: apirequest
|
||||
WestConfig:
|
||||
key: "121a1e41fc1690dd6b90afbcacd80cf4"
|
||||
|
||||
@@ -2,6 +2,10 @@ package IVYZ
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"tianyuan-api/apps/api/internal/validator"
|
||||
"tianyuan-api/pkg/crypto"
|
||||
|
||||
"tianyuan-api/apps/api/internal/svc"
|
||||
"tianyuan-api/apps/api/internal/types"
|
||||
@@ -24,7 +28,59 @@ func NewIVYZ5733Logic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ5733
|
||||
}
|
||||
|
||||
func (l *IVYZ5733Logic) IVYZ5733(req *types.Request) (resp *types.Response, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
//userId, ok := l.ctx.Value("userId").(int64)
|
||||
//if !ok {
|
||||
// return &types.Response{}, errors.New("系统错误,请联系管理员")
|
||||
//}
|
||||
secretKey, ok := l.ctx.Value("secretKey").(string)
|
||||
if !ok {
|
||||
return &types.Response{}, errors.New("系统错误,请联系管理员")
|
||||
}
|
||||
|
||||
return
|
||||
// 1、解密
|
||||
key, err := hex.DecodeString(secretKey)
|
||||
decryptData, err := crypto.AesDecrypt(req.Data, key)
|
||||
if err != nil || len(decryptData) == 0 {
|
||||
return nil, errors.New("参数解密失败")
|
||||
}
|
||||
|
||||
// 2、校验
|
||||
var data validator.IVYZ5733Request
|
||||
|
||||
if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil {
|
||||
return nil, validatorErr
|
||||
}
|
||||
|
||||
// 3、西部加密
|
||||
westConfig := l.svcCtx.Config.WestConfig
|
||||
name, err := crypto.WestDexEncrypt(data.Name, westConfig.Key)
|
||||
if err != nil {
|
||||
logx.Errorf("西部加密错误:%v", err)
|
||||
return nil, errors.New("业务异常")
|
||||
}
|
||||
idCard, err := crypto.WestDexEncrypt(data.IDCard, westConfig.Key)
|
||||
if err != nil {
|
||||
logx.Errorf("西部加密错误:%v", err)
|
||||
return nil, errors.New("业务异常")
|
||||
}
|
||||
// 4、发送请求到西部
|
||||
westdexRequest := map[string]interface{}{
|
||||
"id": idCard,
|
||||
"name": name,
|
||||
}
|
||||
westResp, err := l.svcCtx.WestDexService.CallAPI("G09GX01", westdexRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 5、响应解析
|
||||
//var respData westmodel.G09GX01Response
|
||||
//unmarshalErr := json.Unmarshal(westResp, &respData)
|
||||
//if unmarshalErr != nil {
|
||||
// return nil, unmarshalErr
|
||||
//}
|
||||
//crypto.AesEncrypt()
|
||||
return &types.Response{
|
||||
Data: string(westResp),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ type FLXG3D56Request struct {
|
||||
Name string `json:"name" validate:"required,min=1,validName"`
|
||||
TimeRange string `json:"time_range" validate:"omitempty,validTimeRange"` // 非必填字段
|
||||
}
|
||||
type YYSYf7dbRequest struct {
|
||||
MobileNo
|
||||
StartDate
|
||||
type IVYZ5733Request struct {
|
||||
Name string `json:"name" validate:"required,min=1,validName"`
|
||||
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user