|
@ -23,7 +23,276 @@ public class SceneBean extends IpuAppBean {
|
23
|
23
|
private static final String key = "nkqbtjevrmnxofcwrgwq3xuwoj3tmwcj";//二次认证约定秘钥
|
24
|
24
|
|
25
|
25
|
private static final Logger LOGGER = Logger.getLogger(SceneBean.class);
|
26
|
|
|
27
|
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
|
|
|
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
|
private final static Map<String, String> uniqueAccounts = new ConcurrentHashMap<String, String>();
|
|
223
|
|
|
224
|
public IData uniqueLogin(IData param) throws Exception {
|
|
225
|
IData result = new DataMap();
|
|
226
|
boolean loginResult = true;//用户名和密码校验逻辑实现
|
|
227
|
if (loginResult) {
|
|
228
|
String account = param.getString("ACCOUNT");
|
|
229
|
String sessionIdOld = uniqueAccounts.get(account);
|
|
230
|
ICache cache = IpuSessionManager.getInstance().getSessionCache();
|
|
231
|
ISession session = (ISession) cache.get(sessionIdOld);
|
|
232
|
if (sessionIdOld != null && session != null) {
|
|
233
|
cache.remove(sessionIdOld);// 删除旧的session
|
|
234
|
}
|
|
235
|
|
|
236
|
IpuContextData contextData = new IpuContextData();
|
|
237
|
contextData.put(Constant.Session.ACCOUNT, account);
|
|
238
|
String sessionIdNew = IpuSessionManager.getInstance().createSession(contextData);
|
|
239
|
uniqueAccounts.put(account, sessionIdNew);
|
|
240
|
result.put("state", "success");
|
|
241
|
result.put(Constant.Session.SESSION_ID, sessionIdNew);
|
|
242
|
result.put(Constant.Session.ACCOUNT, account);
|
|
243
|
}else{
|
|
244
|
result.put("state", "login_userpassword_error");
|
|
245
|
}
|
|
246
|
|
|
247
|
return result;
|
|
248
|
}
|
|
249
|
|
|
250
|
public IData checkSessionAvailable(IData param) throws Exception {
|
|
251
|
IData result = new DataMap();
|
|
252
|
String sessionId = param.getString(Constant.Session.SESSION_ID);
|
|
253
|
ICache cache = IpuSessionManager.getInstance().getSessionCache();
|
|
254
|
ISession session = (ISession) cache.get(sessionId);
|
|
255
|
if (sessionId != null && session != null) {
|
|
256
|
result.put("sessionAvailable", true);
|
|
257
|
}
|
|
258
|
else {
|
|
259
|
result.put("sessionAvailable", false);
|
|
260
|
}
|
|
261
|
|
|
262
|
return result;
|
|
263
|
}
|
|
264
|
|
|
265
|
public IData getPersonDetailMore(IData param) {
|
|
266
|
IData result = new DataMap();
|
|
267
|
int personId = param.getInt("id");
|
|
268
|
if (personId <= 0) {
|
|
269
|
throw new RuntimeException("获取参数失败!");
|
|
270
|
}
|
|
271
|
if (personId == 1) {
|
|
272
|
result.put("name", "小胖");
|
|
273
|
result.put("age", 20);
|
|
274
|
result.put("gender", "男");
|
|
275
|
result.put("dept", "移动部门");
|
|
276
|
} else if (personId == 2) {
|
|
277
|
result.put("name", "张三");
|
|
278
|
result.put("age", 22);
|
|
279
|
result.put("gender", "男");
|
|
280
|
result.put("dept", "联通部门");
|
|
281
|
} else if (personId == 3) {
|
|
282
|
result.put("name", "李四");
|
|
283
|
result.put("age", 24);
|
|
284
|
result.put("gender", "女");
|
|
285
|
result.put("dept", "财务部门");
|
|
286
|
}
|
|
287
|
return result;
|
|
288
|
}
|
|
289
|
|
|
290
|
public IData verifyCode(IData param){
|
|
291
|
String code = param.getString("code");
|
|
292
|
IData result = new DataMap();
|
|
293
|
boolean isVerify = AuthGenerator.verify(key,code);
|
|
294
|
result.put("result",isVerify);
|
|
295
|
return result;
|
|
296
|
}
|
28
|
297
|
|
29
|
298
|
}
|