Skip to content

Commit

Permalink
1.增加pdf到处
Browse files Browse the repository at this point in the history
2.增加第三方登录支持QQ、git、微博
3.修改邮件服务器为sendcloud
4.更新浏览器扩展1.4版本
5.新增接口响应头展示,新增响应码,新增结果复制功能。
  • Loading branch information
周靖杰 committed Sep 7, 2016
1 parent 944508a commit 1e48c01
Show file tree
Hide file tree
Showing 177 changed files with 7,779 additions and 1,244 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web/node_modules
36 changes: 24 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
- html 网页源码
- package.json
- webpack.config.js webpack配置

##开发版本
### API
* api.zip 用压缩软件打开并且解压放在tomcat webapps目录下 需要修改tomcat默认端口,防止与静态页面的端口冲突
* 修改WEB-INF/classes/config.properties 中的数据库配置信息,
* 如果要启用QQ,微博登陆,需要配置QQ和微博开发者信息
* 需要修改sql连接地址与账户密码
* 如果需要发邮件则需要配置邮件服务器地址
* 修改api/WEB-INF/classes/config.properties中的数据库配置信息。
* 如果需要使用第三方登录,需要配置对应的地址
* 如果需要使用邮件发送,需要配置sendcloud邮箱配置信息
* config.properties未单独做中文编码处理,为防止乱码,中文需要改为unicode
* 导入sql/xiaoyaoji.sql 文件导入到mysql中,
* 启动tomcat,浏览器运行 http://localhost:端口/api/index.html 能正常显示Hello XiaoYaoJi API 则表示可用。
Expand All @@ -42,20 +42,32 @@
或者直接下载附件中的jar
### WEB
* npm install 下载项目依赖包
* npm run build 编译并且监听文件改动
* npm run build 运行项目
* 编译代码 npm run dist;
* 发布 gulp;
* 浏览器访问http://localhost:8080/html/
* npm run watch 编译并且监听文件改动
* npm run server 运行开发项目-文件夹 (用于开发过程中)
* 浏览器访问http://localhost:8080/ 可以看到正在开发中的项目

* npm run build 编译项目,并且生成built文件夹
* gulp 将built文件夹及html文件夹代码打包到dist文件夹中;
* npm run dist-server 运行dist文件夹下的项目(也就是编译后的项目,一般用于上线前最后测试。)
* 浏览器访问http://localhost:8080/ 可以看到编译打包后的项目

* 修改html/assets/js/config.js配置
* window.root : 接口地址
* window.ctx : 静态页面相对路径
* 构建发布版:gulp;
* 发布后 dist目录就是编译后的静态页面

#### web 直接使用编译好的版本

## 直接使用
#### API
* 导入api/sql/xiaoyaoji.sql 到mysql中。mysql需要5.5以上
* 解压api/target/api.war 并将解压后的文件夹复制到tomcat/webapps目录下。
* 修改api/WEB-INF/classes/config.properties中的数据库配置信息。
* 如果需要使用第三方登录,需要配置对应的地址
* 如果需要使用邮件发送,需要配置sendcloud邮箱配置信息
#### WEB
* 复制dist到本地服务器中根目录,修改 /assets/js/config.js 里面的window.root的地址为你部署api后的访问地址



### 效果
![基本](img/basic.png)
![基本](img/third1.png)
Expand Down
23 changes: 19 additions & 4 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions api/sql/xiaoyaoji.sql
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ CREATE TABLE `module` (
`id` char(14) NOT NULL DEFAULT '',
`name` varchar(50) DEFAULT NULL,
`host` varchar(100) DEFAULT NULL,
`devHost` varchar(100) DEFAULT NULL,
`description` text,
`lastUpdateTime` datetime DEFAULT NULL,
`projectId` char(14) DEFAULT NULL,
Expand Down
111 changes: 111 additions & 0 deletions api/src/main/java/cn/com/xiaoyaoji/api/cache/RedisCache.java
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();
}
}
}

}
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();
}
*/


}
Loading

0 comments on commit 1e48c01

Please sign in to comment.