|
@@ -0,0 +1,65 @@
|
|
|
+package eta_forum
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "hongze/hz_crm_api/models"
|
|
|
+ "hongze/hz_crm_api/utils"
|
|
|
+
|
|
|
+ "io/ioutil"
|
|
|
+ "net/http"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+// GetForumAdminAuthCodeLib 获取登录凭证
|
|
|
+func GetForumAdminAuthCodeLib(req string) (resp *GetForumAdminAuthCodeResp, err error) {
|
|
|
+ _, resultByte, err := post(req, "/v1/auth/auth_code")
|
|
|
+ err = json.Unmarshal(resultByte, &resp)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// post
|
|
|
+func post(paramStr string, urlStr string) (resp *models.BaseResponse, result []byte, err error) {
|
|
|
+ if utils.ETA_FORUM_HUB_URL == "" {
|
|
|
+ err = fmt.Errorf("ETA社区桥接服务地址为空")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ postUrl := utils.ETA_FORUM_HUB_URL + urlStr
|
|
|
+ result, err = HttpPost(postUrl, paramStr, "application/json")
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("调用ETA社区桥接服务接口失败 error:%s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = json.Unmarshal(result, &resp)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func HttpPost(url, postData string, params ...string) ([]byte, error) {
|
|
|
+ body := ioutil.NopCloser(strings.NewReader(postData))
|
|
|
+ client := &http.Client{}
|
|
|
+ req, err := http.NewRequest("POST", url, body)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ contentType := "application/x-www-form-urlencoded;charset=utf-8"
|
|
|
+ if len(params) > 0 && params[0] != "" {
|
|
|
+ contentType = params[0]
|
|
|
+ }
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+ req.Header.Set("authorization", utils.MD5(utils.ETA_FORUM_HUB_NAME_EN+utils.ETA_FORUM_HUB_MD5_KEY))
|
|
|
+ resp, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+ b, err := ioutil.ReadAll(resp.Body)
|
|
|
+ utils.FileLog.Debug("HttpPost:" + string(b))
|
|
|
+ return b, err
|
|
|
+}
|