app.user.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using SiteCore.wechat;
  5. using SQLData;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Data.SqlClient;
  10. using System.Drawing;
  11. using System.Drawing.Imaging;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using System.Web;
  19. using TenPay;
  20. using Utils;
  21. using Utils.ImageUtils;
  22. namespace SiteCore.Handler
  23. {
  24. public partial class app
  25. {
  26. public void ins_opinion()
  27. {
  28. int uid = getDecodeInt("uid");
  29. if (uid == 0)
  30. {
  31. conError("找不到会员");
  32. return;
  33. }
  34. if (UrlPostParmsCheck("con"))
  35. {
  36. string con = GetPostString("con");
  37. string formid = GetPostString("formid");
  38. string images = GetPostString("images").Trim(',');
  39. string sql = string.Format("insert into s_opinion(userid,summary,images,addtime,formid) values({0},'{1}','{2}',getdate(),'{3}')", uid, con, images,formid);
  40. DbHelper.DbConn.ExecuteNonQuery(sql);
  41. conSuccess("感谢您的反馈!");
  42. return;
  43. }
  44. conError("错误的参数");
  45. }
  46. public void del_opinion()
  47. {
  48. int uid = getDecodeInt("uid");
  49. if (uid == 0)
  50. {
  51. conError("找不到会员");
  52. return;
  53. }
  54. if (UrlPostParmsCheck("oid"))
  55. {
  56. int oid = GetPostInt("oid");
  57. string sql = "delete from s_opinion where id=" + oid+" and userid="+uid;
  58. DbHelper.DbConn.ExecuteNonQuery(sql);
  59. conSuccess("删除成功");
  60. return;
  61. }
  62. conError("错误的参数");
  63. }
  64. public void get_opinion()
  65. {
  66. int uid = getDecodeInt("uid");
  67. if (uid == 0)
  68. {
  69. conError("找不到会员");
  70. return;
  71. }
  72. string sql = string.Format("select top 10 * from view_opinion where userid=" + uid+" order by addtime desc");
  73. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  74. conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  75. }
  76. public void upload_opinionimg()
  77. {
  78. int uid = getDecodeInt("uid");
  79. if (uid == 0)
  80. {
  81. conError("找不到会员");
  82. return;
  83. }
  84. string tag = GetPostString("tag");
  85. HttpPostedFile postFile = null;
  86. List<string> lstFile = new List<string>();
  87. int c = con.Request.Files.Count;
  88. if (c > 0)
  89. {
  90. for (int i = 0; i < c; i++)
  91. {
  92. string errMsg = "";
  93. postFile = con.Request.Files[i];
  94. if (!ImageHandler.CheckImage(postFile, out errMsg))
  95. {
  96. conError(errMsg);
  97. return;
  98. }
  99. string fileName = uid + DateTime.Now.ToFileTimeUtc() + ".jpg";
  100. string saveFile = Path.Combine(webConfig.opinionPath, fileName);
  101. string result = "";
  102. using (System.Drawing.Image imgThumb = System.Drawing.Image.FromStream(postFile.InputStream))
  103. {
  104. result = ImageMaker.ToThumbnailImages(imgThumb, saveFile, 800, "", 9, 3);
  105. }
  106. lstFile.Add(fileName);
  107. }
  108. }
  109. string fs = "";
  110. if (lstFile.Count > 0) fs = string.Join(",", lstFile.ToArray());
  111. conSuccess("上传成功", "{\"fname\":\"" + fs + "\"}");
  112. }
  113. public void wx_loginout()
  114. {
  115. int uid = getDecodeInt("uid");
  116. if (uid == 0)
  117. {
  118. //conError("找不到会员");
  119. conSuccess("登出");
  120. return;
  121. }
  122. SUser entity = SUser.Get(uid);
  123. if (entity != null)
  124. {
  125. entity.miniopenid = "";
  126. //entity.UserName = "";
  127. entity.Update();
  128. }
  129. conSuccess("登出");
  130. }
  131. public void wx_loginout_xy()
  132. {
  133. int uid = getDecodeInt("uid");
  134. if (uid == 0)
  135. {
  136. //conError("找不到会员");
  137. conSuccess("登出");
  138. return;
  139. }
  140. SUser entity = SUser.Get(uid);
  141. entity.openid = "";
  142. entity.Update();
  143. conSuccess("登出");
  144. }
  145. static object loginObj = new object();
  146. public void wx_minilogin()
  147. {
  148. if (UrlPostParmsCheck("openid,data,iv,skey"))
  149. {
  150. string data = GetPostString("data");
  151. string iv = GetPostString("iv");
  152. string openid = GetPostString("openid");
  153. string skey = GetPostString("skey");
  154. WechatUserInfo info = Decrypt(data, iv, skey);
  155. string inviteId = GetPostString("inviteId");
  156. int vuid = 0;
  157. if (inviteId.Length > 0)
  158. {
  159. inviteId = inviteId.Replace("$", "=");
  160. vuid = Convert.ToInt32(SecurityHelper.DecodingBase64(inviteId));
  161. }
  162. //unionid,headimgurl,sex,nick
  163. string nick = info.nickName;
  164. int sex = (info.gender == "男" ? 2 : 1);
  165. string headimgurl = info.avatarUrl;
  166. string unionid = info.unionId;
  167. string studentno = GetPostString("studentno");
  168. string uname =GetPostString("uname");
  169. string mobile = GetPostString("mobile");
  170. //XLog.SaveLog(0, openid + "," + nick + "," + sex + "," + province + "," + city + "," + country + "," + headimgurl + "," + unionid);
  171. SUser entity = null;
  172. lock (loginObj)
  173. {
  174. //entity = SUser.GetByWeixinMini(uname, studentno);
  175. //entity = SUser.GetByWeixinMiniOpenId(unionid, openid);
  176. if (entity != null)
  177. {
  178. if (entity.miniopenid != "" && entity.miniopenid != openid)//不是当前的openid
  179. {
  180. conError("该账号己在另一个微信上绑定,请先注销解绑才能使用!");
  181. return;
  182. }
  183. entity.miniopenid = openid;
  184. if (entity.Mobile == "") entity.Mobile = mobile;
  185. entity.LastTime = DateTime.Now;
  186. if (entity.inviteId == 0 && vuid > 0 && vuid != entity.ID)
  187. {
  188. entity.inviteId = vuid;
  189. }
  190. if (entity.UserName == "") entity.UserName = nick;
  191. entity.Update();
  192. }
  193. else
  194. {
  195. if (uname == "")
  196. {
  197. conError("姓名不允许为空");
  198. return;
  199. }
  200. if (studentno == "")
  201. {
  202. conError("证号不允许为空!");
  203. return;
  204. }
  205. if (studentno != "830820" && SUser.Exists("StudentNo=?", studentno))
  206. {
  207. conError("该学生证或工号对应的姓名不符合!");
  208. return;
  209. }
  210. //if (mobile != "")
  211. //{
  212. // if (SUser.Exists("Mobile=?", mobile))
  213. // {
  214. // conError("手机号码己存在!");
  215. // return;
  216. // }
  217. //}
  218. entity = new SUser();
  219. if (studentno != "830820")
  220. {
  221. DataView dv = new DataView(WebCache.LyxyUserTable);
  222. dv.RowFilter = "username='" + uname + "' and UserNo='" + studentno + "'";
  223. if (dv.Count < 1)
  224. {
  225. conError("该学生证或工号对应的姓名不符合,或找不到相关记录!");
  226. return;
  227. }
  228. DataRowView drv = dv[0];
  229. if (drv["unit"].ToString() != "")
  230. {
  231. entity.Faculties = drv["unit"].ToString();
  232. entity.UserType = 1;
  233. }
  234. else
  235. {
  236. entity.Faculties = drv["Faculties"].ToString();
  237. entity.ClassName = drv["ClassName"].ToString();
  238. entity.Major = drv["Major"].ToString();
  239. entity.UserType = 0;
  240. }
  241. entity.Sex = (drv["sex"].ToString() == "女" ? 2 : 1);
  242. }
  243. else
  244. {
  245. entity.UserType = 5;
  246. entity.Faculties = "火蚁官网";
  247. entity.Sex = sex;
  248. }
  249. entity.StudentNo = studentno;
  250. entity.UserName = nick;
  251. entity.NickName = nick;
  252. entity.RealName = uname;
  253. entity.unionid = unionid;
  254. //entity.openid = openid;
  255. entity.RegisterTime = DateTime.Now;
  256. entity.miniopenid = openid;
  257. entity.CreateAndFlush();
  258. if (entity.inviteId == 0 && vuid > 0 && entity.ID != vuid) entity.inviteId = vuid;
  259. entity.UserPic = entity.ID + ".jpg";
  260. entity.Update();
  261. if (headimgurl != null)
  262. {
  263. Thread oThread = new Thread(delegate ()
  264. {
  265. HttpHelper http = new HttpHelper();
  266. HttpItem item = new HttpItem()
  267. {
  268. KeepAlive = true,
  269. Accept = "image/webp,image/*,*/*;q=0.8",
  270. URL = headimgurl,
  271. ResultType = ResultType.Byte
  272. };
  273. HttpResult hResult = http.GetHtml(item);
  274. using (MemoryStream ms = new MemoryStream(hResult.ResultByte))
  275. {
  276. Bitmap bm = new Bitmap(ms);
  277. bm.Save(webConfig.userPicPath + "\\b\\" + entity.ID + ".jpg", ImageFormat.Jpeg);
  278. using (System.Drawing.Image imgThumb = System.Drawing.Image.FromStream(ms))
  279. {
  280. ImageMaker.ToThumbnailImages(imgThumb, webConfig.userPicPath + "\\" + entity.ID + ".jpg", 100, "", 9, 3);
  281. //result = ImageMaker.ToThumbnailImages(imgThumb, saveFile, 600, "", 9, 3);
  282. }
  283. //bm.Save(webConfig.userPicPath + "\\" + entity.ID + ".jpg", ImageFormat.Jpeg);
  284. }
  285. });
  286. oThread.Start();
  287. }
  288. }
  289. }
  290. StringBuilder userStr = new StringBuilder();
  291. userStr.Append("{");
  292. userStr.AppendFormat("\"uid\":\"{0}\"", SecurityHelper.EncodingBase64(entity.ID.ToString()));
  293. //userStr.AppendFormat(",\"gzh_openid\":\"{0}\"", entity.openid);
  294. userStr.AppendFormat(",\"userpic\":\"{0}\"", entity.UserPic);
  295. userStr.AppendFormat(",\"isremind\":\"{0}\"", entity.isremind);
  296. userStr.AppendFormat(",\"mobile\":\"{0}\"", entity.Mobile);
  297. userStr.AppendFormat(",\"username\":\"{0}\"",SecurityHelper.DecodingBase64(entity.UserName));
  298. userStr.AppendFormat(",\"point\":\"{0}\"", entity.UserMoney);
  299. userStr.AppendFormat(",\"sex\":\"{0}\"", entity.Sex);
  300. userStr.AppendFormat(",\"major\":\"{0}\"", entity.Major);
  301. userStr.AppendFormat(",\"qq\":\"{0}\"", entity.QQ);
  302. userStr.AppendFormat(",\"ptags\":\"{0}\"", entity.ptTags);
  303. userStr.AppendFormat(",\"stags\":\"{0}\"", entity.soTags);
  304. userStr.AppendFormat(",\"utype\":\"{0}\"", entity.UserType);
  305. userStr.AppendFormat(",\"studentno\":\"{0}\"", entity.StudentNo);
  306. userStr.AppendFormat(",\"realname\":\"{0}\"", entity.RealName);
  307. userStr.AppendFormat(",\"addressid\":\"{0}\"", entity.addressId);
  308. userStr.Append("}");
  309. conSuccess("登录成功", userStr.ToString());
  310. return;
  311. }
  312. conError("错误的参数");
  313. }
  314. public void get_msgremind()
  315. {
  316. int uid = getDecodeInt("uid");
  317. if (uid == 0)
  318. {
  319. conError("找不到会员");
  320. return;
  321. }
  322. SUser entity = SUser.Get(uid);
  323. if (entity != null)
  324. {
  325. StringBuilder userStr = new StringBuilder();
  326. userStr.Append("{");
  327. userStr.AppendFormat("\"isremind\":\"{0}\"", entity.isremind);
  328. userStr.AppendFormat(",\"gzh_openid\":\"{0}\"", entity.openid);
  329. userStr.Append("}");
  330. conSuccess("suc", userStr.ToString());
  331. return;
  332. }
  333. conError("找不到会员");
  334. }
  335. private int getUserType(string v)
  336. {
  337. switch (v)
  338. {
  339. case "老师": return 1;
  340. case "官方": return 5;
  341. default: return 0;
  342. }
  343. }
  344. public void wx_miniserv()
  345. {
  346. if (UrlPostParmsCheck("code"))
  347. {
  348. string code = GetPostString("code");
  349. //向微信服务端 使用登录凭证 code 获取 session_key 和 openid
  350. string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + mini_Appid + "&secret=" + mini_Secret + "&js_code=" + code + "&grant_type=" + grant_type;
  351. string type = "utf-8";
  352. string json = GetUrltoHtml(url, type);//获取微信服务器返回字符串
  353. JObject jo = (JObject)JsonConvert.DeserializeObject(json);
  354. //微信服务器验证成功
  355. try
  356. {
  357. string openid = jo["openid"].ToString();
  358. string session_key = jo["session_key"].ToString();
  359. SUser entity = SUser.GetByWeixinMiniOpenId(openid);
  360. StringBuilder userStr = new StringBuilder();
  361. userStr.Append("{");
  362. userStr.AppendFormat("\"openid\":\"{0}\"", openid);
  363. userStr.AppendFormat(",\"session_key\":\"{0}\"", session_key);
  364. if (entity != null)
  365. {
  366. entity.LastTime = DateTime.Now;
  367. entity.Update();
  368. userStr.AppendFormat(",\"islogin\":\"1\"");
  369. //userStr.AppendFormat(",\"isremind\":\"{0}\"", entity.isremind);
  370. //userStr.AppendFormat(",\"gzh_openid\":\"{0}\"", entity.openid);
  371. userStr.AppendFormat(",\"isfreeze\":\"{0}\"", entity.IsFreeze ? 1 : 0);
  372. userStr.AppendFormat(",\"uid\":\"{0}\"", SecurityHelper.EncodingBase64(entity.ID.ToString()));
  373. userStr.AppendFormat(",\"userpic\":\"{0}\"", entity.UserPic);
  374. userStr.AppendFormat(",\"mobile\":\"{0}\"", entity.Mobile);
  375. userStr.AppendFormat(",\"username\":\"{0}\"", entity.UserName);
  376. userStr.AppendFormat(",\"point\":\"{0}\"", entity.UserMoney);
  377. userStr.AppendFormat(",\"sex\":\"{0}\"", entity.Sex);
  378. userStr.AppendFormat(",\"major\":\"{0}\"", entity.Major);
  379. userStr.AppendFormat(",\"qq\":\"{0}\"", entity.QQ);
  380. userStr.AppendFormat(",\"ptags\":\"{0}\"", entity.ptTags);
  381. userStr.AppendFormat(",\"stags\":\"{0}\"", entity.soTags);
  382. userStr.AppendFormat(",\"utype\":\"{0}\"", entity.UserType);
  383. userStr.AppendFormat(",\"studentno\":\"{0}\"", entity.StudentNo);
  384. userStr.AppendFormat(",\"realname\":\"{0}\"", entity.RealName);
  385. userStr.AppendFormat(",\"addressid\":\"{0}\"", entity.addressId);
  386. userStr.Append("}");
  387. conSuccess("登录成功", userStr.ToString());
  388. }
  389. else
  390. {
  391. userStr.AppendFormat(",\"islogin\":\"0\"");
  392. userStr.Append("}");
  393. conSuccess("新用户", userStr.ToString());
  394. }
  395. //conSuccess(openid + "|" + session_key);
  396. }
  397. catch (Exception)
  398. {
  399. //微信服务器验证失败
  400. string msg = jo["errcode"].ToString() + "," + jo["errmsg"].ToString();
  401. conError(msg);
  402. }
  403. return;
  404. }
  405. conError("错误的参数");
  406. }
  407. public void wx_miniserv_xy()
  408. {
  409. if (UrlPostParmsCheck("code"))
  410. {
  411. string code = GetPostString("code");
  412. //向微信服务端 使用登录凭证 code 获取 session_key 和 openid
  413. string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + mini_Appid_xy + "&secret=" + mini_Secret_xy + "&js_code=" + code + "&grant_type=" + grant_type;
  414. string type = "utf-8";
  415. string json = GetUrltoHtml(url, type);//获取微信服务器返回字符串
  416. JObject jo = (JObject)JsonConvert.DeserializeObject(json);
  417. //微信服务器验证成功
  418. try
  419. {
  420. string openid = jo["openid"].ToString();
  421. string session_key = jo["session_key"].ToString();
  422. SUser entity = SUser.GetByWeixinMiniOpenId(openid);
  423. StringBuilder userStr = new StringBuilder();
  424. userStr.Append("{");
  425. userStr.AppendFormat("\"openid\":\"{0}\"", openid);
  426. userStr.AppendFormat(",\"session_key\":\"{0}\"", session_key);
  427. if (entity != null)
  428. {
  429. entity.LastTime = DateTime.Now;
  430. entity.Update();
  431. userStr.AppendFormat(",\"islogin\":\"1\"");
  432. //userStr.AppendFormat(",\"isremind\":\"{0}\"",entity.isremind);
  433. //userStr.AppendFormat(",\"gzh_openid\":\"{0}\"", entity.openid);
  434. userStr.AppendFormat(",\"isfreeze\":\"{0}\"", entity.IsFreeze ? 1 : 0);
  435. userStr.AppendFormat(",\"uid\":\"{0}\"", SecurityHelper.EncodingBase64(entity.ID.ToString()));
  436. userStr.AppendFormat(",\"userpic\":\"{0}\"", entity.UserPic);
  437. userStr.AppendFormat(",\"mobile\":\"{0}\"", entity.Mobile);
  438. userStr.AppendFormat(",\"username\":\"{0}\"", entity.UserName);
  439. userStr.AppendFormat(",\"point\":\"{0}\"", entity.UserMoney);
  440. userStr.AppendFormat(",\"sex\":\"{0}\"", entity.Sex);
  441. userStr.AppendFormat(",\"major\":\"{0}\"", entity.Major);
  442. userStr.AppendFormat(",\"qq\":\"{0}\"", entity.QQ);
  443. userStr.AppendFormat(",\"ptags\":\"{0}\"", entity.ptTags);
  444. userStr.AppendFormat(",\"stags\":\"{0}\"", entity.soTags);
  445. userStr.AppendFormat(",\"utype\":\"{0}\"", entity.UserType);
  446. userStr.AppendFormat(",\"studentno\":\"{0}\"", entity.StudentNo);
  447. userStr.AppendFormat(",\"realname\":\"{0}\"", entity.RealName);
  448. userStr.Append("}");
  449. conSuccess("登录成功", userStr.ToString());
  450. }
  451. else
  452. {
  453. userStr.AppendFormat(",\"islogin\":\"0\"");
  454. userStr.Append("}");
  455. conSuccess("新用户", userStr.ToString());
  456. }
  457. //conSuccess(openid + "|" + session_key);
  458. }
  459. catch (Exception)
  460. {
  461. //微信服务器验证失败
  462. string msg = jo["errcode"].ToString() + "," + jo["errmsg"].ToString();
  463. conError(msg);
  464. }
  465. return;
  466. }
  467. conError("错误的参数");
  468. }
  469. public void get_upot()
  470. {
  471. int uid = getDecodeInt("uid");
  472. if (uid == 0)
  473. {
  474. conError("找不到会员");
  475. return;
  476. }
  477. string sql = "select usermoney from s_user where id=" + uid;
  478. object result = DbHelper.DbConn.ExecuteScalar(sql);
  479. if (result != null) conSuccess(GetDoubleString(result));
  480. else conSuccess("0.0");
  481. }
  482. public void upd_user()
  483. {
  484. int uid = getDecodeInt("uid");
  485. if (uid == 0)
  486. {
  487. conError("找不到会员");
  488. return;
  489. }
  490. string nickname = GetPostString("username");
  491. string major = GetPostString("major");
  492. string isremind = GetPostString("isremind");
  493. string sex = GetPostString("sex");
  494. string mobile = GetPostString("mobile");
  495. if (nickname == "" && sex=="" && mobile=="" && major == "" && isremind=="" && con.Request.Files.Count < 1)
  496. {
  497. conError("没有需要修改的数据");
  498. return;
  499. }
  500. SUser entity = SUser.Get(uid);
  501. bool upPic = false;
  502. if (con.Request.Files.Count > 0)
  503. {
  504. HttpPostedFile postFile = con.Request.Files[0];
  505. string errMsg = "";
  506. if (!ImageHandler.CheckImage(postFile, out errMsg))
  507. {
  508. conError(errMsg);
  509. return;
  510. }
  511. string fileName = uid + ".jpg";
  512. string saveFile = Path.Combine(webConfig.userPicPath, fileName);
  513. string result = "";
  514. using (System.Drawing.Image imgThumb = System.Drawing.Image.FromStream(postFile.InputStream))
  515. {
  516. result = ImageMaker.ToThumbnailImages(imgThumb, saveFile, 160, "", 9, 3);
  517. }
  518. upPic = true;
  519. entity.UserPic = fileName;
  520. }
  521. if (nickname.Length > 0)
  522. {
  523. entity.NickName = nickname;
  524. entity.UserName = nickname;
  525. }
  526. if (sex.Length>0) entity.Sex = Convert.ToInt32(sex);
  527. if (mobile.Length > 0) entity.Mobile =mobile;
  528. if (isremind.Length > 0) entity.isremind = Convert.ToInt32(isremind);
  529. if (major.Length > 0) entity.Major = major;
  530. entity.Update();
  531. if (upPic) conSuccess("修改成功!", "{\"pic\":\"" + entity.UserPic + "\"}");
  532. else conSuccess("修改成功!");
  533. }
  534. #region 验证码相关
  535. public static Dictionary<string, int> MobileCache = new Dictionary<string, int>();
  536. private static readonly List<string> mobileKeyList = new List<string>();
  537. private static readonly object usercache_Flag = 1;
  538. public static void AddMobileCache(string key, int value)
  539. {
  540. lock (usercache_Flag)
  541. {
  542. if (MobileCache.Count > 300)
  543. {
  544. MobileCache.Remove(mobileKeyList[mobileKeyList.Count - 1]);
  545. mobileKeyList.RemoveAt(mobileKeyList.Count - 1);
  546. }
  547. if (!mobileKeyList.Contains(key) && !MobileCache.ContainsKey(key))
  548. {
  549. mobileKeyList.Add(key);
  550. MobileCache.Add(key, value);
  551. }
  552. else
  553. {
  554. MobileCache[key] += value;
  555. }
  556. }
  557. }
  558. public static void RemoveMobileCache(string key)
  559. {
  560. if (mobileKeyList.Contains(key) && MobileCache.ContainsKey(key))
  561. {
  562. MobileCache.Remove(key);
  563. mobileKeyList.Remove(key);
  564. }
  565. }
  566. private bool checkFirCode(string mobile)
  567. {
  568. if (!checkMobile(mobile))
  569. {
  570. conError("手机号码不正确!");
  571. return false;
  572. }
  573. if (WebCache.GetCache("interval_" + mobile) != null)
  574. {
  575. conError("验证码请求过于频繁,请稍后再试!");
  576. return false;
  577. }
  578. string mkey = "mobile_" + DateTime.Now.ToString("Md");
  579. if (MobileCache.ContainsKey(mkey) && MobileCache[mkey] >= 3)
  580. {
  581. conError("超出验证码获取次数!");
  582. return false;
  583. }
  584. return true;
  585. }
  586. private bool checkSecCode(string mobile,string mc)
  587. {
  588. if (mc == "")
  589. {
  590. conError("请求过期,请重试!");
  591. return false;
  592. }
  593. if (!checkMobile(mobile))
  594. {
  595. conError("手机号码不正确!");
  596. return false;
  597. }
  598. if (WebCache.GetCache("code_" + mobile) == null)
  599. {
  600. conError("请求过期,请重试!");
  601. return false;
  602. }
  603. else
  604. {
  605. string con = WebCache.GetCache("code_" + mobile).ToString();
  606. string rc = SecurityHelper.EncryptMD5(con.Substring(3, 4) + con.Substring(9, 3));
  607. if (mc != rc.ToLower())
  608. {
  609. conError("参数不正确!");
  610. return false;
  611. }
  612. }
  613. return true;
  614. }
  615. Regex mReg = new Regex("^1[0-9]{10}$");
  616. private bool checkMobile(string mobile)
  617. {
  618. if (!mReg.IsMatch(mobile)) return false;
  619. return true;
  620. }
  621. private bool checkSmsCode(string mobile,string mcode)
  622. {
  623. if (!checkMobile(mobile))
  624. {
  625. conError("手机号码不正确!");
  626. return false;
  627. }
  628. return true;
  629. if (WebCache.GetCache("sms_" + mobile) != null)
  630. {
  631. string _mcode = WebCache.GetCache("sms_" + mobile).ToString();
  632. if (mcode != _mcode)
  633. {
  634. conError("短信验证码不正确!");
  635. return false;
  636. }
  637. }
  638. else
  639. {
  640. conError("短信验证码己过期,请重新获取!");
  641. return false;
  642. }
  643. return true;
  644. }
  645. public void get_mobilecode()
  646. {
  647. }
  648. #endregion
  649. public void user_login()
  650. {
  651. if (UrlPostParmsCheck("mobile,pwd"))
  652. {
  653. string mobile = GetPostString("mobile");
  654. string pwd = GetPostString("pwd");
  655. //string mobile = "13635283686";
  656. //string pwd = "yjsogdsk0820";
  657. SUser entity = SUser.GetUserByPassWord(mobile, SecurityHelper.EncryptSymmetric(pwd));
  658. if (entity == null)
  659. {
  660. conError("用户名或密码错误");
  661. return;
  662. }
  663. //entity.LastTime = DateTime.Now;
  664. //entity.Update();
  665. StringBuilder userStr = new StringBuilder();
  666. userStr.Append("{");
  667. userStr.AppendFormat("\"uid\":\"{0}\"", SecurityHelper.EncodingBase64(entity.ID.ToString()));
  668. userStr.AppendFormat(",\"userpic\":\"{0}\"", entity.UserPic);
  669. userStr.AppendFormat(",\"mobile\":\"{0}\"", entity.Mobile);
  670. userStr.AppendFormat(",\"username\":\"{0}\"", entity.UserName);
  671. userStr.AppendFormat(",\"point\":\"{0}\"", entity.UserMoney);
  672. userStr.AppendFormat(",\"sex\":\"{0}\"", entity.Sex);
  673. userStr.AppendFormat(",\"major\":\"{0}\"", entity.Major);
  674. userStr.AppendFormat(",\"qq\":\"{0}\"", entity.QQ);
  675. userStr.Append("}");
  676. conSuccess("登录成功", userStr.ToString());
  677. return;
  678. }
  679. conError("错误的参数");
  680. }
  681. public void get_regmc()
  682. {
  683. if (UrlPostParmsCheck("mobile"))
  684. {
  685. string mobile = GetPostString("mobile");
  686. if (!checkFirCode(mobile)) return;
  687. if (SUser.CheckExits("Mobile", mobile))
  688. {
  689. conError("该手机号码己存在!");
  690. return;
  691. }
  692. string con = CommonHelper.GetRnd(20, true, true, true, false, "");
  693. //string con = "gxSHXL4NDa12wPn7UmNx";
  694. WebCache.RemoveCache("code_" + mobile);
  695. WebCache.AddCacheTime("code_" + mobile, con, 2);
  696. conSuccess(con);
  697. return;
  698. }
  699. conError("错误的参数");
  700. }
  701. public void ins_register()
  702. {
  703. if(UrlPostParmsCheck("mobile,pwd,nick,major"))
  704. {
  705. string mobile = GetPostString("mobile");
  706. string email = GetPostString("email");
  707. string mcode = GetPostString("mcode");
  708. string pwd = GetPostString("pwd");
  709. string nick = GetPostString("nick");
  710. string major = GetPostString("major");
  711. if (!checkSmsCode(mobile, mcode)) return;
  712. if(SUser.CheckExits("Mobile",mobile))
  713. {
  714. conError("该手机号码己存在!");
  715. return;
  716. }
  717. if(email!="" && SUser.CheckExits("Email", email))
  718. {
  719. conError("该邮箱己存在!");
  720. return;
  721. }
  722. SUser entity = new SUser();
  723. entity.PassWord = SecurityHelper.EncryptSymmetric(pwd);
  724. entity.RegisterTime = DateTime.Now;
  725. entity.Mobile = mobile;
  726. entity.Email = email;
  727. entity.NickName = nick;
  728. entity.UserName = nick;
  729. entity.Major = major;
  730. entity.Create();
  731. StringBuilder userStr = new StringBuilder();
  732. userStr.Append("{");
  733. userStr.AppendFormat("\"uid\":\"{0}\"",SecurityHelper.EncodingBase64(entity.ID.ToString()));
  734. userStr.AppendFormat(",\"userpic\":\"{0}\"", entity.UserPic);
  735. userStr.AppendFormat(",\"mobile\":\"{0}\"", entity.Mobile);
  736. userStr.AppendFormat(",\"username\":\"{0}\"", entity.UserName);
  737. userStr.AppendFormat(",\"point\":\"{0}\"", entity.UserMoney);
  738. userStr.AppendFormat(",\"sex\":\"{0}\"", entity.Sex);
  739. userStr.AppendFormat(",\"major\":\"{0}\"", entity.Major);
  740. userStr.AppendFormat(",\"qq\":\"{0}\"", entity.QQ);
  741. userStr.Append("}");
  742. conSuccess("注册成功",userStr.ToString());
  743. return;
  744. }
  745. conError("错误的参数");
  746. }
  747. public void upd_userpwd()
  748. {
  749. int uid = getDecodeInt("uid");
  750. if (uid == 0)
  751. {
  752. conError("找不到会员");
  753. return;
  754. }
  755. if (UrlPostParmsCheck("oldpwd,newpwd"))
  756. {
  757. string oldpwd = GetPostString("oldpwd");
  758. string newpwd = GetPostString("newpwd");
  759. if (newpwd == "" || !pwdReg.IsMatch(newpwd))
  760. {
  761. conError("输入的新密码不符合要求,最少6位字母数字!");
  762. return;
  763. }
  764. SUser entity = SUser.GetUserByUserId(uid.ToString(),SecurityHelper.EncryptSymmetric(oldpwd));
  765. if (entity != null)
  766. {
  767. entity.PassWord = SecurityHelper.EncryptSymmetric(newpwd);
  768. entity.RKey = "";
  769. entity.Update();
  770. conSuccess("密码修改成功");
  771. }
  772. else
  773. {
  774. conError("无法修改密码!");
  775. }
  776. return;
  777. }
  778. conError("错误的参数");
  779. }
  780. public void get_forgotmc()
  781. {
  782. if (UrlPostParmsCheck("mobile"))
  783. {
  784. string mobile = GetPostString("mobile");
  785. if (!checkFirCode(mobile)) return;
  786. if (!SUser.CheckExits("Mobile", mobile))
  787. {
  788. conError("手机号码不存在!");
  789. return;
  790. }
  791. string con = CommonHelper.GetRnd(20, true, true, true, true, "");
  792. WebCache.RemoveCache("code_" + mobile);
  793. WebCache.AddCacheTime("code_" + mobile, con, 2);
  794. conSuccess(con);
  795. return;
  796. }
  797. conError("错误的参数");
  798. }
  799. public void upd_forgotpwd()
  800. {
  801. if (UrlPostParmsCheck("mobile,mcode,newpwd,newpwd2"))
  802. {
  803. string mobile = GetPostString("mobile");
  804. string mcode = GetPostString("mcode");
  805. string newpwd = GetPostString("newpwd");
  806. string newpwd2 = GetPostString("newpwd2");
  807. if (newpwd == "" || !pwdReg.IsMatch(newpwd))
  808. {
  809. conError("输入的新密码不符合要求!");
  810. return;
  811. }
  812. if(newpwd!=newpwd2)
  813. {
  814. conError("两次输入的密码不一致!");
  815. return;
  816. }
  817. if (!checkSmsCode(mobile, mcode)) return;
  818. SUser entity = SUser.GetUserByMobile(mobile);
  819. if (entity != null)
  820. {
  821. entity.PassWord = SecurityHelper.EncryptSymmetric(newpwd);
  822. entity.RKey = "";
  823. entity.Update();
  824. conSuccess("密码修改成功");
  825. }
  826. else
  827. {
  828. conError("找不到该手机号!");
  829. }
  830. return;
  831. }
  832. conError("错误的参数");
  833. }
  834. public void ins_userallege()
  835. {
  836. if (UrlPostParmsCheck("name,code,idnumber,phone,summary,openid,formid"))
  837. {
  838. string name = GetPostString("name");
  839. string code = GetPostString("code");
  840. string idnumber = GetPostString("idnumber");
  841. string phone = GetPostString("phone");
  842. string summary = GetPostString("summary");
  843. string formid = GetPostString("formid");
  844. string openid = GetPostString("openid");
  845. StringBuilder sql = new StringBuilder();
  846. sql.AppendFormat("insert into s_userallege(name,usercode,phone,summary,addtime,openid,formid,idnumber) values('{0}','{1}','{2}','{3}',getdate(),'{4}','{5}','{6}') ;",
  847. name, code, phone, summary, openid,formid, idnumber);
  848. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  849. conSuccess("提交完成,平台处理后,将发送微信服务消息通知予您!");
  850. return;
  851. }
  852. conError("错误的参数");
  853. }
  854. public void get_userinfo()
  855. {
  856. int uid = getDecodeInt("uid");
  857. if (uid == 0)
  858. {
  859. conError("找不到会员");
  860. return;
  861. }
  862. if (UrlPostParmsCheck("tid"))
  863. {
  864. int tid = GetPostInt("tid") - 98;
  865. string sql = "select top 1 username,userpic,'' as realname,sex,'' as Mobile,Major,Faculties,left(studentno,4) as grade from s_user where id=" + tid;
  866. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  867. conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  868. return;
  869. }
  870. conError("错误的参数");
  871. }
  872. public void get_myamount()
  873. {
  874. int uid = getDecodeInt("uid");
  875. if (uid == 0)
  876. {
  877. conError("找不到会员");
  878. return;
  879. }
  880. string sql = "select usermoney from s_user where id=" + uid;
  881. object result = DbHelper.DbConn.ExecuteScalar(sql);
  882. if (result != null)
  883. {
  884. conSuccess(result.ToString());
  885. return;
  886. }
  887. conError("错误的参数");
  888. }
  889. public void get_useramount()
  890. {
  891. int uid = getDecodeInt("uid");
  892. if (uid == 0)
  893. {
  894. conError("找不到会员");
  895. return;
  896. }
  897. if(UrlPostParmsCheck("st,et"))
  898. {
  899. DataStruct dStruct = GetPostStruct();
  900. List<string> lw = new List<string>();
  901. lw.Add("userid=" + uid);
  902. dStruct.Order = "addtime desc";
  903. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  904. dStruct.Fileds = "amount,summary,addtime";
  905. DataTable dt = WebCache.GetData("S_UserAmount", dStruct);
  906. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  907. return;
  908. }
  909. conError("错误的参数");
  910. }
  911. public void ckug()
  912. {
  913. int uid = getDecodeInt("uid");
  914. if (uid == 0)
  915. {
  916. conError("错误的参数");
  917. return;
  918. }
  919. if (UrlPostParmsCheck("u"))
  920. {
  921. string u = GetPostString("u");
  922. string[] uArr = u.Split('|');
  923. string sql = string.Format("insert into s_usergps(userid,lng,lat,gtime) values({0},'{1}','{2}',getdate()) ;",uid,uArr[0],uArr[1]);
  924. DbHelper.DbConn.ExecuteNonQuery(sql);
  925. conSuccess("60");
  926. return;
  927. }
  928. conError("错误的参数");
  929. }
  930. }
  931. }