Browse Source

Merge remote-tracking branch 'origin/dev' into test

jiapeng 7 years ago
parent
commit
2758686cc8

+ 8 - 48
src/main/java/com/ekexiu/portal/service/SysService.java

@ -1804,7 +1804,10 @@ public class SysService {
1804 1804
1805 1805
	@Get
1806 1806
	@Path("/vcWithBind")
1807
	public String reqBindBindMobilePhone(@JdbcConn(false) Connection con, String userid, String mobilePhone) throws JfwBaseException, SQLException {
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");
1810
		}
1808 1811
		User user = this.userDao.query(con, userid);
1809 1812
		if (null == user)
1810 1813
			return null;
@ -1889,56 +1892,13 @@ public class SysService {
1889 1892
		}
1890 1893
		return key;
1891 1894
	}
1892
//	/**
1893
//	 * 发送手机验证码
1894
//	 * 
1895
//	 * @param con
1896
//	 * @param mobilePhone
1897
//	 *            验证的手机号
1898
//	 * @return
1899
//	 * @throws JfwBaseException
1900
//	 * @throws SQLException
1901
//	 */
1902
//	@Get
1903
//	@Path("/regmobilephone_onlyphone")
1904
//	public String regMobilePhone(@JdbcConn(false) Connection con, String mobilePhone, @DefaultValue("true") boolean checkExists)
1905
//			throws JfwBaseException, SQLException {
1906
//		if (checkExists) {
1907
//			User user = this.userDao.queryByEmailOrMobilePhone(con, mobilePhone);
1908
//			if (null != user) {
1909
//				return null;
1910
//			}
1911
//		}
1912
//		StateCode<String, String> sc = new StateCode<String, String>();
1913
//		final String key = JfwAppContext.cacheObjectAndGenKey(sc);
1914
//		try {
1915
//			Random rd = new Random();
1916
//			int vi = rd.nextInt(10000);
1917
//			String vc = String.format("%04d", vi);
1918
//			sc.setKey(mobilePhone);
1919
//			sc.setValue(vc);
1920
//			this.mobilePhoneServcie.sendMessage(mobilePhone, this.regMobilePhoneContentTemplate, this.regMobilePhoneReplaceKey, vc);
1921
//			long ct = System.currentTimeMillis();
1922
//			long et = ct + this.timeLimitWithRegMobilePhone + 5000;
1923
//			sc.setBuildTime(ct);
1924
//			sc.setExpiredTime(et);
1925
//			JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
1926
//				@Override
1927
//				public void run() {
1928
//					JfwAppContext.removeCachedObject(key);
1929
//				}
1930
//			}, this.timeLimitWithRegMobilePhone + 10000, TimeUnit.MILLISECONDS);
1931
//		} catch (Exception e) {
1932
//			JfwAppContext.removeCachedObject(key);
1933
//			throw new JfwBaseException(10012, "send mobile phone message to " + mobilePhone + " error", e);
1934
//		}
1935
//		return key;
1936
//	}
1937
	
1938 1895
	
1939 1896
	@Get
1940 1897
	@Path("/phoneValidCode")
1941
	public String phoneValidCode(String phone) throws JfwBaseException{
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");
1901
		}
1942 1902
		StateCode<String, String> sc = new StateCode<String, String>();
1943 1903
		final String key = JfwAppContext.cacheObjectAndGenKey(sc);
