|
@@ -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
|
|
|
- WxAppId string
|
|
|
- WxAppSecret string
|
|
|
- WxPlatform int
|
|
|
- EnvVersion string
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ EnvVersion string
|
|
|
SendWxTemplateMsgUrl string
|
|
|
)
|
|
|
|
|
|
func init() {
|
|
|
- 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()
|
|
|
|
|
|
+
|
|
|
+ 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) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-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-研报备用小程序"`
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+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
|
|
|
+}
|