diff --git a/main.go b/main.go index 627f763..eac1495 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "git.echol.cn/loser/lckt/core" "git.echol.cn/loser/lckt/global" "git.echol.cn/loser/lckt/initialize" + "git.echol.cn/loser/lckt/utils/wechat" _ "go.uber.org/automaxprocs" "go.uber.org/zap" ) @@ -41,5 +42,7 @@ func main() { db, _ := global.GVA_DB.DB() defer db.Close() } + + wechat.InitWeOfficial() // 初始化微信公众号SDK core.RunWindowsServer() } diff --git a/initialize/wechat.go b/utils/wechat/wechat.go similarity index 81% rename from initialize/wechat.go rename to utils/wechat/wechat.go index 2b4e6e2..7c4b692 100644 --- a/initialize/wechat.go +++ b/utils/wechat/wechat.go @@ -1,9 +1,12 @@ -package initialize +package wechat import ( + "git.echol.cn/loser/lckt/global" + "github.com/ArtisanCloud/PowerSocialite/v3/src/providers" "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel" "github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount" "github.com/ArtisanCloud/PowerWeChat/v3/src/payment" + "go.uber.org/zap" "log" ) @@ -13,8 +16,8 @@ var WechatPay *payment.Payment // InitWeOfficial 初始化微信公众号 func InitWeOfficial() { OfficialAccountApp, err := officialAccount.NewOfficialAccount(&officialAccount.UserConfig{ - AppID: "[appid]", // 公众号、小程序的appid - Secret: "[app secret]", // + AppID: "wx3d21df18d7f8f9fc", // 公众号、小程序的appid + Secret: "ffce59a9a9272c1aaee53950e96617d8", // Log: officialAccount.Log{ Level: "debug", @@ -25,7 +28,7 @@ func InitWeOfficial() { }, HttpDebug: true, - Debug: false, + Debug: true, }) if err != nil { @@ -70,3 +73,12 @@ func InitWechatPay() { } WechatPay = PaymentService } + +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 +}