|
@@ -2,7 +2,6 @@ package wx_app
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
- "fmt"
|
|
|
wechat "github.com/silenceper/wechat/v2"
|
|
|
"github.com/silenceper/wechat/v2/cache"
|
|
|
"github.com/silenceper/wechat/v2/miniprogram"
|
|
@@ -40,17 +39,16 @@ func init() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func GetWxApp() (mp *miniprogram.MiniProgram) {
|
|
|
+// 注: 研报小程序及备用小程序在同时运行, 基础微信API通过前端请求Header判断来源
|
|
|
+// 模板消息等API则用配置控制具体使用哪一个小程序, 同一时间仅一个小程序可推消息
|
|
|
+func GetWxApp(copyYb string) (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
|
|
|
- }
|
|
|
+ appConf := getWxAppConfByRequest(copyYb)
|
|
|
|
|
|
cfg := &config.Config{
|
|
|
AppID: appConf.WxAppId,
|
|
@@ -63,45 +61,36 @@ func GetWxApp() (mp *miniprogram.MiniProgram) {
|
|
|
}
|
|
|
|
|
|
// GetSession 获取用户详情
|
|
|
-func GetSession(code string) (userInfo auth.ResCode2Session, err error) {
|
|
|
- wechatClient := GetWxApp()
|
|
|
- authClient := wechatClient.GetAuth()
|
|
|
- userInfo, err = authClient.Code2Session(code)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-// GetSession 获取用户详情
|
|
|
-func GetUserInfo(code string) (userInfo auth.ResCode2Session, err error) {
|
|
|
- wechatClient := GetWxApp()
|
|
|
+func GetSession(code, copyYb string) (userInfo auth.ResCode2Session, err error) {
|
|
|
+ wechatClient := GetWxApp(copyYb)
|
|
|
authClient := wechatClient.GetAuth()
|
|
|
- fmt.Println("code:", code)
|
|
|
userInfo, err = authClient.Code2Session(code)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 获取解密信息 GetDecryptInfo
|
|
|
-func GetDecryptInfo(sessionKey, encryptedData, iv string) (decryptData *encryptor.PlainData, err error) {
|
|
|
- wechatClient := GetWxApp()
|
|
|
+func GetDecryptInfo(sessionKey, encryptedData, iv, copyYb string) (decryptData *encryptor.PlainData, err error) {
|
|
|
+ wechatClient := GetWxApp(copyYb)
|
|
|
encryptorClient := wechatClient.GetEncryptor()
|
|
|
decryptData, err = encryptorClient.Decrypt(sessionKey, encryptedData, iv)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetSunCode 获取太阳码
|
|
|
-func GetSunCode(page, scene string) (resp []byte, err error) {
|
|
|
+func GetSunCode(page, scene, copyYb string) (resp []byte, err error) {
|
|
|
codePars := qrcode.QRCoder{
|
|
|
Page: page,
|
|
|
Scene: scene,
|
|
|
EnvVersion: EnvVersion,
|
|
|
}
|
|
|
- wechatClient := GetWxApp()
|
|
|
+ wechatClient := GetWxApp(copyYb)
|
|
|
qr := wechatClient.GetQRCode()
|
|
|
return qr.GetWXACodeUnlimit(codePars)
|
|
|
}
|
|
|
|
|
|
// MsgSecCheck 检查一段文本是否含有违法违规内容。
|
|
|
-func MsgSecCheck(openid string, content string) (result security.Result, err error) {
|
|
|
- wechatClient := GetWxApp()
|
|
|
+func MsgSecCheck(openid, content, copyYb string) (result security.Result, err error) {
|
|
|
+ wechatClient := GetWxApp(copyYb)
|
|
|
myMiniprogram := security.NewMyMiniprogram(wechatClient)
|
|
|
bodyContent := &security.BodyContent{
|
|
|
Version: 2,
|
|
@@ -128,19 +117,24 @@ func GetWxAppConf() (appConf *WxAppConf, err error) {
|
|
|
err = errors.New("获取小程序配置失败, Err: " + e.Error())
|
|
|
return
|
|
|
}
|
|
|
- appConf = &WxAppConf{
|
|
|
+ appConf = getWxAppConfByRequest(conf.ConfigValue)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func getWxAppConfByRequest(copyYb string) *WxAppConf {
|
|
|
+ appConf := &WxAppConf{
|
|
|
WxId: `gh_75abb562a946`,
|
|
|
WxAppId: `wxb059c872d79b9967`,
|
|
|
WxAppSecret: `1737c73e9f69a21de1a345b8f0800258`,
|
|
|
WxPlatform: utils.USER_RECORD_PLATFORM_YB,
|
|
|
MsgRedirectTarget: 1,
|
|
|
}
|
|
|
- if conf.ConfigValue == "true" {
|
|
|
- // 备用小程序
|
|
|
+ // 备用小程序
|
|
|
+ if copyYb == "true" {
|
|
|
appConf.WxAppId = `wx9a2a9b49a00513a0`
|
|
|
appConf.WxAppSecret = `9feb793bd0a8756990a36ac2ade6978c`
|
|
|
appConf.WxPlatform = utils.USER_RECORD_PLATFORM_COPY_YB
|
|
|
appConf.MsgRedirectTarget = 4
|
|
|
}
|
|
|
- return
|
|
|
+ return appConf
|
|
|
}
|