Przeglądaj źródła

Merge branch 'dev/1.2' into dev/1.3

hsun 1 rok temu
rodzic
commit
9900e286fc

+ 230 - 0
controllers/business_conf.go

@@ -0,0 +1,230 @@
+package controllers
+
+import (
+	"encoding/json"
+	"fmt"
+	"hongze/hz_eta_api/models"
+	"hongze/hz_eta_api/utils"
+	"html"
+	"strconv"
+	"strings"
+	"time"
+)
+
+// BusinessConfController 商家配置
+type BusinessConfController struct {
+	BaseAuthController
+}
+
+// Save
+// @Title 保存配置
+// @Description 保存配置
+// @Param	request	body map[string]interface{} true "type json string"
+// @Success 200 Ret=200 操作成功
+// @router /save [post]
+func (this *BusinessConfController) Save() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req map[string]interface{}
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + e.Error()
+		return
+	}
+
+	// 获取配置信息
+	confOb := new(models.BusinessConf)
+	list, e := confOb.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
+	if e != nil {
+		br.Msg = "保存失败"
+		br.ErrMsg = "获取配置列表失败, Err: " + e.Error()
+		return
+	}
+	confMap := make(map[string]*models.BusinessConf)
+	for _, c := range list {
+		confMap[c.ConfKey] = c
+	}
+
+	// 根据配置类型取值
+	updates := make([]models.BusinessConfUpdate, 0)
+	for k, v := range req {
+		// 过滤掉表中没有的key
+		conf := confMap[k]
+		if conf == nil {
+			continue
+		}
+
+		switch conf.ValType {
+		case 1: // 字符串
+			str, ok := v.(string)
+			if !ok {
+				continue
+			}
+			str = strings.TrimSpace(str)
+			if conf.Necessary == 1 && str == "" {
+				br.Msg = conf.Remark + "不可为空"
+				return
+			}
+			updates = append(updates, models.BusinessConfUpdate{
+				ConfKey: k,
+				ConfVal: str,
+			})
+		case 2: // 数值
+			num, ok := v.(float64)
+			if !ok {
+				continue
+			}
+			if conf.Necessary == 1 && num <= 0 {
+				br.Msg = conf.Remark + "不可为空"
+				return
+			}
+			val := strconv.FormatFloat(num, 'f', 0, 64)
+			updates = append(updates, models.BusinessConfUpdate{
+				ConfKey: k,
+				ConfVal: val,
+			})
+		case 3: // 字符串数组
+			arr, ok := v.([]interface{})
+			if !ok {
+				continue
+			}
+			if conf.Necessary == 1 && len(arr) == 0 {
+				br.Msg = conf.Remark + "不可为空"
+				return
+			}
+			strArr := make([]string, 0)
+			for _, a := range arr {
+				if s, ok2 := a.(string); ok2 {
+					strArr = append(strArr, s)
+				}
+			}
+			val := strings.Join(strArr, ",")
+			updates = append(updates, models.BusinessConfUpdate{
+				ConfKey: k,
+				ConfVal: val,
+			})
+		case 4: // 富文本
+			content, ok := v.(string)
+			if !ok {
+				continue
+			}
+			content = strings.TrimSpace(content)
+			if conf.Necessary == 1 && content == "" {
+				br.Msg = conf.Remark + "不可为空"
+				return
+			}
+			content = html.EscapeString(content)
+			updates = append(updates, models.BusinessConfUpdate{
+				ConfKey: k,
+				ConfVal: content,
+			})
+		}
+	}
+
+	if len(updates) > 0 {
+		if e = models.UpdateBusinessConfMulti(updates); e != nil {
+			br.Msg = "保存失败"
+			br.ErrMsg = "保存商家配置失败, Err: " + e.Error()
+			return
+		}
+	}
+
+	// 操作日志
+	go func() {
+		b, e := json.Marshal(req)
+		if e != nil {
+			return
+		}
+		recordOb := new(models.BusinessConfOperationRecord)
+		recordOb.SysUserId = sysUser.AdminId
+		recordOb.SysRealName = sysUser.RealName
+		recordOb.Content = string(b)
+		recordOb.CreateTime = time.Now().Local()
+		_ = recordOb.Create()
+	}()
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}
+
+// Fetch
+// @Title 获取配置
+// @Description 获取配置
+// @Success 200 Ret=200 获取成功
+// @router /fetch [get]
+func (this *BusinessConfController) Fetch() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	list, e := models.GetBusinessConf()
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取商家配置失败, Err: " + e.Error()
+		return
+	}
+
+	br.Data = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}
+
+// CodeEncrypt
+// @Title 商家编码加密
+// @Description 商家编码加密
+// @Success 200 Ret=200 获取成功
+// @router /code_encrypt [get]
+func (this *BusinessConfController) CodeEncrypt() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	res := ""
+	if utils.BusinessCode != "" {
+		res = utils.MD5(fmt.Sprintf("%s%s", utils.BusinessCode, utils.BusinessCodeSalt))
+	}
+
+	br.Data = res
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}

