eric_weixin 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{LICENSE.txt → MIT-LICENSE} +1 -3
- data/README.rdoc +24 -0
- data/Rakefile +36 -1
- data/app/assets/javascripts/eric_weixin/application.js +25 -0
- data/app/assets/javascripts/eric_weixin/cms/base.js +22 -0
- data/app/assets/stylesheets/eric_weixin/application.css +15 -0
- data/app/assets/stylesheets/eric_weixin/cms/base.css.scss +14 -0
- data/app/assets/stylesheets/eric_weixin/cms/foundation_and_overrides.scss +1454 -0
- data/app/controllers/eric_weixin/application_controller.rb +5 -0
- data/app/controllers/eric_weixin/cms/base_controller.rb +19 -0
- data/app/controllers/eric_weixin/cms/weixin/article_datas_controller.rb +45 -0
- data/app/controllers/eric_weixin/cms/weixin/customs_service_records_controller.rb +8 -0
- data/app/controllers/eric_weixin/cms/weixin/news_datas_controller.rb +52 -0
- data/app/controllers/eric_weixin/cms/weixin/public_accounts_controller.rb +36 -0
- data/app/controllers/eric_weixin/cms/weixin/reply_message_rules_controller.rb +49 -0
- data/app/controllers/eric_weixin/cms/weixin/two_dimension_codes_controller.rb +36 -0
- data/app/controllers/eric_weixin/cms/weixin/url_encodes_controller.rb +41 -0
- data/app/controllers/eric_weixin/cms/weixin/users_controller.rb +19 -0
- data/{lib/eric_weixin/app/controllers/weixin → app/controllers/eric_weixin/wz}/weixin_controller.rb +18 -7
- data/app/helpers/eric_weixin/application_helper.rb +4 -0
- data/app/helpers/eric_weixin/cms/weixin/public_accounts_helper.rb +28 -0
- data/{lib/eric_weixin/app/model → app/models/eric_weixin}/access_token.rb +23 -9
- data/{lib/eric_weixin/app/model → app/models/eric_weixin}/article.rb +0 -0
- data/{lib/eric_weixin/app/model → app/models/eric_weixin}/article_news.rb +0 -0
- data/app/models/eric_weixin/customs_service_record.rb +99 -0
- data/{lib/eric_weixin/app/model → app/models/eric_weixin}/message_log.rb +8 -2
- data/{lib/eric_weixin/app/model → app/models/eric_weixin}/news.rb +0 -0
- data/{lib/eric_weixin/app/model → app/models/eric_weixin}/public_account.rb +25 -14
- data/{lib/eric_weixin/app/model → app/models/eric_weixin}/reply_message_rule.rb +56 -12
- data/app/models/eric_weixin/report/interface_data.rb +120 -0
- data/app/models/eric_weixin/report/msg_data.rb +292 -0
- data/app/models/eric_weixin/report/news_data.rb +264 -0
- data/app/models/eric_weixin/report/user_data.rb +98 -0
- data/app/models/eric_weixin/template_message_log.rb +87 -0
- data/{lib/eric_weixin/app/model → app/models/eric_weixin}/two_dimension_code.rb +25 -17
- data/app/models/eric_weixin/weixin_user.rb +155 -0
- data/app/views/eric_weixin/cms/weixin/article_datas/_article_data.html.erb +8 -0
- data/app/views/eric_weixin/cms/weixin/article_datas/edit.html.erb +36 -0
- data/app/views/eric_weixin/cms/weixin/article_datas/index.html.erb +21 -0
- data/app/views/eric_weixin/cms/weixin/article_datas/new.html.erb +36 -0
- data/app/views/eric_weixin/cms/weixin/article_datas/show.html.erb +5 -0
- data/app/views/eric_weixin/cms/weixin/customs_service_records/index.html.erb +66 -0
- data/app/views/eric_weixin/cms/weixin/news_datas/_news_data.html.erb +7 -0
- data/app/views/eric_weixin/cms/weixin/news_datas/edit.html.erb +45 -0
- data/app/views/eric_weixin/cms/weixin/news_datas/index.html.erb +30 -0
- data/app/views/eric_weixin/cms/weixin/news_datas/new.html.erb +49 -0
- data/app/views/eric_weixin/cms/weixin/news_datas/show.html.erb +28 -0
- data/app/views/eric_weixin/cms/weixin/public_accounts/_menu.html.erb +5 -0
- data/app/views/eric_weixin/cms/weixin/public_accounts/_public_account.html.erb +19 -0
- data/app/views/eric_weixin/cms/weixin/public_accounts/_weixin_user.html.erb +7 -0
- data/app/views/eric_weixin/cms/weixin/public_accounts/index.html.erb +27 -0
- data/app/views/eric_weixin/cms/weixin/public_accounts/show.html.erb +8 -0
- data/app/views/eric_weixin/cms/weixin/reply_message_rules/destroy.js.erb +2 -0
- data/app/views/eric_weixin/cms/weixin/reply_message_rules/edit.html.erb +69 -0
- data/app/views/eric_weixin/cms/weixin/reply_message_rules/index.html.erb +38 -0
- data/app/views/eric_weixin/cms/weixin/reply_message_rules/new.html.erb +69 -0
- data/app/views/eric_weixin/cms/weixin/two_dimension_codes/_two_dimension_code_form.html.erb +11 -0
- data/app/views/eric_weixin/cms/weixin/two_dimension_codes/index.html.erb +30 -0
- data/app/views/eric_weixin/cms/weixin/two_dimension_codes/new.html.erb +41 -0
- data/app/views/eric_weixin/cms/weixin/two_dimension_codes/show.html.erb +12 -0
- data/app/views/eric_weixin/cms/weixin/url_encodes/_new.html.erb +25 -0
- data/app/views/eric_weixin/cms/weixin/url_encodes/create.js.erb +1 -0
- data/app/views/eric_weixin/cms/weixin/url_encodes/index.html.erb +43 -0
- data/app/views/eric_weixin/cms/weixin/users/index.html.erb +331 -0
- data/app/views/layouts/eric_weixin/application.html.erb +14 -0
- data/app/views/layouts/eric_weixin/cms/base.html.erb +66 -0
- data/{lib/eric_weixin/app/views → app/views/layouts}/eric_weixin/weixin/aa.erb +0 -0
- data/config/initializers/assets.rb +10 -0
- data/config/routes.rb +36 -0
- data/db/migrate/20150610031604_create_weixin_report_user_data.rb +14 -0
- data/db/migrate/20150610031935_create_weixin_report_news_data.rb +24 -0
- data/db/migrate/20150610032545_create_weixin_report_msg_data.rb +17 -0
- data/db/migrate/20150610032852_create_weixin_report_interface_data.rb +15 -0
- data/db/migrate/20150610035901_add_user_data_type_to_weixin_report_user_data.rb +5 -0
- data/db/migrate/20150610040008_add_news_data_type_to_weixin_report_news_data.rb +5 -0
- data/db/migrate/20150610040059_add_msg_data_type_to_weixin_report_msg_data.rb +5 -0
- data/db/migrate/20150610040145_add_interface_data_type_to_weixin_report_interface_data.rb +5 -0
- data/db/migrate/20150610072952_add_total_online_time_and_user_source_to_weixin_report_news_data.rb +6 -0
- data/db/migrate/20150610084545_add_user_source_to_weixin_report_msg_data.rb +5 -0
- data/db/migrate/20150610090206_create_weixin_user.rb +153 -0
- data/db/migrate/20150612104303_add_index_to_weixin_message_logs.rb +7 -0
- data/db/migrate/20150625065249_delete_clomn_weixin_token_from_public_account.rb +5 -0
- data/lib/eric_weixin/engine.rb +9 -0
- data/lib/eric_weixin/modules/analyze_data.rb +124 -0
- data/lib/eric_weixin/modules/ip.rb +33 -0
- data/lib/eric_weixin/modules/mult_customer.rb +113 -0
- data/lib/eric_weixin/{app/moudles → modules}/reply_message.rb +3 -3
- data/lib/eric_weixin/{app/moudles → modules}/snsapi.rb +3 -3
- data/lib/eric_weixin/version.rb +1 -1
- data/lib/eric_weixin.rb +6 -24
- data/lib/tasks/eric_weixin_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +78 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/eric_weixin_test.rb +7 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +19 -0
- metadata +165 -196
- data/.gitignore +0 -23
- data/.idea/.name +0 -1
- data/.idea/.rakeTasks +0 -7
- data/.idea/encodings.xml +0 -5
- data/.idea/eric_weixin.iml +0 -22
- data/.idea/misc.xml +0 -5
- data/.idea/modules.xml +0 -9
- data/.idea/scopes/scope_settings.xml +0 -5
- data/.idea/vcs.xml +0 -7
- data/.rvmrc +0 -1
- data/Gemfile +0 -4
- data/README.md +0 -29
- data/eric_weixin.gemspec +0 -32
- data/lib/eric_weixin/app/model/template_message_log.rb +0 -75
- data/lib/eric_weixin/app/model/weixin_user.rb +0 -96
- data/lib/eric_weixin/app/moudles/mult_customer.rb +0 -57
@@ -0,0 +1,19 @@
|
|
1
|
+
class EricWeixin::Cms::BaseController < ApplicationController
|
2
|
+
before_filter :need_login
|
3
|
+
around_filter :round
|
4
|
+
|
5
|
+
def round
|
6
|
+
yield
|
7
|
+
end
|
8
|
+
|
9
|
+
def current_user
|
10
|
+
return nil if session[:employee_id].blank?
|
11
|
+
::Personal::Employee.find(session[:employee_id])
|
12
|
+
end
|
13
|
+
|
14
|
+
def need_login
|
15
|
+
redirect_to '/' if current_user.blank?
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class EricWeixin::Cms::Weixin::ArticleDatasController < EricWeixin::Cms::BaseController
|
2
|
+
before_action :set_weixin_article_data, only: [:show, :edit, :update, :destroy]
|
3
|
+
def index
|
4
|
+
@article_datas = ::EricWeixin::Article.all.paginate(page: params[:page], per_page: 5)
|
5
|
+
end
|
6
|
+
|
7
|
+
def new
|
8
|
+
@article_data = ::EricWeixin::Article.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def edit
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def create
|
21
|
+
begin
|
22
|
+
@article_data = ::EricWeixin::Article.create_article_data(weixin_article_data_params)
|
23
|
+
redirect_to "/eric_weixin/cms/weixin/article_datas/#{@article_data.id}"
|
24
|
+
rescue Exception => e
|
25
|
+
set_notice "参数输入有错"
|
26
|
+
redirect_to "/eric_weixin/cms/weixin/article_datas/new"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
pp params
|
32
|
+
@article_data.update(weixin_article_data_params)
|
33
|
+
render :edit
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
private
|
38
|
+
def set_weixin_article_data
|
39
|
+
@article_data = ::EricWeixin::Article.find(params[:id])
|
40
|
+
end
|
41
|
+
|
42
|
+
def weixin_article_data_params
|
43
|
+
params.require(:article).permit(:title, :desc, :pic_url, :link_url)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class EricWeixin::Cms::Weixin::CustomsServiceRecordsController < EricWeixin::Cms::BaseController
|
2
|
+
|
3
|
+
def index
|
4
|
+
options = params.permit(:public_account_id, :opercode, :chat_date, :chat_content, :worker, :nick_name)
|
5
|
+
@customs_service_records = ::EricWeixin::CustomsServiceRecord.common_query options
|
6
|
+
@customs_service_records = @customs_service_records.paginate(page: params[:page], per_page:20)
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class EricWeixin::Cms::Weixin::NewsDatasController < EricWeixin::Cms::BaseController
|
2
|
+
def index
|
3
|
+
@news_datas = ::EricWeixin::News.all.paginate(page: params[:page], per_page: 10)
|
4
|
+
end
|
5
|
+
|
6
|
+
def show
|
7
|
+
@news_data = ::EricWeixin::News.find(params[:id])
|
8
|
+
end
|
9
|
+
|
10
|
+
def edit
|
11
|
+
@news_data = ::EricWeixin::News.find(params[:id])
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
begin
|
16
|
+
@news_data = ::EricWeixin::News.create_news_datas( weixin_news_data_param,
|
17
|
+
params[:weixin_news][:weixin_article_data_ids],
|
18
|
+
params[:weixin_news][:weixin_article_data_sort]
|
19
|
+
)
|
20
|
+
redirect_to "/eric_weixin/cms/weixin/news_datas/#{@news_data.id}/edit", notice: '微信图文消息创建成功.'
|
21
|
+
rescue Exception => e
|
22
|
+
render :edit
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def new
|
27
|
+
@news_data = ::EricWeixin::News.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
begin
|
32
|
+
@news_data = ::EricWeixin::News.update_news_datas(params[:id],
|
33
|
+
weixin_news_data_param,
|
34
|
+
params[:weixin_news][:weixin_article_data_ids],
|
35
|
+
params[:weixin_news][:weixin_article_data_sort]
|
36
|
+
)
|
37
|
+
|
38
|
+
redirect_to "/eric_weixin/cms/weixin/news_datas/#{@news_data.id}/edit", notice: '微信图文消息更新成功.'
|
39
|
+
rescue Exception => e
|
40
|
+
render :edit
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def set_weixin_news_data
|
46
|
+
@weixin_news = ::EricWeixin::News.find(params[:id])
|
47
|
+
end
|
48
|
+
|
49
|
+
def weixin_news_data_param
|
50
|
+
params.require(:weixin_news).permit(:title, :match_key)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class EricWeixin::Cms::Weixin::PublicAccountsController < EricWeixin::Cms::BaseController
|
2
|
+
def index
|
3
|
+
@public_accounts = ::EricWeixin::PublicAccount.all.paginate(page:params[:page], per_page: 5)
|
4
|
+
end
|
5
|
+
def show
|
6
|
+
@public_account = ::EricWeixin::PublicAccount.find(params[:id])
|
7
|
+
@weixin_menus = @public_account.weixin_menus.to_json
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_menu
|
11
|
+
begin
|
12
|
+
@public_account = ::EricWeixin::PublicAccount.find(params[:id])
|
13
|
+
@public_account.create_menu params[:menu_json]
|
14
|
+
rescue Exception => e
|
15
|
+
dispose_exception e
|
16
|
+
flash[:alert] = '创建菜单失败,原因:' + get_notice_str
|
17
|
+
end
|
18
|
+
|
19
|
+
redirect_to :action => :show
|
20
|
+
end
|
21
|
+
|
22
|
+
def rebuild_weixin_users
|
23
|
+
@public_account = ::EricWeixin::PublicAccount.find(params[:id])
|
24
|
+
@public_account.rebuild_users
|
25
|
+
# set_notice("重建成功")
|
26
|
+
flash[:success] = "更新用户列表成功。"
|
27
|
+
redirect_to :action => :index
|
28
|
+
end
|
29
|
+
|
30
|
+
def export
|
31
|
+
@public_account = ::EricWeixin::PublicAccount.find(params[:id])
|
32
|
+
@csv = EricWeixin::WeixinUser.export_users_to_csv(@public_account.id)
|
33
|
+
send_data @csv
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class EricWeixin::Cms::Weixin::ReplyMessageRulesController < EricWeixin::Cms::BaseController
|
2
|
+
before_filter :need_login
|
3
|
+
|
4
|
+
def index
|
5
|
+
@reply_message_rules = ::EricWeixin::ReplyMessageRule.valid.paginate(page: params[:page], per_page:params[:per_page]||10)
|
6
|
+
@public_accounts = ::EricWeixin::PublicAccount.all
|
7
|
+
end
|
8
|
+
|
9
|
+
def new
|
10
|
+
@public_accounts = ::EricWeixin::PublicAccount.all
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
begin
|
15
|
+
::EricWeixin::ReplyMessageRule.create_reply_message_rule params
|
16
|
+
flash[:success] = "创建成功。"
|
17
|
+
redirect_to action: :index
|
18
|
+
rescue Exception=>e
|
19
|
+
dispose_exception e
|
20
|
+
flash.now[:alert] = get_notice_str
|
21
|
+
@public_accounts = ::EricWeixin::PublicAccount.all
|
22
|
+
render :new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def edit
|
27
|
+
@rule = ::EricWeixin::ReplyMessageRule.find(params[:id])
|
28
|
+
@public_accounts = ::EricWeixin::PublicAccount.all
|
29
|
+
end
|
30
|
+
|
31
|
+
def update
|
32
|
+
begin
|
33
|
+
@reply_message_rule = ::EricWeixin::ReplyMessageRule.update_reply_message_rule(params[:id],params)
|
34
|
+
flash[:success] = "更新成功。"
|
35
|
+
redirect_to action: :index
|
36
|
+
rescue Exception=> e
|
37
|
+
dispose_exception e
|
38
|
+
flash.now[:alert] = get_notice_str
|
39
|
+
@public_accounts = ::EricWeixin::PublicAccount.all
|
40
|
+
render :edit
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
rule = ::EricWeixin::ReplyMessageRule.find(params[:id])
|
46
|
+
@rule_id = rule.id
|
47
|
+
rule.destroy
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class EricWeixin::Cms::Weixin::TwoDimensionCodesController < EricWeixin::Cms::BaseController
|
2
|
+
# before_action :set_weixin_article_data, only: [:show, :edit, :update, :destroy]
|
3
|
+
def index
|
4
|
+
@two_dimension_codes = ::EricWeixin::TwoDimensionCode.where("action_info <> ?", '')
|
5
|
+
end
|
6
|
+
|
7
|
+
def show
|
8
|
+
@two_dimension_code = ::EricWeixin::TwoDimensionCode.find(params[:id])
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
begin
|
13
|
+
@two_dimension_code = ::EricWeixin::TwoDimensionCode.get_long_time_two_dimension_code(two_dimension_code_params)
|
14
|
+
redirect_to cms_weixin_two_dimension_code_path(@two_dimension_code.id)
|
15
|
+
rescue Exception => e
|
16
|
+
dispose_exception e
|
17
|
+
message = get_notice_str
|
18
|
+
redirect_to new_cms_weixin_two_dimension_code_path
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def new
|
23
|
+
@two_dimension_code = ::EricWeixin::TwoDimensionCode.new
|
24
|
+
@public_accounts = ::EricWeixin::PublicAccount.all
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def find_two_dimension_code
|
29
|
+
@two_dimension_code = ::EricWeixin::TwoDimensionCode.find(params[:id])
|
30
|
+
end
|
31
|
+
|
32
|
+
def two_dimension_code_params
|
33
|
+
params.require(:two).permit(:action_info, :scene_str, :app_id)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class EricWeixin::Cms::Weixin::UrlEncodesController < EricWeixin::Cms::BaseController
|
2
|
+
def index
|
3
|
+
end
|
4
|
+
|
5
|
+
def create
|
6
|
+
params = url_params
|
7
|
+
p params[:details]
|
8
|
+
if params[:only_short_url].blank?
|
9
|
+
if params[:details] == '1'
|
10
|
+
@details_url = EricWeixin::Snsapi.get_snsapi_userinfo_url params
|
11
|
+
temp_params = params
|
12
|
+
temp_params[:url] = @details_url
|
13
|
+
@short_details_url = EricWeixin::TwoDimensionCode.short_url temp_params
|
14
|
+
end
|
15
|
+
if params[:only_id] == '1'
|
16
|
+
@only_id_url = EricWeixin::Snsapi.get_snsapi_base_url params
|
17
|
+
temp_params = params
|
18
|
+
temp_params[:url] = @only_id_url
|
19
|
+
@short_only_id_url = EricWeixin::TwoDimensionCode.short_url temp_params
|
20
|
+
end
|
21
|
+
if params[:details] == '0' && params[:only_id] == '0'
|
22
|
+
@details_url = EricWeixin::Snsapi.get_snsapi_userinfo_url params
|
23
|
+
temp_params = params
|
24
|
+
temp_params[:url] = @details_url
|
25
|
+
@short_details_url = EricWeixin::TwoDimensionCode.short_url temp_params
|
26
|
+
end
|
27
|
+
else
|
28
|
+
params[:url] = params[:only_short_url]
|
29
|
+
@short_url = EricWeixin::TwoDimensionCode.short_url params
|
30
|
+
end
|
31
|
+
|
32
|
+
respond_to do |format|
|
33
|
+
format.js {}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def url_params
|
39
|
+
params.require('/eric_weixin/cms/weixin/url_encodes').permit(:url, :schema_host, :app_id, :details, :only_id, :only_short_url)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class EricWeixin::Cms::Weixin::UsersController < EricWeixin::Cms::BaseController
|
2
|
+
def index
|
3
|
+
pp user_params
|
4
|
+
@user = ::EricWeixin::WeixinUser.search_weixin_user(user_params).paginate(:page => params[:page], :per_page => 10)
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
def modify_remark
|
9
|
+
user = ::EricWeixin::WeixinUser.find(params[:id])
|
10
|
+
user.set_remark params[:new_remark]
|
11
|
+
user.reload
|
12
|
+
render text: user.remark
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def user_params
|
17
|
+
params.permit(:id, :openid, :sex, :nickname, :language, :city, :province, :country, :subscribe_time_start, :subscribe, :subscribe_time_end, :created_at_start, :created_at_end, :updated_at_start, :updated_at_end, :remark, :member_info_id, :weixin_public_account_id, :last_register_channel, :first_register_channel)
|
18
|
+
end
|
19
|
+
end
|
data/{lib/eric_weixin/app/controllers/weixin → app/controllers/eric_weixin/wz}/weixin_controller.rb
RENAMED
@@ -1,24 +1,29 @@
|
|
1
1
|
require "pp"
|
2
2
|
module EricWeixin
|
3
|
-
class WeixinController <
|
3
|
+
class Wz::WeixinController < ApplicationController
|
4
4
|
# 第一次接入时,用于微信服务器验证开者服务器的真实性。
|
5
|
+
protect_from_forgery except: :reply
|
5
6
|
def index
|
6
|
-
render
|
7
|
+
render :text => params[:echostr]
|
7
8
|
end
|
8
9
|
|
10
|
+
|
11
|
+
|
9
12
|
def reply
|
10
13
|
request_body = request.body.read
|
11
|
-
public_account =
|
14
|
+
public_account = PublicAccount.find_by_weixin_app_id params[:app_id]
|
15
|
+
BusinessException.raise 'ip不正确' unless Ip.is_ip_exist? public_account_id: public_account.id,
|
16
|
+
ip: get_ip
|
12
17
|
"message from wechat: ".to_logger
|
13
18
|
request_body.to_logger
|
14
19
|
weixin_message = MultiXml.parse(request_body).deep_symbolize_keys[:xml]
|
15
|
-
message =
|
20
|
+
message = ReplyMessageRule.process_rule(weixin_message, public_account)
|
16
21
|
render xml: message
|
17
22
|
end
|
18
23
|
|
19
24
|
def snsapi_api
|
20
25
|
require "base64"
|
21
|
-
weixin_public_account =
|
26
|
+
weixin_public_account = PublicAccount.where(weixin_app_id: params["weixin_app_id"]).first
|
22
27
|
response = RestClient.get "https://api.weixin.qq.com/sns/oauth2/access_token?appid=#{weixin_public_account.weixin_app_id}&secret=#{weixin_public_account.weixin_secret_key}&code=#{params[:code]}&grant_type=authorization_code"
|
23
28
|
result_hash = JSON.parse(response.body)
|
24
29
|
url = URI(Base64.decode64(params["url"]))
|
@@ -32,7 +37,7 @@ module EricWeixin
|
|
32
37
|
|
33
38
|
def snsapi_userinfo
|
34
39
|
require "base64"
|
35
|
-
weixin_public_account =
|
40
|
+
weixin_public_account = PublicAccount.where(weixin_app_id: params["weixin_app_id"]).first
|
36
41
|
url = URI(Base64.decode64(params["url"]))
|
37
42
|
query_array = URI.decode_www_form url.query||''
|
38
43
|
query_array << ["state", params["state"]]
|
@@ -58,7 +63,7 @@ module EricWeixin
|
|
58
63
|
response = RestClient.get "https://api.weixin.qq.com/sns/userinfo?access_token=#{result_hash['access_token']}&openid=#{result_hash['openid']}&lang=zh_CN"
|
59
64
|
user_info_hash = JSON.parse(response.body)
|
60
65
|
query_array << ["nickname", user_info_hash['nickname']]
|
61
|
-
query_array << ["sex",
|
66
|
+
query_array << ["sex", WeixinUser::SEX[user_info_hash['nickname'].to_i]]
|
62
67
|
query_array << ["province", user_info_hash['province']]
|
63
68
|
query_array << ["city", user_info_hash['city']]
|
64
69
|
query_array << ["country", user_info_hash['country']]
|
@@ -73,5 +78,11 @@ module EricWeixin
|
|
73
78
|
@ee = 12
|
74
79
|
end
|
75
80
|
|
81
|
+
private
|
82
|
+
def get_ip
|
83
|
+
ip = request.env["HTTP_X_FORWARDED_FOR"]||"127.0.0.1"
|
84
|
+
ip = begin ip.split(',')[0] rescue "127.0.0.1" end
|
85
|
+
end
|
86
|
+
|
76
87
|
end
|
77
88
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module EricWeixin::Cms::Weixin::PublicAccountsHelper
|
2
|
+
def weixin_menu_show_tag json
|
3
|
+
puts "****"*300
|
4
|
+
puts json.class
|
5
|
+
puts "****"*300
|
6
|
+
return '<h6>还没有任何菜单哦!</h6>' if json.blank? || json == "null"
|
7
|
+
result = '<table border="1" style="word-break:break-all;"><thead><th width="140">button name</th><th width="140">sub_button name</th><th width="60">type</th><th width="150">key</th><th>url</th></thead><tbody>'
|
8
|
+
obj = JSON.parse json
|
9
|
+
button = obj['button']
|
10
|
+
menu_lv1_count = button.count
|
11
|
+
0.upto menu_lv1_count-1 do |fi|
|
12
|
+
if button[fi]['sub_button'].blank? || button[fi]['sub_button'].count == 0
|
13
|
+
result += "<tr><td>#{button[fi]['name']}</td><td></td><td>#{button[fi]['type']}</td><td>#{button[fi]['key']}</td><td>#{button[fi]['url']}</td></tr>"
|
14
|
+
else
|
15
|
+
sub_button = button[fi]['sub_button']
|
16
|
+
menu_lv2_count = sub_button.count
|
17
|
+
result += "<tr><td rowspan='#{menu_lv2_count}'>#{button[fi]['name']}</td><td>#{sub_button[0]['name']}</td><td>#{sub_button[0]['type']}</td><td>#{sub_button[0]['key']}</td><td>#{sub_button[0]['url']}</td></tr>"
|
18
|
+
if menu_lv2_count >= 2
|
19
|
+
1.upto menu_lv2_count-1 do |si|
|
20
|
+
result += "<tr><td>#{sub_button[si]['name']}</td><td>#{sub_button[si]['type']}</td><td>#{sub_button[si]['key']}</td><td>#{sub_button[si]['url']}</td></tr>"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
result += '</tbody></table>'
|
26
|
+
result
|
27
|
+
end
|
28
|
+
end
|
@@ -5,15 +5,27 @@ module EricWeixin
|
|
5
5
|
|
6
6
|
self.table_name = "weixin_access_tokens"
|
7
7
|
|
8
|
+
#设定最初的腾讯微信服务器列表
|
9
|
+
$ip_list = {"no-ip" => true}
|
10
|
+
|
11
|
+
|
12
|
+
# 获取 AccessToken 方法一。根据 APPID 查到微信公众号 PublicAccount.id ,然后
|
13
|
+
# 调用 ::EricWeixin::AccessToken.get_valid_access_token 获取 AccessToken 并作为返回值返回.
|
14
|
+
# ===参数说明
|
15
|
+
# * app_id #微信公众号的 app_id
|
16
|
+
# ===调用示例
|
17
|
+
# ::EricWeixin::AccessToken.get_valid_access_token_by_app_id app_id: 'wx51729870d9012531'
|
8
18
|
def self.get_valid_access_token_by_app_id options
|
9
19
|
pa = ::EricWeixin::PublicAccount.find_by_weixin_app_id options[:app_id]
|
10
20
|
::EricWeixin::AccessToken.get_valid_access_token public_account_id: pa.id
|
11
21
|
end
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
22
|
+
|
23
|
+
# 获取 AccessToken 方法二。根据微信公众号 PublicAccount.id 获取 AccessToken.
|
24
|
+
# 若微信公众号未存在 AccessToken 或者 AccessToken 过期都立即获取新的并返回。
|
25
|
+
# ===参数说明
|
26
|
+
# * public_account_id #公众账号 ID
|
27
|
+
# ===调用示例
|
28
|
+
# ::EricWeixin::AccessToken.get_valid_access_token public_account_id: 1
|
17
29
|
def self.get_valid_access_token options
|
18
30
|
::EricWeixin::AccessToken.transaction do
|
19
31
|
access_token = ::EricWeixin::AccessToken.find_by_public_account_id options[:public_account_id]
|
@@ -34,15 +46,17 @@ module EricWeixin
|
|
34
46
|
access_token.access_token
|
35
47
|
end
|
36
48
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
49
|
+
|
50
|
+
# 根据微信公众号从微信服务器获取最新的 AccessToken.
|
51
|
+
# ===参数说明
|
52
|
+
# * public_account_id #公众账号 ID
|
53
|
+
# ===调用示例
|
54
|
+
# ::EricWeixin::AccessToken.get_new_token '5e3b98ca0000959946657212739fd535'
|
40
55
|
def self.get_new_token public_account_id
|
41
56
|
account = ::EricWeixin::PublicAccount.find_by_id public_account_id
|
42
57
|
BusinessException.raise 'account 不存在' if account.blank?
|
43
58
|
url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=#{account.weixin_app_id}&secret=#{account.weixin_secret_key}"
|
44
59
|
response = RestClient.get url
|
45
|
-
pp '.........'
|
46
60
|
pp response
|
47
61
|
JSON.parse(response)["access_token"]
|
48
62
|
end
|