🎨 完善微信登录相关工具类
This commit is contained in:
parent
159ef59749
commit
ad6773c575
3
main.go
3
main.go
@ -4,6 +4,7 @@ import (
|
|||||||
"git.echol.cn/loser/lckt/core"
|
"git.echol.cn/loser/lckt/core"
|
||||||
"git.echol.cn/loser/lckt/global"
|
"git.echol.cn/loser/lckt/global"
|
||||||
"git.echol.cn/loser/lckt/initialize"
|
"git.echol.cn/loser/lckt/initialize"
|
||||||
|
"git.echol.cn/loser/lckt/utils/wechat"
|
||||||
_ "go.uber.org/automaxprocs"
|
_ "go.uber.org/automaxprocs"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
@ -41,5 +42,7 @@ func main() {
|
|||||||
db, _ := global.GVA_DB.DB()
|
db, _ := global.GVA_DB.DB()
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wechat.InitWeOfficial() // 初始化微信公众号SDK
|
||||||
core.RunWindowsServer()
|
core.RunWindowsServer()
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package initialize
|
package wechat
|
||||||
|
|
||||||
import (
|
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/kernel"
|
||||||
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount"
|
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount"
|
||||||
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment"
|
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment"
|
||||||
|
"go.uber.org/zap"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,8 +16,8 @@ var WechatPay *payment.Payment
|
|||||||
// InitWeOfficial 初始化微信公众号
|
// InitWeOfficial 初始化微信公众号
|
||||||
func InitWeOfficial() {
|
func InitWeOfficial() {
|
||||||
OfficialAccountApp, err := officialAccount.NewOfficialAccount(&officialAccount.UserConfig{
|
OfficialAccountApp, err := officialAccount.NewOfficialAccount(&officialAccount.UserConfig{
|
||||||
AppID: "[appid]", // 公众号、小程序的appid
|
AppID: "wx3d21df18d7f8f9fc", // 公众号、小程序的appid
|
||||||
Secret: "[app secret]", //
|
Secret: "ffce59a9a9272c1aaee53950e96617d8", //
|
||||||
|
|
||||||
Log: officialAccount.Log{
|
Log: officialAccount.Log{
|
||||||
Level: "debug",
|
Level: "debug",
|
||||||
@ -25,7 +28,7 @@ func InitWeOfficial() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
HttpDebug: true,
|
HttpDebug: true,
|
||||||
Debug: false,
|
Debug: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -70,3 +73,12 @@ func InitWechatPay() {
|
|||||||
}
|
}
|
||||||
WechatPay = PaymentService
|
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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user