+ 19 - 1
controllers/ppt_v2.go

@@ -922,6 +922,24 @@ func (this *PptV2Controller) ToEn() {
 		return
 	}
 
+	// 从基础配置中取出第一张封面图, 作为英文PPT的图片, 没有则取原PPT背景图
+	conf, e := models.GetBusinessConf()
+	if e != nil {
+		br.Msg = "获取PPT图配置失败"
+		br.ErrMsg = "获取PPT图配置失败, Err: " + e.Error()
+		return
+	}
+	coverImg := ""
+	if conf[models.BusinessConfEnPptCoverImgs] != "" {
+		imgArr := strings.Split(conf[models.BusinessConfEnPptCoverImgs], ",")
+		if len(imgArr) > 0 {
+			coverImg = imgArr[0]
+		}
+	}
+	if coverImg == "" {
+		coverImg = origin.BackgroundImg
+	}
+
 	_, e = ppt_english.GetPptGroupByGroupIdAdminId(int64(req.GroupId), this.SysUser.AdminId)
 	if e != nil {
 		br.Msg = "目录信息有误"
@@ -939,7 +957,7 @@ func (this *PptV2Controller) ToEn() {
 	var newId int64
 	pptInfo := &ppt_english.PptEnglish{
 		TemplateType:  origin.TemplateType,
-		BackgroundImg: origin.BackgroundImg,
+		BackgroundImg: coverImg,
 		Title:         newTitle,
 		ReportType:    origin.ReportType,
 		PptDate:       origin.PptDate,

+ 167 - 0
models/business_conf.go

@@ -0,0 +1,167 @@
+package models
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"html"
+	"strings"
+	"time"
+)
+
+const (
+	BusinessConfUseXf          = "UseXf"
+	BusinessConfXfAppid        = "XfAppid"
+	BusinessConfXfApiKey       = "XfApiKey"
+	BusinessConfXfApiSecret    = "XfApiSecret"
+	BusinessConfXfVcn          = "XfVcn"
+	BusinessConfEnPptCoverImgs = "EnPptCoverImgs"
+)
+
+// BusinessConf 商户配置表
+type BusinessConf struct {
+	Id         int    `orm:"column(id);pk"`
+	ConfKey    string `description:"配置Key"`
+	ConfVal    string `description:"配置值"`
+	ValType    int    `description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
+	Necessary  int    `description:"是否必填:0-否;1-是"`
+	Remark     string `description:"备注"`
+	CreateTime time.Time
+}
+
+func (m *BusinessConf) TableName() string {
+	return "business_conf"
+}
+
+func (m *BusinessConf) PrimaryId() string {
+	return "id"
+}
+
+func (m *BusinessConf) Create() (err error) {
+	o := orm.NewOrm()
+	id, err := o.Insert(m)
+	if err != nil {
+		return
+	}
+	m.Id = int(id)
+	return
+}
+
+func (m *BusinessConf) CreateMulti(items []*BusinessConf) (err error) {
+	if len(items) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(len(items), items)
+	return
+}
+
+func (m *BusinessConf) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(m, cols...)
+	return
+}
+
+func (m *BusinessConf) Del() (err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
+	_, err = o.Raw(sql, m.Id).Exec()
+	return
+}
+
+func (m *BusinessConf) GetItemById(id int) (item *BusinessConf, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
+	err = o.Raw(sql, id).QueryRow(&item)
+	return
+}
+
+func (m *BusinessConf) GetItemByCondition(condition string, pars []interface{}) (item *BusinessConf, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&item)
+	return
+}
+
+func (m *BusinessConf) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func (m *BusinessConf) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BusinessConf, err error) {
+	o := orm.NewOrm()
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+func (m *BusinessConf) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*BusinessConf, err error) {
+	o := orm.NewOrm()
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+// GetBusinessConf 获取商家配置
+func GetBusinessConf() (list map[string]string, err error) {
+	list = make(map[string]string)
+
+	var items []*BusinessConf
+	o := orm.NewOrm()
+	sql := `SELECT * FROM business_conf`
+	_, err = o.Raw(sql).QueryRows(&items)
+	if err != nil {
+		return
+	}
+
+	for _, v := range items {
+		if v.ValType == 4 {
+			list[v.ConfKey] = html.UnescapeString(v.ConfVal)
+			continue
+		}
+		list[v.ConfKey] = v.ConfVal
+	}
+	return
+}
+
+// BusinessConfUpdate 更新配置
+type BusinessConfUpdate struct {
+	ConfKey string
+	ConfVal string
+}
+
+// UpdateBusinessConfMulti 批量修改配置
+func UpdateBusinessConfMulti(items []BusinessConfUpdate) (err error) {
+	o := orm.NewOrm()
+	p, err := o.Raw("UPDATE business_conf SET conf_val = ? WHERE conf_key = ?").Prepare()
+	if err != nil {
+		return
+	}
+	defer func() {
+		_ = p.Close()
+	}()
+	for _, v := range items {
+		_, err = p.Exec(v.ConfVal, v.ConfKey)
+		if err != nil {
+			return
+		}
+	}
+	return
+}

+ 108 - 0
models/business_conf_operation_record.go

@@ -0,0 +1,108 @@
+package models
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"strings"
+	"time"
+)
+
+// BusinessConfOperationRecord 商户配置操作记录表
+type BusinessConfOperationRecord struct {
+	Id          int       `orm:"column(id);pk"`
+	SysUserId   int       `description:"操作人ID"`
+	SysRealName string    `description:"操作人姓名"`
+	Content     string    `description:"操作数据"`
+	CreateTime  time.Time `description:"操作时间"`
+}
+
+func (m *BusinessConfOperationRecord) TableName() string {
+	return "business_conf_operation_record"
+}
+
+func (m *BusinessConfOperationRecord) PrimaryId() string {
+	return "id"
+}
+
+func (m *BusinessConfOperationRecord) Create() (err error) {
+	o := orm.NewOrm()
+	id, err := o.Insert(m)
+	if err != nil {
+		return
+	}
+	m.Id = int(id)
+	return
+}
+
+func (m *BusinessConfOperationRecord) CreateMulti(items []*BusinessConfOperationRecord) (err error) {
+	if len(items) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(len(items), items)
+	return
+}
+
+func (m *BusinessConfOperationRecord) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(m, cols...)
+	return
+}
+
+func (m *BusinessConfOperationRecord) Del() (err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
+	_, err = o.Raw(sql, m.Id).Exec()
+	return
+}
+
+func (m *BusinessConfOperationRecord) GetItemById(id int) (item *BusinessConfOperationRecord, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
+	err = o.Raw(sql, id).QueryRow(&item)
+	return
+}
+
+func (m *BusinessConfOperationRecord) GetItemByCondition(condition string, pars []interface{}) (item *BusinessConfOperationRecord, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&item)
+	return
+}
+
+func (m *BusinessConfOperationRecord) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func (m *BusinessConfOperationRecord) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BusinessConfOperationRecord, err error) {
+	o := orm.NewOrm()
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+func (m *BusinessConfOperationRecord) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*BusinessConfOperationRecord, err error) {
+	o := orm.NewOrm()
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}

+ 11 - 0
models/db.go

@@ -133,6 +133,9 @@ func init() {
 
 	//AI 聊天记录
 	initAiChat()
+
+	// 商家配置
+	initBusinessConf()
 }
 
 // initSystem 系统表 数据表
@@ -395,3 +398,11 @@ func initAiChat() {
 		new(aimod.AiChat),      //聊天
 	)
 }
+
+// initBusinessConf 商家配置
+func initBusinessConf() {
+	orm.RegisterModel(
+		new(BusinessConf),                // 商家配置表
+		new(BusinessConfOperationRecord), // 商家配置操作记录表
+	)
+}

+ 27 - 0
routers/commentsRouter.go

@@ -4354,6 +4354,33 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_eta_api/controllers:BusinessConfController"] = append(beego.GlobalControllerRouter["hongze/hz_eta_api/controllers:BusinessConfController"],
+        beego.ControllerComments{
+            Method: "CodeEncrypt",
+            Router: `/code_encrypt`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hz_eta_api/controllers:BusinessConfController"] = append(beego.GlobalControllerRouter["hongze/hz_eta_api/controllers:BusinessConfController"],
+        beego.ControllerComments{
+            Method: "Fetch",
+            Router: `/fetch`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hz_eta_api/controllers:BusinessConfController"] = append(beego.GlobalControllerRouter["hongze/hz_eta_api/controllers:BusinessConfController"],
+        beego.ControllerComments{
+            Method: "Save",
+            Router: `/save`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_eta_api/controllers:ClassifyController"] = append(beego.GlobalControllerRouter["hongze/hz_eta_api/controllers:ClassifyController"],
         beego.ControllerComments{
             Method: "Add",

+ 5 - 0
routers/router.go

@@ -259,6 +259,11 @@ func init() {
 				&english_report.EnglishClassifyController{},
 			),
 		),
+		web.NSNamespace("/business_conf",
+			web.NSInclude(
+				&controllers.BusinessConfController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 43 - 14
services/video.go

@@ -6,6 +6,7 @@ import (
 	"encoding/binary"
 	"encoding/json"
 	"errors"
+	"fmt"
 	"github.com/PuerkitoBio/goquery"
 	"github.com/kgiannakakis/mp3duration/src/mp3duration"
 	"hongze/hz_eta_api/models"
@@ -21,10 +22,6 @@ import (
 )
 
 func CreateVideo(report *models.ReportDetail) (err error) {
-	if utils.XfAPPID == `` {
-		// 如果科大讯飞未配置,那么就直接返回,不生成音频了
-		return
-	}
 	defer func() {
 		if err != nil {
 			utils.FileLog.Error("CreateVideo Err:%s", err.Error())
@@ -32,6 +29,24 @@ func CreateVideo(report *models.ReportDetail) (err error) {
 			//go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "Err:"+err.Error(), utils.EmailSendToUsers)
 		}
 	}()
+
+	// 获取基础配置, 若未配置则直接返回
+	conf, e := models.GetBusinessConf()
+	if e != nil {
+		err = fmt.Errorf("获取基础配置失败, Err: " + e.Error())
+		return
+	}
+	if conf[models.BusinessConfUseXf] != "true" {
+		return
+	}
+	if conf[models.BusinessConfXfAppid] == "" || conf[models.BusinessConfXfApiKey] == "" || conf[models.BusinessConfXfApiSecret] == "" || conf[models.BusinessConfXfVcn] == "" {
+		return
+	}
+	var xfReq XfParams
+	xfReq.XfAPPID = conf[models.BusinessConfXfAppid]
+	xfReq.XfAPIKey = conf[models.BusinessConfXfApiKey]
+	xfReq.XfAPISecret = conf[models.BusinessConfXfApiSecret]
+
 	ct, err := time.Parse(utils.FormatDateTime, report.CreateTime)
 	createTime := ct.Format("0102")
 	videoName := report.Title + "(" + createTime + ")"
@@ -46,11 +61,11 @@ func CreateVideo(report *models.ReportDetail) (err error) {
 	}
 
 	param := new(models.XfSendParam)
-	param.Common.AppId = utils.XfAPPID
+	param.Common.AppId = conf[models.BusinessConfXfAppid]
 	param.Business.Aue = "lame"
 	param.Business.Sfl = 1
 	param.Business.Auf = "audio/L16;rate=16000"
-	param.Business.Vcn = utils.XfVcn
+	param.Business.Vcn = conf[models.BusinessConfXfVcn]
 	param.Business.Speed = 50
 	param.Business.Volume = 100
 	param.Business.Pitch = 50
@@ -74,7 +89,7 @@ func CreateVideo(report *models.ReportDetail) (err error) {
 		if err != nil {
 			return err
 		}
-		err = GetXfVideo(result, savePath)
+		err = GetXfVideo(result, savePath, xfReq)
 		if err != nil {
 			err = errors.New("GetXfVideo Err:" + err.Error())
 			utils.FileLog.Error("GetXfVideo err", err.Error())
@@ -192,10 +207,6 @@ func getFourccType(boxHeader BoxHeader) (fourccType string) {
 
 // CreateReportVideo 生成报告video
 func CreateReportVideo(reportTitle, reportContent, reportTime string) (uploadUrl, videoName, sizeStr string, playSeconds float64, err error) {
-	if utils.XfAPPID == `` {
-		// 如果科大讯飞未配置,那么就直接返回,不生成音频了
-		return
-	}
 	defer func() {
 		if err != nil {
 			utils.FileLog.Error("CreateReportVideo Err:%s", err.Error())
@@ -206,6 +217,24 @@ func CreateReportVideo(reportTitle, reportContent, reportTime string) (uploadUrl
 	if reportContent == "" {
 		return
 	}
+
+	// 获取基础配置, 若未配置则直接返回
+	conf, e := models.GetBusinessConf()
+	if e != nil {
+		err = fmt.Errorf("获取基础配置失败, Err: " + e.Error())
+		return
+	}
+	if conf[models.BusinessConfUseXf] != "true" {
+		return
+	}
+	if conf[models.BusinessConfXfAppid] == "" || conf[models.BusinessConfXfApiKey] == "" || conf[models.BusinessConfXfApiSecret] == "" || conf[models.BusinessConfXfVcn] == "" {
+		return
+	}
+	var xfReq XfParams
+	xfReq.XfAPPID = conf[models.BusinessConfXfAppid]
+	xfReq.XfAPIKey = conf[models.BusinessConfXfApiKey]
+	xfReq.XfAPISecret = conf[models.BusinessConfXfApiSecret]
+
 	ct, err := time.Parse(utils.FormatDateTime, reportTime)
 	if err != nil {
 		return
@@ -223,11 +252,11 @@ func CreateReportVideo(reportTitle, reportContent, reportTime string) (uploadUrl
 	}
 
 	param := new(models.XfSendParam)
-	param.Common.AppId = utils.XfAPPID
+	param.Common.AppId = conf[models.BusinessConfXfAppid]
 	param.Business.Aue = "lame"
 	param.Business.Sfl = 1
 	param.Business.Auf = "audio/L16;rate=16000"
-	param.Business.Vcn = utils.XfVcn
+	param.Business.Vcn = conf[models.BusinessConfXfVcn]
 	param.Business.Speed = 50
 	param.Business.Volume = 100
 	param.Business.Pitch = 50
@@ -251,7 +280,7 @@ func CreateReportVideo(reportTitle, reportContent, reportTime string) (uploadUrl
 		if tmpErr != nil {
 			return
 		}
-		err = GetXfVideo(result, savePath)
+		err = GetXfVideo(result, savePath, xfReq)
 		if err != nil {
 			err = errors.New("GetXfVideo Err:" + err.Error())
 			utils.FileLog.Error("GetXfVideo err", err.Error())

+ 11 - 5
services/xfyun.go

@@ -14,9 +14,15 @@ import (
 	"hongze/hz_eta_api/utils"
 )
 
+type XfParams struct {
+	XfAPPID     string
+	XfAPIKey    string
+	XfAPISecret string
+}
+
 // 科大讯飞,语音合成
-func GetXfVideo(body []byte, savePath string) (err error) {
-	path, err := assembleAuthUrl()
+func GetXfVideo(body []byte, savePath string, req XfParams) (err error) {
+	path, err := assembleAuthUrl(req)
 	if err != nil {
 		return
 	}
@@ -79,7 +85,7 @@ webSocketClose:
 // @hosturl :  like  wss://iat-api.xfyun.cn/v2/iat
 // @apikey : apiKey
 // @apiSecret : apiSecret
-func assembleAuthUrl() (callUrl string, err error) {
+func assembleAuthUrl(req XfParams) (callUrl string, err error) {
 	ul, err := url.Parse(utils.XfHostUrl)
 	if err != nil {
 		return
@@ -92,9 +98,9 @@ func assembleAuthUrl() (callUrl string, err error) {
 	sign := strings.Join(signString, "\n")
 	fmt.Println("sign:", sign)
 	//签名结果
-	sha := crypt.HmacSha256EncryptToBase64([]byte(sign), []byte(utils.XfAPISecret))
+	sha := crypt.HmacSha256EncryptToBase64([]byte(sign), []byte(req.XfAPISecret))
 	//构建请求参数 此时不需要urlencoding
-	authUrl := fmt.Sprintf("api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"", utils.XfAPIKey,
+	authUrl := fmt.Sprintf("api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"", req.XfAPIKey,
 		"hmac-sha256", "host date request-line", sha)
 	//将请求参数使用base64编码
 	authorization := base64.StdEncoding.EncodeToString([]byte(authUrl))

+ 22 - 17
utils/config.go

@@ -110,17 +110,17 @@ var (
 
 // 科大讯飞--语音合成
 var (
-	XfSTATUS_FIRST_FRAME    = 0 //第一帧标识
-	XfSTATUS_CONTINUE_FRAME = 1 //中间帧标识
-	XfSTATUS_LAST_FRAME     = 2 //最后一帧标识
-	XfHost                  = "tts-api.xfyun.cn"
-	XfMaxFontSize           = 8000
-	XfAPPID                 string
-	XfAPIKey                string
-	XfAPISecret             string
-	XfHostUrl               string
-	XfOrigin                string
-	XfVcn                   string //发言人
+	//XfSTATUS_FIRST_FRAME    = 0 //第一帧标识
+	//XfSTATUS_CONTINUE_FRAME = 1 //中间帧标识
+	//XfSTATUS_LAST_FRAME     = 2 //最后一帧标识
+	//XfHost                  = "tts-api.xfyun.cn"
+	//XfMaxFontSize           = 8000
+	//XfAPPID                 string
+	//XfAPIKey                string
+	//XfAPISecret             string
+	XfHostUrl string
+	//XfOrigin  string
+	//XfVcn                   string //发言人
 )
 
 // 阿里云配置
@@ -169,6 +169,9 @@ var LibreOfficePath string
 // CrmEtaServerUrl CRM-ETA服务地址
 var CrmEtaServerUrl string
 
+// BusinessCode 商家编码
+var BusinessCode string
+
 func init() {
 	tmpRunMode, err := web.AppConfig.String("run_mode")
 	if err != nil {
@@ -366,13 +369,12 @@ func init() {
 
 	// 科大讯飞
 	{
-
-		XfAPPID = config["xf_appid"]
-		XfAPIKey = config["xf_api_key"]
-		XfAPISecret = config["xf_api_secret"]
+		//XfAPPID = config["xf_appid"]
+		//XfAPIKey = config["xf_api_key"]
+		//XfAPISecret = config["xf_api_secret"]
 		XfHostUrl = config["xf_host_url"]
-		XfOrigin = config["xf_origin"]
-		XfVcn = config["xf_vcn"]
+		//XfOrigin = config["xf_origin"]
+		//XfVcn = config["xf_vcn"]
 	}
 
 	// ES 索引
@@ -388,6 +390,9 @@ func init() {
 	CrmEtaServerUrl = config["crm_eta_server_url"]
 	LibreOfficePath = config["libre_office_path"]
 
+	// 商家编码
+	BusinessCode = config["business_code"]
+
 	// 初始化ES
 	initEs()
 }

+ 3 - 0
utils/constants.go

@@ -296,3 +296,6 @@ const (
 	SOURCE_CRM_FLAG = 1
 	SOURCE_ETA_FLAG = 2
 )
+
+// BusinessCodeSalt 商家编码盐值
+const BusinessCodeSalt = "dr7WY0OZgGR7upw1"