Merge branch 'weixin_guange' of https://git.trustie.net/jacknudt/trustieforge into weixin_guange
This commit is contained in:
commit
65719add19
|
@ -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
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<link type="text/css" rel="stylesheet" href="/stylesheets/weui/weui.min.css" />
|
||||
<%= stylesheet_link_tag '/stylesheets/weui/weixin.css' %>
|
||||
|
||||
<script src="//res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
|
||||
<script type="text/javascript">
|
||||
window.g_debug = false; //调试标志,如果在本地请置为true
|
||||
window.apiUrl = '/api/v1/';
|
||||
|
@ -21,6 +22,27 @@
|
|||
<% elsif @project_id %>
|
||||
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: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
||||
appId: '<%= @appid %>', // 必填,公众号的唯一标识
|
||||
timestamp: <%= @sign_params[:timestamp] %>, // 必填,生成签名的时间戳
|
||||
nonceStr: '<%= @sign_params[:noncestr] %>', // 必填,生成签名的随机串
|
||||
signature: '<%= @sign_params[:signature] %>',// 必填,签名,见附录1
|
||||
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone',
|
||||
'hideOptionMenu','showOptionMenu','showMenuItems', 'hideMenuItems',
|
||||
'hideAllNonBaseMenuItem','showAllNonBaseMenuItem','closeWindow', 'scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
|
||||
});
|
||||
|
||||
wx.ready(function(){
|
||||
console.log("wx ready");
|
||||
});
|
||||
|
||||
wx.error(function(err){
|
||||
console.log(err);
|
||||
});
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -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://wechat.trustie.net/', // 分享链接
|
||||
imgUrl: 'http://wechat.trustie.net/images/logo2.png', // 分享图标
|
||||
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(
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
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.ready(function(){
|
||||
wx.hideOptionMenu();
|
||||
})
|
||||
|
||||
if(auth.get_bind().then(function(){
|
||||
$location.path("/activities");
|
||||
}));
|
||||
|
@ -33,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);
|
||||
|
|
|
@ -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){
|
||||
//是否已经绑定
|
||||
|
|
Loading…
Reference in New Issue