Browse Source

Merge branch 'yb/new_yb' into debug

hsun 2 years ago
parent
commit
d548e5abc3

+ 1 - 1
controller/community/question.go

@@ -120,7 +120,7 @@ func QuestionAsk(c *gin.Context) {
 	}
 	// 敏感词校验, 只有小程序的用户才能走敏感词过滤接口
 	userinfo := user.GetInfoByClaims(c)
-	if userinfo.RecordInfo.OpenID != "" && userinfo.RecordInfo.CreatePlatform == 6 {
+	if userinfo.RecordInfo.OpenID != "" && (userinfo.RecordInfo.CreatePlatform == utils.USER_RECORD_PLATFORM_YB || userinfo.RecordInfo.CreatePlatform == utils.USER_RECORD_PLATFORM_COPY_YB) {
 		checkResult, e := wx_app.MsgSecCheck(userinfo.RecordInfo.OpenID, req.QuestionContent)
 		if e == nil {
 			if checkResult.Result != nil && checkResult.Result.Suggest != "pass" {

+ 7 - 1
controller/wechat/wechat.go

@@ -56,7 +56,13 @@ func Login(c *gin.Context) {
 		response.Fail("获取失败,Err:"+err.Error(), c)
 		return
 	}
-	token, userId, isBind, err := user.WxLogin(wx_app.WxPlatform, wxUserInfo)
+	appConf, e := wx_app.GetWxAppConf()
+	if e != nil {
+		response.FailMsg("获取失败", "获取小程序配置失败, Err: " + e.Error(), c)
+		return
+	}
+
+	token, userId, isBind, err := user.WxLogin(appConf.WxPlatform, wxUserInfo)
 	if err != nil {
 		response.Fail("登录失败,Err:"+err.Error(), c)
 		return

+ 1 - 1
logic/yb_community_question/yb_community_question_comment.go

@@ -59,7 +59,7 @@ func Comment(user user.UserInfo, communityQuestionID uint32, content string, sou
 	}
 
 	// 敏感词过滤
-	if user.RecordInfo.OpenID != "" && user.RecordInfo.CreatePlatform == 6 { //只有小程序的用户才能走敏感词过滤接口
+	if user.RecordInfo.OpenID != "" && (user.RecordInfo.CreatePlatform == utils.USER_RECORD_PLATFORM_YB || user.RecordInfo.CreatePlatform == utils.USER_RECORD_PLATFORM_COPY_YB) { //只有小程序的用户才能走敏感词过滤接口
 		checkResult, tErr := wx_app.MsgSecCheck(user.RecordInfo.OpenID, content)
 		/*if tErr != nil {
 			errMsg = "敏感词过滤失败" + tErr.Error()

+ 38 - 0
models/tables/yb_config/entity.go

@@ -0,0 +1,38 @@
+package yb_config
+
+import (
+	"time"
+)
+
+// YbConfig 研报相关配置表
+type YbConfig struct {
+	ConfigID    int       `gorm:"primaryKey;column:config_id;type:int(11);not null" json:"-"`
+	ConfigCode  string    `gorm:"column:config_code;type:varchar(50);default:''" json:"configCode"` // 配置编码
+	ConfigValue string    `gorm:"column:config_value;type:text" json:"configValue"`                 // 配置值
+	Remark      string    `gorm:"column:remark;type:varchar(255);default:''" json:"remark"`         // 备注信息
+	CreateTime  time.Time `gorm:"column:create_time;type:datetime" json:"createTime"`               // 创建时间
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *YbConfig) TableName() string {
+	return "yb_config"
+}
+
+// YbConfigColumns get sql column name.获取数据库列名
+var YbConfigColumns = struct {
+	ConfigID    string
+	ConfigCode  string
+	ConfigValue string
+	Remark      string
+	CreateTime  string
+}{
+	ConfigID:    "config_id",
+	ConfigCode:  "config_code",
+	ConfigValue: "config_value",
+	Remark:      "remark",
+	CreateTime:  "create_time",
+}
+
+var (
+	KeyUseCopyYb = "use_copy_yb"
+)

+ 11 - 0
models/tables/yb_config/model.go

@@ -0,0 +1,11 @@
+package yb_config
+
+import "hongze/hongze_yb/global"
+
+// GetConfigByCode 查询配置详情
+func GetConfigByCode(configCode string) (item *YbConfig, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbConfig{}).
+		Where("config_code = ?", configCode).
+		First(&item).Error
+	return
+}

+ 1 - 1
services/comment/comment.go

@@ -49,7 +49,7 @@ func Comment(user user.UserInfo, req reqComment.ReqComment) (ret response.RespCo
 		return
 	}
 	// 敏感词过滤
-	if user.RecordInfo.OpenID != "" && user.RecordInfo.CreatePlatform == 6 {   //只有小程序的用户才能走敏感词过滤接口
+	if user.RecordInfo.OpenID != "" && (user.RecordInfo.CreatePlatform == utils.USER_RECORD_PLATFORM_YB || user.RecordInfo.CreatePlatform == utils.USER_RECORD_PLATFORM_COPY_YB) {   //只有小程序的用户才能走敏感词过滤接口
 		checkResult, tErr := wx_app.MsgSecCheck(user.RecordInfo.OpenID, req.Content)
 		/*if tErr != nil {
 			errMsg = "敏感词过滤失败" + tErr.Error()

+ 9 - 2
services/report_push.go

@@ -9,7 +9,7 @@ import (
 	models "hongze/hongze_yb/models/tables/report_send_ths_detail"
 	"hongze/hongze_yb/models/tables/voice_broadcast"
 	"hongze/hongze_yb/services/alarm_msg"
-	"hongze/hongze_yb/services/wechat"
+	"hongze/hongze_yb/services/wx_app"
 	"hongze/hongze_yb/utils"
 	"io/ioutil"
 	"net/http"
@@ -168,8 +168,15 @@ func SendVoiceBroadcastToThs(voice *voice_broadcast.VoiceBroadcast) (err error)
 		}
 	}()
 	permissionName := "宏观" //写死宏观,默认所有群都推
+
+	appConf, e := wx_app.GetWxAppConf()
+	if e != nil {
+		err = errors.New("获取小程序配置失败, Err: " + e.Error())
+		return
+	}
+
 	//小程序跳转地址
-	jumpBaseUrl := wechat.WxYbAppId + `/pages-voice/voiceDetail?voiceId=`
+	jumpBaseUrl := appConf.WxAppId + `/pages-voice/voiceDetail?voiceId=`
 
 	logoUrl := `https://hongze.oss-cn-shanghai.aliyuncs.com/hzyj.png`
 

+ 2 - 2
services/wechat/wechat.go

@@ -24,7 +24,7 @@ var (
 	WxAppSecret                     string
 	TemplateIdWithCommunityQuestion string // 问答社区回复模板消息ID
 	TemplateIdWithCommunityQuestionNotifyAdmin string // 问答社区 有提问通知管理员
-	WxYbAppId                       string // 研报小程序AppID
+	//WxYbAppId                       string // 研报小程序AppID
 	PcWxAppId                       string //pc版AppId
 	PcWxAppSecret                   string //pc版AppSecret
 
@@ -38,7 +38,7 @@ var (
 )
 
 func init() {
-	WxYbAppId = "wxb059c872d79b9967"
+	//WxYbAppId = "wxb059c872d79b9967"
 
 	WxMobileCrmAppId = `wx67b68e39913e511e`
 	WxMobileCrmId = `wx67b68e39913e511e`

+ 57 - 17
services/wx_app/wx_app.go

@@ -1,6 +1,7 @@
 package wx_app
 
 import (
+	"errors"
 	"fmt"
 	wechat "github.com/silenceper/wechat/v2"
 	"github.com/silenceper/wechat/v2/cache"
@@ -11,24 +12,25 @@ import (
 	"github.com/silenceper/wechat/v2/miniprogram/qrcode"
 	"github.com/silenceper/wechat/v2/util"
 	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/models/tables/yb_config"
 	"hongze/hongze_yb/services/wx_app/security"
 )
 
 //微信小程序配置信息
 var (
-	WxId        string //微信原始ID
-	WxAppId     string
-	WxAppSecret string
-	WxPlatform  int    //用户来源,需要入库,用来保存该用户来自哪个平台,默认是:1
-	EnvVersion  string // 小程序版本, release-正式版; trial-体验版; develop-开发版
+	//WxId                 string //微信原始ID
+	//WxAppId              string
+	//WxAppSecret          string
+	//WxPlatform           int    //用户来源,需要入库,用来保存该用户来自哪个平台,默认是:1
+	EnvVersion           string // 小程序版本, release-正式版; trial-体验版; develop-开发版
 	SendWxTemplateMsgUrl string
 )
 
 func init() {
-	WxAppId = `wxb059c872d79b9967`
-	WxId = `gh_75abb562a946`
-	WxAppSecret = `1737c73e9f69a21de1a345b8f0800258`
-	WxPlatform = 6 //弘则研报来源
+	//WxAppId = `wxb059c872d79b9967`
+	//WxId = `gh_75abb562a946`
+	//WxAppSecret = `1737c73e9f69a21de1a345b8f0800258`
+	//WxPlatform = 6 //弘则研报来源
 	if global.CONFIG.Serve.RunMode == "release" {
 		EnvVersion = "release"
 		SendWxTemplateMsgUrl = "http://127.0.0.1:8086/v1/wechat/send_template_msg"
@@ -38,17 +40,25 @@ func init() {
 	}
 }
 
-func GetWxApp() (miniprogram *miniprogram.MiniProgram) {
+func GetWxApp() (mp *miniprogram.MiniProgram) {
 	wc := wechat.NewWechat()
 	memory := cache.NewMemory()
 	//memory := cache.NewRedis(global.Redis)
+
+	mp = new(miniprogram.MiniProgram)
+
+	appConf, e := GetWxAppConf()
+	if e != nil {
+		return mp
+	}
+
 	cfg := &config.Config{
-		AppID:     WxAppId,
-		AppSecret: WxAppSecret,
+		AppID:     appConf.WxAppId,
+		AppSecret: appConf.WxAppSecret,
 		Cache:     memory,
 	}
 
-	miniprogram = wc.GetMiniProgram(cfg)
+	mp = wc.GetMiniProgram(cfg)
 	return
 }
 
@@ -132,14 +142,44 @@ func GetSunCode(page, scene string) (resp []byte, err error) {
 }
 
 // MsgSecCheck 检查一段文本是否含有违法违规内容。
-func MsgSecCheck(openid string,content string) (result security.Result, err error) {
+func MsgSecCheck(openid string, content string) (result security.Result, err error) {
 	wechatClient := GetWxApp()
 	myMiniprogram := security.NewMyMiniprogram(wechatClient)
 	bodyContent := &security.BodyContent{
 		Version: 2,
 		Content: content,
-		Openid: openid,
-		Scene: 2,
+		Openid:  openid,
+		Scene:   2,
 	}
 	return myMiniprogram.MsgSecCheckWithResult(bodyContent)
-}
+}
+
+type WxAppConf struct {
+	WxId        string `description:"微信原始ID"`
+	WxAppId     string
+	WxAppSecret string
+	WxPlatform  int `description:"app来源: 6-研报小程序; 7-研报备用小程序"`
+}
+
+// GetWxAppConf 获取小程序配置
+func GetWxAppConf() (appConf *WxAppConf, err error) {
+	// 根据配置选择小程序
+	conf, e := yb_config.GetConfigByCode(yb_config.KeyUseCopyYb)
+	if e != nil {
+		err = errors.New("获取小程序配置失败, Err: " + e.Error())
+		return
+	}
+	appConf = &WxAppConf{
+		WxId:        `wxb059c872d79b9967`,
+		WxAppId:     `gh_75abb562a946`,
+		WxAppSecret: `1737c73e9f69a21de1a345b8f0800258`,
+		WxPlatform:  6,
+	}
+	if conf.ConfigValue == "true" {
+		// 备用小程序
+		appConf.WxAppId = `wx9a2a9b49a00513a0`
+		appConf.WxAppSecret = `9feb793bd0a8756990a36ac2ade6978c`
+		appConf.WxPlatform = 7
+	}
+	return
+}

+ 2 - 1
utils/constants.go

@@ -164,7 +164,8 @@ const (
 	USER_RECORD_PLATFORM_PC                   // PC端网站
 	USER_RECORD_PLATFORM_CYGX                 // 查研观向小程序
 	_
-	USER_RECORD_PLATFORM_YB // 研报小程序
+	USER_RECORD_PLATFORM_YB      // 研报小程序-6
+	USER_RECORD_PLATFORM_COPY_YB // 研报备用小程序-7
 )
 
 const (