From 60931dde6ab2a87cf6c6b0a1a794635ce51b5749 Mon Sep 17 00:00:00 2001
From: guange <8863824@gmail.com>
Date: Sat, 26 Mar 2016 15:52:14 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96openid?=
=?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/wechats_controller.rb | 12 ++++++++++
config/menu.yml | 2 +-
config/routes.rb | 1 +
public/assets/wechat/issue.html | 1 +
public/javascripts/wechat/auth.js | 29 +++++++++++++++++++++++++
public/javascripts/wechat/wechat-dev.js | 25 +++++++++++----------
6 files changed, 58 insertions(+), 12 deletions(-)
create mode 100644 public/javascripts/wechat/auth.js
diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb
index 60a674446..c00a8a86e 100644
--- a/app/controllers/wechats_controller.rb
+++ b/app/controllers/wechats_controller.rb
@@ -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]
diff --git a/config/menu.yml b/config/menu.yml
index 711b087d1..106bbfd07 100644
--- a/config/menu.yml
+++ b/config/menu.yml
@@ -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: "意见返馈"
diff --git a/config/routes.rb b/config/routes.rb
index 396be9c66..2313088cc 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1165,6 +1165,7 @@ RedmineApp::Application.routes.draw do
collection do
get :login
post :bind
+ get :get_open_id
end
end
diff --git a/public/assets/wechat/issue.html b/public/assets/wechat/issue.html
index 7b6eedde2..86c4e494a 100644
--- a/public/assets/wechat/issue.html
+++ b/public/assets/wechat/issue.html
@@ -47,6 +47,7 @@
+