123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package eta_trial
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/eta_trial"
- "eta_gn/eta_api/utils"
- "fmt"
- "io/ioutil"
- "net/http"
- "strings"
- )
- type EtaTrialQuestionnaireListResp struct {
- Code int `json:"code" description:"状态码"`
- Msg string `json:"msg" description:"提示信息"`
- Data eta_trial.EtaTrialQuestionnaireResp `json:"data" description:"返回数据"`
- ErrMsg string `json:"-" description:"错误信息,不用返回给前端,只是做日志记录"`
- }
- // GetEtaTrialQuestionnaireList CRM_ETA服务-获取问卷列表
- func GetEtaTrialQuestionnaireList() (res eta_trial.EtaTrialQuestionnaireResp, err error) {
- url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta_trial/questionnaire/list")
- body := ioutil.NopCloser(strings.NewReader(""))
- client := &http.Client{}
- req, e := http.NewRequest("POST", url, body)
- 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)
- req.Header.Set("Authorization", utils.CrmEtaAuthorization)
- resp, e := client.Do(req)
- if e != nil {
- err = fmt.Errorf("http client do err: %s", e.Error())
- return
- }
- defer func() {
- _ = resp.Body.Close()
- }()
- b, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = fmt.Errorf("resp body read err: %s", e.Error())
- return
- }
- if len(b) == 0 {
- err = fmt.Errorf("resp body is empty")
- return
- }
- // 生产环境解密, 注意有个坑前后的双引号
- if utils.RunMode == "release" {
- str := string(b)
- str = strings.Trim(str, `"`)
- b = utils.DesBase64Decrypt([]byte(str), utils.CrmEtaServerDes3Key)
- }
- result := new(EtaTrialQuestionnaireListResp)
- if e = json.Unmarshal(b, &result); e != nil {
- err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
- return
- }
- if result.Code != 200 {
- err = fmt.Errorf("result: %s", string(b))
- return
- }
- res = result.Data
- return
- }
- type EtaTrialQuestionnaireCommitReq struct {
- List []eta_trial.EtaTrialQuestionnaireRecord
- }
- // EtaTrialQuestionnaireCommit CRM_ETA服务-提交问卷调查
- func EtaTrialQuestionnaireCommit(pars EtaTrialQuestionnaireCommitReq) (res bool, err error) {
- url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta_trial/questionnaire/commit")
- params, e := json.Marshal(pars)
- if e != nil {
- err = fmt.Errorf("data json marshal err: %s", e.Error())
- return
- }
- body := ioutil.NopCloser(strings.NewReader(string(params)))
- client := &http.Client{}
- req, e := http.NewRequest("POST", url, body)
- 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)
- req.Header.Set("Authorization", utils.CrmEtaAuthorization)
- resp, e := client.Do(req)
- if e != nil {
- err = fmt.Errorf("http client do err: %s", e.Error())
- return
- }
- defer func() {
- _ = resp.Body.Close()
- }()
- b, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = fmt.Errorf("resp body read err: %s", e.Error())
- return
- }
- if len(b) == 0 {
- err = fmt.Errorf("resp body is empty")
- return
- }
- // 生产环境解密, 注意有个坑前后的双引号
- if utils.RunMode == "release" {
- str := string(b)
- str = strings.Trim(str, `"`)
- b = utils.DesBase64Decrypt([]byte(str), utils.CrmEtaServerDes3Key)
- }
- result := new(models.ResultData)
- if e = json.Unmarshal(b, &result); e != nil {
- err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
- return
- }
- if result.Code != 200 {
- err = fmt.Errorf("result: %s", string(b))
- return
- }
- res = true
- return
- }
|