From c9c63eeb85291930f14c87ac6842bc2ac4c731db Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Tue, 6 Sep 2016 14:41:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E4=BF=AE=E6=94=B9=E8=B5=84?= =?UTF-8?q?=E6=96=99=E5=90=8E=E5=8F=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/new_comment.rb | 1 + app/api/mobile/apis/users.rb | 93 +++++++++++++++++++ app/services/users_service.rb | 7 ++ app/services/wechat_service.rb | 37 ++++++++ config/wechat.yml.template | 1 + config/wechat.yml.test | 1 + public/assets/wechat/blog_detail.html | 12 +-- public/assets/wechat/course_discussion.html | 12 +-- public/assets/wechat/course_notice.html | 12 +-- public/assets/wechat/homework_detail.html | 12 +-- public/assets/wechat/issue_detail.html | 12 +-- public/assets/wechat/jour_message_detail.html | 12 +-- public/assets/wechat/project_discussion.html | 12 +-- .../wechat/directives/input_on_change.js | 25 +++++ public/javascripts/wechat/others/factory.js | 22 +++-- 15 files changed, 220 insertions(+), 51 deletions(-) create mode 100644 public/javascripts/wechat/directives/input_on_change.js diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 22b654e1b..d98977661 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -313,6 +313,7 @@ module Mobile end present :result, result present :status, status + present :act_id, update_id present :tip, tip present :subscribe,subscribe end diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 764dc957f..ed9115382 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -221,6 +221,99 @@ module Mobile present :data,my_jours,with:Mobile::Entities::Jours present :status,0 end + + desc "我的资料" + + params do + requires :token, type: String + end + + get 'my_userinfo' do + authenticate! + present :data, current_user, with: Mobile::Entities::User + present :status, 0 + end + + desc "我的资料" + + params do + requires :token, type: String + requires :nickname, type: String + requires :sex, type: Integer + requires :mail, type: String + end + + post 'edit_userinfo' do + authenticate! + user = current_user + status = 0 + message = "" + + #昵称 不能超过30个字符 + if params[:nickname].length > 30 then + message = "姓名不能超过30个字符!" + status = -1 + end + + if params[:mail].length > 60 then + message = "邮箱地址不能超过60个字符!" + status = -1 + end + + if !(params[:mail].match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i)) + message = "请输入正确的邮箱地址!" + status = -1 + end + + if status == 0 + # 修改邮箱的时候同步修改到gitlab + if user.mail != params[:mail] + g = Gitlab.client + begin + g.edit_user(user.gid, :email => params[:mail]) + rescue + logger.error "sync user's email of gitlab failed!" + end + end + + user.lastname = params[:nickname] + + se = user.extensions + + se.gender = params[:sex] + + if user.save && se.save + status = 0 + else + message = "保存数据失败!" + status = -1 + end + end + + if status == 0 + present :data, current_user, with: Mobile::Entities::User + present :status, 0 + else + present :status, -1 + present :message, message + end + end + + desc "解除绑定" + + params do + requires :token, type: String + end + + post 'unbind' do + authenticate! + + us = UsersService.new + us.wechat_unbind uw + + present :status, 0 + end + end end end diff --git a/app/services/users_service.rb b/app/services/users_service.rb index abc0d513a..c275e20dd 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -320,8 +320,15 @@ class UsersService end def wechat_unbind uw + user = uw.user + + #发重新绑定的微信模版消息 + ws = WechatService.new + ws.rebind_notice user.id, "login", user.id, "尊敬的用户,您已解除绑定。", "个人原因",format_time(Time.now), "点击进入重新绑定" + uw.user_id = nil uw.delete + end end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 8adc1392f..c11826896 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -445,4 +445,41 @@ class WechatService end end + def rebind_notice(user_id, type, id, first, key1, key2,remark="") + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = { + touser:uw.openid, + template_id:Wechat.config.rebind_notice, + url:Wechat.config.auto_openid_url_1+Wechat.config.auto_openid_url_2+"login"+Wechat.config.auto_openid_url_3, + topcolor:"#FF0000", + data:{ + first: { + value:first, + color:"#707070" + }, + keyword1:{ + value:key1, + color:"#707070" + }, + keyword2:{ + value:key2, + color:"#707070" + }, + remark:{ + value:remark, + color:"#707070" + } + } + } + #data = three_keys_template uw.openid,Wechat.config.create_class_notice, type, id, first, key1, key2, key3, remark + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[rebind_notice] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + end \ No newline at end of file diff --git a/config/wechat.yml.template b/config/wechat.yml.template index 8ca6ac237..734ed0e51 100644 --- a/config/wechat.yml.template +++ b/config/wechat.yml.template @@ -26,6 +26,7 @@ default: &default join_project_notice: "TtXvy0XMIQyCgpnXHhoB8t-x0QIfy-78gAJXsGf9afg" project_issue_notice: "HP8JejOnkzmvFopTarc0l1Tp4bU9qnxzdH27x3186lI" at_notice: "U3kqzgriCaqkPI9qX0NDQOInJ5hiwHCz6wgTsPysSx4" + rebind_notice: "OYsiECfqUlHKlzF_X-pz_xsGh_vAAUunX0jYRdHlyFU" auto_openid_url_1: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e1ab05163a28e37&redirect_uri=https://www.trustie.net/wechat/user_activities" auto_openid_url_2: "&response_type=code&scope=snsapi_base&state=" diff --git a/config/wechat.yml.test b/config/wechat.yml.test index 12cee4751..28c9d974e 100644 --- a/config/wechat.yml.test +++ b/config/wechat.yml.test @@ -26,6 +26,7 @@ default: &default join_project_notice: "3KnMQEMUCmQWkB5JvzrpmguEwnN8bvUHUdpOTudxv_M" project_issue_notice: "HAF2aCta7BtnaOd_cotGvU4tErGWwCd9I9aiClFN7w8" at_notice: "p4HfyZQuF8O5bP_44RbbJS30SGojLJAuZEqp34iB4JU" + rebind_notice: "B97nOiW9cscB_d078I3k0jaPLHeJThTKUuxMoUnWZ2U" auto_openid_url_1: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities" auto_openid_url_2: "&response_type=code&scope=snsapi_base&state=" diff --git a/public/assets/wechat/blog_detail.html b/public/assets/wechat/blog_detail.html index 3b97e7df4..9b9141481 100644 --- a/public/assets/wechat/blog_detail.html +++ b/public/assets/wechat/blog_detail.html @@ -79,9 +79,9 @@