Forráskód Böngészése

Merge branch 'needs_fix' into debug

hsun 2 éve
szülő
commit
77c73f9548

+ 25 - 0
controller/report/report.go

@@ -3,6 +3,8 @@ package report
 import (
 	"github.com/gin-gonic/gin"
 	"hongze/hongze_yb/controller/response"
+	"hongze/hongze_yb/models/request"
+	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services/report"
 	userService "hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/utils"
@@ -195,4 +197,27 @@ func TickerData(c *gin.Context)  {
 	}
 	response.OkData("查询成功", chapterDetail, c )
 	return
+}
+
+// RddpShareImg 日度点评分享图(要得急,先这么写吧=_=!)
+func RddpShareImg(c *gin.Context)  {
+	var req request.RddpReportShareImgReq
+	if c.ShouldBind(&req) != nil {
+		response.Fail("参数异常", c)
+		return
+	}
+	defaultImg := "https://hzstatic.hzinsights.com/static/icon/hzyb/rddp-share-bg.png"
+	if req.Title == "" {
+		response.OkData("获取成功", defaultImg, c)
+		return
+	}
+	imgUrl, err := services.GetRddpShareImg(req.Title)
+	if err != nil {
+		response.FailData("获取分享海报失败", "获取分享海报失败, Err: "+err.Error(), c)
+		return
+	}
+	if imgUrl == "" {
+		imgUrl = defaultImg
+	}
+	response.OkData("获取成功", imgUrl, c)
 }

+ 5 - 0
models/request/public.go

@@ -0,0 +1,5 @@
+package request
+
+type RddpReportShareImgReq struct {
+	Title string `description:"标题" json:"title"`
+}

+ 1 - 0
routers/report.go

@@ -14,6 +14,7 @@ func InitReport(r *gin.Engine)  {
 	rGroup.GET("/list", report.List)
 	rGroup.GET("/collect", report.CollectReportList)
 	rGroup.GET("/search", report.Search)
+	rGroup.POST("/detail/rddp_share_img", report.RddpShareImg)
 
 	rGroup2 := r.Group("api/classify").Use(middleware.Token())
 	rGroup2.GET("/ficc", report.ClassifyFirstList)

+ 30 - 0
services/share_poster.go

@@ -476,3 +476,33 @@ func fillContent2Html(source, pars, sunCodeUrl string, height int) (contentStr s
 	contentStr = strings.Replace(contentStr, "{{SUN_CODE}}", sunCodeUrl, 1)
 	return
 }
+
+// GetRddpShareImg 获取日度点评分享图
+func GetRddpShareImg(title string) (imgUrl string, err error) {
+	if title == "" {
+		return
+	}
+	template := fmt.Sprint("static/htm2img/rddp-share.html")
+	contentByte, e := ioutil.ReadFile(template)
+	if e != nil {
+		err = errors.New("读取模板失败, Err: " + e.Error())
+		return
+	}
+	contentStr := string(contentByte)
+	contentStr = strings.Replace(contentStr, "{{TITLE}}", title, 1)
+	htm2ImgReq := make(map[string]interface{})
+	htm2ImgReq["html_content"] = contentStr
+	htm2ImgReq["width"] = 1000
+	htm2ImgReq["height"] = 800
+	res, e := postHtml2Img(htm2ImgReq)
+	if e != nil || res == nil {
+		err = errors.New("html转图片请求失败")
+		return
+	}
+	if res.Code != 200 {
+		err = errors.New("html转图片请求失败: " + res.Msg)
+		return
+	}
+	imgUrl = res.Data
+	return
+}

+ 40 - 0
static/htm2img/rddp-share.html

@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <style>
+        html,body{
+            margin: 0;
+            padding: 0;
+        }
+        div{
+            box-sizing: border-box;
+        }
+        .box{
+            width: 1000px;
+            height: 800px;
+            background-color: #ccc;
+            background-image: url('https://hzstatic.hzinsights.com/static/icon/hzyb/rddp-share-bg.png');
+            background-repeat: no-repeat;
+            background-size: cover;
+            display: table-cell;
+            vertical-align: middle;
+        }
+        .text{
+            color: #fff;
+            font-size: 54px;
+            line-height: 1.5;
+            text-align: center;
+            padding: 0 100px;
+        }
+    </style>
+</head>
+<body>
+    <div class="box">
+        <div class="text">{{TITLE}}</div>
+    </div>
+</body>
+</html>