1944 1904
		try {

+ 66 - 43
src/main/java/com/ekexiu/push/service/PushService.java

@ -11,6 +11,7 @@ import java.security.cert.CertificateException;
11 11
import java.security.cert.X509Certificate;
12 12
import java.util.HashMap;
13 13
import java.util.Map;
14
import java.util.Random;
14 15
import java.util.UUID;
15 16
import java.util.concurrent.ConcurrentHashMap;
16 17

@ -56,7 +57,6 @@ public class PushService {
56 57
	private static Map<String, String> ERR_MAP = new HashMap<String, String>();
57 58

58 59
	final static char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
59
	// UiIGJTfKNR8oXb8apYdGh3
60 60
	private String secret = "U96j677DHoA1Pv5X0mxMU9";
61 61
	private String appKey = "48nq7d7yHu8dgbzVHuisp6";
62 62
	private String appId = "TUdvbnxu1c97r6Fb6cUy57";
@ -125,24 +125,22 @@ public class PushService {
125 125
		}
126 126
	}
127 127

128
	private void checkResult(Map<String, Object> ret) {
129
		Object obj = ret.get("result");
130
		if ("ok".equals(obj))
131
			return;
128
	private void raiseGeTuiError(Object obj){
132 129
		String errMsg = null;
133 130
		errMsg = ERR_MAP.get(obj);
134 131
		if (errMsg == null)
135 132
			errMsg = "其他错误";
136
		log.error("调用用个推restApi,返回结果错误:" + obj + ":" + errMsg);
137 133
		throw new RuntimeException("调用用个推restApi,返回结果错误:" + obj + ":" + errMsg);
138 134
	}
135
	private void checkResult(Map<String, Object> ret) {
136
		Object obj = ret.get("result");
137
		if (!"ok".equals(obj)){
138
			raiseGeTuiError(obj);
139
		}
140
	}
141
	
142

139 143

140
//	private void checkToken() {
141
//		if (this.token == null) {
142
//			log.error("token is null");
143
//			throw new RuntimeException("token is null");
144
//		}
145
//	}
146 144

147 145
	public String allocateRequesstId() {
148 146
		UUID uuid = UUID.randomUUID();
@ -243,6 +241,23 @@ public class PushService {
243 241
		}
244 242
	}
245 243
	
244
	
245
	@Get
246
	@Path("/token")
247
	public String getToken(){
248
		String ret = this.token;
249
		if(ret!=null){
250
			int len = ret.length();
251
			Random random = new Random();
252
			int idx = random.nextInt(len-1);
253
			if(idx<1 || idx >=len){
254
				return ret;
255
			}
256
			return ret.substring(idx)+ret.substring(0,idx)+"_"+idx;
257
		}
258
		return null;
259
	}
260
	
246 261
	@Path("/bindTags")
247 262
	@Post
248 263
	public boolean bindTags(String[] tags, String cid) {
@ -259,22 +274,6 @@ public class PushService {
259 274
			return false;
260 275
		}
261 276
	}
262
	@Path("/applyBadge")
263
	@Get
264
	public void applyBadge(int badge,String cid,String devtoken){
265
		String url = "https://restapi.getui.com/v1/" + this.appId + "/set_badge";
266
		StringBuilder sb = new StringBuilder();
267
		sb.append("{\"badge\":").append(badge).append(",\"cid_list\":[\"").append(cid).append("\"],\"devicetoken_list\":[\"").append(devtoken).append("\"]}");
268
		System.out.println(sb.toString());
269
		try {
270
			Map<String, Object> ret = post(url, TOKEN_MAP, sb.toString().getBytes(ConstData.UTF8));
271
			this.checkResult(ret);
272
		} catch (IOException e) {
273
			log.error("apply badge error[cid:" + cid + ",devtoken:" + devtoken + "]", e);
274
		}
275
		
276
	}
277
	
278 277
	private  Map<String,Object > createIosMessage(String title,String content,String payload){
279 278
		Map<String,Object> ret = new HashMap<String,Object>();
280 279
		Map<String,Object> message= new HashMap<String,Object>();
@ -338,8 +337,6 @@ public class PushService {
338 337
		andriodMessage.put("requestid",this.allocateRequesstId());
339 338
		iosMessage.put("requestid",this.allocateRequesstId());		
340 339
		
341
//		System.out.println(JsonService.toJson(andriodMessage));
342
//		System.out.println(JsonService.toJson(iosMessage));
343 340
		try {
344 341
			Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(andriodMessage).getBytes(ConstData.UTF8));
345 342
			this.checkResult(ret);
@ -401,8 +398,6 @@ public class PushService {
401 398
		iosMessage.put("requestid",this.allocateRequesstId());		
402 399
		iosMessage.put("cid",cid);
403 400
		
404
//		System.out.println(JsonService.toJson(androidMessage));
405
//		System.out.println(JsonService.toJson(iosMessage));
406 401
		try {
407 402
			Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(androidMessage).getBytes(ConstData.UTF8));
408 403
			this.checkResult(ret);
@ -422,24 +417,39 @@ public class PushService {
422 417
		Map<String,Object> androidMessage = this.createAndriodMessage(title, content, pl_str);
423 418
		Map<String,Object> iosMessage = this.createIosMessage(title, content, pl_str);
424 419
		androidMessage.put("requestid",this.allocateRequesstId());
425
		androidMessage.put("alias",alias);
420
		androidMessage.put("alias","A_"+alias);
426 421
		iosMessage.put("requestid",this.allocateRequesstId());		
427
		iosMessage.put("alias",alias);
422
		iosMessage.put("alias","I_"+alias);
428 423
		
429
//		System.out.println(JsonService.toJson(androidMessage));
430
//		System.out.println(JsonService.toJson(iosMessage));
424
		boolean  sended = false;
425
		Object result = null;
426
		Map<String,Object> ret = null;
431 427
		try {
432
			Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(androidMessage).getBytes(ConstData.UTF8));
433
			this.checkResult(ret);
428
			ret = post(url, TOKEN_MAP,JsonService.toJson(androidMessage).getBytes(ConstData.UTF8));
434 429
		} catch (Exception e) {
435 430
			log.error("send app message error",e);
436 431
		}
432
		result = ret.get("result");
433
		if("ok".equals(result)){
434
			sended=true;
435
		}else if(!"alias_notbind".equals(result)){
436
			raiseGeTuiError(result);
437
		}
437 438
		try {
438
			Map<String,Object> ret = post(url, TOKEN_MAP,JsonService.toJson(iosMessage).getBytes(ConstData.UTF8));
439
			this.checkResult(ret);
439
			 ret = post(url, TOKEN_MAP,JsonService.toJson(iosMessage).getBytes(ConstData.UTF8));
440 440
		} catch (Exception e) {
441 441
			log.error("send app message error",e);
442
		}	
442
		}
443
		result = ret.get("result");
444
		if("ok".equals(result)){
445
			return;
446
		}else if("alias_notbind".equals(result)){
447
			raiseGeTuiError("alias_notbind");
448
		}else{
449
			if(!sended){				
450
				raiseGeTuiError(result);
451
			}
452
		}
443 453
	}
444 454
	
445 455
	
@ -529,9 +539,22 @@ public class PushService {
529 539
		PushService s = new PushService();
530 540
//		 s.buildToken();
531 541
//		 s.checkToken();
532
//		TOKEN_MAP.put("authtoken", "ef60d2aa2bc3193fc99a99ef43906cee70658156dfb41156acc35f7e7b7fb3dd");
542
		
543
		
544
	
545
		
546
		String t="44f123977f387165a8c2b77f83ce30ccad8be50a922a21a96976700dad3a5f61";
547
		int idx = 51;
548
		int len = t.length();
549
		idx = len-idx;
550
		System.out.println();
551

552
		TOKEN_MAP.put("authtoken", t.substring(idx)+t.substring(0,idx));
533 553
	long l = System.currentTimeMillis();
534
		s.toApp("title_" + l, "content_" + l, "payload_" + l);
554
		//s.toApp("title_" + l, "content_" + l, "payload_" + l);
555
	s.pushWithAlias("title_" + l, "content_" + l, "payload_" + l,"1A21F6D7BD4C549A1A2ABC415DE7701BD");
556
//	s.applyBadge(10, "f293af1f1cc043185ee9d921b63c4807", "9982595B6AAAE1EFABD0B40E215A76507E74D12477573491AF023B89807A01AA");
557
	System.out.println(l);
535 558

536 559
//	s.applyBadge(1, "f293af1f1cc043185ee9d921b63c4807", "D380AD6865B61F4D179DBB208EE3C7268A672AB9821385050596608A186F6023");
537 560
		// for(int i = 0 ;i < 100;++i){

+ 2 - 2
src/main/resources/project-test-dev.properties

@ -104,7 +104,7 @@ com_ekexiu_portal_service_SysService.phoneRetrievePasswordReplaceKey=yzm
104 104
com_ekexiu_portal_service_SysService.phoneRetrievePasswordContentTemplate=\u3010\u79D1\u8896\u3011\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801yzm\uFF0C\u5B8C\u6210\u5BC6\u7801\u91CD\u7F6E\u3002\u8BF7\u4E8E3\u5206\u949F\u5185\u6B63\u786E\u8F93\u5165\u9A8C\u8BC1\u7801\u3002\u5982\u975E\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u5FFD\u7565\u672C\u77ED\u4FE1\u3002
105 105
#手机验证-注册用户
106 106
com_ekexiu_portal_service_SysService.regMobilePhoneReplaceKey=yzm
107
com_ekexiu_portal_service_SysService.regMobilePhoneContentTemplate=\u3010\u79D1\u8896\u3011\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801yzm\uFF0C\u5B8C\u6210\u624B\u673A\u6CE8\u518C\u3002\u8BF7\u4E8E3\u5206\u949F\u5185\u6B63\u786E\u8F93\u5165\u9A8C\u8BC1\u7801\u3002\u5982\u975E\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u5FFD\u7565\u672C\u77ED\u4FE1\u3002
107
com_ekexiu_portal_service_SysService.regMobilePhoneContentTemplate=\u3010\u79D1\u8896\u3011\u60A8\u7684\u9A8C\u8BC1\u7801\u4E3Ayzm\uFF0C\u8BF7\u4E8E3\u5206\u949F\u5185\u6B63\u786E\u8F93\u5165\uFF0C\u5982\u975E\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u5FFD\u7565\u6B64\u77ED\u4FE1\u3002
108 108
#手机验证-用户登录
109 109
com_ekexiu_portal_service_SysService.loginMobilePhoneReplaceKey=yzm
110 110
com_ekexiu_portal_service_SysService.loginMobilePhoneContentTemplate=\u3010\u79D1\u8896\u3011\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801yzm\uFF0C\u5B8C\u6210\u77ED\u4FE1\u767B\u5F55\u3002\u8BF7\u4E8E3\u5206\u949F\u5185\u6B63\u786E\u8F93\u5165\u9A8C\u8BC1\u7801\u3002\u5982\u975E\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u5FFD\u7565\u672C\u77ED\u4FE1\u3002
@ -273,4 +273,4 @@ com_ekexiu_portal_oauth_OAuthService.handlers-ref=oauthService_handlers
273 273
oauthService_handlers::map=java.util.HashMap
274 274
oauthService_handlers.map-key-1=weixin
275 275
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler
276
com_ekexiu_push_service_PushService.enable::boolean=true
276
com_ekexiu_push_service_PushService.enable::boolean=false

+ 2 - 2
src/main/resources/project-test.properties

@ -104,7 +104,7 @@ com_ekexiu_portal_service_SysService.phoneRetrievePasswordReplaceKey=yzm
104 104
com_ekexiu_portal_service_SysService.phoneRetrievePasswordContentTemplate=\u3010\u79D1\u8896\u3011\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801yzm\uFF0C\u5B8C\u6210\u5BC6\u7801\u91CD\u7F6E\u3002\u8BF7\u4E8E3\u5206\u949F\u5185\u6B63\u786E\u8F93\u5165\u9A8C\u8BC1\u7801\u3002\u5982\u975E\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u5FFD\u7565\u672C\u77ED\u4FE1\u3002
105 105
#手机验证-注册用户
106 106
com_ekexiu_portal_service_SysService.regMobilePhoneReplaceKey=yzm
107
com_ekexiu_portal_service_SysService.regMobilePhoneContentTemplate=\u3010\u79D1\u8896\u3011\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801yzm\uFF0C\u5B8C\u6210\u624B\u673A\u6CE8\u518C\u3002\u8BF7\u4E8E3\u5206\u949F\u5185\u6B63\u786E\u8F93\u5165\u9A8C\u8BC1\u7801\u3002\u5982\u975E\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u5FFD\u7565\u672C\u77ED\u4FE1\u3002
107
com_ekexiu_portal_service_SysService.regMobilePhoneContentTemplate=\u3010\u79D1\u8896\u3011\u60A8\u7684\u9A8C\u8BC1\u7801\u4E3Ayzm\uFF0C\u8BF7\u4E8E3\u5206\u949F\u5185\u6B63\u786E\u8F93\u5165\uFF0C\u5982\u975E\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u5FFD\u7565\u6B64\u77ED\u4FE1\u3002
108 108
#手机验证-用户登录
109 109
com_ekexiu_portal_service_SysService.loginMobilePhoneReplaceKey=yzm
110 110
com_ekexiu_portal_service_SysService.loginMobilePhoneContentTemplate=\u3010\u79D1\u8896\u3011\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801yzm\uFF0C\u5B8C\u6210\u77ED\u4FE1\u767B\u5F55\u3002\u8BF7\u4E8E3\u5206\u949F\u5185\u6B63\u786E\u8F93\u5165\u9A8C\u8BC1\u7801\u3002\u5982\u975E\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u5FFD\u7565\u672C\u77ED\u4FE1\u3002
@ -273,4 +273,4 @@ com_ekexiu_portal_oauth_OAuthService.handlers-ref=oauthService_handlers
273 273
oauthService_handlers::map=java.util.HashMap
274 274
oauthService_handlers.map-key-1=weixin
275 275
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler
276
com_ekexiu_push_service_PushService.enable::boolean=false
276
com_ekexiu_push_service_PushService.enable::boolean=true

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

@ -104,7 +104,7 @@ com_ekexiu_portal_service_SysService.phoneRetrievePasswordReplaceKey=yzm
104 104
com_ekexiu_portal_service_SysService.phoneRetrievePasswordContentTemplate=\u3010\u79D1\u8896\u3011\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801yzm\uFF0C\u5B8C\u6210\u5BC6\u7801\u91CD\u7F6E\u3002\u8BF7\u4E8E3\u5206\u949F\u5185\u6B63\u786E\u8F93\u5165\u9A8C\u8BC1\u7801\u3002\u5982\u975E\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u5FFD\u7565\u672C\u77ED\u4FE1\u3002
105 105
#手机验证-注册用户
106 106
com_ekexiu_portal_service_SysService.regMobilePhoneReplaceKey=yzm
107
com_ekexiu_portal_service_SysService.regMobilePhoneContentTemplate=\u3010\u79D1\u8896\u3011\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801yzm\uFF0C\u5B8C\u6210\u624B\u673A\u6CE8\u518C\u3002\u8BF7\u4E8E3\u5206\u949F\u5185\u6B63\u786E\u8F93\u5165\u9A8C\u8BC1\u7801\u3002\u5982\u975E\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u5FFD\u7565\u672C\u77ED\u4FE1\u3002
107
com_ekexiu_portal_service_SysService.regMobilePhoneContentTemplate=\u3010\u79D1\u8896\u3011\u60A8\u7684\u9A8C\u8BC1\u7801\u4E3Ayzm\uFF0C\u8BF7\u4E8E3\u5206\u949F\u5185\u6B63\u786E\u8F93\u5165\uFF0C\u5982\u975E\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u5FFD\u7565\u6B64\u77ED\u4FE1\u3002
108 108
#手机验证-用户登录
109 109
com_ekexiu_portal_service_SysService.loginMobilePhoneReplaceKey=yzm
110 110
com_ekexiu_portal_service_SysService.loginMobilePhoneContentTemplate=\u3010\u79D1\u8896\u3011\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801yzm\uFF0C\u5B8C\u6210\u77ED\u4FE1\u767B\u5F55\u3002\u8BF7\u4E8E3\u5206\u949F\u5185\u6B63\u786E\u8F93\u5165\u9A8C\u8BC1\u7801\u3002\u5982\u975E\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u5FFD\u7565\u672C\u77ED\u4FE1\u3002