|
@@ -21,6 +21,8 @@ import (
|
|
|
var (
|
|
|
ServerUrl = "http://127.0.0.1:5008/"
|
|
|
Cygx_activity_sigin_html = "cygx_activity_sigin_html"
|
|
|
+ Cygx_mp3_html = "cygx_mp3_html"
|
|
|
+ Cygx_mp4_html = "cygx_mp4_html"
|
|
|
)
|
|
|
|
|
|
type Html2ImgResp struct {
|
|
@@ -233,3 +235,81 @@ func MakeActivitySigninImg(activityId int) (imgUrl string, err error) {
|
|
|
err = cygx.AddCygxActivityPoster(item)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// 生成音视频分享封面图
|
|
|
+func MakeCygxMp3HtmlImg(videoDuration string) (imgUrl string, err error) {
|
|
|
+ var msg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil || msg != "" {
|
|
|
+ fmt.Println(err)
|
|
|
+ go alarm_msg.SendAlarmMsg("生成音视频分享封面图,失败 MakeCygxMp3HtmlImg:"+err.Error()+";msg:"+msg, 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ detailConfig, e := cygx.GetCygxConfigDetailByCode(Cygx_mp3_html)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxConfigDetailByCode 获取配置生成音视频分享封面图格式信息失败, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //先转换时长展示样式再替换
|
|
|
+ secondNum, _ := strconv.Atoi(videoDuration)
|
|
|
+ videoDuration = utils.HideSecondsToMs(secondNum)
|
|
|
+
|
|
|
+ configValue := detailConfig.ConfigValue
|
|
|
+ configValue = strings.Replace(configValue, "{{TITLE}}", videoDuration, -1)
|
|
|
+ htm2ImgReq := make(map[string]interface{})
|
|
|
+ htm2ImgReq["html_content"] = configValue
|
|
|
+ htm2ImgReq["width"] = 1364
|
|
|
+ htm2ImgReq["height"] = 2060
|
|
|
+ res, err := postHtml2Img(htm2ImgReq)
|
|
|
+ if err != nil || res == nil {
|
|
|
+ msg = "html转图片请求失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if res.Code != 200 {
|
|
|
+ msg = "html转图片请求失败"
|
|
|
+ err = errors.New("html转图片失败: " + res.Msg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ imgUrl = res.Data
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 生成音视频分享封面图
|
|
|
+func MakeCygxMp4HtmlImg(videoDuration string) (imgUrl string, err error) {
|
|
|
+ var msg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil || msg != "" {
|
|
|
+ fmt.Println(err)
|
|
|
+ go alarm_msg.SendAlarmMsg("生成音视频分享封面图,失败 MakeCygxMp4HtmlImg:"+err.Error()+";msg:"+msg, 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ detailConfig, e := cygx.GetCygxConfigDetailByCode(Cygx_mp4_html)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxConfigDetailByCode 获取配置生成音视频分享封面图格式信息失败, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //先转换时长展示样式再替换
|
|
|
+ secondNum, _ := strconv.Atoi(videoDuration)
|
|
|
+ videoDuration = utils.HideSecondsToMs(secondNum)
|
|
|
+
|
|
|
+ configValue := detailConfig.ConfigValue
|
|
|
+ configValue = strings.Replace(configValue, "{{TITLE}}", videoDuration, -1)
|
|
|
+ htm2ImgReq := make(map[string]interface{})
|
|
|
+ htm2ImgReq["html_content"] = configValue
|
|
|
+ htm2ImgReq["width"] = 1364
|
|
|
+ htm2ImgReq["height"] = 2060
|
|
|
+ res, err := postHtml2Img(htm2ImgReq)
|
|
|
+ if err != nil || res == nil {
|
|
|
+ msg = "html转图片请求失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if res.Code != 200 {
|
|
|
+ msg = "html转图片请求失败"
|
|
|
+ err = errors.New("html转图片失败: " + res.Msg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ imgUrl = res.Data
|
|
|
+ return
|
|
|
+}
|