diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 8c46d530c..8b27803ad 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -11,11 +11,12 @@ module Mobile params do requires :type, type: String requires :content, type: String + requires :openid, type: String end post ':id' do type = params[:type] result = 1 - current_user = User.find 8686 + current_user = UserWechat.find_by_openid(params[:openid]).user if params[:content]!="" && current_user case type when "HomeworkCommon" diff --git a/public/javascripts/wechat/homework_detail.js b/public/javascripts/wechat/homework_detail.js index 39d016133..166ed20bf 100644 --- a/public/javascripts/wechat/homework_detail.js +++ b/public/javascripts/wechat/homework_detail.js @@ -68,23 +68,26 @@ $(document).ready(function(){ replyNum++; $(".reply-num").text("(" + replyNum + ")"); - //获取并传送回复用户数据 - var userInfo = { - "type" : "HomeworkCommon", - "content" : postInput - }; - - $.ajax({ - type: "POST", //提交方式 - dataType: "json", //类型 - url: apiUrl + 'new_comment/' + homeworkID, //提交的页面,方法名 - data: userInfo, //参数,如果没有,可以为null - success: function (data) { //如果执行成功,那么执行此方法 - setReplyTemplate(data.data); - }, - error: function (err) { //如果执行不成功,那么执行此方法 - alert("err:" + err); - } + getOpenId(function(openid) { + //获取并传送回复用户数据 + var userInfo = { + "type": "HomeworkCommon", + "content": postInput, + openid: openid + }; + + $.ajax({ + type: "POST", //提交方式 + dataType: "json", //类型 + url: apiUrl + 'new_comment/' + homeworkID, //提交的页面,方法名 + data: userInfo, //参数,如果没有,可以为null + success: function (data) { //如果执行成功,那么执行此方法 + setReplyTemplate(data.data); + }, + error: function (err) { //如果执行不成功,那么执行此方法 + alert("err:" + err); + } + }) }); } diff --git a/public/javascripts/wechat/issue_detail.js b/public/javascripts/wechat/issue_detail.js index 03ebda233..2b2766d29 100644 --- a/public/javascripts/wechat/issue_detail.js +++ b/public/javascripts/wechat/issue_detail.js @@ -72,23 +72,26 @@ $(document).ready(function(){ replyNum++; $(".reply-num").text("(" + replyNum + ")"); - //获取并传送回复用户数据 - var userInfo = { - "type" : "Issue", - "content" : postInput - }; - - $.ajax({ - type: "POST", //提交方式 - dataType: "json", //类型 - url: apiUrl + 'new_comment/' + IssueID, //提交的页面,方法名 - data: userInfo, //参数,如果没有,可以为null - success: function (data) { //如果执行成功,那么执行此方法 - setReplyTemplate(data.data); - }, - error: function (err) { //如果执行不成功,那么执行此方法 - alert("err:" + err); - } + getOpenId(function(openid) { + //获取并传送回复用户数据 + var userInfo = { + "type": "Issue", + "content": postInput, + openid: openid, + }; + + $.ajax({ + type: "POST", //提交方式 + dataType: "json", //类型 + url: apiUrl + 'new_comment/' + IssueID, //提交的页面,方法名 + data: userInfo, //参数,如果没有,可以为null + success: function (data) { //如果执行成功,那么执行此方法 + setReplyTemplate(data.data); + }, + error: function (err) { //如果执行不成功,那么执行此方法 + alert("err:" + err); + } + }) }); }