浏览代码

Merge branch 'bzq1/dw_bridge_conflict' of eta_server/eta_api into debug

鲍自强 10 月之前
父节点
当前提交
d11604bc25
共有 5 个文件被更改,包括 83 次插入8 次删除
  1. 0 1
      controllers/base_auth.go
  2. 7 5
      controllers/report.go
  3. 58 0
      services/third/dw_msg.go
  4. 6 1
      services/wechat_send_msg.go
  5. 12 1
      utils/config.go

+ 0 - 1
controllers/base_auth.go

@@ -290,7 +290,6 @@ func (c *BaseAuthController) ServeJSON(encoding ...bool) {
 		}
 	}
 
-
 	//新增uuid记录
 	{
 		if _, ok := AdminOperateRecordMap[urlPath]; !ok && !strings.Contains(urlPath, "cygx") {

+ 7 - 5
controllers/report.go

@@ -9,9 +9,6 @@ import (
 	"eta/eta_api/services/data"
 	"eta/eta_api/utils"
 	"fmt"
-	"github.com/beego/beego/v2/server/web"
-	"github.com/h2non/filetype"
-	"github.com/tealeg/xlsx"
 	"html"
 	"io/ioutil"
 	"os"
@@ -20,6 +17,10 @@ import (
 	"strconv"
 	"strings"
 	"time"
+
+	"github.com/beego/beego/v2/server/web"
+	"github.com/h2non/filetype"
+	"github.com/tealeg/xlsx"
 )
 
 // ReportController 报告
@@ -29,7 +30,7 @@ type ReportController struct {
 
 // ReportCommonController 报告
 type ReportCommonController struct {
-	BaseCommonController
+	BaseCommonController 
 }
 
 // ReportUploadCommonController 报告上传
@@ -90,7 +91,7 @@ func (this *ReportController) PublishReport() {
 			br.ErrMsg = "图表刷新未完成,请稍后操作"
 			br.IsSendEmail = false
 			return
-		}
+		} 
 
 		var publishTime time.Time
 		if report.MsgIsSend == 1 && report.PublishTime != "" { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
@@ -2090,6 +2091,7 @@ func (this *ReportController) SendMsg() {
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
+
 	if req.ReportId <= 0 {
 		br.Msg = "参数错误"
 		br.ErrMsg = "参数错误"

+ 58 - 0
services/third/dw_msg.go

@@ -0,0 +1,58 @@
+package third
+
+import (
+	"encoding/json"
+	"errors"
+	"eta/eta_api/models"
+	"eta/eta_api/utils"
+	"fmt"
+	"io"
+	"net/http"
+	"time"
+)
+
+func HttpGet(url string) (body []byte, err error) {
+	client := &http.Client{}
+	req, err := http.NewRequest("GET", url, nil)
+	if err != nil {
+		return
+	}
+	nonce := utils.GetRandStringNoSpecialChar(16)
+	timestamp := time.Now().Format(utils.FormatDateTimeUnSpace)
+	signature := utils.GetSign(nonce, timestamp, utils.ETA_MINI_APPID, utils.ETA_MINI_APP_SECRET)
+	//增加header选项
+	req.Header.Add("Nonce", nonce)
+	req.Header.Add("Timestamp", timestamp)
+	req.Header.Add("Appid", utils.ETA_MINI_APPID)
+	req.Header.Add("Signature", signature)
+	req.Header.Set("Content-Type", "application/json")
+
+	response, err := client.Do(req)
+	if err != nil {
+		return
+	}
+	defer response.Body.Close()
+
+	body, err = io.ReadAll(response.Body)
+	if err != nil {
+		return
+	}
+	return
+}
+
+func DwSendTemplatedMsg(reportId int) error {
+	url := fmt.Sprintf("%swechat/send_template_msg?ReportId=%d", utils.ETAMiniBridgeUrl, reportId)
+	body, err := HttpGet(url)
+	if err != nil {
+		return err
+	}
+	result := new(models.BaseResponse)
+	if err := json.Unmarshal(body, &result); err != nil {
+		return err
+	}
+	if result.Ret != 200 {
+		err = errors.New(string(body))
+		return err
+	}
+	return nil
+}

+ 6 - 1
services/wechat_send_msg.go

@@ -3,10 +3,11 @@ package services
 import (
 	"encoding/json"
 	"errors"
-	"fmt"
 	"eta/eta_api/models"
 	"eta/eta_api/services/alarm_msg"
+	"eta/eta_api/services/third"
 	"eta/eta_api/utils"
+	"fmt"
 	"io/ioutil"
 	"net/http"
 	"strconv"
@@ -28,6 +29,10 @@ type ClearQuotaResponse struct {
 func SendMiniProgramReportWxMsg(reportId int) (err error) {
 	var msg string
 	reportIdStr := strconv.Itoa(reportId)
+	if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
+		err = third.DwSendTemplatedMsg(reportId)
+		return
+	}
 	defer func() {
 		if err != nil {
 			fmt.Println("msg:", msg)

+ 12 - 1
utils/config.go

@@ -3,11 +3,12 @@ package utils
 import (
 	"errors"
 	"fmt"
+	"strconv"
+
 	beeLogger "github.com/beego/bee/v2/logger"
 	"github.com/beego/beego/v2/server/web"
 	"github.com/qiniu/qmgo"
 	"github.com/spf13/viper"
-	"strconv"
 )
 
 var (
@@ -98,6 +99,10 @@ var (
 	EtaBridgeDesKey    string // 桥接服务Des密钥-解密数据用
 	EtaBridgeLoginUrl  string // 第三方登录鉴权接口地址
 	EtaBridgeLogoutUrl string // 第三方登出接口地址
+
+	ETAMiniBridgeUrl    string // 桥接服务地址
+	ETA_MINI_APPID      string // 桥接服务-鉴权用
+	ETA_MINI_APP_SECRET string // 桥接服务-鉴权用
 )
 
 // 微信配置信息
@@ -534,6 +539,12 @@ func init() {
 	}
 	// 商家编码
 	BusinessCode = config["business_code"]
+	// eta_mini_bridge 小程序桥接服务地址
+	{
+		ETAMiniBridgeUrl = config["eta_mini_bridge_url"]
+		ETA_MINI_APPID = config["eta_mini_api_appid"]       // 桥接服务-鉴权用
+		ETA_MINI_APP_SECRET = config["eta_mini_api_secret"] // 桥接服务-鉴权用
+	}
 
 	// MinIo相关
 	{