app.du.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. using BizCom;
  2. using SiteCore.Msn;
  3. using SiteCore.Redis;
  4. using SQLData;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Web;
  11. using Utils;
  12. namespace SiteCore.Handler
  13. {
  14. public partial class app
  15. {
  16. public static FrequencyControler DuFrequency = new FrequencyControler("duba", 10, 3);
  17. public static FrequencyControler DoorFrequency = new FrequencyControler("door",6, 3);
  18. public static FrequencyControler TmpDoorFrequency = new FrequencyControler("door", 6, 3);
  19. public static readonly Object lockMsn = new object();
  20. public void quduba_sendms()
  21. {
  22. if (UrlPostParmsCheck("tmp,mobile"))
  23. {
  24. //string tmp = GetPostString("tmp");
  25. //int qid = WebHelper.getDecodeUid(tmp);
  26. //if (qid == 0)
  27. //{
  28. // con.Response.Write("{\"s\":0,\"msg\":\"无法访问,请稍候再试\"}");
  29. // return;
  30. //}
  31. if (con.Session["uid"] == null || con.Session["uid"].ToString()=="")
  32. {
  33. con.Response.Write("{\"s\":0,\"msg\":\"已过期,无法发送验证码\"}");
  34. return;
  35. }
  36. string mobile = GetPostString("mobile");
  37. lock (lockMsn)
  38. {
  39. MsnObj mo = redis.RedisHelper.StringGet<MsnObj>(mobile);
  40. if (mo == null)
  41. {
  42. if(SDuUser.Exists("Mobile=?",mobile))
  43. {
  44. con.Response.Write("{\"s\":0,\"msg\":\"该手机号已验证过!\"}");
  45. return;
  46. }
  47. }
  48. else if (mo.isFinish)
  49. {
  50. con.Response.Write("{\"s\":0,\"msg\":\"该手机号已验证过!\"}");
  51. return;
  52. }
  53. Random random = new Random();
  54. string smsCode = random.Next(1000, 9999).ToString();
  55. string msg = "";
  56. bool isSend = MnsHelper.SendBindSms(mobile, smsCode, out msg);
  57. if (isSend) con.Response.Write("{\"s\":1,\"msg\":\"验证码已发送\"}");
  58. else con.Response.Write("{\"s\":0,\"msg\":\"" + msg + "\"}");
  59. }
  60. }
  61. else
  62. {
  63. con.Response.Write("{\"s\":0,\"msg\":\"错误的参数,无法发送验证码\"}");
  64. }
  65. }
  66. public void quduba_sign()
  67. {
  68. if (DuFrequency.IsTooFrequently(true))
  69. {
  70. con.Response.Write("{\"s\":0,\"msg\":\"访问太频繁\"}");
  71. return;
  72. }
  73. //name,idcard,
  74. if (UrlPostParmsCheck("mobile,code,tmp"))
  75. {
  76. string mobile = GetPostString("mobile");
  77. MsnObj mo = redis.RedisHelper.StringGet<MsnObj>(mobile);
  78. if (mo == null)
  79. {
  80. con.Response.Write("{\"s\":0,\"msg\":\"验证码不正确\"}");
  81. return;
  82. }
  83. string code = GetPostString("code");
  84. if (code != mo.code)
  85. {
  86. con.Response.Write("{\"s\":0,\"msg\":\"验证码不正确\"}");
  87. return;
  88. }
  89. //string tmp= GetPostString("tmp");
  90. //int qid = WebHelper.getDecodeUid(tmp);
  91. //if (qid == 0)
  92. //{
  93. // con.Response.Write("{\"s\":0,\"msg\":\"无法访问,请稍候再试\"}");
  94. // return;
  95. //}
  96. if (con.Session["uid"] == null || con.Session["uid"].ToString() == "")
  97. {
  98. con.Response.Write("{\"s\":0,\"msg\":\"注册已过期,请重试\"}");
  99. }
  100. try
  101. {
  102. int uid = Convert.ToInt32(con.Session["uid"]);
  103. SDuUser entity = SDuUser.Get(uid);
  104. if (entity != null)
  105. {
  106. entity.Mobile = mobile;
  107. entity.Update();
  108. redis.RedisHelper.StringSet(entity.openid, entity.ID + "|" + entity.State);
  109. //RedisHelper.StringSet(entity.openid, entity.ID+"|"+entity.State);
  110. con.Session["openid"] = entity.openid;
  111. mo.isFinish = true;
  112. redis.RedisHelper.StringSet(mobile, mo, TimeSpan.FromDays(2));
  113. con.Response.Write("{\"s\":1,\"code\":\"" + DecryptHelper.Encrypt(WebHelper.ConvertDateTimeToInt(DateTime.Now).ToString()) + "\"}");
  114. }
  115. else
  116. {
  117. con.Response.Write("{\"s\":0,\"msg\":\"页面己过期,请重新进入\"}");
  118. }
  119. }
  120. catch (Exception ex)
  121. {
  122. XLog.SaveLog(0, ex.Message);
  123. }
  124. return;
  125. }
  126. con.Response.Write("{\"s\":0,\"msg\":\"无法访问,请稍候再试\"}");
  127. }
  128. public void quduba_sign2()
  129. {
  130. if (DuFrequency.IsTooFrequently(true))
  131. {
  132. con.Response.Write("{\"s\":0,\"msg\":\"访问太频繁\"}");
  133. return;
  134. }
  135. //name,idcard,
  136. if (UrlPostParmsCheck("mobile,code,uname,birth,sex,duty"))
  137. {
  138. string mobile = GetPostString("mobile");
  139. MsnObj mo = redis.RedisHelper.StringGet<MsnObj>(mobile);
  140. if (mo == null)
  141. {
  142. con.Response.Write("{\"s\":0,\"msg\":\"验证码不正确\"}");
  143. return;
  144. }
  145. string code = GetPostString("code");
  146. if (code != mo.code)
  147. {
  148. con.Response.Write("{\"s\":0,\"msg\":\"验证码不正确\"}");
  149. return;
  150. }
  151. string uname = GetPostString("uname");
  152. if (uname.Length < 2)
  153. {
  154. con.Response.Write("{\"s\":0,\"msg\":\"请输入您的姓名\"}");
  155. return;
  156. }
  157. int sex = GetPostInt("sex");
  158. if (sex <= 0 && sex > 2)
  159. {
  160. con.Response.Write("{\"s\":0,\"msg\":\"请选择您的性别\"}");
  161. return;
  162. }
  163. string duty = GetPostString("duty");
  164. if (duty.Length < 1)
  165. {
  166. con.Response.Write("{\"s\":0,\"msg\":\"请输入您的职业\"}");
  167. return;
  168. }
  169. string work = GetPostString("work");
  170. string birth = GetPostString("birth");
  171. if (birth.Length < 1)
  172. {
  173. con.Response.Write("{\"s\":0,\"msg\":\"请选择出生年月\"}");
  174. return;
  175. }
  176. //int age = GetPostInt("age");
  177. //if(age<=0 && age > 10)
  178. //{
  179. // con.Response.Write("{\"s\":0,\"msg\":\"请选择您的年龄段\"}");
  180. // return;
  181. //}
  182. //if (work.Length < 1)
  183. //{
  184. // con.Response.Write("{\"s\":0,\"msg\":\"请输入您的工作单位\"}");
  185. // return;
  186. //}
  187. //string tmp= GetPostString("tmp");
  188. //int qid = WebHelper.getDecodeUid(tmp);
  189. //if (qid == 0)
  190. //{
  191. // con.Response.Write("{\"s\":0,\"msg\":\"无法访问,请稍候再试\"}");
  192. // return;
  193. //}
  194. if (con.Session["uid"] == null || con.Session["uid"].ToString() == "")
  195. {
  196. con.Response.Write("{\"s\":0,\"msg\":\"注册已过期,请重试\"}");
  197. }
  198. try
  199. {
  200. int uid = Convert.ToInt32(con.Session["uid"]);
  201. SDuUser entity = SDuUser.Get(uid);
  202. if (entity != null)
  203. {
  204. entity.RealName = uname;
  205. entity.Sex = sex;
  206. //entity.Age = age;
  207. entity.Birthday = birth;
  208. entity.Duty = duty;
  209. entity.WorkUnit = work;
  210. entity.Mobile = mobile;
  211. entity.Update();
  212. redis.RedisHelper.StringSet(entity.openid, entity.ID + "|" + entity.State);
  213. con.Session["openid"] = entity.openid;
  214. mo.isFinish = true;
  215. redis.RedisHelper.StringSet(mobile, mo, TimeSpan.FromDays(2));
  216. con.Response.Write("{\"s\":1,\"code\":\"" + DecryptHelper.Encrypt(WebHelper.ConvertDateTimeToInt(DateTime.Now).ToString()) + "\"}");
  217. }
  218. else
  219. {
  220. con.Response.Write("{\"s\":0,\"msg\":\"页面己过期,请重新进入\"}");
  221. }
  222. }
  223. catch (Exception ex)
  224. {
  225. XLog.SaveLog(0, ex.Message);
  226. }
  227. return;
  228. }
  229. con.Response.Write("{\"s\":0,\"msg\":\"填写的信息不完整或无法访问,请稍候再试\"}");
  230. }
  231. public void quduba_qcode()
  232. {
  233. //string userAgent = con.Request.UserAgent;
  234. //if (!WebHelper.isWeiXinAgent(userAgent))
  235. //{
  236. // con.Response.Write("0");
  237. // return;
  238. //}
  239. if (UrlPostParmsCheck("code"))
  240. {
  241. string code = GetPostString("code");
  242. if (!string.IsNullOrEmpty(code))
  243. {
  244. try
  245. {
  246. //if (con.Session["openid"] == null || con.Session["openid"].ToString() == "")
  247. //{
  248. // con.Response.Write("{\"msg\":\"二维码已过期\",\"ncode\":\"\"}");
  249. // return;
  250. //}
  251. //string openid = con.Session["openid"].ToString();
  252. string openid = WebHelper.getCookie("openid");
  253. if (con.Session["openid"] == null || con.Session["openid"].ToString() == "")
  254. {
  255. openid = WebHelper.getCookie("openid");
  256. if (openid == "")
  257. {
  258. con.Response.Write("{\"msg\":\"二维码已过期\",\"ncode\":\"\"}");
  259. return;
  260. }
  261. }
  262. else
  263. {
  264. openid = con.Session["openid"].ToString();
  265. }
  266. string re = redis.RedisHelper.StringGet(openid);
  267. if (!string.IsNullOrEmpty(re))
  268. {
  269. code = WebHelper.getEncodeCodeByNormal(re);
  270. con.Response.Write("{\"msg\":\"\",\"ncode\":\"" + code + "\"}");
  271. return;
  272. }
  273. }
  274. catch(Exception ex)
  275. {
  276. XLog.SaveLog(0, ex.Message);
  277. //Response.Clear();
  278. //con.Response.Write("0");
  279. //Response.End();
  280. }
  281. }
  282. }
  283. con.Response.Write("{\"msg\":\"无法生成二维码\",\"ncode\":\"\"}");
  284. }
  285. public void quduba_week()
  286. {
  287. if (UrlPostParmsCheck("sid,qt"))
  288. {
  289. string t = GetPostString("qt");
  290. //t = HttpUtility.UrlDecode(t);
  291. try
  292. {
  293. string[] vArr = t.Split('|');
  294. if (vArr.Length >= 7)
  295. {
  296. int siteid = GetPostInt("sid");
  297. string sql = string.Format("update S_DuSite set opentime='{0}' where id={1}", t, siteid);
  298. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  299. con.Response.Write("yes");
  300. return;
  301. }
  302. }
  303. catch (Exception ex)
  304. {
  305. XLog.SaveLog(0, ex.Message);
  306. }
  307. con.Response.Write("no");
  308. }
  309. }
  310. public void quduba_door()
  311. {
  312. if (DoorFrequency.IsTooFrequently(true))
  313. {
  314. con.Response.Write("访问太频繁!");
  315. return;
  316. }
  317. byte[] input = con.Request.BinaryRead(con.Request.TotalBytes);
  318. if (input.Length < 1)
  319. {
  320. con.Response.Write("no");
  321. return;
  322. }
  323. else
  324. {
  325. string s = Encoding.UTF8.GetString(input);
  326. try
  327. {
  328. string v = DecryptHelper.Decrypt(s);
  329. string[] vArr = v.Split('|');
  330. if (vArr.Length > 3)
  331. {
  332. //int uid = Convert.ToInt32(vArr[0]);
  333. int uid = Convert.ToInt32(SecurityHelper.DecryptSymmetric(vArr[0]));
  334. int siteid = Convert.ToInt32(vArr[1]);
  335. int inout = Convert.ToInt32(vArr[2]);
  336. DateTime dTime = Convert.ToDateTime(vArr[3]);
  337. string sTime = dTime.ToString("yyyy-MM-dd HH:mm");
  338. StringBuilder sql = new StringBuilder();
  339. sql.AppendFormat("if (select count(0) from s_duentryexit where userid={0} and siteid={1} and inout={2} and datediff(MINUTE,addtime,'{3}')<=2)<1 begin ", uid, siteid, inout, dTime);
  340. sql.AppendFormat("insert into s_duentryexit(userid,siteid,inout,addtime) values({0},{1},{2},'{3}')",uid,siteid,inout,sTime);
  341. sql.AppendFormat(" end ");
  342. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  343. string key = "open_" + uid;
  344. duRedis.RedisHelper.StringSet(key, "1|开门成功", TimeSpan.FromSeconds(10));
  345. con.Response.Write("op");
  346. return;
  347. }
  348. }
  349. catch(Exception ex)
  350. {
  351. XLog.SaveLog(0,"开门访问,"+ s +","+ ex.Message);
  352. }
  353. con.Response.Write("no");
  354. }
  355. }
  356. public void quduba_tmpdoor()
  357. {
  358. byte[] input = con.Request.BinaryRead(con.Request.TotalBytes);
  359. if (input.Length < 1)
  360. {
  361. con.Response.Write("no");
  362. return;
  363. }
  364. else
  365. {
  366. string s = Encoding.Unicode.GetString(input);
  367. try
  368. {
  369. string v = DecryptHelper.Decrypt(s);
  370. string[] itArr = v.Split('§');
  371. string[] vArr;
  372. StringBuilder sql = new StringBuilder();
  373. for (int i = 0; i < itArr.Length; i++)
  374. {
  375. vArr = itArr[i].Split('|');
  376. int uid= Convert.ToInt32(SecurityHelper.DecryptSymmetric(vArr[0]));
  377. //int uid = Convert.ToInt32(vArr[0]);
  378. int siteid = Convert.ToInt32(vArr[1]);
  379. int inout = Convert.ToInt32(vArr[2]);
  380. DateTime dTime = Convert.ToDateTime(vArr[3]);
  381. string sTime = dTime.ToString("yyyy-MM-dd HH:mm");
  382. sql.AppendFormat("insert into s_duentryexit(userid,siteid,inout,addtime) values({0},{1},{2},'{3}') ;",
  383. uid, siteid, inout, sTime);
  384. }
  385. if (sql.Length > 0)
  386. {
  387. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  388. con.Response.Write("suc");
  389. return;
  390. }
  391. }
  392. catch (Exception ex)
  393. {
  394. XLog.SaveLog(0, "tmpdoor_定时发送" + ex.Message);
  395. }
  396. }
  397. con.Response.Write("no");
  398. }
  399. public void get_qdbmsg()
  400. {
  401. if (UrlPostParmsCheck("tmp"))
  402. {
  403. int qid = GetPostInt("tmp");
  404. string key = "open_" + qid;
  405. try
  406. {
  407. object msg = duRedis.RedisHelper.StringGet(key);
  408. if (msg != null && msg.ToString() != "")
  409. {
  410. if (duRedis.RedisHelper.KeyExists(key)) duRedis.RedisHelper.KeyDelete(key);
  411. string[] mArr = msg.ToString().Split('|');
  412. if (mArr[0] == "0") conError(mArr[1]);
  413. else conSuccess(mArr[1]);
  414. return;
  415. //redis.RedisHelper.StringSet(mobile, mo, TimeSpan.FromDays(2));
  416. }
  417. }
  418. catch { }
  419. }
  420. conError("");
  421. }
  422. public void set_qdbmsg()
  423. {
  424. if (UrlPostParmsCheck("tmp,msg"))
  425. {
  426. //int uid = GetPostInt("uid");
  427. try
  428. {
  429. string tmp = GetPostString("tmp");
  430. tmp = HttpUtility.UrlDecode(tmp);
  431. string uid = SecurityHelper.DecryptSymmetric(tmp);
  432. string msg2 = GetPostString("msg");
  433. string key = "open_" + uid;
  434. duRedis.RedisHelper.StringSet(key, msg2, TimeSpan.FromSeconds(10));
  435. con.Response.Write("1");
  436. }
  437. catch
  438. {
  439. }
  440. }
  441. }
  442. }
  443. }