Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

微信多应用程序,中台Token自定义机制 #385

Open
Matrix-X opened this issue Aug 31, 2023 · 1 comment
Open

微信多应用程序,中台Token自定义机制 #385

Matrix-X opened this issue Aug 31, 2023 · 1 comment

Comments

@Matrix-X
Copy link
Contributor

Pls Check

https://github.com/ArtisanCloud/PowerWeChat/releases/tag/v3.0.64

@coincoc
Copy link

coincoc commented Jun 26, 2024

你好
我在学习PowerWechat这个框架,看到了这个机制,目前PowerWechat存放的access_token是json格式,如果我需要修改成仅仅存储一个字符串。在实现GetCustomToken 的时候需要手动实现获取access_token的相关逻辑,不知道框架内是否有api可以直接调用,或者后续会增加相关的api吗?
谢谢

func InitClient() {
	cache := kernel.NewRedisClient(&kernel.UniversalOptions{
		Addrs:    []string{"127.0.0.1:6379"},
		Password: "",
		DB:       0,
	})
	client, _ := miniProgram.NewMiniProgram(&miniProgram.UserConfig{
		AppID:     "",
		Secret:    "",
		HttpDebug: true,
		// 可选,不传默认走程序内存
		Cache: cache,
	})

	client.AccessToken.SetCacheKey("access_token")
	client.AccessToken.SetCustomToken = func(token *response.ResponseGetToken) interface{} {
		return token.AccessToken
	}
	client.AccessToken.GetCustomToken = func(key string, refresh bool) object.HashMap {
		if !refresh && cache.Has(key) {
			value, err := cache.Get(key, nil)
			if err == nil && value != nil {
				return object.HashMap{
					"access_token": value,
					"expires_in":   float64(7200),
				}
			}

		}

		// 请求access_token
		return object.HashMap{}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants