Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
完整支持多微信公众号
原先版本可在声明 wechat_responder 时通过指定参数有限度支持多个微信公众号,其它地方并不支持,比如 Wechat.api 和 wechat 命令行工具并不支持,现在增加完整的多微信公众号支持特性。
使用方法
1.配置文件可增加多个公众号配置,用法类似 Rails 中 database.yml 多数据库配置的处理
development, test, production 段是默认公众号配置
[account_env] 是额外公众号配置,如
wx007_development, wx007_test, wx007_production 增加了 wx007 这个公众号的相关配置。
2.wechat_responder 声明
wechat_responder account: :wx007
3.wechat api 使用
Wechat.api(:wx007) 表示使用 wx007 这个公众号的 api
Wechat.api 和 Wechat.api(:default) 表示默认的 api
4.wechat 命令行使用
增加可选参数 -a, [--account=ACCOUNT]
如
wechat users -a wx007
表示列举 wx007 这个公众号的粉丝列表实现原理
关键处理
1.扩展配置文件规则和加载处理,通过 公众号 <-> 配置 的 hash 对象存储多个公众号配置
2.扩展 Wechat.config Wechat.api Wechat::ApiLoader.config 和 Wechat::ApiLoader.with 方法,
允许获取指定公众号的 config 和 api。