Browse Source

Merge remote-tracking branch 'origin/test'

jiapeng 7 years ago
parent
commit
a9987af1e6

+ 4 - 1
src/main/java/com/ekexiu/portal/dao/ProfessorDao.java

@ -482,7 +482,7 @@ public abstract class ProfessorDao {
482 482
	public EditProfessor queryEditBaseInfo(Connection con, String id) throws SQLException {
483 483
		int index = 1;
484 484
		String sql = "SELECT P.OFFICE,P.DEPARTMENT,P.TITLE,AUTHENTICATION,AUTH_TYPE,P.AUTH_STATUS,"
485
				+ " P.ID,P.NAME,P.ADDRESS,P.STAR_LEVEL,P.CONSULT_COUNT,P.ORG_AUTH,ORGANIZATION.NAME,P.SHARE_ID "
485
				+ " P.ID,P.NAME,P.ADDRESS,P.STAR_LEVEL,P.CONSULT_COUNT,P.ORG_AUTH,ORGANIZATION.NAME,P.SHARE_ID,P.PHONE,P.EMAIL,P.PROVINCE "
486 486
				+ " FROM PROFESSOR P LEFT JOIN ORGANIZATION ON P.ORG_ID = ORGANIZATION.ID WHERE P.ID = ?";
487 487
		PreparedStatement ps = con.prepareStatement(sql);
488 488
		try {
@ -529,6 +529,9 @@ public abstract class ProfessorDao {
529 529
					}
530 530
					professor.setOrgName(orgName);
531 531
					professor.setShareId(rs.getLong(14));
532
					professor.setPhone(rs.getString(15));
533
					professor.setEmail(rs.getString(16));
534
					professor.setProvince(rs.getString(17));
532 535
					return professor;
533 536
				} else {
534 537
					return null;

+ 2 - 2
src/main/java/com/ekexiu/portal/msg/WebMsgDao.java

@ -53,12 +53,12 @@ public interface WebMsgDao {
53 53

54 54
	@UpdateWith
55 55
	@From(WebMsgIdx.class)
56
	@SetSentence("NUM_OF_ACTOR = NUM_OF_ACTOR + 1,SHOW_OF_ACTOR='1'")
56
	@SetSentence("NUM_OF_ACTOR = NUM_OF_ACTOR + 1,SHOW_OF_ACTOR='1',SHOW_OF_OWNER='1'")
57 57
	int incActorNum(Connection con, String owner, String actor, @Set String lastCnt, @Set long lastTime) throws SQLException;
58 58

59 59
	@UpdateWith
60 60
	@From(WebMsgIdx.class)
61
	@SetSentence("NUM_OF_OWNER = NUM_OF_OWNER + 1,SHOW_OF_OWNER='1'")
61
	@SetSentence("NUM_OF_OWNER = NUM_OF_OWNER + 1,SHOW_OF_OWNER='1',SHOW_OF_ACTOR='1'")
62 62
	int incOwnerNum(Connection con, String owner, String actor, @Set String lastCnt, @Set long lastTime) throws SQLException;
63 63

64 64
	@UpdateWith

+ 27 - 0
src/main/java/com/ekexiu/portal/oauth/BaseOAuthHandler.java

@ -0,0 +1,27 @@
1
package com.ekexiu.portal.oauth;
2

3
import org.jfw.util.exception.JfwBaseException;
4

5
public class BaseOAuthHandler implements OAuthHandler {
6
	private String type;
7
	
8
	public void setType(String type){
9
		this.type = type;
10
	}
11

12
	@Override
13
	public String getType() {
14
		return type;
15
	}
16

17
	@Override
18
	public String getLoginUrl() {
19
		throw new UnsupportedOperationException();
20
	}
21

22
	@Override
23
	public OAuthUser login(String code) throws JfwBaseException {
24
		throw new UnsupportedOperationException();
25
	}
26

27
}

+ 21 - 6
src/main/java/com/ekexiu/portal/oauth/OAuthService.java

@ -1,5 +1,7 @@
1 1
package com.ekexiu.portal.oauth;
2 2

3
import java.io.IOException;
4
import java.lang.reflect.Type;
3 5
import java.sql.Connection;
4 6
import java.sql.SQLException;
5 7
import java.util.HashMap;
@ -14,6 +16,7 @@ import org.jfw.apt.web.annotation.operate.Post;
14 16
import org.jfw.apt.web.annotation.param.JdbcConn;
15 17
import org.jfw.util.context.JfwAppContext;
16 18
import org.jfw.util.exception.JfwBaseException;
19
import org.jfw.util.reflect.TypeReference;
17 20
import org.jfw.util.state.StateCode;
18 21

19 22
import com.ekexiu.portal.dao.ProfessorDao;
@ -23,10 +26,14 @@ import com.ekexiu.portal.po.Professor;
23 26
import com.ekexiu.portal.po.User;
24 27
import com.ekexiu.portal.po.UserOpenId;
25 28
import com.ekexiu.portal.pojo.SessionUser;
29
import com.ekexiu.portal.util.HttpUtil;
26 30

27 31
@Path("/oauth")
28 32
public class OAuthService {
29 33

34
	private static final Type MAP_TYPE = new TypeReference<Map<String, Object>>() {
35
	}.getType();
36

30 37
	private long expriesWithOpenId = 1000 * 60 * 10;
31 38

32 39
	@Autowrie
@ -36,6 +43,9 @@ public class OAuthService {
36 43
	@Autowrie
37 44
	private ProfessorDao professorDao;
38 45

46
	private String xcxAppid = "wx92750263b1138a96";
47
	private String xcxSecret = "246e17b10923a30bfd6cc8da1ca88b8a";
48

39 49
	private Map<String, OAuthHandler> handlers;
40 50

41 51
	public Map<String, OAuthHandler> getHandlers() {
@ -122,7 +132,7 @@ public class OAuthService {
122 132
		User user = this.userDao.query(con, sc.getValue().getUserid());
123 133
		if (null == user)
124 134
			return null;
125
		
135

126 136
		JfwAppContext.removeCachedObject(authCode);
127 137
		SessionUser ret = new SessionUser();
128 138
		ret.setId(user.getId());
@ -191,16 +201,14 @@ public class OAuthService {
191 201
			}
192 202
		}
193 203
	}
194
	
195
	
196
	
204

197 205
	@Post
198 206
	@Path("/checkAssociated")
199
	public boolean associcated(@JdbcConn(false) Connection con,String userid,String oauthType)throws SQLException,JfwBaseException{
207
	public boolean associcated(@JdbcConn(false) Connection con, String userid, String oauthType) throws SQLException, JfwBaseException {
200 208
		if (null == this.handlers.get(oauthType)) {
201 209
			throw new JfwBaseException(-1, "invalid oauthType");
202 210
		}
203
		return userOpenIdDao.queryByUserid(con, oauthType, userid)!=null;
211
		return userOpenIdDao.queryByUserid(con, oauthType, userid) != null;
204 212
	}
205 213

206 214
	@Post
@ -238,6 +246,13 @@ public class OAuthService {
238 246
		return ret;
239 247
	}
240 248

249
	@Get
250
	@Path("/xcx/openid")
251
	public String jscode2session(String code) throws IOException {
252
		return (String) HttpUtil.<Map<String, Object>> loadJsonObject("https://api.weixin.qq.com/sns/jscode2session?appid=" + this.xcxAppid + "&secret="
253
				+ this.xcxSecret + "&js_code=" + code + "&grant_type=authorization_code", MAP_TYPE).get("openid");
254
	}
255

241 256
	public static class AuthLoginResponse {
242 257
		private boolean associated;
243 258
		private String authCode;

+ 49 - 10
src/main/java/com/ekexiu/portal/service/SysService.java

@ -46,6 +46,7 @@ import com.ekexiu.portal.po.Professor;
46 46
import com.ekexiu.portal.po.User;
47 47
import com.ekexiu.portal.po.UserOpenId;
48 48
import com.ekexiu.portal.pojo.SessionUser;
49
import com.ekexiu.portal.util.PictureVC;
49 50
50 51
@Path
51 52
public class SysService {
@ -1804,9 +1805,18 @@ public class SysService {
1804 1805
1805 1806
	@Get
1806 1807
	@Path("/vcWithBind")
1807
	public String reqBindBindMobilePhone(@JdbcConn(false) Connection con, String userid, String mobilePhone,String vcode,@SessionVal(value="verification",remove=true) String scode) throws JfwBaseException, SQLException {
1808
		if(!vcode.toUpperCase().equals(scode)){
1809
			throw new JfwBaseException(20001, "valid code error");
1808
	public String reqBindBindMobilePhone(@JdbcConn(false) Connection con, String userid, String mobilePhone,String vcode,@Nullable @SessionVal(value="verification",remove=true) String scode,@Nullable String token) throws JfwBaseException, SQLException {
1809
		if(token!=null){
1810
			if(!PictureVC.match(token, vcode.toUpperCase(), true)){
1811
				throw new JfwBaseException(20001, "valid code error");
1812
			}
1813
		}else{
1814
			if(scode==null) {
1815
				throw new IllegalArgumentException("not found session value:verification");
1816
			}
1817
			if(!vcode.toUpperCase().equals(scode)){
1818
				throw new JfwBaseException(20001, "valid code error");
1819
			}
1810 1820
		}
1811 1821
		User user = this.userDao.query(con, userid);
1812 1822
		if (null == user)
@ -1856,10 +1866,19 @@ public class SysService {
1856 1866
	 */
1857 1867
	@Get
1858 1868
	@Path("/regmobilephone")
1859
	public String regMobilePhone(@JdbcConn(false) Connection con, String mobilePhone, @DefaultValue("true") boolean checkExists,String vcode,@SessionVal(value="verification",remove=true) String scode)
1869
	public String regMobilePhone(@JdbcConn(false) Connection con, String mobilePhone, @DefaultValue("true") boolean checkExists,String vcode,@Nullable @SessionVal(value="verification",remove=true) String scode,@Nullable String token)
1860 1870
			throws JfwBaseException, SQLException {
1861
		if(!vcode.toUpperCase().equals(scode)){
1862
			throw new JfwBaseException(20001, "valid code error");
1871
		if(token!=null){
1872
			if(!PictureVC.match(token, vcode.toUpperCase(), true)){
1873
				throw new JfwBaseException(20001, "valid code error");
1874
			}
1875
		}else{
1876
			if(scode==null) {
1877
				throw new IllegalArgumentException("not found session value:verification");
1878
			}
1879
			if(!vcode.toUpperCase().equals(scode)){
1880
				throw new JfwBaseException(20001, "valid code error");
1881
			}
1863 1882
		}
1864 1883
		if (checkExists) {
1865 1884
			User user = this.userDao.queryByEmailOrMobilePhone(con, mobilePhone);
@ -1895,9 +1914,18 @@ public class SysService {
1895 1914
	
1896 1915
	@Get
1897 1916
	@Path("/phoneValidCode")
1898
	public String phoneValidCode(String phone,String vcode,@SessionVal(value="verification",remove=true)String scode) throws JfwBaseException{
1899
		if(!vcode.toUpperCase().equals(scode)){
1900
			throw new JfwBaseException(20001, "valid code error");
1917
	public String phoneValidCode(String phone,String vcode,@Nullable @SessionVal(value="verification",remove=true)String scode,@Nullable String token) throws JfwBaseException{
1918
		if(token!=null){
1919
			if(!PictureVC.match(token, vcode.toUpperCase(), true)){
1920
				throw new JfwBaseException(20001, "valid code error");
1921
			}
1922
		}else{
1923
			if(scode==null) {
1924
				throw new IllegalArgumentException("not found session value:verification");
1925
			}
1926
			if(!vcode.toUpperCase().equals(scode)){
1927
				throw new JfwBaseException(20001, "valid code error");
1928
			}
1901 1929
		}
1902 1930
		StateCode<String, String> sc = new StateCode<String, String>();
1903 1931
		final String key = JfwAppContext.cacheObjectAndGenKey(sc);
@ -2034,8 +2062,13 @@ public class SysService {
2034 2062
2035 2063
	@Post
2036 2064
	@Path("/checkPicture")
2037
	public boolean checkPictureVC(@SessionVal(value = "verification", defaultvalue = "null", remove = true) String verification, String submitVerification)
2065
	public boolean checkPictureVC(@Nullable @SessionVal(value = "verification", remove = false) String verification, String submitVerification,@Nullable String token)
2038 2066
			throws JfwBaseException {
2067
		if(token!=null){
2068
			return PictureVC.match(token, submitVerification.toUpperCase(), false);
2069
		}
2070
		
2071
		
2039 2072
		if (null == verification) {
2040 2073
			throw new JfwBaseException("Picture is expire !");
2041 2074
		}
@ -2205,6 +2238,12 @@ public class SysService {
2205 2238
		return emails.length;
2206 2239
	}
2207 2240
2241
	@Get
2242
	@Path("/guid")
2243
	public String guid(){
2244
		return StringUtil.buildUUID();
2245
	}
2246
2208 2247
	public void sendInviteMail(@JdbcConn Connection con, String email, @Nullable String mobilePhone, String inviteCode)
2209 2248
			throws SQLException, MessagingException {
2210 2249
		String mailContent = this.inviteMailContentTempalte;

+ 17 - 0
src/main/java/com/ekexiu/portal/service/ToolService.java

@ -0,0 +1,17 @@
1
package com.ekexiu.portal.service;
2

3
import java.io.IOException;
4

5
import org.jfw.apt.web.annotation.Path;
6
import org.jfw.util.codec.Base64;
7

8
import com.ekexiu.portal.util.HttpUtil;
9

10
@Path("/tool")
11
public class ToolService {
12
	@Path("/resource/url/base64")
13
	public String urlResource(String uri)throws IOException{
14
		Base64 bs64 = new Base64();
15
		return bs64.encodeToString(HttpUtil.load(uri));		
16
	}
17
}

+ 13 - 0
src/main/java/com/ekexiu/portal/util/HttpUtil.java

@ -37,6 +37,19 @@ public final class HttpUtil {
37 37
            }
38 38
        }
39 39
    }
40
    
41
    public static byte[] load(String url)throws IOException{
42
    	   URL aurl = new URL(url);
43
           HttpURLConnection uc = (HttpURLConnection) aurl.openConnection();
44
           try {
45
               return IoUtil.readStream(uc.getInputStream(), true);
46
           } finally {
47
               try {
48
                   uc.disconnect();
49
               } catch (Throwable th) {
50
               }
51
           }
52
    }
40 53

41 54
    public static <T> T loadJsonObject(String url, String enc, Type typeOfT) throws IOException {
42 55
        URL aurl = new URL(url);

+ 97 - 18
src/main/java/com/ekexiu/portal/util/PictureVC.java

@ -1,6 +1,9 @@
1 1
package com.ekexiu.portal.util;
2 2

3 3
import java.io.IOException;
4
import java.util.LinkedList;
5
import java.util.concurrent.ConcurrentHashMap;
6
import java.util.concurrent.TimeUnit;
4 7

5 8
import javax.servlet.Servlet;
6 9
import javax.servlet.ServletException;
@ -9,23 +12,99 @@ import javax.servlet.http.HttpServletRequest;
9 12
import javax.servlet.http.HttpServletResponse;
10 13
import javax.servlet.http.HttpSession;
11 14

12
public class PictureVC extends HttpServlet implements Servlet {  
13
  
15
import org.jfw.util.context.JfwAppContext;
16
import org.jfw.util.state.StateCode;
17

18
public class PictureVC extends HttpServlet implements Servlet {
19

14 20
	private static final long serialVersionUID = 2459158903781864570L;
15 21

16
	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
17
        response.setHeader("Pragma", "No-cache");  
18
        response.setHeader("Cache-Control", "no-cache");  
19
        response.setDateHeader("Expires", 0);  
20
        response.setContentType("image/jpeg");  
21
        HttpSession session = request.getSession();
22
        //生成随机字符串  
23
        String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
24
        //将验证码设置到session里 方便验证
25
        session.setAttribute("verification", verifyCode);
26
        //生成图片  
27
        int w = 100, h = 40;  
28
        VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);  
29
  
30
    }  
31
} 
22
	private static long timeout = 1000 * 60 * 5;
23
	private static long interval = 1000 * 60;
24

25
	private static ConcurrentHashMap<String, StateCode<String, String>> tokens = new ConcurrentHashMap<String, StateCode<String, String>>();
26

27
	public static void put(String key, String val) {
28
		StateCode<String, String> code = new StateCode<String, String>();
29
		code.setBuildTime(System.currentTimeMillis());
30
		code.setExpiredTime(code.getBuildTime() + timeout);
31
		code.setKey(key);
32
		code.setValue(val);
33
		tokens.put(key, code);
34
	}
35

36
	public static boolean match(String key, String val, boolean removed) {
37
		boolean result = false;
38
		StateCode<String, String> code = tokens.get(key);
39
		if (code != null) {
40
			if (System.currentTimeMillis() < code.getExpiredTime()) {
41
				result = code.getValue().equals(val);
42
				if (removed) {
43
					tokens.remove(key, code);
44
				}
45
			}
46
		}
47
		return result;
48
	}
49

50
	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
51
		response.setHeader("Pragma", "No-cache");
52
		response.setHeader("Cache-Control", "no-cache");
53
		response.setDateHeader("Expires", 0);
54
		response.setContentType("image/jpeg");
55

56
		// 生成随机字符串
57
		String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
58
		String token = request.getParameter("token");
59
		if (token != null && token.length() == 32) {
60
			put(token, verifyCode);
61
		} else {
62
			HttpSession session = request.getSession();
63
			// 将验证码设置到session里 方便验证
64
			session.setAttribute("verification", verifyCode);
65
		}
66
		// 生成图片
67
		int w = 100, h = 40;
68
		VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
69
	}
70

71
	@Override
72
	public void init() throws ServletException {
73
		long longValue = 0;
74
		String tmp = this.getServletConfig().getInitParameter("timeout");
75
		try {
76
			longValue = Long.parseLong(tmp);
77
			if (longValue > (1000 * 90)) {
78
				PictureVC.timeout = longValue;
79
			}
80
		} catch (Throwable th) {
81
		}
82

83
		tmp = this.getServletConfig().getInitParameter("cleanInterval");
84
		try {
85
			longValue = Long.parseLong(tmp);
86
			if (longValue > (1000)) {
87
				PictureVC.interval = longValue;
88
			}
89
		} catch (Throwable th) {
90
		}
91
		JfwAppContext.getScheduledExecutorService().scheduleAtFixedRate(new Runnable() {
92

93
			@Override
94
			public void run() {
95
				LinkedList<StateCode<String, String>> list = new LinkedList<StateCode<String, String>>();
96
				long time = System.currentTimeMillis();
97
				for (StateCode<String, String> st : tokens.values()) {
98
					if ((time - st.getExpiredTime()) > 1000) {
99
						list.add(st);
100
					}
101
				}
102
				for (StateCode<String, String> st : list) {
103
					tokens.remove(st.getKey(), st);
104
				}
105
			}
106
		}, 1000, PictureVC.interval, TimeUnit.MILLISECONDS);
107

108
	}
109

110
}

+ 5 - 1
src/main/resources/project-test-dev.properties

@ -275,4 +275,8 @@ oauthService_handlers.map-key-1=weixin
275 275
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler
276 276
com_ekexiu_push_service_PushService.enable::boolean=false
277 277
com_ekexiu_portal_cms_TemplateService.source::java.io.File=/kexiu/www/html1/fw_template_r3254
278
com_ekexiu_portal_cms_TemplateService.dir::java.io.File=/kexiu/webdata1/shtml
278
com_ekexiu_portal_cms_TemplateService.dir::java.io.File=/kexiu/webdata1/shtml
279
com_ekexiu_portal_oauth_BaseOAuthHandler=com.ekexiu.portal.oauth.BaseOAuthHandler
280
com_ekexiu_portal_oauth_BaseOAuthHandler.type=weixinxiaochengxu
281
oauthService_handlers.map-key-2=weixinxiaochengxu
282
oauthService_handlers.map-val-2-ref=com_ekexiu_portal_oauth_BaseOAuthHandler

+ 5 - 1
src/main/resources/project-test.properties

@ -275,4 +275,8 @@ oauthService_handlers.map-key-1=weixin
275 275
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler
276 276
com_ekexiu_push_service_PushService.enable::boolean=true
277 277
com_ekexiu_portal_cms_TemplateService.source::java.io.File=/kexiu/www/html/fw_template_r3254
278
com_ekexiu_portal_cms_TemplateService.dir::java.io.File=/kexiu/webdata/shtml
278
com_ekexiu_portal_cms_TemplateService.dir::java.io.File=/kexiu/webdata/shtml
279
com_ekexiu_portal_oauth_BaseOAuthHandler=com.ekexiu.portal.oauth.BaseOAuthHandler
280
com_ekexiu_portal_oauth_BaseOAuthHandler.type=weixinxiaochengxu
281
oauthService_handlers.map-key-2=weixinxiaochengxu
282
oauthService_handlers.map-val-2-ref=com_ekexiu_portal_oauth_BaseOAuthHandler

+ 5 - 0
src/main/resources/project.properties

@ -277,3 +277,8 @@ com_ekexiu_push_service_PushService.appKey=xXqSF9Gmb69SG37XVT3lL2
277 277
com_ekexiu_push_service_PushService.appId=vGS5OBXtmV6SrDVJDQ8dGA
278 278
com_ekexiu_portal_cms_TemplateService.source::java.io.File=/kexiu/www/html/fw_template_r3254
279 279
com_ekexiu_portal_cms_TemplateService.dir::java.io.File=/kexiu/webdata/shtml
280
com_ekexiu_portal_oauth_BaseOAuthHandler=com.ekexiu.portal.oauth.BaseOAuthHandler
281
com_ekexiu_portal_oauth_BaseOAuthHandler.type=weixinxiaochengxu
282
oauthService_handlers.map-key-2=weixinxiaochengxu
283
oauthService_handlers.map-val-2-ref=com_ekexiu_portal_oauth_BaseOAuthHandler
284