forked from Bin-mario/xiaoyaoji
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.增加第三方登录支持QQ、git、微博 3.修改邮件服务器为sendcloud 4.更新浏览器扩展1.4版本 5.新增接口响应头展示,新增响应码,新增结果复制功能。
- Loading branch information
周靖杰
committed
Sep 7, 2016
1 parent
944508a
commit 1e48c01
Showing
177 changed files
with
7,779 additions
and
1,244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,15 @@ | |
<modelVersion>4.0.0</modelVersion> | ||
<packaging>war</packaging> | ||
<artifactId>api</artifactId> | ||
<description>小幺鸡,简单好用的在线接口文档管理工具</description> | ||
<url>http://www.xiaoyaoji.com.cn</url> | ||
<developers> | ||
<developer> | ||
<name>zhoujingjie</name> | ||
<url>http://git.oschina.net/zhoujingjie</url> | ||
<email>[email protected]</email> | ||
</developer> | ||
</developers> | ||
<dependencies> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
|
@@ -29,7 +38,7 @@ | |
<dependency> | ||
<groupId>org.mangoframework</groupId> | ||
<artifactId>mango-core</artifactId> | ||
<version>1.2.3</version> | ||
<version>1.2.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
|
@@ -83,12 +92,18 @@ | |
<artifactId>commons-httpclient</artifactId> | ||
<version>3.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-email</artifactId> | ||
<version>1.4</version> | ||
<groupId>redis.clients</groupId> | ||
<artifactId>jedis</artifactId> | ||
<version>2.8.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.itextpdf</groupId> | ||
<artifactId>itextpdf</artifactId> | ||
<version>5.5.9</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<finalName>api</finalName> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
api/src/main/java/cn/com/xiaoyaoji/api/cache/RedisCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package cn.com.xiaoyaoji.api.cache; | ||
|
||
import redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.JedisPool; | ||
import redis.clients.jedis.JedisPoolConfig; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.TypeReference; | ||
|
||
/** | ||
* @author zhoujingjie | ||
* @date 2016-08-31 | ||
*/ | ||
public class RedisCache implements Cache { | ||
|
||
private JedisPool pool; | ||
|
||
public RedisCache(String host, int port, int timeout) { | ||
this(host, port, timeout, null); | ||
} | ||
|
||
public RedisCache(String host, int port, int timeout, String password) { | ||
pool = new JedisPool(new JedisPoolConfig(), host, port, timeout, password); | ||
} | ||
|
||
public RedisCache(String host, int port) { | ||
this(host, port, 2000); | ||
} | ||
|
||
@Override | ||
public void put(String token, String key, Object data, int expires) { | ||
synchronized (this) { | ||
Jedis jedis = null; | ||
try { | ||
String json = JSON.toJSONString(data); | ||
jedis = pool.getResource(); | ||
jedis.hset(token, key, json); | ||
jedis.expire(token, expires); | ||
} finally { | ||
if (jedis != null) | ||
jedis.close(); | ||
} | ||
} | ||
} | ||
|
||
public void put(String key, String data, int expires){ | ||
synchronized (this) { | ||
Jedis jedis = null; | ||
try { | ||
jedis = pool.getResource(); | ||
jedis.set(key, data); | ||
jedis.expire(key, expires); | ||
} finally { | ||
if (jedis != null) | ||
jedis.close(); | ||
} | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public Object get(String token, String key, int expires) { | ||
return hget(token, key, expires); | ||
} | ||
|
||
public <T> T get(String token, String key, int expires, Class<T> clazz){ | ||
String data = (String) get(token, key, expires); | ||
return JSON.parseObject(data,clazz); | ||
} | ||
public <T> T get(String token, String key, int expires, TypeReference<T> clazz){ | ||
String data = (String) get(token, key, expires); | ||
return JSON.parseObject(data,clazz); | ||
} | ||
|
||
|
||
|
||
public String get(String key, int expires){ | ||
Jedis jedis = null; | ||
try { | ||
jedis = pool.getResource(); | ||
String rs= jedis.get(key); | ||
if (rs != null) { | ||
jedis.expire(key, expires); | ||
} | ||
return rs; | ||
}finally { | ||
if(jedis!=null){ | ||
jedis.close(); | ||
} | ||
} | ||
} | ||
|
||
private String hget(String token, String key, int expire) { | ||
if (key == null) | ||
return null; | ||
Jedis jedis = null; | ||
try { | ||
jedis = pool.getResource(); | ||
String rs = jedis.hget(token, key); | ||
if (rs != null) { | ||
jedis.expire(token, expire); | ||
} | ||
return rs; | ||
} finally { | ||
if (jedis != null) { | ||
jedis.close(); | ||
} | ||
} | ||
} | ||
|
||
} |
137 changes: 88 additions & 49 deletions
137
api/src/main/java/cn/com/xiaoyaoji/api/controller/CallbackController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,107 @@ | ||
package cn.com.xiaoyaoji.api.controller; | ||
|
||
import cn.com.xiaoyaoji.api.annotations.Ignore; | ||
import cn.com.xiaoyaoji.api.ex._HashMap; | ||
import cn.com.xiaoyaoji.api.thirdly.Github; | ||
import cn.com.xiaoyaoji.api.thirdly.QQ; | ||
import cn.com.xiaoyaoji.api.thirdly.Weibo; | ||
import cn.com.xiaoyaoji.api.thirdly.github.User; | ||
import cn.com.xiaoyaoji.api.thirdly.qq.AccessToken; | ||
import cn.com.xiaoyaoji.api.utils.ConfigUtils; | ||
import cn.com.xiaoyaoji.api.view.JspView; | ||
import org.apache.log4j.Logger; | ||
import org.mangoframework.core.annotation.Get; | ||
import org.mangoframework.core.annotation.RequestMapping; | ||
import org.mangoframework.core.dispatcher.Parameter; | ||
import org.mangoframework.core.view.ResultView; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author zhoujingjie | ||
* @date 2016-06-03 | ||
*/ | ||
@RequestMapping("callback") | ||
public class CallbackController { | ||
/* | ||
private static Logger logger = Logger.getLogger(CallbackController.class); | ||
private Set<String> states = new HashSet<String>() {{ | ||
add("login"); | ||
add("relation"); | ||
}}; | ||
|
||
@Ignore | ||
@Get(value = "qq", template = "/third-party") | ||
public Object qqCallback(Parameter parameter) { | ||
String code = parameter.getParamString().get("code"); | ||
String state = parameter.getParamString().get("state"); | ||
logger.info("callback qq -> code:"+code+" state:"+state); | ||
if (states.contains(state)) { | ||
QQ qq = new QQ(); | ||
AccessToken accessToken = qq.getAccessToken(code, ConfigUtils.getProperty("qq.redirect_uri")); | ||
String openId = qq.getOpenid(accessToken.getAccess_token()); | ||
return new _HashMap<>() | ||
.add("openId", openId) | ||
.add("type", "qq") | ||
.add("state", state) | ||
.add("accessToken", accessToken.getAccess_token()); | ||
} | ||
|
||
return illegalView(); | ||
} | ||
|
||
private ResultView illegalView() { | ||
JspView view = new JspView("/WEB-INF/jsp", ".jsp"); | ||
view.setTemplate("/illegal"); | ||
view.setData(new _HashMap<>().add("errorMsg", "非法请求")); | ||
return view; | ||
} | ||
|
||
|
||
@Ignore | ||
@Get("qq") | ||
public Object qqCallback(Parameter parameter) throws QQConnectException, IOException { | ||
HttpServletRequest request = parameter.getRequest(); | ||
//PrintWriter out = parameter.getResponse().getWriter(); | ||
AccessToken accessTokenObj = (new Oauth()).getAccessTokenByRequest(request); | ||
String accessToken = null, openID = null; | ||
long tokenExpireIn = 0L; | ||
if (accessTokenObj.getAccessToken().equals("")) { | ||
// 我们的网站被CSRF攻击了或者用户取消了授权 | ||
// 做一些数据统计工作 | ||
System.out.print("没有获取到响应参数"); | ||
return new StringView("invalid code"); | ||
} else { | ||
accessToken = accessTokenObj.getAccessToken(); | ||
tokenExpireIn = accessTokenObj.getExpireIn(); | ||
request.getSession().setAttribute("qq_access_token", accessToken); | ||
request.getSession().setAttribute("qq_token_expirein", String.valueOf(tokenExpireIn)); | ||
// 利用获取到的accessToken 去获取当前用的openid -------- start | ||
OpenID openIDObj = new OpenID(accessToken); | ||
openID = openIDObj.getUserOpenID(); | ||
return new RedirectView(request.getContextPath() + "/login/thirdly?type=qq&openid=" + openID); | ||
@Get(value = "weibo", template = "/third-party") | ||
public Object weibo(Parameter parameter) { | ||
String code = parameter.getParamString().get("code"); | ||
String state = parameter.getParamString().get("state"); | ||
logger.info("callback weibo -> code:"+code+" state:"+state); | ||
if (states.contains(state)) { | ||
Weibo weibo = new Weibo(); | ||
cn.com.xiaoyaoji.api.thirdly.weibo.AccessToken accessToken = weibo.getAccessToken(ConfigUtils.getProperty("weibo.appkey"), ConfigUtils.getProperty("weibo.appsecret"), code, ConfigUtils.getProperty("weibo.redirect_uri")); | ||
return new _HashMap<>() | ||
.add("type", "weibo") | ||
.add("state", state) | ||
.add("accessToken", accessToken.getAccess_token()) | ||
.add("uid", accessToken.getUid()); | ||
} | ||
}*/ | ||
return illegalView(); | ||
} | ||
|
||
/* | ||
@Ignore | ||
@Get("weibo") | ||
public RedirectView weibo(Parameter parameter) throws WeiboException { | ||
@Get(value = "weibo/cancel") | ||
public Object weiboCancel(Parameter parameter) { | ||
logger.info("callback weibo cancel"); | ||
return null; | ||
} | ||
|
||
|
||
@Ignore | ||
@Get(value = "github", template = "/third-party") | ||
public Object github(Parameter parameter) { | ||
String code = parameter.getParamString().get("code"); | ||
AssertUtils.notNull(code,"无效请求"); | ||
weibo4j.Oauth oauth = new weibo4j.Oauth(); | ||
weibo4j.http.AccessToken accessToken = oauth.getAccessTokenByCode(code); | ||
String token = accessToken.getAccessToken(); | ||
Users users = new Users(token); | ||
User user= users.showUserById(accessToken.getUid()); | ||
Thirdparty thirdparty = new Thirdparty(); | ||
thirdparty.setId(user.getId()); | ||
thirdparty.setNickName(user.getName()); | ||
thirdparty.setLogo(user.getAvatarLarge()); | ||
org.xiqiguguai.service.data.bean.User myUser = ServiceFactory.instance().loginByThirdparty(thirdparty); | ||
UserUtils.setUser(parameter,myUser); | ||
String referer = (String)parameter.getRequest().getSession().getAttribute("referer"); | ||
if(referer != null) { | ||
parameter.getRequest().getSession().setAttribute("referer",null); | ||
return new RedirectView(referer); | ||
String state = parameter.getParamString().get("state"); | ||
logger.info("callback github -> code:"+code+" state:"+state); | ||
if (states.contains(state)) { | ||
Github github = new Github(); | ||
cn.com.xiaoyaoji.api.thirdly.AccessToken accessToken = github.getAccessToken(ConfigUtils.getProperty("github.clientid"),ConfigUtils.getProperty("github.secret"),code,ConfigUtils.getProperty("github.redirect_uri")); | ||
User user = github.getUser(accessToken.getAccess_token()); | ||
return new _HashMap<>() | ||
.add("type", "github") | ||
.add("gitid",user.getId()) | ||
.add("state", state) | ||
.add("accessToken", accessToken.getAccess_token()); | ||
} | ||
String redirectURL = parameter.getRequest().getContextPath()+"/"; | ||
return new RedirectView(redirectURL); | ||
return illegalView(); | ||
} | ||
*/ | ||
|
||
|
||
} |
Oops, something went wrong.