|
@ -24,275 +24,6 @@ public class SceneBean extends IpuAppBean {
|
24
|
24
|
|
25
|
25
|
private static final Logger LOGGER = Logger.getLogger(SceneBean.class);
|
26
|
26
|
|
27
|
|
/**
|
28
|
|
* 数据请求场景
|
29
|
|
*
|
30
|
|
* @param param
|
31
|
|
* @return
|
32
|
|
* @throws Exception
|
33
|
|
*/
|
34
|
|
public IData dataRequestScene(IData param) throws Exception {
|
35
|
|
IData result = new DataMap();
|
36
|
27
|
|
37
|
|
// 获取从前台传过来的数据
|
38
|
|
String data = param.getString("data");
|
39
|
|
|
40
|
|
// 获取人品--随机数
|
41
|
|
Random random = new Random();
|
42
|
|
int testCharacter = random.nextInt(100);
|
43
|
|
|
44
|
|
StringBuffer retMsg = new StringBuffer();
|
45
|
|
if (testCharacter > 0 && testCharacter < 20) {
|
46
|
|
retMsg.append("是我不好...不应该和你谈人品问题的...");
|
47
|
|
} else if (testCharacter >= 20 && testCharacter < 40) {
|
48
|
|
retMsg.append("您的人品之低下实在让人惊讶啊...");
|
49
|
|
} else if (testCharacter >= 40 && testCharacter < 60) {
|
50
|
|
retMsg.append("您的人品太差了..稍不小心就会去干坏事了吧?");
|
51
|
|
} else if (testCharacter >= 60 && testCharacter < 80) {
|
52
|
|
retMsg.append("您的人品勉勉强强...要自己好自为之...");
|
53
|
|
} else if (testCharacter >= 80 && testCharacter <= 100) {
|
54
|
|
retMsg.append("您的人品太好了...你就是当代活雷锋啊...");
|
55
|
|
}
|
56
|
|
|
57
|
|
result.put("retName", data);
|
58
|
|
result.put("retMsg", retMsg);
|
59
|
|
return result;
|
60
|
|
|
61
|
|
}
|
62
|
|
|
63
|
|
/**
|
64
|
|
* 页面跳转(调用数据接口)场景
|
65
|
|
*
|
66
|
|
* @param param
|
67
|
|
* @return
|
68
|
|
* @throws Exception
|
69
|
|
*/
|
70
|
|
public IData openPageScene(IData param) throws Exception {
|
71
|
|
IData result = new DataMap();
|
72
|
|
|
73
|
|
// 获取从前台传过来的数据
|
74
|
|
String data = param.getString("data", "");
|
75
|
|
|
76
|
|
// 处理前台传过来的数据
|
77
|
|
if ("1".equals(data.trim())) {
|
78
|
|
result.put("retMsg", "太棒了,回答正确");
|
79
|
|
} else {
|
80
|
|
result.put("retMsg", "哎呀,回答错误了,答案:1个,因为再吃的时候就不是空着肚子了");
|
81
|
|
}
|
82
|
|
|
83
|
|
return result;
|
84
|
|
|
85
|
|
}
|
86
|
|
|
87
|
|
/**
|
88
|
|
* 调用IPU场景
|
89
|
|
*
|
90
|
|
* @param param
|
91
|
|
* @return
|
92
|
|
* @throws Exception
|
93
|
|
*/
|
94
|
|
public IData openIPUScene(IData param) throws Exception {
|
95
|
|
IData result = new DataMap();
|
96
|
|
|
97
|
|
// 获取从前台传过来的数据"
|
98
|
|
String s = param.getString("value1", "");
|
99
|
|
result.put("value1", s);
|
100
|
|
s = param.getString("value2", "");
|
101
|
|
result.put("value2", s);
|
102
|
|
s = param.getString("value3", "");
|
103
|
|
result.put("value3", s);
|
104
|
|
|
105
|
|
return result;
|
106
|
|
|
107
|
|
}
|
108
|
|
|
109
|
|
/**
|
110
|
|
* 初始化验证码
|
111
|
|
*
|
112
|
|
* @param param
|
113
|
|
* @return
|
114
|
|
* @throws Exception
|
115
|
|
*/
|
116
|
|
public IData initVerifyCode(IData param) {
|
117
|
|
IData result = new DataMap();
|
118
|
|
|
119
|
|
try {
|
120
|
|
// 获取验证码
|
121
|
|
String verifyCode = ImageVerify.getVerifyCode(4, 2);
|
122
|
|
BufferedImage image = ImageVerify.getImageVerify(verifyCode);
|
123
|
|
String imageVerifyCode = ImageVerify.getImageBase64(image);
|
124
|
|
|
125
|
|
// 创建session
|
126
|
|
IpuContextData contextData = new IpuContextData();
|
127
|
|
String sessionId = IpuSessionManager.getInstance()
|
128
|
|
.createSession(contextData);
|
129
|
|
contextData.setVerifyCode(verifyCode.toUpperCase());
|
130
|
|
|
131
|
|
result.put("VERIFY_IMG", imageVerifyCode);
|
132
|
|
result.put("SESSION_ID", sessionId);
|
133
|
|
} catch (Exception e) {
|
134
|
|
LOGGER.error("context", e);
|
135
|
|
}
|
136
|
|
|
137
|
|
return result;
|
138
|
|
}
|
139
|
|
|
140
|
|
/**
|
141
|
|
*
|
142
|
|
* @Title: refreshVerifyCode
|
143
|
|
* @Description: 刷新验证码
|
144
|
|
* @author 王玉娟
|
145
|
|
* @param prama
|
146
|
|
* @return
|
147
|
|
* @throws Exception
|
148
|
|
* @throws
|
149
|
|
*/
|
150
|
|
public IData refreshVerifyCode(IData prama) throws Exception {
|
151
|
|
// 获取验证码
|
152
|
|
String verifyCode = ImageVerify.getVerifyCode(4, 2);
|
153
|
|
BufferedImage image = ImageVerify.getImageVerify(verifyCode);
|
154
|
|
String imageVerifyCode = ImageVerify.getImageBase64(image);
|
155
|
|
|
156
|
|
if (getContextData() == null) {
|
157
|
|
// 创建session
|
158
|
|
IpuContextData contextData = new IpuContextData();
|
159
|
|
IpuSessionManager.getInstance().createSession(contextData);
|
160
|
|
}
|
161
|
|
|
162
|
|
getContextData().setVerifyCode(verifyCode);
|
163
|
|
|
164
|
|
IData result = new DataMap();
|
165
|
|
result.put("VERIFY_IMG", imageVerifyCode);
|
166
|
|
return result;
|
167
|
|
}
|
168
|
|
|
169
|
|
/**
|
170
|
|
* 登陆
|
171
|
|
*
|
172
|
|
* @param param
|
173
|
|
* @return
|
174
|
|
*/
|
175
|
|
public IData login(IData param) {
|
176
|
|
IData result = new DataMap();
|
177
|
|
|
178
|
|
// 校验验证码是否输入正确
|
179
|
|
if (!checkLoginVerifyCode(param)) {
|
180
|
|
MobileUtility.error("登陆失败,验证码输入错误!");
|
181
|
|
return result;
|
182
|
|
}
|
183
|
|
|
184
|
|
// 将用户信息保存至session
|
185
|
|
try {
|
186
|
|
getContextData().setAccount(param.getString("USER_NAME"));
|
187
|
|
return getContextData().getData();
|
188
|
|
} catch (Exception e) {
|
189
|
|
// TODO Auto-generated catch block
|
190
|
|
LOGGER.error("context", e);
|
191
|
|
return result;
|
192
|
|
}
|
193
|
|
|
194
|
|
}
|
195
|
|
|
196
|
|
/**
|
197
|
|
*
|
198
|
|
* @Title: checkLoginVerifyCode
|
199
|
|
* @Description: 校验登陆的验证码
|
200
|
|
* @author 王玉娟
|
201
|
|
* @param param
|
202
|
|
* @return true:验证码正确;false:验证码输入错误
|
203
|
|
* @throws
|
204
|
|
*/
|
205
|
|
private boolean checkLoginVerifyCode(IData param) {
|
206
|
|
try {
|
207
|
|
String verifyCode = getContextData().getVerifyCode();
|
208
|
|
String clientVerifyCode = param.getString("VERIFY_CODE");
|
209
|
|
if (clientVerifyCode == null || verifyCode == null
|
210
|
|
|| !verifyCode.equalsIgnoreCase(clientVerifyCode)) {
|
211
|
|
return false;
|
212
|
|
}
|
213
|
|
|
214
|
|
return true;
|
215
|
|
} catch (Exception e) {
|
216
|
|
// TODO Auto-generated catch block
|
217
|
|
LOGGER.error("context", e);
|
218
|
|
return false;
|
219
|
|
}
|
220
|
|
}
|
221
|
|
|
222
|
|
public IData getPersonDetailMore(IData param) {
|
223
|
|
IData result = new DataMap();
|
224
|
|
int personId = param.getInt("id");
|
225
|
|
if (personId <= 0) {
|
226
|
|
throw new RuntimeException("获取参数失败!");
|
227
|
|
}
|
228
|
|
if (personId == 1) {
|
229
|
|
result.put("name", "小胖");
|
230
|
|
result.put("age", 20);
|
231
|
|
result.put("gender", "男");
|
232
|
|
result.put("dept", "移动部门");
|
233
|
|
} else if (personId == 2) {
|
234
|
|
result.put("name", "张三");
|
235
|
|
result.put("age", 22);
|
236
|
|
result.put("gender", "男");
|
237
|
|
result.put("dept", "联通部门");
|
238
|
|
} else if (personId == 3) {
|
239
|
|
result.put("name", "李四");
|
240
|
|
result.put("age", 24);
|
241
|
|
result.put("gender", "女");
|
242
|
|
result.put("dept", "财务部门");
|
243
|
|
}
|
244
|
|
return result;
|
245
|
|
}
|
246
|
|
|
247
|
|
public IData verifyCode(IData param){
|
248
|
|
String code = param.getString("code");
|
249
|
|
IData result = new DataMap();
|
250
|
|
boolean isVerify = AuthGenerator.verify(key,code);
|
251
|
|
result.put("result",isVerify);
|
252
|
|
return result;
|
253
|
|
}
|
254
|
|
|
255
|
|
private final static Map<String, String> uniqueAccounts = new ConcurrentHashMap<String, String>();
|
256
|
|
|
257
|
|
public IData uniqueLogin(IData param) throws Exception {
|
258
|
|
IData result = new DataMap();
|
259
|
|
boolean loginResult = true;//用户名和密码校验逻辑实现
|
260
|
|
if (loginResult) {
|
261
|
|
String account = param.getString("ACCOUNT");
|
262
|
|
String sessionIdOld = uniqueAccounts.get(account);
|
263
|
|
ICache cache = IpuSessionManager.getInstance().getSessionCache();
|
264
|
|
ISession session = (ISession) cache.get(sessionIdOld);
|
265
|
|
if (sessionIdOld != null && session != null) {
|
266
|
|
cache.remove(sessionIdOld);// 删除旧的session
|
267
|
|
}
|
268
|
|
|
269
|
|
IpuContextData contextData = new IpuContextData();
|
270
|
|
contextData.put(Constant.Session.ACCOUNT, account);
|
271
|
|
String sessionIdNew = IpuSessionManager.getInstance().createSession(contextData);
|
272
|
|
uniqueAccounts.put(account, sessionIdNew);
|
273
|
|
result.put("state", "success");
|
274
|
|
result.put(Constant.Session.SESSION_ID, sessionIdNew);
|
275
|
|
result.put(Constant.Session.ACCOUNT, account);
|
276
|
|
}else{
|
277
|
|
result.put("state", "login_userpassword_error");
|
278
|
|
}
|
279
|
|
|
280
|
|
return result;
|
281
|
|
}
|
282
|
|
|
283
|
|
public IData checkSessionAvailable(IData param) throws Exception {
|
284
|
|
IData result = new DataMap();
|
285
|
|
String sessionId = param.getString(Constant.Session.SESSION_ID);
|
286
|
|
ICache cache = IpuSessionManager.getInstance().getSessionCache();
|
287
|
|
ISession session = (ISession) cache.get(sessionId);
|
288
|
|
if (sessionId != null && session != null) {
|
289
|
|
result.put("sessionAvailable", true);
|
290
|
|
}
|
291
|
|
else {
|
292
|
|
result.put("sessionAvailable", false);
|
293
|
|
}
|
294
|
|
|
295
|
|
return result;
|
296
|
|
}
|
297
|
28
|
|
298
|
29
|
}
|