{"id":42077167,"url":"https://github.com/wuweiit/token-manager","last_synced_at":"2026-01-26T09:36:31.946Z","repository":{"id":57729756,"uuid":"396329041","full_name":"wuweiit/token-manager","owner":"wuweiit","description":"三方对接Token管理器，支持自动刷新Token，基于Redis多服务共享，2level缓存，适用微信小程序Token等三方Token管理续期","archived":false,"fork":false,"pushed_at":"2024-08-26T23:34:56.000Z","size":118,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-25T14:18:32.622Z","etag":null,"topics":["java","redis","token"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wuweiit.png","metadata":{"files":{"readme":"readme.md","changelog":"history.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-15T11:29:53.000Z","updated_at":"2025-05-14T12:31:00.000Z","dependencies_parsed_at":"2022-09-10T23:40:55.577Z","dependency_job_id":null,"html_url":"https://github.com/wuweiit/token-manager","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/wuweiit/token-manager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuweiit%2Ftoken-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuweiit%2Ftoken-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuweiit%2Ftoken-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuweiit%2Ftoken-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wuweiit","download_url":"https://codeload.github.com/wuweiit/token-manager/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuweiit%2Ftoken-manager/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28772914,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T08:38:24.014Z","status":"ssl_error","status_checked_at":"2026-01-26T08:38:22.080Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","redis","token"],"created_at":"2026-01-26T09:36:31.248Z","updated_at":"2026-01-26T09:36:31.937Z","avatar_url":"https://github.com/wuweiit.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TokenManager\n\nTokenManager是一款基于Java开发的Springboot组件，用于管理自身平台以外的三方Token。\n\nTokenManager将全场景的远程调用获取Token抽象到TokenManager接口中，通过调用指定的API实现各类三方系统的Token的管理。\n\n通过Redis的消息订阅特性实现了延时消息监听Token生命周期过期时间，从而自动刷新Token。\n确保在高并发请求下，用户不会调用具体的三方接口实时获取Token。\n\nTokenManager原理图如下所示：\n\n![image](image/img.png)\n\n开发者：marker\n\n### TokenManger更新历史\n\n[更新历史文档](#history.md)\n\n### TokenManager特性\n\n- **多环境Token共享**\n  例如：调试微信，获取appid+secrt换取accessToken，在开发环境和测试环境共用appid的情况下，Token共享。\n\n- **自动刷新accessToken**\n  支持基于Oauth2协议的刷新Token机制，无需干预自动刷新，最佳的管理方式，提高接口响应速度。\n  \n- **多级缓存（待实现)**\n  支持本地缓存与远程缓存。本地缓存JVM级别的，远程缓存基于Redis。提高Token的访问速度，防止Redis击穿雪崩。\n  本地缓存的生命周期动态管理。\n\n- **可扩展**\n  支持扩展现有的API实现，能够支持除了微信以外的其他平台。采用自动装配技术，实例动态注入到Spring容器中。\n\n- **支持请求日志拦截**\n  通过RestTempalte 拦截器实现了请求日志拦截，默认实现了请求Slf4j的info级别日志。可以自定义配置个性化的拦截实现。\n  \n### 快速开始\n\n准备好Redis-server，服务IP与端口还有密码\n\n```\n服务：127.0.0.1:6379\n密码：123456\n```\n\n如果您没有Redis服务环境，推荐使用Docker部署测试。\n\n\n在您的项目中pom.xml加入maven依赖：\n```\n\u003c!-- 开发者：marker 三方Token管理器 --\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.wuweibi\u003c/groupId\u003e\n    \u003cartifactId\u003etoken-manager\u003c/artifactId\u003e\n    \u003cversion\u003e0.0.3\u003c/version\u003e\n\u003c/dependency\u003e\n```  \n\n\n### TokenAPI\n\nTokenAPI 提供了获取Token和刷新token两种接口，参数包含SecretConfig和Map，这里使用Map的原因是我们不能确定获取Token需要c端用户传递哪些数据字段，因此使用Map会较为通用的方式。\n\n\nTokenManager会通过类型自动判断调用那个接口实现，当然我们也可以采用策略模式直接设置TokenAPI到TokenManger实例里。\n\n\n\n### Springboot配置内容\n\n```\nspring:\n  ## 三方Token管理器\n  token-manager:\n    enabled: true\n    # redis链接地址\n    host: ${TOKEN_REDIS_HOST:192.168.1.6}\n    # redis密码\n    password : ${TOKEN_REDIS_PASSWORD:xxx}\n    # redis数据索引 默认14\n    database : ${TOKEN_REDIS_DB:13}\n    port: ${TOKEN_REDIS_PORT:6379}\n    lettuce:\n      #在关闭客户端连接之前等待任务处理完成的最长时间，在这之后，无论任务是否执行完成，都会被执行器关闭，默认100ms\n      shutdownTimeout: 100\n      pool:\n        # 连接池最大连接数（使用负值表示没有限制）\n        maxActive: 50\n        # 连接池中的最大空闲连接\n        maxIdle: 10\n        # 连接池中的最小空闲连接\n        minIdle: 9\n        # 连接池最大阻塞等待时间（使用负值表示没有限制）\n        maxWait: -1\n    # Token管理器多实例配置\n    configMap:\n      # 微信Token接口配置\n      weixinMp:\n        type: WEIXIN\n        appid: wx03698c0a99f50cfb\n        appsecret: 82aee19d923384fcda0be1ad9f23619c\n        offsetTime: 60\n```\n\n使用代码\n\n```  \n\n// 注入控制器或service\n  @Lazy\n  @Resource\n  private TokenManager tokenManager;\n\n// 调用获取token （内部会自动维护过期时间）\nTokenInfo tokenInfo = tokenManager.getToken();\nBufferedImage bufferedImage = WxaAPI.getwxacodeunlimit(tokenInfo.getAccessToken(), getwxacodeunlimit);\n\n\n```  ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwuweiit%2Ftoken-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwuweiit%2Ftoken-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwuweiit%2Ftoken-manager/lists"}