Files
lckt-server/utils/wechat/wechat.go
2025-07-25 23:02:43 +08:00

45 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package wechat
import (
"git.echol.cn/loser/lckt/global"
"github.com/ArtisanCloud/PowerSocialite/v3/src/providers"
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount"
"go.uber.org/zap"
"log"
)
var WeOfficial *officialAccount.OfficialAccount
// InitWeOfficial 初始化微信公众号
func InitWeOfficial() {
OfficialAccountApp, err := officialAccount.NewOfficialAccount(&officialAccount.UserConfig{
AppID: "wx3d21df18d7f8f9fc", // 公众号、小程序的appid
Secret: "3ab19e9b6a5e155c25ac6457be650047", //
Log: officialAccount.Log{
Level: "debug",
// 可以重定向到你的目录下如果设置File和Error默认会在当前目录下的wechat文件夹下生成日志
File: "/Users/user/wechat/official-account/info.log",
Error: "/Users/user/wechat/official-account/error.log",
Stdout: false, // 是否打印在终端
},
HttpDebug: true,
Debug: true,
})
if err != nil {
log.Println("初始化微信公众号 SDK失败", err)
}
WeOfficial = OfficialAccountApp
}
func GetUserInfo(code string) *providers.User {
userFromCode, err := WeOfficial.OAuth.UserFromCode(code)
if err != nil {
global.GVA_LOG.Error("通过code获取微信用户信息失败", zap.Error(err))
return nil
}
return userFromCode
}