Browse Source

no message

xingzai 1 năm trước cách đây
mục cha
commit
dd56ac5a62

+ 10 - 2
controllers/cygx/askserie_video.go

@@ -78,13 +78,15 @@ func (this *AskserieVideoController) PreserveAndPublish() {
 	item.ChartPermissionName = chartPermissionName
 	item.PublishStatus = 1
 	item.BackgroundImg = backgroundImg
-	item.ShareImg = shareImg
+
 	item.AdminId = sysUser.AdminId
 	item.ModifyDate = time.Now()
 	item.PublishDate = time.Now()
 	item.CreateTime = time.Now()
 
 	if askserieVideoId == 0 {
+		shareImg, _ = cygxService.MakeCygxMp3HtmlImg(videoDuration) //生成分享图片
+		item.ShareImg = shareImg
 		//新增
 		newId, err := cygx.AddCygxAskserieVideo(item, industrialManagementIds)
 		if err != nil {
@@ -95,12 +97,18 @@ func (this *AskserieVideoController) PreserveAndPublish() {
 		askserieVideoId = int(newId)
 	} else {
 		//更新
-		_, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
+		detail, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
 		if err != nil {
 			br.Msg = "详情不存在"
 			br.ErrMsg = "获取失败,Err:" + err.Error()
 			return
 		}
+		//如果时长有变更就更新分享图片
+		if detail.VideoDuration != videoDuration {
+			shareImg, _ = cygxService.MakeCygxMp3HtmlImg(videoDuration) //生成分享图片
+			item.ShareImg = shareImg
+		}
+
 		err = cygx.UpdateCygxAskserieVideo(item, industrialManagementIds)
 		if err != nil {
 			br.Msg = "保存失败"

+ 2 - 1
controllers/cygx/micro_roadshow.go

@@ -254,7 +254,8 @@ func (this *MicroRoadshowController) Add() {
 			return
 		}
 	}
-
+	shareImg, _ := cygxService.MakeCygxMp4HtmlImg(req.VideoDuration) //生成分享图片
+	req.ShareImgUrl = shareImg
 	if req.VideoId > 0 {
 		//更新
 		item := cygx.CygxMicroRoadshowVideo{

+ 6 - 1
services/cygx/activity_ocr.go

@@ -175,6 +175,8 @@ func UpdateActivityVideoAndVoice(activityInfo *cygx.ActivityDetail, itemVoice *c
 			err = errors.New("GetCygxActivityVoiceCount" + e.Error())
 			return
 		}
+		shareImg, _ := MakeCygxMp3HtmlImg(itemVoice.VoicePlaySeconds) //生成分享图片
+		itemVoice.ShareImg = shareImg
 		//如果等于0就新增,反之就修改
 		if total == 0 {
 			newId, e := cygx.AddCygxActivityVoice(itemVoice)
@@ -204,7 +206,6 @@ func UpdateActivityVideoAndVoice(activityInfo *cygx.ActivityDetail, itemVoice *c
 				err = errors.New("DeleteCygxActivityVoice" + e.Error())
 				return
 			}
-
 			go UpdateActivityVoiceResourceData(voiceDetail.ActivityVoiceId) //写入首页最新  cygx_resource_data 表
 		}
 	}
@@ -218,6 +219,10 @@ func UpdateActivityVideoAndVoice(activityInfo *cygx.ActivityDetail, itemVoice *c
 			err = errors.New("GetActivityVideoCount" + e.Error())
 			return
 		}
+
+		shareImg, _ := MakeCygxMp4HtmlImg(itemVideo.VideoDuration) //生成分享图片
+		itemVideo.ShareImg = shareImg
+
 		//视频文件更换阿里云oss地址 避免卡顿
 		var newOssUrl string
 		newOssUrl = strings.Replace(itemVideo.VideoUrl, "https://hzstatic.hzinsights.com", "https://hzchart.oss-accelerate.aliyuncs.com", -1)

+ 80 - 0
services/cygx/activity_poster.go

@@ -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
+}

+ 25 - 1
utils/common.go

@@ -1095,6 +1095,30 @@ func GetAttendanceDetailSeconds(secondNum int) string {
 	return timeStr
 }
 
+// 音视频时长秒转换成 分秒字符串样式
+func HideSecondsToMs(secondNum int) string {
+	var formatString string
+	m := secondNum / 60
+	s := secondNum % 60
+
+	if m == 0 {
+		formatString = fmt.Sprint("00:")
+	} else if m > 0 && m < 10 {
+		formatString = fmt.Sprint("0", m, ":")
+	} else {
+		formatString = fmt.Sprint(m, ":")
+	}
+
+	if s == 0 {
+		formatString += fmt.Sprint("00")
+	} else if s > 0 && s < 10 {
+		formatString += fmt.Sprint("0", s)
+	} else {
+		formatString += fmt.Sprint(s)
+	}
+	return formatString
+}
+
 // SubStr 截取字符串(中文)
 func SubStr(str string, subLen int) string {
 	strRune := []rune(str)
@@ -2110,4 +2134,4 @@ func ArticleHasImgUrl(body string) (hasImg bool, err error) {
 		hasImg = true
 	})
 	return
-}
+}