Merge branch 'weixin_guange' of https://git.trustie.net/jacknudt/trustieforge into weixin_guange

Conflicts:
	public/javascripts/wechat/wechat-dev.js
This commit is contained in:
Tim 2016-03-28 14:47:11 +08:00
commit 406bb7930c
6 changed files with 373 additions and 325 deletions

View File

@ -171,6 +171,18 @@ class WechatsController < ActionController::Base
end
end
def get_open_id
begin
raise "非法操作, code不存在" unless params[:code]
openid = get_openid(params[:code])
raise "无法获取到openid" unless openid
render :text => {status:0, openid: openid}.to_json
rescue Exception=>e
render :text => {status: -1, msg: e.message}.to_json
end
end
def bind
begin
raise "非法操作, code不存在" unless params[:code]

View File

@ -2,7 +2,7 @@ button:
-
type: "view"
name: "最新动态"
url: "http://wechat.trustie.net/assets/wechat/issue.html"
url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=http://wechat.trustie.net/assets/wechat/issue.html&response_type=code&scope=snsapi_base&state=123#wechat_redirect"
-
type: "click"
name: "意见返馈"

View File

@ -1165,6 +1165,7 @@ RedmineApp::Application.routes.draw do
collection do
get :login
post :bind
get :get_open_id
end
end

View File

@ -15,9 +15,6 @@
<body>
<div id="container"></div>
<!-- 模板1开始可以使用scripttype设置为text/html来存放模板片段并且用id标示 -->
<script id="t:result-list" type="text/html">
@ -47,6 +44,7 @@
<script src="/javascripts/jquery-1.3.2.js"></script>
<script src="/javascripts/baiduTemplate.js"></script>
<script src="/javascripts/wechat/auth.js"></script>
<script src="/javascripts/wechat/wechat-dev.js"></script>
</body>
</html>

View File

@ -0,0 +1,35 @@
$(function(){
//获取url中的参数
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return unescape(r[2]); return null; //返回参数值
}
var debug = false;
var g_openid = "";
if(debug){
g_openid = "填写要调试的openid即可";
}
window.getOpenId = function(cb){
if (g_openid.length>0){
cb(g_openid);
}
var code = getUrlParam("code");
$.ajax({
url: '/wechat/get_open_id?code='+code,
type: 'get',
dataType: 'json',
success: function(data){
g_openid = data.openid;
cb(g_openid);
},
error: function(xhr,err){
alert("认证失败: "+err);
}
});
}
});

View File

@ -11,8 +11,6 @@ $(document).ready(function(){
var apiUrl = '/api/v1/'
var setTemplate = function(data){
console.log(data);
var html=bt('t:result-list',{issues: data});
$('#container').prepend(html);
descToggle();
@ -20,8 +18,9 @@ $(document).ready(function(){
}
var loadDataFromServer = function(page){
getOpenId(function(openid){
$.ajax({
url: apiUrl + 'activities/' + page + "?openid=",
url: apiUrl + 'issues/' + id + "?openid="+openid,
dataType: 'json',
success: function(data){
setTemplate(data.data);
@ -29,7 +28,10 @@ $(document).ready(function(){
error: function(xhr,status,err){
console.log(err);
}
});
})
};