|
@@ -17,7 +17,6 @@ import (
|
|
|
func PublicGetDate(url, authorization string) (body []byte, err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- fmt.Println(url + "Get Err:" + err.Error())
|
|
|
go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", url+"Get ErrMsg:"+err.Error(), utils.EmailSendToUsers)
|
|
|
}
|
|
|
}()
|
|
@@ -25,19 +24,16 @@ func PublicGetDate(url, authorization string) (body []byte, err error) {
|
|
|
client := &nhttp.Client{}
|
|
|
req, err := nhttp.NewRequest(method, url, nil)
|
|
|
if err != nil {
|
|
|
- fmt.Println(url+"Get Err:", err.Error())
|
|
|
return
|
|
|
}
|
|
|
req.Header.Add("Authorization", authorization)
|
|
|
res, err := client.Do(req)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
defer res.Body.Close()
|
|
|
body, err = ioutil.ReadAll(res.Body)
|
|
|
if err != nil {
|
|
|
- fmt.Println("Getres.Body Err:", err.Error())
|
|
|
return
|
|
|
}
|
|
|
return
|
|
@@ -47,7 +43,6 @@ func PublicGetDate(url, authorization string) (body []byte, err error) {
|
|
|
func GetChartListByApi(cont context.Context) (err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- fmt.Println("GetArticleListByApi Err:" + err.Error())
|
|
|
go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
|
|
|
}
|
|
|
}()
|
|
@@ -55,13 +50,11 @@ func GetChartListByApi(cont context.Context) (err error) {
|
|
|
authorization := utils.ApiAuthorization
|
|
|
body, err := PublicGetDate(url, authorization)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
var chartResult models.ChartResultApi
|
|
|
err = json.Unmarshal(body, &chartResult)
|
|
|
if err != nil {
|
|
|
- fmt.Println("Getres.pdfResult Err:", err.Error())
|
|
|
return err
|
|
|
}
|
|
|
for _, v := range chartResult.Data {
|
|
@@ -80,13 +73,11 @@ func GetChartListByApi(cont context.Context) (err error) {
|
|
|
item.Iframe = v.Iframe
|
|
|
count, err := models.GetChartCountById(v.ChartId)
|
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- fmt.Println("GetChartCountById Err:", err.Error())
|
|
|
return err
|
|
|
}
|
|
|
if count == 0 {
|
|
|
_, err := models.AddCygxChart(item)
|
|
|
if err != nil {
|
|
|
- fmt.Println("AddCygxChart Err:", err.Error())
|
|
|
return err
|
|
|
}
|
|
|
} else {
|
|
@@ -104,9 +95,7 @@ func GetChartListByApi(cont context.Context) (err error) {
|
|
|
whereParam := map[string]interface{}{"chart_id": v.ChartId}
|
|
|
err = models.UpdateByExpr(models.CygxChart{}, whereParam, updateParams)
|
|
|
}
|
|
|
- fmt.Println(v)
|
|
|
}
|
|
|
-
|
|
|
return
|
|
|
|
|
|
}
|
|
@@ -115,7 +104,6 @@ func GetChartListByApi(cont context.Context) (err error) {
|
|
|
func GetChartPtagByApi() (items []*models.ChartPtagResp, err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- fmt.Println("GetChartPtagByApi Err:" + err.Error())
|
|
|
go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetChartPtagByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
|
|
|
}
|
|
|
}()
|
|
@@ -123,13 +111,11 @@ func GetChartPtagByApi() (items []*models.ChartPtagResp, err error) {
|
|
|
authorization := utils.ApiAuthorization
|
|
|
body, err := PublicGetDate(url, authorization)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
var chartResult models.ChartPtagResultApi
|
|
|
err = json.Unmarshal(body, &chartResult)
|
|
|
if err != nil {
|
|
|
- fmt.Println("Getres.pdfResult Err:", err.Error())
|
|
|
return
|
|
|
}
|
|
|
for _, v := range chartResult.Data {
|
|
@@ -151,41 +137,46 @@ func GetChartPtagByApi() (items []*models.ChartPtagResp, err error) {
|
|
|
|
|
|
//获取用户的Token
|
|
|
func GetUserTokenByMobile(mobile string) (token string, err error) {
|
|
|
- url := "https://vmp.hzinsights.com/v2api/auth/login"
|
|
|
- method := "POST"
|
|
|
- payload := strings.NewReader(`{
|
|
|
- "phone_number":"` + mobile + `",
|
|
|
- "password":"hz123456"
|
|
|
-}`)
|
|
|
- client := &nhttp.Client{}
|
|
|
- req, err := nhttp.NewRequest(method, url, payload)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- return
|
|
|
+ //缓存校验
|
|
|
+ cacheKey := fmt.Sprint("xygx_chart:chart_token:add:", "Mobile", mobile)
|
|
|
+ ttlTime := utils.Rc.GetRedisTTL(cacheKey)
|
|
|
+ if ttlTime > 0 {
|
|
|
+ token, _ = utils.Rc.RedisString(cacheKey)
|
|
|
}
|
|
|
- req.Header.Add("Content-Type", "application/json")
|
|
|
- req.Header.Add("Cookie", "sessionid=naj5j5kl1jjynh7og1rsaxkl1vrsl829")
|
|
|
-
|
|
|
- res, err := client.Do(req)
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- return
|
|
|
- }
|
|
|
- defer res.Body.Close()
|
|
|
-
|
|
|
- body, err := ioutil.ReadAll(res.Body)
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- return
|
|
|
- }
|
|
|
- var chartResult models.ChartUserTokenResultApi
|
|
|
- err = json.Unmarshal(body, &chartResult)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Getres.pdfResult Err:", err.Error())
|
|
|
- return
|
|
|
+ if token == "" {
|
|
|
+ url := utils.ApiUrl + "auth/login"
|
|
|
+ method := "POST"
|
|
|
+ payload := strings.NewReader(`{
|
|
|
+ "phone_number":"` + mobile + `",
|
|
|
+ "password":"hz123456"}`)
|
|
|
+ client := &nhttp.Client{}
|
|
|
+ req, errReq := nhttp.NewRequest(method, url, payload)
|
|
|
+ if errReq != nil {
|
|
|
+ err = errReq
|
|
|
+ return
|
|
|
+ }
|
|
|
+ req.Header.Add("Content-Type", "application/json")
|
|
|
+ req.Header.Add("Cookie", "sessionid=naj5j5kl1jjynh7og1rsaxkl1vrsl829")
|
|
|
+ res, errReq := client.Do(req)
|
|
|
+ if errReq != nil {
|
|
|
+ err = errReq
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer res.Body.Close()
|
|
|
+ body, errReq := ioutil.ReadAll(res.Body)
|
|
|
+ if errReq != nil {
|
|
|
+ err = errReq
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var chartResult models.ChartUserTokenResultApi
|
|
|
+ errReq = json.Unmarshal(body, &chartResult)
|
|
|
+ if errReq != nil {
|
|
|
+ err = errReq
|
|
|
+ return
|
|
|
+ }
|
|
|
+ token = chartResult.Data.AccessToken
|
|
|
+ utils.Rc.Put(cacheKey, token, time.Hour*24)
|
|
|
}
|
|
|
- token = chartResult.Data.AccessToken
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -193,31 +184,25 @@ func GetUserTokenByMobile(mobile string) (token string, err error) {
|
|
|
func GetChartCollectionByApi(mobile string, take, skip int) (items []*models.HomeChartListResp, err error, total int) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- fmt.Println("GetChartPtagByApi Err:" + err.Error())
|
|
|
go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetChartPtagByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
|
|
|
}
|
|
|
}()
|
|
|
url := utils.ApiUrl + "charts/favorites?take=" + strconv.Itoa(take) + "&skip=" + strconv.Itoa(skip)
|
|
|
authorization, err := GetUserTokenByMobile(mobile)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
authorization = "bearer " + authorization
|
|
|
body, err := PublicGetDate(url, authorization)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
- fmt.Println(string(body))
|
|
|
var chartResult models.ChartFavoritesResultApi
|
|
|
err = json.Unmarshal(body, &chartResult)
|
|
|
if err != nil {
|
|
|
- fmt.Println("Getres.pdfResult Err:", err.Error())
|
|
|
return
|
|
|
}
|
|
|
for _, v := range chartResult.Data {
|
|
|
- fmt.Println(v)
|
|
|
item := new(models.HomeChartListResp)
|
|
|
item.ChartId = v.ChartId
|
|
|
item.Title = v.ChartInfo.Title
|
|
@@ -241,15 +226,11 @@ func GetIsCollectionChart(mobile string, chartId int) (isCollection bool, err er
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- fmt.Println(list)
|
|
|
- fmt.Println(mobile)
|
|
|
for _, v := range list {
|
|
|
- fmt.Println(v.ChartId)
|
|
|
if v.ChartId == chartId {
|
|
|
isCollection = true
|
|
|
}
|
|
|
}
|
|
|
- fmt.Println(isCollection)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -257,20 +238,17 @@ func GetIsCollectionChart(mobile string, chartId int) (isCollection bool, err er
|
|
|
func AddCollectionChart(mobile string, chartId int) (err error) {
|
|
|
authorization, err := GetUserTokenByMobile(mobile)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
authorization = "bearer " + authorization
|
|
|
- url := "https://vmp.hzinsights.com/v2api/charts/favorites"
|
|
|
+ url := utils.ApiUrl + "charts/favorites"
|
|
|
method := "POST"
|
|
|
payload := strings.NewReader(`{
|
|
|
"chart_id":` + strconv.Itoa(chartId) + `
|
|
|
}`)
|
|
|
client := &nhttp.Client{}
|
|
|
req, err := nhttp.NewRequest(method, url, payload)
|
|
|
- fmt.Println("添加")
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
req.Header.Add("Authorization", authorization)
|
|
@@ -278,17 +256,13 @@ func AddCollectionChart(mobile string, chartId int) (err error) {
|
|
|
req.Header.Add("Cookie", "sessionid=naj5j5kl1jjynh7og1rsaxkl1vrsl829")
|
|
|
res, err := client.Do(req)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
defer res.Body.Close()
|
|
|
-
|
|
|
- body, err := ioutil.ReadAll(res.Body)
|
|
|
+ _, err = ioutil.ReadAll(res.Body)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
- fmt.Println(string(body))
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -296,31 +270,26 @@ func AddCollectionChart(mobile string, chartId int) (err error) {
|
|
|
func DeleteCollectionChart(mobile string, chartId int) (err error) {
|
|
|
authorization, err := GetUserTokenByMobile(mobile)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
authorization = "bearer " + authorization
|
|
|
- url := "https://vmp.hzinsights.com/v2api/charts/favorites/" + strconv.Itoa(chartId)
|
|
|
+ url := utils.ApiUrl + "charts/favorites/" + strconv.Itoa(chartId)
|
|
|
method := "DELETE"
|
|
|
client := &nhttp.Client{}
|
|
|
req, err := nhttp.NewRequest(method, url, nil)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
req.Header.Add("Authorization", authorization)
|
|
|
req.Header.Add("Cookie", "sessionid=naj5j5kl1jjynh7og1rsaxkl1vrsl829")
|
|
|
res, err := client.Do(req)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
defer res.Body.Close()
|
|
|
- body, err := ioutil.ReadAll(res.Body)
|
|
|
+ _, err = ioutil.ReadAll(res.Body)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
- fmt.Println(string(body))
|
|
|
return
|
|
|
}
|