增加了app的配置文件

This commit is contained in:
wucongxing8150 2024-09-20 14:38:46 +08:00
parent 63ab3fc50c
commit 4f47c2922e
6 changed files with 35 additions and 23 deletions

View File

@ -69,4 +69,11 @@ amqp:
port: 5672
user: gdxz_2022rabbitmq
password: qwr2p&¥e@3.2p
vhost: gdxz_hepa
vhost: gdxz_hepa
# [app]
app:
apiUrl: https://dev-wx.igandan.com
secretKey: RY8pcn04#TSdzHVX6YgWnyCue9!T&QP^
imagePrefix: https://dev-doc.igandan.com/app
platform: suanyisuan

8
config/app.go Normal file
View File

@ -0,0 +1,8 @@
package config
type App struct {
ApiUrl string `mapstructure:"apiUrl" json:"apiUrl" yaml:"apiUrl"`
SecretKey string `mapstructure:"secretKey" json:"secretKey" yaml:"secretKey"`
ImagePrefix string `mapstructure:"imagePrefix" json:"imagePrefix" yaml:"imagePrefix"`
Platform string `mapstructure:"platform" json:"platform" yaml:"platform"`
}

View File

@ -14,4 +14,5 @@ type Config struct {
Dysms Dysms `mapstructure:"dysms" json:"dysms" yaml:"dysms"`
Wechat Wechat `mapstructure:"wechat" json:"wechat" yaml:"wechat"`
Amqp Amqp `mapstructure:"amqp" json:"amqp" yaml:"amqp"`
App App `mapstructure:"app" json:"app" yaml:"app"`
}

View File

@ -8,13 +8,12 @@ import (
"strings"
)
const (
apiUrl = "https://dev-wx.igandan.com" // 接口地址
secretKey = "RY8pcn04#TSdzHVX6YgWnyCue9!T&QP^" // 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
platform = "suanyisuan" // 所属平台
devImagePrefix = "https://dev-doc.igandan.com/app" // 测试环境图片地址前缀
prodImagePrefix = "https://dev-doc.igandan.com/app" // 正式环境图片地址前缀
)
//const (
// apiUrl = "https://dev-wx.igandan.com" // 接口地址
// secretKey = "RY8pcn04#TSdzHVX6YgWnyCue9!T&QP^" // 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
// platform = "suanyisuan" // 所属平台
// imagePrefix = "https://dev-doc.igandan.com/app" // 图片地址前缀
//)
// GenSignature 生成签名信息
func GenSignature(params map[string]interface{}) (string, error) {
@ -27,7 +26,7 @@ func GenSignature(params map[string]interface{}) (string, error) {
return "", err
}
sing := utils.HmacSHA256(string(jsonData), secretKey)
sing := utils.HmacSHA256(string(jsonData), config.C.App.SecretKey)
return sing, nil
}
@ -77,12 +76,7 @@ func HandleImagePrefix(u string) (string, error) {
// 去除oss前缀
u = utils.RemoveOssDomain(u)
var imgPath string
if config.C.Env == "prod" {
imgPath = strings.Replace(u, devImagePrefix, "", 1)
} else {
imgPath = strings.Replace(u, prodImagePrefix, "", 1)
}
imgPath := strings.Replace(u, config.C.App.ImagePrefix, "", 1)
if imgPath == "/null" {
return "", nil

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"hepa-calc-api/config"
"hepa-calc-api/utils"
"io"
"net/http"
@ -84,7 +85,7 @@ func GetUserCaseByAppIden(appIden string) (g *GetUserCaseByAppIdenResponse, err
// 准备要发送的 JSON 数据
requestData := GetUserCaseByAppIdenRequest{
PatientUuid: appIden,
Platform: platform,
Platform: config.C.App.Platform,
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
}
@ -110,7 +111,7 @@ func GetUserCaseByAppIden(appIden string) (g *GetUserCaseByAppIdenResponse, err
requestBody := bytes.NewBuffer(jsonData)
// 设置请求 URL
url := apiUrl + "/patient-api/getDiseaseInfo"
url := config.C.App.ApiUrl + "/patient-api/getDiseaseInfo"
// 创建 POST 请求
req, err := http.NewRequest("POST", url, requestBody)
@ -164,7 +165,7 @@ func GetUserCaseByAppIden(appIden string) (g *GetUserCaseByAppIdenResponse, err
// UpdateUserCase 修改用户病例
func UpdateUserCase(reqData UpdateUserCaseRequest) (g *UpdateUserCaseResponse, err error) {
reqData.Platform = platform
reqData.Platform = config.C.App.Platform
reqData.Timestamp = strconv.FormatInt(time.Now().Unix(), 10)
// 将 JSON 数据编码为字节数组
@ -189,7 +190,7 @@ func UpdateUserCase(reqData UpdateUserCaseRequest) (g *UpdateUserCaseResponse, e
requestBody := bytes.NewBuffer(jsonData)
// 设置请求 URL
url := apiUrl + "/patient-api/upDiseaseInfo"
url := config.C.App.ApiUrl + "/patient-api/upDiseaseInfo"
// 创建 POST 请求
req, err := http.NewRequest("POST", url, requestBody)

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"hepa-calc-api/config"
"hepa-calc-api/utils"
"io"
"net/http"
@ -81,7 +82,7 @@ func GetInfoByMobile(mobile string) (g *GetInfoByMobileResponse, err error) {
// 准备要发送的 JSON 数据
requestData := GetInfoByMobileRequest{
Mobile: mobile,
Platform: platform,
Platform: config.C.App.Platform,
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
}
@ -107,7 +108,7 @@ func GetInfoByMobile(mobile string) (g *GetInfoByMobileResponse, err error) {
requestBody := bytes.NewBuffer(jsonData)
// 设置请求 URL
url := apiUrl + "/patient-api/getInfo"
url := config.C.App.ApiUrl + "/patient-api/getInfo"
// 创建 POST 请求
req, err := http.NewRequest("POST", url, requestBody)
@ -161,7 +162,7 @@ func GetInfoByMobile(mobile string) (g *GetInfoByMobileResponse, err error) {
// UpdateInfo 修改用户信息
func UpdateInfo(reqData UpdateInfoRequest) (g *UpdateInfoResponse, err error) {
reqData.Platform = platform
reqData.Platform = config.C.App.Platform
reqData.Timestamp = strconv.FormatInt(time.Now().Unix(), 10)
// 将 JSON 数据编码为字节数组
@ -186,7 +187,7 @@ func UpdateInfo(reqData UpdateInfoRequest) (g *UpdateInfoResponse, err error) {
requestBody := bytes.NewBuffer(jsonData)
// 设置请求 URL
url := apiUrl + "/patient-api/updateInfo"
url := config.C.App.ApiUrl + "/patient-api/updateInfo"
// 创建 POST 请求
req, err := http.NewRequest("POST", url, requestBody)