|
@@ -1,6 +1,7 @@
|
|
|
package cygx
|
|
|
|
|
|
import (
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"hongze/hz_crm_api/models"
|
|
|
"hongze/hz_crm_api/models/cygx"
|
|
@@ -583,3 +584,72 @@ func DoXzsChooseSend(chartPermissionName string) string {
|
|
|
}
|
|
|
return allIn
|
|
|
}
|
|
|
+
|
|
|
+//func init() {
|
|
|
+// //MakeArticleMomentsImg(1000408)
|
|
|
+// var condition string
|
|
|
+// var pars []interface{}
|
|
|
+// condition = " AND article_type_id > 0 AND publish_status = 1 ORDER BY article_id DESC "
|
|
|
+// list, errList := cygx.GetCygxArticleList(condition, pars, 0, 999)
|
|
|
+// if errList != nil {
|
|
|
+// fmt.Println(errList)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// fmt.Println("list", len(list))
|
|
|
+// //return
|
|
|
+// for k, v := range list {
|
|
|
+// fmt.Println(k)
|
|
|
+// MakeArticleMomentsImg(v.ArticleId)
|
|
|
+// }
|
|
|
+//}
|
|
|
+
|
|
|
+// 生成文章分享到朋友圈的图片
|
|
|
+func MakeArticleMomentsImg(articleId int) {
|
|
|
+ var err error
|
|
|
+ //time.Sleep(3*time.Second) // 有时候同时添加多个活动,延迟三秒
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("err:", err)
|
|
|
+ go alarm_msg.SendAlarmMsg("生成文章分享到朋友圈的图片,MakeArticleMomentsImg Err:"+err.Error()+"文章ID"+strconv.Itoa(articleId), 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ articleInfo, e := cygx.GetArticleInfoOtherByArticleId(articleId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetArticleInfoOtherByArticleId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ configCode := "article_moments_img_html"
|
|
|
+ detailConfig, e := cygx.GetCygxConfigDetailByCode(configCode)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxConfigDetailByCode 获取生成文章分享到朋友圈的图片格式信息失败, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ configValue := detailConfig.ConfigValue
|
|
|
+ configValue = strings.Replace(configValue, "{{Title}}", articleInfo.Title, -1)
|
|
|
+ configValue = strings.Replace(configValue, "{{HeadImgUrl}}", articleInfo.HeadImgUrl, -1)
|
|
|
+ configValue = strings.Replace(configValue, "{{NickName}}", articleInfo.NickName, -1)
|
|
|
+ configValue = strings.Replace(configValue, "{{PublishDate}}", articleInfo.PublishDate.Format(utils.FormatDateTime), -1)
|
|
|
+ configValue = strings.Replace(configValue, "{{Abstract}}", articleInfo.Abstract, -1)
|
|
|
+ configValue = strings.Replace(configValue, "{{BodyText}}", articleInfo.BodyText, -1)
|
|
|
+
|
|
|
+ htm2ImgReq := make(map[string]interface{})
|
|
|
+ htm2ImgReq["html_content"] = configValue
|
|
|
+ htm2ImgReq["width"] = 2250
|
|
|
+ htm2ImgReq["height"] = 3813
|
|
|
+ res, err := postHtml2Img(htm2ImgReq)
|
|
|
+ if err != nil || res == nil {
|
|
|
+ err = errors.New("html转图片失败: " + res.Msg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if res.Code != 200 {
|
|
|
+ err = errors.New("html转图片失败: " + res.Msg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ imgUrl := res.Data
|
|
|
+ //fmt.Println(imgUrl)
|
|
|
+ // 记录海报信息
|
|
|
+ err = cygx.UpdateCygxArticleMomentsImg(imgUrl, articleId)
|
|
|
+ return
|
|
|
+
|
|
|
+}
|