From 2632f7aa593d132a1c90b3eb640e789be089cc74 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 2 Aug 2016 17:01:10 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=BC=95=E5=85=A5wechat=20js=20sdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/wechats_controller.rb | 11 +++++++++++ app/views/wechats/user_activities.html.erb | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 87ede1365..190502a3c 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -383,7 +383,15 @@ class WechatsController < ActionController::Base render 'wechats/user_activities', layout: nil end + + def user_activities + + @appid = Wechat.config.appid + ## sign + + @sign_params = wechat.jsapi_ticket.signature(current_url) + session[:wechat_code] = params[:code] if params[:code] @path = '/'+(params[:state] || '') open_id = get_openid_from_code(params[:code]) rescue @@ -431,6 +439,9 @@ class WechatsController < ActionController::Base uw = UserWechat.where(openid: openid).first end + def current_url + "#{request.protocol}#{request.host_with_port}#{request.fullpath}" + end end diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb index f5cfb8250..e06d84bfb 100644 --- a/app/views/wechats/user_activities.html.erb +++ b/app/views/wechats/user_activities.html.erb @@ -12,6 +12,7 @@ <%= stylesheet_link_tag '/stylesheets/weui/weixin.css' %> + From 2a67ec5407defd7a748a5e5c41ad954391bb2185 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 2 Aug 2016 17:27:40 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=A1=B5=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/wechats/user_activities.html.erb | 5 ++++- public/javascripts/wechat/controllers/login.js | 7 +++++-- public/javascripts/wechat/others/factory.js | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb index e06d84bfb..e7b89f224 100644 --- a/app/views/wechats/user_activities.html.erb +++ b/app/views/wechats/user_activities.html.erb @@ -23,6 +23,8 @@ window.g_projectid = <%= @project_id %>; <% end %> + //参考文档 + //https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN wx.config({ debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: '<%= @appid %>', // 必填,公众号的唯一标识 @@ -30,7 +32,8 @@ nonceStr: '<%= @sign_params[:noncestr] %>', // 必填,生成签名的随机串 signature: '<%= @sign_params[:signature] %>',// 必填,签名,见附录1 jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone', - 'hideMenuItems','closeWindow', 'scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 + 'hideOptionMenu','showOptionMenu','showMenuItems', 'hideMenuItems', + 'hideAllNonBaseMenuItem','showAllNonBaseMenuItem','closeWindow', 'scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ diff --git a/public/javascripts/wechat/controllers/login.js b/public/javascripts/wechat/controllers/login.js index f31dd629f..b70398955 100644 --- a/public/javascripts/wechat/controllers/login.js +++ b/public/javascripts/wechat/controllers/login.js @@ -1,5 +1,8 @@ -app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams', 'alertService', 'config','auth','session', - function ($scope, $http, $location, $routeParams, alertService, config, auth,session) { +app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams', 'alertService', 'config','auth','session','wx', + function ($scope, $http, $location, $routeParams, alertService, config, auth,session, wx) { + // 登录页不用显示菜音 + wx.hideOptionMenu(); + if(auth.get_bind().then(function(){ $location.path("/activities"); })); diff --git a/public/javascripts/wechat/others/factory.js b/public/javascripts/wechat/others/factory.js index 89e2b700f..6e110a6ea 100644 --- a/public/javascripts/wechat/others/factory.js +++ b/public/javascripts/wechat/others/factory.js @@ -30,6 +30,10 @@ app.factory('alertService', function(){ } }); +app.factory('wx', ['$window', function($window){ + var wechat = $window.wx; + return wechat; +}]); app.factory('auth', ['$http','$routeParams', '$q', 'session', 'config',function($http,$routeParams, $q, session,config){ //是否已经绑定 From 56d6f4b9bc308d200716e6a1f42983d71b469729 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 2 Aug 2016 17:36:59 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=AE=9A=E5=88=B6=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wechat/controllers/invite_code.js | 16 +++++++++++++++- public/javascripts/wechat/controllers/login.js | 5 ++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/public/javascripts/wechat/controllers/invite_code.js b/public/javascripts/wechat/controllers/invite_code.js index ca69e308c..ec0a3ee65 100644 --- a/public/javascripts/wechat/controllers/invite_code.js +++ b/public/javascripts/wechat/controllers/invite_code.js @@ -3,9 +3,23 @@ */ -app.controller('InviteCodeController', ['$scope','$http', '$routeParams','config','auth', function($scope, $http, $routeParams, config, auth){ +app.controller('InviteCodeController', ['$scope','$http', '$routeParams','config','auth','wx', function($scope, $http, $routeParams, config, auth, wx){ var vm = $scope; + wx.ready(function(){ + wx.onMenuShareTimeline({ + title: '定制的标题', // 分享标题 + link: 'http://www.baidu.com', // 分享链接 + imgUrl: 'https://rescdn.qqmail.com/zh_CN/htmledition/images/webp/spacer1e9c5d.gif', // 分享图标 + success: function () { + console.log("share successed."); + }, + cancel: function () { + console.log("share canceled."); + } + }); + }); + vm.course = {}; var courseid = $routeParams.id; $http.get(config.apiUrl+ 'courses/'+courseid+"?token="+auth.token()).then( diff --git a/public/javascripts/wechat/controllers/login.js b/public/javascripts/wechat/controllers/login.js index b70398955..863af07ee 100644 --- a/public/javascripts/wechat/controllers/login.js +++ b/public/javascripts/wechat/controllers/login.js @@ -1,7 +1,10 @@ app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams', 'alertService', 'config','auth','session','wx', function ($scope, $http, $location, $routeParams, alertService, config, auth,session, wx) { + // 登录页不用显示菜音 - wx.hideOptionMenu(); + wx.ready(function(){ + wx.hideOptionMenu(); + }) if(auth.get_bind().then(function(){ $location.path("/activities"); From 6f2b84570ff550703dda9a5a0df22e440434233d Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 2 Aug 2016 17:48:51 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/wechats/user_activities.html.erb | 2 +- public/javascripts/wechat/controllers/invite_code.js | 4 ++-- public/javascripts/wechat/controllers/login.js | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb index e7b89f224..ac3b845ff 100644 --- a/app/views/wechats/user_activities.html.erb +++ b/app/views/wechats/user_activities.html.erb @@ -26,7 +26,7 @@ //参考文档 //https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN wx.config({ - debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 + debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: '<%= @appid %>', // 必填,公众号的唯一标识 timestamp: <%= @sign_params[:timestamp] %>, // 必填,生成签名的时间戳 nonceStr: '<%= @sign_params[:noncestr] %>', // 必填,生成签名的随机串 diff --git a/public/javascripts/wechat/controllers/invite_code.js b/public/javascripts/wechat/controllers/invite_code.js index ec0a3ee65..0467dee5d 100644 --- a/public/javascripts/wechat/controllers/invite_code.js +++ b/public/javascripts/wechat/controllers/invite_code.js @@ -9,8 +9,8 @@ app.controller('InviteCodeController', ['$scope','$http', '$routeParams','config wx.ready(function(){ wx.onMenuShareTimeline({ title: '定制的标题', // 分享标题 - link: 'http://www.baidu.com', // 分享链接 - imgUrl: 'https://rescdn.qqmail.com/zh_CN/htmledition/images/webp/spacer1e9c5d.gif', // 分享图标 + link: 'http://wechat.trustie.net/', // 分享链接 + imgUrl: 'http://wechat.trustie.net/images/logo2.png', // 分享图标 success: function () { console.log("share successed."); }, diff --git a/public/javascripts/wechat/controllers/login.js b/public/javascripts/wechat/controllers/login.js index 863af07ee..f8e87a93f 100644 --- a/public/javascripts/wechat/controllers/login.js +++ b/public/javascripts/wechat/controllers/login.js @@ -39,8 +39,7 @@ app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams vm.loginFailed = (response.data.status != 0); if (!$scope.loginFailed) { //绑定成功 vm.alertService.showMessage('提示', response.data.message, function(){ -// $location.path("/activities"); - window.WeixinJSBridge.call('closeWindow'); + wx.closeWindow(); }); } else { vm.alertService.showMessage('出错了', response.data.message);