|
@@ -81,7 +81,76 @@ func HttpEtaBridgePost(urlStr string, param interface{}) (bResult []byte, err er
|
|
|
result := new(BaseEtaBridgeDataResp)
|
|
|
if e = json.Unmarshal(bResult, &result); e != nil {
|
|
|
err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(bResult))
|
|
|
- utils.FileLog.Info("第三方登录(向桥接服务换取token):\n" + string(bResult))
|
|
|
+ utils.FileLog.Info("桥接服务post请求失败:\n" + string(bResult))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if result.Code != 200 {
|
|
|
+ errMsg = result.Msg
|
|
|
+ err = fmt.Errorf("result: %s", string(bResult))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// HttpEtaBridgeGet
|
|
|
+// @Description: eta-bridge的get请求
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-02-28 16:55:02
|
|
|
+// @param urlStr string
|
|
|
+// @param postData string
|
|
|
+// @return bResult []byte
|
|
|
+// @return err error
|
|
|
+// @return errMsg string
|
|
|
+func HttpEtaBridgeGet(urlStr string) (bResult []byte, err error, errMsg string) {
|
|
|
+ if utils.EtaBridgeUrl == "" {
|
|
|
+ errMsg = `未配置第三方的桥接服务地址`
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ postUrl := utils.EtaBridgeUrl + "/api" + urlStr
|
|
|
+
|
|
|
+ client := &http.Client{}
|
|
|
+ req, e := http.NewRequest("GET", postUrl, nil)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("http create request err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ contentType := "application/json;charset=utf-8"
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+
|
|
|
+ checkToken := utils.MD5(utils.EtaBridgeAppNameEn + utils.EtaBridgeMd5Key)
|
|
|
+ req.Header.Set("Authorization", checkToken)
|
|
|
+ resp, e := client.Do(req)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("http client do err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ _ = resp.Body.Close()
|
|
|
+ }()
|
|
|
+ bResult, e = io.ReadAll(resp.Body)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("resp body read err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(bResult) == 0 {
|
|
|
+ err = fmt.Errorf("resp body is empty")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 生产环境解密, 注意有个坑前后的双引号
|
|
|
+ if utils.RunMode == "release" {
|
|
|
+ str := string(bResult)
|
|
|
+ str = strings.Trim(str, `"`)
|
|
|
+ bResult = utils.DesBase64Decrypt([]byte(str), utils.EtaBridgeDesKey)
|
|
|
+ }
|
|
|
+
|
|
|
+ result := new(BaseEtaBridgeDataResp)
|
|
|
+ if e = json.Unmarshal(bResult, &result); e != nil {
|
|
|
+ err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(bResult))
|
|
|
+ utils.FileLog.Info("桥接服务get请求失败:\n" + string(bResult))
|
|
|
return
|
|
|
}
|
|
|
if result.Code != 200 {
|