123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package services
- import (
- "encoding/json"
- "fmt"
- "hongze/hongze_yb/global"
- "hongze/hongze_yb/models/response/chart_info"
- "hongze/hongze_yb/utils"
- "io/ioutil"
- "net/http"
- "strings"
- )
- type ChartCommonDetailReq struct {
- UniqueCode string `description:"图表唯一编码"`
- }
- type ChartCommonDetailResp struct {
- Ret int
- Msg string
- ErrMsg string
- ErrCode string
- Success bool `description:"true 执行成功,false 执行失败"`
- IsSendEmail bool `description:"true 发送邮件,false 不发送邮件"`
- Data *chart_info.ChartLibChartInfoDetailResp
- }
- func GetBalanceChartDetail(uniqueCode string) (respData *chart_info.ChartLibChartInfoDetailResp, err error) {
-
- postUrl := fmt.Sprintf("%s/chart_auth/detail?UniqueCode=%s", global.CONFIG.EtaChartLib.ServerUrl, uniqueCode)
-
- result, err := httpGet(postUrl)
- if err != nil {
- return
- }
-
- var resp ChartCommonDetailResp
- if err = json.Unmarshal(result, &resp); err != nil {
- return
- }
- if resp.Ret != 200 {
- err = fmt.Errorf("%s,%s", resp.Msg, resp.ErrMsg)
- return
- }
- respData = resp.Data
- 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)
- resp, err := client.Do(req)
- if err != nil {
- return nil, err
- }
- defer resp.Body.Close()
- b, err := ioutil.ReadAll(resp.Body)
- fmt.Println("HttpPost:" + string(b))
- return b, err
- }
- func httpGet(url string) ([]byte, error) {
- client := &http.Client{}
- req, err := http.NewRequest("GET", url, nil)
- if err != nil {
- return nil, err
- }
- req.Header.Set("authorization", utils.MD5(global.CONFIG.EtaChartLib.AppNameEn+global.CONFIG.EtaChartLib.Md5Key))
- resp, err := client.Do(req)
- if err != nil {
- return nil, err
- }
- defer resp.Body.Close()
- b, err := ioutil.ReadAll(resp.Body)
- fmt.Println("httpGet:" + string(b))
- return b, err
- }
|