12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package wx_app
- import (
- "eta/eta_mini_api/utils"
- wechat "github.com/silenceper/wechat/v2"
- "github.com/silenceper/wechat/v2/cache"
- "github.com/silenceper/wechat/v2/miniprogram"
- "github.com/silenceper/wechat/v2/miniprogram/auth"
- "github.com/silenceper/wechat/v2/miniprogram/config"
- "github.com/silenceper/wechat/v2/miniprogram/encryptor"
- )
- func GetWxApp() (miniprogram *miniprogram.MiniProgram) {
- wc := wechat.NewWechat()
- memory := cache.NewMemory()
- // memory := cache.NewRedis(utils.Redis)
- cfg := &config.Config{
- AppID: utils.WX_MINI_APPID,
- AppSecret: utils.WX_MINI_APP_SECRET,
- Cache: memory,
- }
- miniprogram = wc.GetMiniProgram(cfg)
- return
- }
- // GetSession 获取用户详情
- func GetSession(code string) (userInfo auth.ResCode2Session, err error) {
- wechatClient := GetWxApp()
- authClient := wechatClient.GetAuth()
- userInfo, err = authClient.Code2Session(code)
- return
- }
- // 获取解密信息 GetDecryptInfo
- func GetDecryptInfo(sessionKey, encryptedData, iv string) (decryptData *encryptor.PlainData, err error) {
- wechatClient := GetWxApp()
- encryptorClient := wechatClient.GetEncryptor()
- decryptData, err = encryptorClient.Decrypt(sessionKey, encryptedData, iv)
- return
- }
- // // MsgSecCheck 检查一段文本是否含有违法违规内容。
- // 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,
- // }
- // return myMiniprogram.MsgSecCheckWithResult(bodyContent)
- // }
|