diff --git a/config.yaml b/config.yaml index 68f7024..e2f02c2 100644 --- a/config.yaml +++ b/config.yaml @@ -69,4 +69,11 @@ amqp: port: 5672 user: gdxz_2022rabbitmq password: qwr2p&¥e@3.2p - vhost: gdxz_hepa \ No newline at end of file + 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 \ No newline at end of file diff --git a/config/app.go b/config/app.go new file mode 100644 index 0000000..2e83620 --- /dev/null +++ b/config/app.go @@ -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"` +} diff --git a/config/config.go b/config/config.go index 4a24ee6..709ebe6 100644 --- a/config/config.go +++ b/config/config.go @@ -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"` } diff --git a/extend/app/base.go b/extend/app/base.go index c8c299a..faf7226 100644 --- a/extend/app/base.go +++ b/extend/app/base.go @@ -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 diff --git a/extend/app/userCase.go b/extend/app/userCase.go index 3974a58..1d20e99 100644 --- a/extend/app/userCase.go +++ b/extend/app/userCase.go @@ -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) diff --git a/extend/app/userInfo.go b/extend/app/userInfo.go index 61ddd34..3436a80 100644 --- a/extend/app/userInfo.go +++ b/extend/app/userInfo.go @@ -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)