wechat-gate 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca58efe7130862ff001bf9c8f1ae6e2fc20862f3
4
- data.tar.gz: 588aeee145bb71ff8e552ede1538dac430100cc5
3
+ metadata.gz: 9ba598a7d910af520e8bc6c9b3594718e15b903b
4
+ data.tar.gz: 2e701b25edda15379406b633fe6d484b8653f140
5
5
  SHA512:
6
- metadata.gz: 862464a34266eb84ff53bd07c40f19f3ec67f5ed39c10fd005292a8bbcdbb5b442b2eb8140200734f95dacf3fa2123b826cebade52c00db749a18e72cb37ca7a
7
- data.tar.gz: 228643ff98b0d2157c2b53c3b2b380cb536d8d4c1e77cea45e622310f42a3670b5485e2700dd908a1f37b931fda509c59a61940bfbed57f33c1e5207d0d64c7e
6
+ metadata.gz: 6f9deb00d3e385360bfb1f54c65469b302d3bf124d1460d7283216b7fdcaaf5bab2400ee821962f02d7e8fd7be4d1037b195c8bb844127fb9ac11d5c33092f41
7
+ data.tar.gz: a047f4680fff1355ce6af76b3f05193aa6cf4333c59c75a51d3c28010053f3f73a138a6b77b46674bdabf2d131bcdf30be2c6e4f0751a77514fb04f00d5f2648
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wechat-gate (0.1.3)
4
+ wechat-gate (0.1.4)
5
5
  activesupport (~> 5.0.1)
6
6
  rest-client (~> 1.8)
7
7
 
data/README.md CHANGED
@@ -152,6 +152,38 @@ var wxServerConfig = <%= @data.to_json.html_safe %>;
152
152
  })();
153
153
  ```
154
154
 
155
+ ## 其他功能
156
+
157
+ ### 自定义菜单
158
+
159
+ 首先设置菜单配置文件,config/wechat_menu.yml,支持erb,格式请参考[微信自定义菜单文档](https://mp.weixin.qq.com/wiki):
160
+
161
+ ```
162
+ button:
163
+ - type: view
164
+ name: 我的2
165
+ url: <%= @config.oauth2_entrance_url(scope: 'snsapi_userinfo', state: 'profile') %>
166
+ - type: view
167
+ name: 课程
168
+ sub_button:
169
+ - type: view
170
+ name: 免费课程
171
+ url: <%= @config.oauth2_entrance_url(scope: 'snsapi_userinfo', state: 'free') %>
172
+ - type: view
173
+ name: 付费课程
174
+ url: <%= @config.oauth2_entrance_url(scope: 'snsapi_userinfo', state: 'paid') %>
175
+ ```
176
+
177
+ > 其中的**@config**变量为当前微信公众号实例,请不要修改,直接使用
178
+
179
+ 然后执行rake任务:
180
+
181
+ ```shell
182
+ $rails wechat_gate:create_menu APP_NAME=eggman CONFIG=/path/to/wechat.yml MENU=/path/to/wechat_menu
183
+ ```
184
+
185
+ 其中,CONFIG默认为config/wechat.yml,MENU默认为config/wechat_menu.yml,APP_NAME必须指定
186
+
155
187
  ## TODO
156
188
 
157
189
  添加测试
data/RELEASE.md CHANGED
@@ -1,2 +1,7 @@
1
+ # v0.1.4
2
+
3
+ - add create_menu rake task
4
+
1
5
  # v0.1.3
6
+
2
7
  # v0.1.2
@@ -0,0 +1,22 @@
1
+ require 'wechat_gate/exception'
2
+
3
+ namespace :wechat_gate do
4
+
5
+ def validate_envs
6
+ raise WechatGate::Exception::ConfigException, 'need specify APP_NAME!' unless ENV['APP_NAME']
7
+ end
8
+
9
+ desc "create menu, APP_NAME=app_name, CONFIG=/path/to/config/file.yml, MENU=/path/to/menu/config/file.yml"
10
+ task :create_menu => :environment do
11
+ validate_envs
12
+
13
+ @config = WechatGate::Config.new(ENV['APP_NAME'], ENV['CONFIG'])
14
+
15
+ menu_file = ENV['MENU']
16
+ menu_file = "#{Dir.pwd}/config/wechat_menu.yml" unless menu_file
17
+ raise WechatGate::Exception::ConfigException, "MENU #{menu_file} not found!" unless File.exists?(menu_file)
18
+
19
+ menu = YAML.load(ERB.new(File.read(menu_file)).result(binding))
20
+ @config.menu_create(JSON.generate(menu))
21
+ end
22
+ end
data/lib/wechat-gate.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "wechat_gate/version"
2
2
  require "wechat_gate/config"
3
+ require "wechat_gate/railtie" if defined?(Rails)
3
4
 
4
5
  if defined?(ActionController)
5
6
  ActionController::Base.send(:include, WechatGate::Controller)
@@ -0,0 +1,8 @@
1
+ module WechatGate
2
+ require 'rails'
3
+
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks { load "tasks/wechat_gate.rake" }
6
+ end
7
+
8
+ end
@@ -1,3 +1,3 @@
1
1
  module WechatGate
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wechat-gate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lei Lee
@@ -85,6 +85,7 @@ files:
85
85
  - bin/refresh_token_and_ticket
86
86
  - bin/setup
87
87
  - config/wechat.yml
88
+ - lib/tasks/wechat_gate.rake
88
89
  - lib/wechat-gate.rb
89
90
  - lib/wechat_gate/config.rb
90
91
  - lib/wechat_gate/controller.rb
@@ -93,6 +94,7 @@ files:
93
94
  - lib/wechat_gate/menu.rb
94
95
  - lib/wechat_gate/message.rb
95
96
  - lib/wechat_gate/oauth.rb
97
+ - lib/wechat_gate/railtie.rb
96
98
  - lib/wechat_gate/request.rb
97
99
  - lib/wechat_gate/send_message.rb
98
100
  - lib/wechat_gate/tokens/access_token.rb