From ad6773c5756a72bcab4926767f62bb0016adb03a Mon Sep 17 00:00:00 2001 From: Echo <1711788888@qq.com> Date: Fri, 9 May 2025 11:17:04 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=AE=8C=E5=96=84=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=9B=B8=E5=85=B3=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 3 +++ {initialize => utils/wechat}/wechat.go | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) rename {initialize => utils/wechat}/wechat.go (81%) 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 +}