VerifyAjax.cs
19.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Quiz.BLL;
using Quiz.Models;
using Quiz.Models.Domain;
using Quiz.Utility;
namespace Quiz.SiteBase
{
public partial class VerifyAjax : WebSiteBase
{
public void Verify(string action)
{
OperationResult m = new OperationResult(OperationResultType.Error);
RequestGeter rg = new RequestGeter(Request.Form);
switch (action)
{
//发送验证码
case "sendmsgcode":
{
string mobile = Request["mobile"];
//先判断是否答过题,如果答过题不发送短信
if (BLL.UserBll.IsAnswer(mobile)>0)
{
m.Status=OperationResultType.ValidError;
m.Message = "你已经答过题了";
break;
}
//判断该号码是否在库里面,如果不在则不发短信
List<Models.User> userList = (List<Models.User>)SiteBase.Cache.CacheManage.User.CacheData;
var curUser = userList.Find(o => o.PhoneName == mobile&&o.UserType==(int)UserTypeEnum.学生家长);
if (curUser == null)
{
m.Message = "仅收到【绍兴市教育局】邀请短信的抽样用户可以参与本次调查。";
break;
}
//生成4位随机码
Random rad = new Random();//实例化随机数产生器rad;
int code = rad.Next(1000, 10000);//用rad生成大于等于1000,小于等于9999的随机数;
#region 老版短信发送
// var ss = new XSTWeb.Modules.SmsServer.Models.SmsSendRequest()
//{
// MsgContent = string.Format("您正在参与的教育调查4位验证码为:{0}",code),
// SchoolId = 2,
// SendId = 0,
// Sno = "",
// SendTime = DateTime.Now,
// Type = 1,//*
// SmsType = 2,//*
// SendUserId = mobile,
// ReceiveInfos = new List<XSTWeb.Modules.SmsServer.Models.SmsSendRequest.ReceiveInfo>()
//};
//ss.ReceiveInfos.Add(new XSTWeb.Modules.SmsServer.Models.SmsSendRequest.ReceiveInfo()
//{
// ClassId = 0,
// ReceiveId = 1,
// ReceivePhone = mobile,
// ReceiveUserId = mobile,
// Type = 3
//});
#region
//var ss = new XSTWeb.Modules.SmsServer.Models.SmsSendRequest()
//{
// MsgContent = string.Format("您正在参与的教育调查4位验证码为:{0}", code),
// SchoolId = 2,
// SendId = 0,
// Sno = "",
// SendTime = DateTime.Now,
// Type = 1,//*
// SmsType = 2,//*
// SendUserId = mobile,
// ReceiveInfos = new List<XSTWeb.Modules.SmsServer.Models.SmsSendRequest.ReceiveInfo>()
//};
//ss.ReceiveInfos.Add(new XSTWeb.Modules.SmsServer.Models.SmsSendRequest.ReceiveInfo()
//{
// ClassId = 0,
// ReceiveId = 1,
// ReceivePhone = mobile,
// ReceiveUserId = mobile,
// Type = 3
//});
//var result = XSTWeb.Modules.SmsServer.DataSource.SendSms(ss);
//Utility.Helper.SaveLog(string.Format("status={0}&code={1}&mobile={2}", result.Status, code, mobile), "mobilecode");
//if (result.Status == XSTWeb.Modules.SmsServer.Utility.OperationResultType.Success)
//{
// m.Status = OperationResultType.Success;
// m.Data = code;
//}
//else
//{
// m.Message = result.Message;
//}
#endregion
#endregion
List<string> Mymobile = new List<string>();
Mymobile.Add(mobile);
string cons = string.Format("您正在参与的教育调查4位验证码为:{0}", code);
var ss = new sendDC()
{
Content = cons,
Mobile = Mymobile
};
string postData = Newtonsoft.Json.JsonConvert.SerializeObject(ss);
var reset = BLL.UserBll.ExamineSendMsg(cons, mobile);
// string result = PostUrl("http://campus.myjxt.com/api/Common/ExamineSendMsg", postData);
//resetModel reset = Newtonsoft.Json.JsonConvert.DeserializeObject<resetModel>(result);
//Utility.Helper.SaveLog(string.Format("status={0}&code={1}&mobile={2}", reset.status, code, mobile), "mobilecode");
if (reset)
{
m.Status = OperationResultType.Success;
m.Data = code;
}
else
{
m.Message ="失败";
}
}
break;
case "checkcode":
{
var mobile = Request["mobile"];
int usertype = RequestInt("usertype");
int flag = UserBll.IsAnswer(mobile);
if (flag > 0)
{
m.Status=OperationResultType.ValidError;
m.Message = "你已经答过题了";
break;
}
List<Models.User> userList = (List<Models.User>)SiteBase.Cache.CacheManage.User.CacheData;
var curUser = userList.Find(o => o.PhoneName == mobile&&o.UserType==usertype);
if (curUser != null) //如果在缓存中能找到该手机 号码
{
m.Status = OperationResultType.Success;
m.Data = curUser.StudentName;
m.Message = curUser.SchoolName;
}
else
{
m.Message = "仅收到【绍兴市教育局】邀请短信的抽样用户可以参与本次调查,请确认您的身份是“家长”或“市民”";
}
}
break;
case "getquestion":
{
int current = RequestInt("current");
int qtype = RequestInt("qtype");
int num = RequestInt("num");
List<Models.Topic> list = null;
if (SiteBase.Cache.CacheManage.Topic.CacheData == null) list = new List<Models.Topic>();
else
{
list = (List<Models.Topic>) SiteBase.Cache.CacheManage.Topic.CacheData;
}
var TopicList = list.Where(o => o.TopicType == qtype).ToList();
int total = TopicList.Count;
StringBuilder html = new StringBuilder();
for (int i = current; i < current + num; i++)
{
if (i + 1 > total)
{
break;
}
if (!string.IsNullOrEmpty(TopicList[i].A) && !string.IsNullOrEmpty(TopicList[i].D))
{
html.AppendFormat("<article class=\"question required\">" +
"<div class=\"t\"><span class=\"num\" >{0}.</span>{1}<span style=\" font-weight: bolder;\">{8}</span>{9}</div>" +
"<div class=\"b\">" +
"<input class=\"questionId\" name=\"topid{2}\" value=\"{3}\" type=\"hidden\" />" +
"<label class=\"opt\"><input type=\"radio\" name=\"question{2}\" value=\"A\" />A.{4}</label>" +
"<label class=\"opt\"><input type=\"radio\" name=\"question{2}\" value=\"B\" />B.{5}</label>" +
"<label class=\"opt\"><input type=\"radio\" name=\"question{2}\" value=\"C\" />C.{6}</label>" +
"<label class=\"opt\" {8}><input type=\"radio\" name=\"question{2}\" value=\"D\" />D.{7}</label>" +
"</div></article>",
i + 1,
TopicList[i].TitleOne,
i,
TopicList[i].ID,
TopicList[i].A,
TopicList[i].B,
TopicList[i].C,
TopicList[i].D,
!string.IsNullOrEmpty(TopicList[i].D) ? "" : "style=\"display:none;\"",TopicList[i].TitleTwo, TopicList[i].TitleTree);
}
else if (!string.IsNullOrEmpty(TopicList[i].A) && string.IsNullOrEmpty(TopicList[i].D))
{
html.AppendFormat("<article class=\"question required\">" +
"<div class=\"t\"><span class=\"num\" >{0}.</span>{1}<span style=\" font-weight: bolder;\">{7}</span>{8}</div>" +
"<div class=\"b\">" +
"<input class=\"questionId\" name=\"topid{2}\" value=\"{3}\" type=\"hidden\" />" +
"<label class=\"opt\"><input type=\"radio\" name=\"question{2}\" value=\"A\" />A.{4}</label>" +
"<label class=\"opt\"><input type=\"radio\" name=\"question{2}\" value=\"B\" />B.{5}</label>" +
"<label class=\"opt\"><input type=\"radio\" name=\"question{2}\" value=\"C\" />C.{6}</label>" +
"</div></article>",
i + 1,
TopicList[i].TitleOne,
i,
TopicList[i].ID,
TopicList[i].A,
TopicList[i].B,
TopicList[i].C, TopicList[i].TitleTwo, TopicList[i].TitleTree);
}
else
{
html.AppendFormat("<article class=\"question question-textarea\">" +
"<div class=\"t\">评价/建议:</div>" +
"<div class=\"b\" >" +
"<input class=\"questionId\" name=\"topid{0}\" value=\"{1}\" type=\"hidden\" />" +
"<textarea name=\"question{0}\" placeholder=\"{2}:\" style=\" height: 300px;\"></textarea>" +
"</div></article>",
i,
TopicList[i].ID,
TopicList[i].Question
);
// html.AppendFormat("<article class=\"question question-textarea\">" +
// "<div class=\"t\">意见与建议</div>" +
// "<div class=\"b\">" +
// "<input class=\"questionId\" name=\"topid{0}\" value=\"{1}\" type=\"hidden\" />" +
// "<textarea name=\"question{0}\" placeholder=\"您的意见与建议:\"></textarea>" +
// "</div></article>",
//i,
//TopicList[i].ID
//);
}
}
if (!string.IsNullOrEmpty(html.ToString()))
{
m.Status = OperationResultType.Success;
m.Data = html.ToString();
}
}
break;
case "questions":
{
string mobile = Request["mobile"];
int qtype = RequestInt("qtype");
string name = Request["name"];
string schoolname = Request["schoolname"];
//判断是否答过题
if (BLL.UserBll.IsAnswer(mobile) > 0)
{
m.Message = "请勿重复提交";
break;
}
List<Models.User> userList = (List<Models.User>)SiteBase.Cache.CacheManage.User.CacheData;
var curUser = userList.Find(o => o.PhoneName == mobile&&o.UserType==qtype);
if (curUser == null)
{
m.Message = "仅收到【绍兴市教育局】邀请短信的抽样用户可以参与本次调查,请确认您的身份是“家长”或“市民”";
break;
}
Models.UserAnswer people = new Models.UserAnswer
{
StudentName = curUser.StudentName,
SchoolName = curUser.SchoolName,
ClassName = curUser.ClassName,
ParentName = curUser.ParentName,
PhoneName = curUser.PhoneName,
schoolType=curUser.schoolType,
State = 1,
Intime = DateTime.Now,
UserType = qtype
};
if (qtype == (int) UserTypeEnum.社会人士)
{
people.StudentName = name;
people.SchoolName = schoolname;
}
List<Models.Topic> list = null;
if (SiteBase.Cache.CacheManage.Topic.CacheData == null) list = new List<Models.Topic>();
else
{
list = (List<Models.Topic>)SiteBase.Cache.CacheManage.Topic.CacheData;
}
var TopicList = list.Where(o => o.TopicType == qtype).ToList();
try
{
List<Models.Domain.TopicKeys> tkList = new List<TopicKeys>();
string str = "";
int correctnumbers = 0;
for (int i = 0; i < TopicList.Count; i++)
{
var ans = Request["question" + i];
var tid = RequestInt("topid" + i);
tkList.Add(new TopicKeys { Keys = ans, TopicId = tid });
}
TopicKeyTypes keyTypes=new TopicKeyTypes();
keyTypes.KeyList=new List<TopicKeys>();
keyTypes.KeyList.AddRange(tkList);
str += Quiz.Utility.XmlSerializer.Serializer<TopicKeyTypes>(keyTypes);
people.Keys = str;
people.Intime = DateTime.Now;
if (BLL.UserBll.AddUserAnswer(people))
{
m.Status = OperationResultType.Success;
m.Data = correctnumbers;
}
}
catch (Exception e)
{
m.Message = e.Message;
}
} break;
case "getinfo":
{
string mobile = Request["mobile"];
//List<Models.User> userList = (List<Models.User>)SiteBase.Cache.CacheManage.User.CacheData;
//var curUser = userList.Find(o => o.PhoneName == mobile);
//if (curUser != null)
//{
// m.Status=OperationResultType.Success;
// m.Message = curUser.StudentName;
// m.Data = curUser.SchoolName;
//}
var userAnswer = BLL.UserBll.GetUserAnswerOne(mobile);
if (userAnswer != null)
{
m.Status=OperationResultType.Success;
m.Message = userAnswer.StudentName;
m.Data = userAnswer.SchoolName;
}
}
break;
case "getschool":
{
int schooltype = RequestInt("schooltype");
List<Models.School> schoolList = (List<Models.School>) SiteBase.Cache.CacheManage.School.CacheData;
if (schoolList == null || schoolList.Count <= 0)
{
m.Message = "数据库中没有数据";
break;
}
var list = schoolList.Where(o => o.SchoolType == schooltype).ToList();
if (list == null || list.Count <= 0)
{
m.Message = "不存在该种类型的学校";
break;
}
m.Status=OperationResultType.Success;
m.Data = list;
}
break;
}
Response.Write(JsonHelper.SerializeObject(m));
Response.End();
}
public static string PostUrl(string url, string postData)
{
string result = "";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
//req.TimeOut = "800";//设置请求超时时间,单位为毫秒
req.ContentType = "application/json";
byte[] data = Encoding.UTF8.GetBytes(postData);
req.ContentLength = data.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(data, 0, data.Length);
reqStream.Close();
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
//获取响应内容
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
result = reader.ReadToEnd();
}
return result;
}
}
}