| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- using BizCom;
- using SiteCore.Msn;
- using SiteCore.Redis;
- using SQLData;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web;
- using Utils;
- namespace SiteCore.Handler
- {
- public partial class app
- {
- public static FrequencyControler DuFrequency = new FrequencyControler("duba", 10, 3);
- public static FrequencyControler DoorFrequency = new FrequencyControler("door",6, 3);
- public static FrequencyControler TmpDoorFrequency = new FrequencyControler("door", 6, 3);
- public static readonly Object lockMsn = new object();
- public void quduba_sendms()
- {
- if (UrlPostParmsCheck("tmp,mobile"))
- {
- //string tmp = GetPostString("tmp");
- //int qid = WebHelper.getDecodeUid(tmp);
- //if (qid == 0)
- //{
- // con.Response.Write("{\"s\":0,\"msg\":\"无法访问,请稍候再试\"}");
- // return;
- //}
- if (con.Session["uid"] == null || con.Session["uid"].ToString()=="")
- {
- con.Response.Write("{\"s\":0,\"msg\":\"已过期,无法发送验证码\"}");
- return;
- }
- string mobile = GetPostString("mobile");
- lock (lockMsn)
- {
- MsnObj mo = redis.RedisHelper.StringGet<MsnObj>(mobile);
- if (mo == null)
- {
- if(SDuUser.Exists("Mobile=?",mobile))
- {
- con.Response.Write("{\"s\":0,\"msg\":\"该手机号已验证过!\"}");
- return;
- }
- }
- else if (mo.isFinish)
- {
- con.Response.Write("{\"s\":0,\"msg\":\"该手机号已验证过!\"}");
- return;
- }
- Random random = new Random();
- string smsCode = random.Next(1000, 9999).ToString();
- string msg = "";
- bool isSend = MnsHelper.SendBindSms(mobile, smsCode, out msg);
- if (isSend) con.Response.Write("{\"s\":1,\"msg\":\"验证码已发送\"}");
- else con.Response.Write("{\"s\":0,\"msg\":\"" + msg + "\"}");
- }
- }
- else
- {
- con.Response.Write("{\"s\":0,\"msg\":\"错误的参数,无法发送验证码\"}");
- }
- }
- public void quduba_sign()
- {
- if (DuFrequency.IsTooFrequently(true))
- {
- con.Response.Write("{\"s\":0,\"msg\":\"访问太频繁\"}");
- return;
- }
- //name,idcard,
- if (UrlPostParmsCheck("mobile,code,tmp"))
- {
- string mobile = GetPostString("mobile");
- MsnObj mo = redis.RedisHelper.StringGet<MsnObj>(mobile);
- if (mo == null)
- {
- con.Response.Write("{\"s\":0,\"msg\":\"验证码不正确\"}");
- return;
- }
- string code = GetPostString("code");
- if (code != mo.code)
- {
- con.Response.Write("{\"s\":0,\"msg\":\"验证码不正确\"}");
- return;
- }
- //string tmp= GetPostString("tmp");
- //int qid = WebHelper.getDecodeUid(tmp);
- //if (qid == 0)
- //{
- // con.Response.Write("{\"s\":0,\"msg\":\"无法访问,请稍候再试\"}");
- // return;
- //}
- if (con.Session["uid"] == null || con.Session["uid"].ToString() == "")
- {
- con.Response.Write("{\"s\":0,\"msg\":\"注册已过期,请重试\"}");
- }
- try
- {
- int uid = Convert.ToInt32(con.Session["uid"]);
- SDuUser entity = SDuUser.Get(uid);
- if (entity != null)
- {
- entity.Mobile = mobile;
- entity.Update();
- redis.RedisHelper.StringSet(entity.openid, entity.ID + "|" + entity.State);
- //RedisHelper.StringSet(entity.openid, entity.ID+"|"+entity.State);
- con.Session["openid"] = entity.openid;
- mo.isFinish = true;
- redis.RedisHelper.StringSet(mobile, mo, TimeSpan.FromDays(2));
- con.Response.Write("{\"s\":1,\"code\":\"" + DecryptHelper.Encrypt(WebHelper.ConvertDateTimeToInt(DateTime.Now).ToString()) + "\"}");
- }
- else
- {
- con.Response.Write("{\"s\":0,\"msg\":\"页面己过期,请重新进入\"}");
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, ex.Message);
- }
- return;
- }
- con.Response.Write("{\"s\":0,\"msg\":\"无法访问,请稍候再试\"}");
- }
- public void quduba_sign2()
- {
- if (DuFrequency.IsTooFrequently(true))
- {
- con.Response.Write("{\"s\":0,\"msg\":\"访问太频繁\"}");
- return;
- }
- //name,idcard,
- if (UrlPostParmsCheck("mobile,code,uname,birth,sex,duty"))
- {
- string mobile = GetPostString("mobile");
- MsnObj mo = redis.RedisHelper.StringGet<MsnObj>(mobile);
- if (mo == null)
- {
- con.Response.Write("{\"s\":0,\"msg\":\"验证码不正确\"}");
- return;
- }
- string code = GetPostString("code");
- if (code != mo.code)
- {
- con.Response.Write("{\"s\":0,\"msg\":\"验证码不正确\"}");
- return;
- }
- string uname = GetPostString("uname");
- if (uname.Length < 2)
- {
- con.Response.Write("{\"s\":0,\"msg\":\"请输入您的姓名\"}");
- return;
- }
- int sex = GetPostInt("sex");
- if (sex <= 0 && sex > 2)
- {
- con.Response.Write("{\"s\":0,\"msg\":\"请选择您的性别\"}");
- return;
- }
-
- string duty = GetPostString("duty");
- if (duty.Length < 1)
- {
- con.Response.Write("{\"s\":0,\"msg\":\"请输入您的职业\"}");
- return;
- }
- string work = GetPostString("work");
- string birth = GetPostString("birth");
- if (birth.Length < 1)
- {
- con.Response.Write("{\"s\":0,\"msg\":\"请选择出生年月\"}");
- return;
- }
- //int age = GetPostInt("age");
- //if(age<=0 && age > 10)
- //{
- // con.Response.Write("{\"s\":0,\"msg\":\"请选择您的年龄段\"}");
- // return;
- //}
- //if (work.Length < 1)
- //{
- // con.Response.Write("{\"s\":0,\"msg\":\"请输入您的工作单位\"}");
- // return;
- //}
- //string tmp= GetPostString("tmp");
- //int qid = WebHelper.getDecodeUid(tmp);
- //if (qid == 0)
- //{
- // con.Response.Write("{\"s\":0,\"msg\":\"无法访问,请稍候再试\"}");
- // return;
- //}
- if (con.Session["uid"] == null || con.Session["uid"].ToString() == "")
- {
- con.Response.Write("{\"s\":0,\"msg\":\"注册已过期,请重试\"}");
- }
- try
- {
- int uid = Convert.ToInt32(con.Session["uid"]);
- SDuUser entity = SDuUser.Get(uid);
- if (entity != null)
- {
- entity.RealName = uname;
- entity.Sex = sex;
- //entity.Age = age;
- entity.Birthday = birth;
- entity.Duty = duty;
- entity.WorkUnit = work;
- entity.Mobile = mobile;
- entity.Update();
- redis.RedisHelper.StringSet(entity.openid, entity.ID + "|" + entity.State);
- con.Session["openid"] = entity.openid;
- mo.isFinish = true;
- redis.RedisHelper.StringSet(mobile, mo, TimeSpan.FromDays(2));
- con.Response.Write("{\"s\":1,\"code\":\"" + DecryptHelper.Encrypt(WebHelper.ConvertDateTimeToInt(DateTime.Now).ToString()) + "\"}");
- }
- else
- {
- con.Response.Write("{\"s\":0,\"msg\":\"页面己过期,请重新进入\"}");
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, ex.Message);
- }
- return;
- }
- con.Response.Write("{\"s\":0,\"msg\":\"填写的信息不完整或无法访问,请稍候再试\"}");
- }
- public void quduba_qcode()
- {
- //string userAgent = con.Request.UserAgent;
- //if (!WebHelper.isWeiXinAgent(userAgent))
- //{
- // con.Response.Write("0");
- // return;
- //}
- if (UrlPostParmsCheck("code"))
- {
- string code = GetPostString("code");
- if (!string.IsNullOrEmpty(code))
- {
- try
- {
- //if (con.Session["openid"] == null || con.Session["openid"].ToString() == "")
- //{
- // con.Response.Write("{\"msg\":\"二维码已过期\",\"ncode\":\"\"}");
- // return;
- //}
- //string openid = con.Session["openid"].ToString();
- string openid = WebHelper.getCookie("openid");
- if (con.Session["openid"] == null || con.Session["openid"].ToString() == "")
- {
- openid = WebHelper.getCookie("openid");
- if (openid == "")
- {
- con.Response.Write("{\"msg\":\"二维码已过期\",\"ncode\":\"\"}");
- return;
- }
- }
- else
- {
- openid = con.Session["openid"].ToString();
- }
- string re = redis.RedisHelper.StringGet(openid);
- if (!string.IsNullOrEmpty(re))
- {
- code = WebHelper.getEncodeCodeByNormal(re);
- con.Response.Write("{\"msg\":\"\",\"ncode\":\"" + code + "\"}");
- return;
- }
- }
- catch(Exception ex)
- {
- XLog.SaveLog(0, ex.Message);
- //Response.Clear();
- //con.Response.Write("0");
- //Response.End();
- }
- }
- }
- con.Response.Write("{\"msg\":\"无法生成二维码\",\"ncode\":\"\"}");
- }
- public void quduba_week()
- {
- if (UrlPostParmsCheck("sid,qt"))
- {
- string t = GetPostString("qt");
- //t = HttpUtility.UrlDecode(t);
- try
- {
- string[] vArr = t.Split('|');
- if (vArr.Length >= 7)
- {
- int siteid = GetPostInt("sid");
- string sql = string.Format("update S_DuSite set opentime='{0}' where id={1}", t, siteid);
- DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- con.Response.Write("yes");
- return;
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, ex.Message);
- }
- con.Response.Write("no");
- }
- }
- public void quduba_door()
- {
- if (DoorFrequency.IsTooFrequently(true))
- {
- con.Response.Write("访问太频繁!");
- return;
- }
- byte[] input = con.Request.BinaryRead(con.Request.TotalBytes);
- if (input.Length < 1)
- {
- con.Response.Write("no");
- return;
- }
- else
- {
- string s = Encoding.UTF8.GetString(input);
- try
- {
- string v = DecryptHelper.Decrypt(s);
- string[] vArr = v.Split('|');
- if (vArr.Length > 3)
- {
- //int uid = Convert.ToInt32(vArr[0]);
- int uid = Convert.ToInt32(SecurityHelper.DecryptSymmetric(vArr[0]));
- int siteid = Convert.ToInt32(vArr[1]);
- int inout = Convert.ToInt32(vArr[2]);
- DateTime dTime = Convert.ToDateTime(vArr[3]);
- string sTime = dTime.ToString("yyyy-MM-dd HH:mm");
- StringBuilder sql = new StringBuilder();
- 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);
- sql.AppendFormat("insert into s_duentryexit(userid,siteid,inout,addtime) values({0},{1},{2},'{3}')",uid,siteid,inout,sTime);
- sql.AppendFormat(" end ");
- DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- string key = "open_" + uid;
- duRedis.RedisHelper.StringSet(key, "1|开门成功", TimeSpan.FromSeconds(10));
- con.Response.Write("op");
- return;
- }
- }
- catch(Exception ex)
- {
- XLog.SaveLog(0,"开门访问,"+ s +","+ ex.Message);
- }
- con.Response.Write("no");
- }
- }
- public void quduba_tmpdoor()
- {
- byte[] input = con.Request.BinaryRead(con.Request.TotalBytes);
- if (input.Length < 1)
- {
- con.Response.Write("no");
- return;
- }
- else
- {
- string s = Encoding.Unicode.GetString(input);
- try
- {
- string v = DecryptHelper.Decrypt(s);
- string[] itArr = v.Split('§');
- string[] vArr;
- StringBuilder sql = new StringBuilder();
- for (int i = 0; i < itArr.Length; i++)
- {
- vArr = itArr[i].Split('|');
- int uid= Convert.ToInt32(SecurityHelper.DecryptSymmetric(vArr[0]));
- //int uid = Convert.ToInt32(vArr[0]);
- int siteid = Convert.ToInt32(vArr[1]);
- int inout = Convert.ToInt32(vArr[2]);
- DateTime dTime = Convert.ToDateTime(vArr[3]);
- string sTime = dTime.ToString("yyyy-MM-dd HH:mm");
- sql.AppendFormat("insert into s_duentryexit(userid,siteid,inout,addtime) values({0},{1},{2},'{3}') ;",
- uid, siteid, inout, sTime);
- }
- if (sql.Length > 0)
- {
- DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- con.Response.Write("suc");
- return;
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "tmpdoor_定时发送" + ex.Message);
- }
- }
- con.Response.Write("no");
- }
- public void get_qdbmsg()
- {
- if (UrlPostParmsCheck("tmp"))
- {
- int qid = GetPostInt("tmp");
- string key = "open_" + qid;
- try
- {
- object msg = duRedis.RedisHelper.StringGet(key);
- if (msg != null && msg.ToString() != "")
- {
- if (duRedis.RedisHelper.KeyExists(key)) duRedis.RedisHelper.KeyDelete(key);
- string[] mArr = msg.ToString().Split('|');
- if (mArr[0] == "0") conError(mArr[1]);
- else conSuccess(mArr[1]);
- return;
- //redis.RedisHelper.StringSet(mobile, mo, TimeSpan.FromDays(2));
- }
- }
- catch { }
- }
- conError("");
- }
- public void set_qdbmsg()
- {
- if (UrlPostParmsCheck("tmp,msg"))
- {
- //int uid = GetPostInt("uid");
- try
- {
- string tmp = GetPostString("tmp");
- tmp = HttpUtility.UrlDecode(tmp);
- string uid = SecurityHelper.DecryptSymmetric(tmp);
- string msg2 = GetPostString("msg");
- string key = "open_" + uid;
- duRedis.RedisHelper.StringSet(key, msg2, TimeSpan.FromSeconds(10));
- con.Response.Write("1");
- }
- catch
- {
- }
- }
- }
- }
- }
|