jiapeng лет назад: 7
Родитель
Сommit
ac07ff1aaa

+ 17 - 0
src/main/java/com/ekexiu/portal/msg/Service.java

@ -27,6 +27,7 @@ import org.jfw.util.jdbc.ResultSetExtractor;
27 27
import org.jfw.util.json.JsonService;
28 28

29 29
import com.ekexiu.portal.util.WebMsgSocketServlet;
30
import com.ekexiu.push.service.PushService;
30 31

31 32
@Path("/webMsg")
32 33
public class Service {
@ -37,6 +38,19 @@ public class Service {
37 38

38 39
	@Autowrie
39 40
	private WebMsgDao webMsgDao;
41
	
42
	@Autowrie
43
	private PushService pushService;
44
	
45
	
46

47
	public PushService getPushService() {
48
		return pushService;
49
	}
50

51
	public void setPushService(PushService pushService) {
52
		this.pushService = pushService;
53
	}
40 54

41 55
	public WebMsgDao getWebMsgDao() {
42 56
		return webMsgDao;
@ -240,6 +254,9 @@ public class Service {
240 254
				con.commit();
241 255
				next = false;
242 256
				WebMsgSocketServlet.sendMessage(reciver, JsonService.toJson(wmc));
257
				try{
258
					pushService.pushWithAlias("通知","您收到了一条消息", "msgsend", reciver);
259
				}catch(Throwable thr){}
243 260
			} catch (SQLException e) {
244 261
				if ("23505".equals(e.getSQLState())) {
245 262
					con.rollback();

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

@ -1889,51 +1889,51 @@ public class SysService {
1889 1889
		}
1890 1890
		return key;
1891 1891
	}
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
	}
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 1937
	
1938 1938
	
1939 1939
	@Get

+ 29 - 0
src/main/java/com/ekexiu/portal/util/DebugService.java

@ -1,15 +1,44 @@
1 1
package com.ekexiu.portal.util;
2 2

3
import org.jfw.apt.annotation.Autowrie;
4
import org.jfw.apt.annotation.Nullable;
3 5
import org.jfw.apt.web.annotation.Path;
4 6
import org.jfw.apt.web.annotation.operate.Get;
5 7
import org.jfw.apt.web.annotation.operate.Post;
6 8

9
import com.ekexiu.push.service.PushService;
10

7 11
@Path("/debug")
8 12
public class DebugService {
13
	@Autowrie
14
	private PushService pushService;
15
	
16
	
17
	public PushService getPushService() {
18
		return pushService;
19
	}
20

21

22
	public void setPushService(PushService pushService) {
23
		this.pushService = pushService;
24
	}
25

26

9 27
	@Get
10 28
	@Post
11 29
	@Path("/msg/send")
12 30
	public void sendMsg(String to,String cnt){
13 31
		WebMsgSocketServlet.sendMessage(to, cnt);
14 32
	}
33
	@Get
34
	@Post
35
	@Path("/push")
36
	public void send(@Nullable String alias,@Nullable String[] tag,String title,String cnt,@Nullable String json){
37
		if(alias!=null){
38
			pushService.pushWithAlias(title, cnt, json, alias);
39
		}else{
40
			pushService.pushWithTag(title, cnt, json, tag);
41
		}
42
		
43
	}
15 44
}

+ 18 - 8
src/main/java/com/ekexiu/push/service/PushService.java

@ -61,6 +61,7 @@ public class PushService {
61 61
	private String appKey = "48nq7d7yHu8dgbzVHuisp6";
62 62
	private String appId = "TUdvbnxu1c97r6Fb6cUy57";
63 63
	private int timeout = 0;
64
	private boolean enable = false;
64 65

65 66
	private String token = null;
66 67
	private long lastBuildTime = 0;
@ -97,6 +98,16 @@ public class PushService {
97 98
		this.timeout = timeout;
98 99
	}
99 100

101
	
102
	
103
	public boolean isEnable() {
104
		return enable;
105
	}
106

107
	public void setEnable(boolean enable) {
108
		this.enable = enable;
109
	}
110

100 111
	private String buildSign(long flag) {
101 112
		String p = this.appKey + flag + this.secret;
102 113
		MessageDigest messageDigest;
@ -126,12 +137,12 @@ public class PushService {
126 137
		throw new RuntimeException("调用用个推restApi,返回结果错误:" + obj + ":" + errMsg);
127 138
	}
128 139

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

136 147
	public String allocateRequesstId() {
137 148
		UUID uuid = UUID.randomUUID();
@ -139,7 +150,6 @@ public class PushService {
139 150
	}
140 151

141 152
	private void buildToken() {
142
		if(true) return;
143 153
		long time = System.currentTimeMillis();
144 154
		String sign = this.buildSign(time);
145 155
		StringBuilder sb = new StringBuilder();
@ -164,7 +174,7 @@ public class PushService {
164 174
		if ((this.token != null) && ((System.currentTimeMillis() - this.lastBuildTime) < (24 * 60 * 60 * 1000 - 5000))) {
165 175
			return;
166 176
		}
167
		this.buildToken();
177
		if(enable)	this.buildToken();
168 178
	}
169 179

170 180
	public Map<String, Object> post(String url, Map<String, String> header, byte[] data) throws IOException {

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

@ -272,4 +272,5 @@ com_ekexiu_portal_service_GrowthRuleService.signInSixDays::int=10
272 272
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
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler
275
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler
276
com_ekexiu_push_service_PushService.enable::boolean=true

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

@ -272,4 +272,5 @@ com_ekexiu_portal_service_GrowthRuleService.signInSixDays::int=10
272 272
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
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler
275
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler
276
com_ekexiu_push_service_PushService.enable::boolean=false

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

@ -271,4 +271,4 @@ com_ekexiu_portal_oauth_OAuthService.handlers-ref=oauthService_handlers
271 271
oauthService_handlers::map=java.util.HashMap
272 272
oauthService_handlers.map-key-1=weixin
273 273
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler
274
274
com_ekexiu_push_service_PushService.enable::boolean=false