예제 #1
0
파일: TXSXAPI.cs 프로젝트: fl1029/QJCore
        /// <summary>
        /// 生日提醒
        /// </summary>
        public static void AUTOALERTSR()
        {
            try
            {
                List <JH_Auth_QY> QyModel = new JH_Auth_QYB().GetEntities(d => d.ComId != 0).ToList();
                WXHelp            wx      = new WXHelp(QyModel[0]);

                var qdata = new JH_Auth_UserB().GetEntities(d => d.Birthday != null);
                foreach (var item in qdata)
                {
                    if (item.Birthday.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
                    {
                        Article ar0 = new Article();
                        ar0.Title       = "生日提醒";
                        ar0.Description = "";
                        ar0.Url         = "http://www.baidu.com";
                        ar0.PicUrl      = "";
                        List <Article> al = new List <Article>();
                        al.Add(ar0);
                        wx.SendTPMSG("XXFB", al, item.UserName);
                    }
                }
            }
            catch (Exception)
            {
            }
        }
예제 #2
0
        public void CHECKREGISTERPHONE(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            var qy2 = new JH_Auth_QYB().GetEntities(p => p.Mobile == P1.Trim());

            if (qy2.Count() > 0)
            {
                msg.ErrorMsg = "此手机已注册企业,请更换手机号继续注册";
            }
        }
예제 #3
0
        public static string SendSMS(string telephone, string content, int ComId = 0)
        {
            string err = "";

            try
            {
                string  dxqz         = "企捷科技";
                decimal amcountmoney = 0;
                var     qy           = new JH_Auth_QYB().GetEntity(d => d.ComId == ComId);
                if (qy != null)
                {
                    dxqz         = qy.DXQZ;
                    amcountmoney = qy.AccountMoney.HasValue ? qy.AccountMoney.Value : 0;
                }

                string[] tels = telephone.Trim().Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace(',', ',').Split(',');

                //判断金额是否够
                decimal DXCost = decimal.Parse(CommonHelp.GetConfig("DXCost"));
                decimal amount = tels.Length * DXCost;
                if (ComId != 0 && amcountmoney < amount) //短信余额不足
                {
                    err = "短信余额不足";
                }
                else
                {
                    string re = "";
                    foreach (string tel in tels)
                    {
                        re = SendDX(tel, content + "【" + dxqz + "】", "");
                    }

                    err = "发送成功";

                    //扣款
                    if (ComId != 0 && qy != null)
                    {
                        qy.AccountMoney = qy.AccountMoney - amount;
                        new JH_Auth_QYB().Update(qy);

                        //记录明细
                        //SZHL_DDGL_ITEM im = new SZHL_DDGL_ITEM();
                        //im.ComId = qy.ComId;
                        //im.SerialID = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                        //im.Change = -amount;
                        //im.Balance = amcountmoney - amount;
                        //im.Memo = "短信消费";
                        //im.Status = "已消费";
                        //im.CRDate = DateTime.Now;

                        //new SZHL_DDGL_ITEMB().Insert(im);
                    }
                }
            }
            catch { }
            return(err);
        }
예제 #4
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1">用户名</param>
        /// <param name="P2">密码(未解码的)</param>
        /// <param name="UserInfo"></param>
        public void LOGIN(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string password = context.Request["password"] ?? "";
            string username = context.Request["UserName"] ?? "";
            string chkcode  = context.Request["chkcode"] ?? "";

            msg.ErrorMsg = "";
            //取消验证码 Weiler
            //if (context.Session["chkcode"] != null)
            //{

            //    if (!chkcode.ToUpper().Equals(context.Session["chkcode"].ToString()))
            //    {
            //        msg.ErrorMsg = "验证码不正确";
            //        return;
            //    }
            //}
            //else
            //{
            //    msg.ErrorMsg = "验证码已过期";
            //    return;
            //}


            JH_Auth_QY qyModel = new JH_Auth_QYB().GetALLEntities().First();

            password = CommonHelp.GetMD5(password);
            JH_Auth_User userInfo = new JH_Auth_User();

            List <JH_Auth_User> userList = new JH_Auth_UserB().GetEntities(d => (d.UserName == username || d.mobphone == username) && d.UserPass == password).ToList();

            if (userList.Count() == 0)
            {
                msg.ErrorMsg = "用户名或密码不正确";
                return;
            }
            else
            {
                userInfo = userList[0];
                if (userInfo.IsUse != "Y")
                {
                    msg.ErrorMsg = "用户被禁用,请联系管理员";
                    return;
                }
                if (string.IsNullOrEmpty(userInfo.pccode))
                {
                    userInfo.pccode = CommonHelp.CreatePCCode(userInfo);
                }
                userInfo.logindate = DateTime.Now;
                new JH_Auth_UserB().Update(userInfo);
                msg.Result  = userInfo.pccode;
                msg.Result1 = userInfo.UserName;
                msg.Result4 = userInfo;
            }
        }
예제 #5
0
        public void REGISTERYSOLD(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            JH_Auth_QY QY = new JH_Auth_QYB().GetEntity(d => d.ComId == 10334);

            QY.CRDate        = DateTime.Now.AddYears(-2);
            QY.QYProfile     = QY.FileServerUrl;
            QY.FileServerUrl = "";
            QY.IsUseWX       = "N";
            new JH_Auth_QYB().Update(QY);
            msg.Result = QY;
        }
예제 #6
0
 /// <summary>
 /// 验证企业名称
 /// </summary>
 /// <param name="context"></param>
 /// <param name="msg"></param>
 /// <param name="P1"></param>
 /// <param name="P2"></param>
 /// <param name="UserInfo"></param>
 public void YZQYMC(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
 {
     if (!string.IsNullOrEmpty(P1))
     {
         var qy = new JH_Auth_QYB().GetEntity(p => p.QYName == P1);
         if (qy != null)
         {
             msg.ErrorMsg = "企业名称已存在";
         }
     }
 }
예제 #7
0
        /// <summary>
        /// 获取文件在服务器上的预览文件路径
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>

        /// <summary>
        /// 更新企业空间占用
        /// </summary>
        /// <param name="FileSize"></param>
        /// <returns></returns>
        public int AddSpace(int ComId, int FileSize)
        {
            JH_Auth_QY qymodel = new JH_Auth_QYB().GetEntity(d => d.ComId == ComId);

            if (qymodel != null)
            {
                qymodel.QyExpendSpace = qymodel.QyExpendSpace + FileSize;
            }
            new JH_Auth_QYB().Update(qymodel);
            return(qymodel.QyExpendSpace.Value);
        }
예제 #8
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void REGISTERNEW(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            JObject tt     = (JObject)JsonConvert.DeserializeObject(P1);
            string  qyName = tt["QYName"].ToString();
            var     qy     = new JH_Auth_QYB().GetEntity(p => p.QYName == qyName);

            if (qy != null)
            {
                msg.ErrorMsg = "企业名称已存在!";
            }
            if (tt["xm"].ToString() == "")
            {
                msg.ErrorMsg = "姓名不能为空!";
            }
            string mobile = tt["mobphone"].ToString();
            var    qy2    = new JH_Auth_QYB().GetEntities(p => p.Mobile == mobile);

            if (qy2.Count() > 0)
            {
                msg.ErrorMsg = "此手机已注册企业,请更换手机号继续注册";
            }
            if (string.IsNullOrEmpty(msg.ErrorMsg))
            {
                string QyScape  = CommonHelp.GetConfig("initSpace").ToString(); //公司初始控件
                string password = CommonHelp.GetMD5(tt["UserPass"].ToString());

                #region 判断获取不重复的qycode随机code,如果表中存在重复code,while继续获取,否则直接执行下一步
                bool   flag   = true;
                string qyCode = "";
                while (flag == true)
                {
                    //生成code随机数
                    Random ran = new Random((int)DateTime.Now.Ticks);
                    qyCode = ran.Next().ToString();
                    if (new JH_Auth_QYB().GetEntities(p => p.QYCode == qyCode).Count() == 0)
                    {
                        flag = false;
                        continue;
                    }
                }
                #endregion

                string fileUrl  = new FileHelp().GetFileServerUrl(qyCode);
                string userName = mobile;

                new JH_Auth_UserB().ExsSclarSql("exec RegistCompany '" + tt["QYName"].ToString() + "','" + tt["mobphone"].ToString() + "','" + userName + "','" + password + "','" + qyCode + "','" + fileUrl + "','" + tt["xm"].ToString() + "'," + QyScape);

                new FileHelp().AddQycode(qyCode, tt["QYName"].ToString());
                string content = "您的[" + tt["QYName"].ToString() + "]公司账号已经注册成功:\r\n登录网站: \r\n管理员账号:" + tt["mobphone"].ToString() + "\r\n管理员密码:" + tt["UserPass"].ToString() + "\r\n";
                CommonHelp.SendSMS(tt["mobphone"].ToString(), content, 0);
                string user = context.Request["ID"] ?? "";
            }
        }
예제 #9
0
파일: BLL.cs 프로젝트: weipengyang/qywecha
        public string SendSMS(string telephone, string content, int ComId = 0)
        {
            string err = "";

            try
            {
                string  dxqz         = "爱卡养车";
                decimal amcountmoney = 0;
                var     qy           = new JH_Auth_QYB().GetEntity(d => d.ComId == ComId);
                if (qy != null)
                {
                    dxqz         = qy.DXQZ;
                    amcountmoney = qy.AccountMoney.HasValue ? qy.AccountMoney.Value : 0;
                }

                string[] tels = telephone.Trim().Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace(',', ',').Split(',');

                //判断金额是否够
                decimal DXCost = decimal.Parse(CommonHelp.GetConfig("DXCost"));
                decimal amount = tels.Length * DXCost;
                if (ComId != 0 && amcountmoney < amount) //短信余额不足
                {
                    err = "短信余额不足";
                }
                else
                {
                    string re = "";
                    foreach (string tel in tels)
                    {
                        re = CommonHelp.SendDX(tel, content + "【" + dxqz + "】", "");
                    }

                    err = "发送成功";

                    //扣款
                    if (ComId != 0 && qy != null)
                    {
                        qy.AccountMoney = qy.AccountMoney - amount;
                        new JH_Auth_QYB().Update(qy);
                    }
                }
            }
            catch { }
            return(err);
        }
예제 #10
0
파일: PubManage.cs 프로젝트: fl1029/QJCore
        /// <summary>
        /// 获取文档资源
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETWDZY(JObject context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            FT_File    ff = new FT_FileB().GetEntities(p => p.zyid == P1).FirstOrDefault();
            JH_Auth_QY QY = new JH_Auth_QYB().GetALLEntities().FirstOrDefault();

            if (ff != null)
            {
                HttpWebResponse ResponseData = CommonHelp.CreateHttpResponse(QY.FileServerUrl + "/document/officecov/" + ff.zyid, null, 0, "", null, "GET");
                string          Returndata   = CommonHelp.GetResponseString(ResponseData);
                msg.Result  = Returndata.ToString().Split(',')[1];
                msg.Result1 = ff.Name;
                msg.Result2 = QY.FileServerUrl;
            }
            else
            {
                msg.ErrorMsg = "此文件不存在或您没有权限!";
            }
        }
예제 #11
0
        public ActionResult <string> XXJS()
        {
            var context = _accessor.HttpContext;

            String strCorpID = context.Request.Query["corpid"].ToString();
            string strCode   = context.Request.Query["Code"].ToString();

            try
            {
                JH_Auth_QY    jaq = new JH_Auth_QYB().GetALLEntities().FirstOrDefault();
                JH_Auth_Model jam = new JH_Auth_ModelB().GetEntity(p => p.ModelCode == strCode);
                if (jaq != null && jam != null)
                {
                    string echoString = context.Request.Query["echoStr"].ToString();
                    string signature  = context.Request.Query["msg_signature"].ToString();//企业号的 msg_signature
                    string timestamp  = context.Request.Query["timestamp"].ToString();
                    string nonce      = context.Request.Query["nonce"].ToString();

                    string decryptEchoString = "";
                    if (new MOBAPI().CheckSignature(jam.Token, signature, timestamp, nonce, jaq.corpId, jam.EncodingAESKey, echoString, ref decryptEchoString))
                    {
                        if (!string.IsNullOrEmpty(decryptEchoString))
                        {
                            Int64 v = Convert.ToInt64(decryptEchoString);
                            context.Response.Clear();

                            using (StreamWriter writer = new StreamWriter(Response.Body))
                            {
                                writer.Write(v);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Model.ErrorMsg = ex.ToString();
                CommonHelp.WriteLOG(ex.ToString());
            }

            return(ControHelp.CovJson(Model));
        }
예제 #12
0
        public void DFile(string fileID)
        {
            if (!string.IsNullOrEmpty(fileID))
            {
                int     fileId = int.Parse(fileID.Split(',')[0]);
                FT_File file   = new FT_FileB().GetEntity(d => d.ID == fileId);

                JH_Auth_QY QYMODEL = new JH_Auth_QYB().GetALLEntities().FirstOrDefault();

                var    context  = _accessor.HttpContext;
                string width    = context.Request.Query["width"].ToString();
                string height   = context.Request.Query["height"].ToString();
                string filename = QYMODEL.FileServerUrl + "/" + QYMODEL.QYCode + "/document/" + file.zyid;
                if (width + height != "")
                {
                    filename = QYMODEL.FileServerUrl + "/" + QYMODEL.QYCode + "/document/image/" + file.zyid + (width + height != "" ? ("/" + width + "/" + height) : "");
                }
                context.Response.Redirect(filename);
            }
        }
예제 #13
0
        /// <summary>
        /// 向服务器发送压缩目录命令
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1">目录ID</param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void COMPRESSFOLDER(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strCode = P1;
            int    ComId   = int.Parse(P2);

            FT_FolderB.FoldFile Mode = new FT_FolderB.FoldFile();
            Mode.FolderID  = -1;
            Mode.Name      = "压缩文件";
            Mode.SubFileS  = new List <FT_File>();
            Mode.SubFolder = new List <FT_FolderB.FoldFile>();
            foreach (string item in P1.SplitTOList(','))
            {
                int    FileID  = int.Parse(item.Split('|')[0].ToString());
                string strType = item.Split('|')[1].ToString();
                if (item.Split('|')[1].ToString() == "file")
                {
                    FT_File file = new FT_FileB().GetEntity(d => d.ID == FileID);
                    file.YLUrl = "";
                    Mode.SubFileS.Add(file);
                }
                else
                {
                    List <FT_FolderB.FoldFileItem> ListID = new List <FT_FolderB.FoldFileItem>();
                    FT_FolderB.FoldFile            obj    = new FT_FolderB().GetWDTREE(FileID, ref ListID, ComId);
                    Mode.SubFolder.Add(obj);
                }
            }
            IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();

            timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            string     Result  = JsonConvert.SerializeObject(Mode, Newtonsoft.Json.Formatting.Indented, timeConverter).Replace("null", "\"\"");
            JH_Auth_QY qymodel = new JH_Auth_QYB().GetEntity(d => d.ComId == ComId);
            //压缩文件
            Dictionary <String, String> DATA = new Dictionary <String, String>();

            DATA.Add("data", Result);
            HttpWebResponse ResponseData = CommonHelp.CreatePostHttpResponse(qymodel.FileServerUrl + "zipfolder", DATA, 0, "", null);
            string          strData      = CommonHelp.GetResponseString(ResponseData);

            msg.Result = strData;
        }
예제 #14
0
        public void REGISTERYS(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string       strXM    = P2;
            string       strPhone = P1;
            JH_Auth_User user1    = new JH_Auth_UserB().GetUserByUserName(10334, P1);

            if (user1 != null)
            {
                msg.ErrorMsg = "用户已存在";
                return;
            }
            JH_Auth_User user = new JH_Auth_User();

            user.UserName     = strPhone;
            user.mobphone     = strPhone;
            user.UserRealName = P2;
            user.UserPass     = CommonHelp.GetMD5("abc123");
            user.ComId        = 10334;
            user.BranchCode   = 1728;
            user.CRDate       = DateTime.Now;
            user.CRUser       = "******";
            user.logindate    = DateTime.Now;
            user.IsUse        = "Y";
            if (!new JH_Auth_UserB().Insert(user))
            {
                msg.ErrorMsg = "添加用户失败";
            }
            else
            {
                JH_Auth_QY QY = new JH_Auth_QYB().GetEntity(d => d.ComId == 10334);
                WXHelp     wx = new WXHelp(QY);
                wx.WX_CreateUser(user);

                //添加默认员工角色
                JH_Auth_UserRole Model = new JH_Auth_UserRole();
                Model.UserName = user.UserName;
                Model.RoleCode = 1219;
                Model.ComId    = user.ComId;
                new JH_Auth_UserRoleB().Insert(Model);
            }
        }
예제 #15
0
        /// <summary>
        /// 获取企业信息
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETQYINFO(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string qycode = context.Request["qycode"];
            //string qycode = "2072782222";
            JH_Auth_QY Qyinfo = new JH_Auth_QYB().GetEntity(d => d.QYCode == qycode);

            if (Qyinfo == null)
            {
                msg.ErrorMsg = "没有找到该企业";
            }
            else
            {
                msg.Result = Qyinfo;


                //WXHelp wx = new WXHelp(Qyinfo);
                //var list = wx.GetAppList().agentlist.Select(p => new { id = p.agentid, info = wx.GetAPPinfo(Int32.Parse(p.agentid)) });
                //wx.WX_WxCreateMenuNew(138, "GZBG");
                //msg.Result1 = list;
            }
        }
예제 #16
0
        public ActionResult <string> Login(Object PostData)
        {
            JObject JsonData = JObject.FromObject(PostData);
            string  username = JsonData["UserName"] == null ? "" : JsonData["UserName"].ToString();
            string  password = JsonData["password"] == null ? "" : JsonData["password"].ToString();
            Dictionary <string, string> results3 = JsonConvert.DeserializeObject <Dictionary <string, string> >(PostData.ToString());

            Model.ErrorMsg = "";
            JH_Auth_QY qyModel = new JH_Auth_QYB().GetALLEntities().First();

            password = CommonHelp.GetMD5(password);
            JH_Auth_User        userInfo = new JH_Auth_User();
            List <JH_Auth_User> userList = new JH_Auth_UserB().GetEntities(d => (d.UserName == username || d.mobphone == username) && d.UserPass == password).ToList();

            if (userList.Count() == 0)
            {
                Model.ErrorMsg = "用户名或密码不正确";
            }
            else
            {
                userInfo = userList[0];
                if (userInfo.IsUse != "Y")
                {
                    Model.ErrorMsg = "用户被禁用,请联系管理员";
                }
                if (Model.ErrorMsg == "")
                {
                    Model.Result  = JwtHelper.CreateJWT(username, "Admin");
                    Model.Result1 = userInfo.UserName;
                    Model.Result2 = qyModel.FileServerUrl;
                    Model.Result4 = userInfo;

                    CacheHelp.Remove(userInfo.UserName);
                }
            }


            return(ControHelp.CovJson(Model));;
        }
예제 #17
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            string strAction = context.Request["Action"] ?? "";
            string UserName  = context.Request["UserName"] ?? "";
            string strIP     = CommonHelp.getIP(context);

            Msg_Result Model = new Msg_Result()
            {
                Action = strAction.ToUpper(), ErrorMsg = ""
            };

            if (!string.IsNullOrEmpty(strAction))
            {
                #region 企业号应用callback
                if (strAction == "XXJS")
                {
                    String strCorpID = context.Request["corpid"] ?? "";
                    string strCode   = context.Request["Code"] ?? "";
                    try
                    {
                        JH_Auth_QY    jaq = new JH_Auth_QYB().GetALLEntities().FirstOrDefault();
                        JH_Auth_Model jam = new JH_Auth_ModelB().GetEntity(p => p.ModelCode == strCode);
                        //if (jaq != null && jam != null && !string.IsNullOrEmpty(jam.TJId))
                        if (jaq != null && jam != null)
                        {
                            #region POST
                            if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")
                            {
                                string signature = HttpContext.Current.Request.QueryString["msg_signature"];//企业号的 msg_signature
                                string timestamp = HttpContext.Current.Request.QueryString["timestamp"];
                                string nonce     = HttpContext.Current.Request.QueryString["nonce"];

                                // 获得客户端RAW HttpRequest
                                StreamReader srResult    = new StreamReader(context.Request.InputStream);
                                string       str         = srResult.ReadToEnd();
                                XmlDocument  XmlDocument = new XmlDocument();
                                XmlDocument.LoadXml(HttpContext.Current.Server.UrlDecode(str));
                                string ToUserName = string.Empty;
                                string strde      = string.Empty;
                                string msgtype    = string.Empty;//微信响应类型
                                foreach (XmlNode xn in XmlDocument.ChildNodes[0].ChildNodes)
                                {
                                    if (xn.Name == "ToUserName")
                                    {
                                        ToUserName = xn.InnerText;
                                    }
                                }
                                var pj = new JH_Auth_WXPJB().GetEntity(p => p.TJID == jam.TJId);
                                Tencent.WXBizMsgCrypt wxcpt = new Tencent.WXBizMsgCrypt(pj.Token, pj.EncodingAESKey, ToUserName);
                                int         n            = wxcpt.DecryptMsg(signature, timestamp, nonce, str, ref strde);
                                XmlDocument XmlDocument1 = new XmlDocument();
                                XmlDocument1.LoadXml(HttpContext.Current.Server.UrlDecode(strde));
                                foreach (XmlNode xn1 in XmlDocument1.ChildNodes[0].ChildNodes)
                                {
                                    if (xn1.Name == "MsgType")
                                    {
                                        msgtype = xn1.InnerText;
                                    }
                                    //CommonHelp.WriteLOG(XmlDocument1.OuterXml);
                                }
                                if (msgtype == "event")//处理事件
                                {
                                    //需要处理进入应用的菜单更改事件
                                    string strEvent    = XmlDocument1.ChildNodes[0]["Event"].InnerText;
                                    string strUserName = XmlDocument1.ChildNodes[0]["FromUserName"].InnerText;
                                    string strAgentID  = XmlDocument1.ChildNodes[0]["AgentID"].InnerText;
                                    string strEventKey = XmlDocument1.ChildNodes[0]["EventKey"].InnerText;

                                    if (strEvent.ToLower() == "enter_agent" || strEvent.ToLower() == "view")
                                    {
                                        //进入应用和点击菜单
                                        //JH_Auth_User jau = new JH_Auth_UserB().GetEntity(p => p.ComId == jaq.ComId && p.UserName == strUserName);
                                        //JH_Auth_QY_Model jhqm = new JH_Auth_QY_ModelB().GetEntity(p => p.ComId == jaq.ComId && p.AgentId == strAgentID);
                                        //if (jau != null && jhqm != null)
                                        //{
                                        //    JH_Auth_YYLog jay = new JH_Auth_YYLog();
                                        //    jay.ComId = jaq.ComId;
                                        //    jay.AgentID = strAgentID;
                                        //    jay.CorpID = strCorpID;
                                        //    jay.CRDate = DateTime.Now;
                                        //    jay.CRUser = strUserName;
                                        //    jay.Event = strEvent;
                                        //    jay.EventKey = strEventKey;
                                        //    jay.ModelCode = strCode;
                                        //    jay.ModelID = jhqm.ModelID;
                                        //    jay.QYName = jaq.QYName;
                                        //    jay.TJID = jam.TJId;
                                        //    jay.Type = msgtype;
                                        //    jay.UserName = strUserName;
                                        //    jay.UserRealName = jau.UserRealName;

                                        //    new JH_Auth_YYLogB().Insert(jay);

                                        //    if (strEvent.ToLower() == "enter_agent")
                                        //    {
                                        //        var jays = new JH_Auth_YYLogB().GetEntities(p => p.ComId == jaq.ComId && p.Event == "enter_agent" && p.AgentID == strAgentID && p.CRUser == strUserName);
                                        //        if (jays.Count() <= 1)
                                        //        {
                                        //        }
                                        //    }
                                        //}
                                    }
                                }
                                if (new List <string> {
                                    "text", "image", "voice", "video", "shortvideo", "link"
                                }.Contains(msgtype))                                                                               //处理消息事件
                                {
                                    if (XmlDocument1.ChildNodes.Count > 0)
                                    {
                                        JH_Auth_WXMSG wxmsgModel = new JH_Auth_WXMSG();
                                        wxmsgModel.AgentID      = int.Parse(XmlDocument1.ChildNodes[0]["AgentID"].InnerText);
                                        wxmsgModel.ComId        = jaq.ComId;
                                        wxmsgModel.ToUserName   = XmlDocument1.ChildNodes[0]["ToUserName"].InnerText;
                                        wxmsgModel.FromUserName = XmlDocument1.ChildNodes[0]["FromUserName"].InnerText;
                                        wxmsgModel.CRDate       = DateTime.Now;
                                        wxmsgModel.CRUser       = XmlDocument1.ChildNodes[0]["FromUserName"].InnerText;
                                        wxmsgModel.MsgId        = XmlDocument1.ChildNodes[0]["MsgId"].InnerText;
                                        wxmsgModel.MsgType      = msgtype;
                                        wxmsgModel.ModeCode     = strCode;
                                        wxmsgModel.Tags         = "微信收藏";

                                        switch (msgtype)
                                        {
                                        case "text":
                                            wxmsgModel.MsgContent = XmlDocument1.ChildNodes[0]["Content"].InnerText;
                                            break;

                                        case "image":
                                            wxmsgModel.PicUrl  = XmlDocument1.ChildNodes[0]["PicUrl"].InnerText;
                                            wxmsgModel.MediaId = XmlDocument1.ChildNodes[0]["MediaId"].InnerText;
                                            break;

                                        case "voice":
                                            wxmsgModel.MediaId = XmlDocument1.ChildNodes[0]["MediaId"].InnerText;
                                            wxmsgModel.Format  = XmlDocument1.ChildNodes[0]["Format"].InnerText;
                                            break;

                                        case "video":
                                            wxmsgModel.MediaId      = XmlDocument1.ChildNodes[0]["MediaId"].InnerText;
                                            wxmsgModel.ThumbMediaId = XmlDocument1.ChildNodes[0]["ThumbMediaId"].InnerText;
                                            break;

                                        case "shortvideo":
                                            wxmsgModel.MediaId      = XmlDocument1.ChildNodes[0]["MediaId"].InnerText;
                                            wxmsgModel.ThumbMediaId = XmlDocument1.ChildNodes[0]["ThumbMediaId"].InnerText;
                                            break;

                                        case "link":
                                            wxmsgModel.Description = XmlDocument1.ChildNodes[0]["Description"].InnerText;
                                            wxmsgModel.Title       = XmlDocument1.ChildNodes[0]["Title"].InnerText;
                                            wxmsgModel.URL         = XmlDocument1.ChildNodes[0]["Url"].InnerText;
                                            wxmsgModel.PicUrl      = XmlDocument1.ChildNodes[0]["PicUrl"].InnerText;
                                            break;
                                        }
                                        if (new List <string>()
                                        {
                                            "link", "text"
                                        }.Contains(msgtype))
                                        {
                                            if (msgtype == "link")
                                            {
                                                var jaw = new JH_Auth_WXMSGB().GetEntity(p => p.ComId == jaq.ComId && p.MsgId == wxmsgModel.MsgId);
                                                if (jaw == null)
                                                {
                                                    string strMedType = ".jpg";
                                                    JH_Auth_UserB.UserInfo UserInfo = new JH_Auth_UserB.UserInfo();
                                                    UserInfo = new JH_Auth_UserB().GetUserInfo(jaq.ComId, wxmsgModel.FromUserName);
                                                    string fileID = CommonHelp.ProcessWxIMGUrl(wxmsgModel.PicUrl, UserInfo, strMedType);

                                                    wxmsgModel.FileId = fileID;
                                                    new JH_Auth_WXMSGB().Insert(wxmsgModel);

                                                    if (strCode == "TSSQ")
                                                    {
                                                        SZHL_TXSX tx1 = new SZHL_TXSX();
                                                        tx1.ComId   = jaq.ComId;
                                                        tx1.APIName = "TSSQ";
                                                        tx1.MsgID   = wxmsgModel.ID.ToString();
                                                        tx1.FunName = "SENDWXMSG";
                                                        tx1.Date    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                                        tx1.CRUser  = wxmsgModel.CRUser;
                                                        tx1.CRDate  = DateTime.Now;
                                                        TXSX.TXSXAPI.AddALERT(tx1); //时间为发送时间
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                new JH_Auth_WXMSGB().Insert(wxmsgModel);
                                            }
                                        }
                                        if (!string.IsNullOrEmpty(wxmsgModel.MediaId))
                                        {
                                            var jaw = new JH_Auth_WXMSGB().GetEntity(p => p.ComId == jaq.ComId && p.MediaId == wxmsgModel.MediaId);
                                            if (jaw == null)
                                            {
                                                string strMedType = ".jpg";
                                                if (strCode == "QYWD" || strCode == "CRM")             //判断模块
                                                {
                                                    if (msgtype == "shortvideo" || msgtype == "video") //视频,小视频
                                                    {
                                                        strMedType = ".mp4";
                                                    }
                                                    if (new List <string>()
                                                    {
                                                        "image", "shortvideo", "video", "voice"
                                                    }.Contains(msgtype))                                                                 //下载到本地服务器
                                                    {
                                                        JH_Auth_UserB.UserInfo UserInfo = new JH_Auth_UserB.UserInfo();
                                                        UserInfo = new JH_Auth_UserB().GetUserInfo(jaq.ComId, wxmsgModel.FromUserName);
                                                        string fileID = CommonHelp.ProcessWxIMG(wxmsgModel.MediaId, strCode, UserInfo, strMedType);
                                                        wxmsgModel.FileId = fileID;
                                                        new JH_Auth_WXMSGB().Insert(wxmsgModel);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region GET
                            if (HttpContext.Current.Request.HttpMethod.ToUpper() == "GET")
                            {
                                Auth(jam.Token, jam.EncodingAESKey, jaq.corpId);
                            }
                            #endregion
                        }
                    }
                    catch (Exception ex)
                    {
                        Model.ErrorMsg = ex.ToString();
                        CommonHelp.WriteLOG(ex.ToString());
                    }
                }
                #endregion

                #region 企业会话
                if (strAction == "QYIM")
                {
                    if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")
                    {
                        string corpId = context.Request["corpid"] ?? "";

                        try
                        {
                            JH_Auth_QY jaq = new JH_Auth_QYB().GetEntity(p => p.corpId == corpId);
                            if (jaq != null)
                            {
                                string signature = HttpContext.Current.Request.QueryString["msg_signature"];//企业号的 msg_signature
                                string timestamp = HttpContext.Current.Request.QueryString["timestamp"];
                                string nonce     = HttpContext.Current.Request.QueryString["nonce"];

                                // 获得客户端RAW HttpRequest
                                StreamReader srResult = new StreamReader(context.Request.InputStream);
                                string       str      = srResult.ReadToEnd();

                                string strde = string.Empty;

                                var pj = new JH_Auth_WXPJB().GetEntity(p => p.TJID == "tj7882b1f8bc56f05f");

                                Tencent.WXBizMsgCrypt wxcpt = new Tencent.WXBizMsgCrypt(pj.Token, pj.EncodingAESKey, corpId);

                                wxcpt.DecryptMsg(signature, timestamp, nonce, str, ref strde);

                                //string strde = HttpContext.Current.Request.QueryString[0];

                                XmlDocument XmlDocument = new XmlDocument();
                                XmlDocument.LoadXml(HttpContext.Current.Server.UrlDecode(strde));

                                string AgentType  = string.Empty;
                                string ToUserName = string.Empty;
                                string ItemCount  = string.Empty;
                                string PackageId  = string.Empty;
                                string Item       = string.Empty;

                                #region XML文档处理
                                foreach (XmlNode xn in XmlDocument.ChildNodes[0].ChildNodes)
                                {
                                    if (xn.Name == "AgentType")
                                    {
                                        AgentType = xn.InnerText;
                                    }
                                    if (xn.Name == "ToUserName")
                                    {
                                        ToUserName = xn.InnerText;
                                    }
                                    if (xn.Name == "ItemCount")
                                    {
                                        ItemCount = xn.InnerText;
                                    }
                                    if (xn.Name == "PackageId")
                                    {
                                        PackageId = xn.InnerText;
                                    }
                                    if (xn.Name == "Item")
                                    {
                                        Item += xn.InnerXml;

                                        string MsgType = xn.ChildNodes[2].InnerText;

                                        if (MsgType == "event")
                                        {
                                        }
                                        else if (new List <string> {
                                            "text", "image", "voice", "file", "link"
                                        }.Contains(MsgType))
                                        {
                                            #region 内容处理


                                            #endregion
                                        }
                                    }
                                }
                                #endregion

                                HttpContext.Current.Response.Write(PackageId);
                                HttpContext.Current.Response.End();
                            }
                        }
                        catch (Exception ex)
                        {
                            CommonHelp.WriteLOG("QYIM:" + ex.ToString() + "\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        }
                    }
                }
                #endregion

                #region 获取唯一code
                if (strAction.ToUpper() == "GetUserCodeByCode".ToUpper())
                {
                    #region 获取Code
                    Model.ErrorMsg = "获取Code错误,请重试";

                    string strCode      = context.Request["code"] ?? "";
                    string strCorpID    = context.Request["corpid"] ?? "";
                    string strModelCode = context.Request["funcode"] ?? "";

                    if (!string.IsNullOrEmpty(strCode))
                    {
                        var qy = new JH_Auth_QYB().GetEntity(p => p.corpId == strCorpID);
                        if (qy != null)
                        {
                            try
                            {
                                //通过微信接口获取用户名
                                WXHelp wx       = new WXHelp(qy);
                                string username = wx.GetUserDataByCode(strCode, strModelCode);
                                if (!string.IsNullOrEmpty(username))
                                {
                                    var jau = new JH_Auth_UserB().GetUserByUserName(qy.ComId, username);
                                    if (jau != null)
                                    {
                                        //如果PCCode为空或者超过60分钟没操作,统统重新生成PCCode,并更新最新操作时间
                                        if (jau.logindate == null)
                                        {
                                            jau.logindate = DateTime.Now;
                                        }
                                        TimeSpan ts = new TimeSpan(jau.logindate.Value.Ticks).Subtract(new TimeSpan(DateTime.Now.Ticks)).Duration();
                                        if (string.IsNullOrEmpty(jau.pccode) || ts.TotalMinutes > 60)
                                        {
                                            string strGuid = CommonHelp.CreatePCCode(jau);
                                            jau.pccode    = strGuid;
                                            jau.logindate = DateTime.Now;
                                            new JH_Auth_UserB().Update(jau);
                                        }
                                        Model.ErrorMsg = "";
                                        Model.Result   = jau.pccode;
                                        Model.Result1  = jau.UserName;
                                        Model.Result2  = ts.TotalMinutes;
                                    }
                                }
                                else
                                {
                                    Model.ErrorMsg = "当前用户不存在";
                                }
                            }
                            catch (Exception ex)
                            {
                                Model.ErrorMsg = ex.ToString();
                            }
                        }
                        else
                        {
                            Model.ErrorMsg = "当前企业号未在电脑端注册";
                        }
                    }
                    else
                    {
                        Model.ErrorMsg = "Code为空";
                    }
                    #endregion
                }
                #endregion
                #region 是否存在
                if (strAction.ToUpper() == "isexist".ToUpper())
                {
                    string strcorpid = context.Request["corpid"] ?? "";
                    if (strcorpid != "")
                    {
                        var qy = new JH_Auth_QYB().GetEntity(p => p.corpId == strcorpid);
                        if (qy == null)
                        {
                            Model.ErrorMsg = "当前企业号未注册此平台";
                        }
                        else
                        {
                            if (context.Request.Cookies["szhlcode"] != null)
                            {
                                //通过Cookies获取Code
                                //string szhlcode = "5ab470be-4988-4bb3-9658-050481b98fca";
                                string szhlcode = context.Request.Cookies["szhlcode"].Value.ToString();
                                //通过Code获取用户名,然后执行接口方法
                                var jau = new JH_Auth_UserB().GetUserByPCCode(szhlcode);
                                if (jau == null)
                                {
                                    Model.ErrorMsg = "用户Code不存在";
                                }
                                else
                                {
                                    if (new JH_Auth_QYB().GetEntity(d => d.ComId == jau.ComId.Value).corpId != strcorpid)
                                    {
                                        Model.ErrorMsg = "企业需要重新选择";
                                    }
                                    //重写CODE
                                }
                            }
                        }
                    }
                    else
                    {
                        Model.ErrorMsg = "企业号连接有误,请重新连接";
                    }
                }
                #endregion
                #region 发送提醒
                if (strAction.ToUpper() == "AUTOALERT")
                {
                    TXSX.TXSXAPI.AUTOALERT();
                }
                #endregion
            }
            else
            {
                #region 获取SuiteTicket
                if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")
                {
                    string signature = HttpContext.Current.Request.QueryString["msg_signature"];//企业号的 msg_signature
                    string timestamp = HttpContext.Current.Request.QueryString["timestamp"];
                    string nonce     = HttpContext.Current.Request.QueryString["nonce"];

                    // 获得客户端RAW HttpRequest
                    StreamReader srResult = new StreamReader(context.Request.InputStream);
                    string       str      = srResult.ReadToEnd();

                    XmlDocument XmlDocument = new XmlDocument();
                    XmlDocument.LoadXml(HttpContext.Current.Server.UrlDecode(str));

                    string ToUserName = string.Empty;
                    string Encrypt    = string.Empty;

                    string strde       = string.Empty;
                    string strinfotype = string.Empty;


                    foreach (XmlNode xn in XmlDocument.ChildNodes[0].ChildNodes)
                    {
                        if (xn.Name == "ToUserName")
                        {
                            ToUserName = xn.InnerText;
                        }
                        if (xn.Name == "Encrypt")
                        {
                            Encrypt = xn.InnerText;
                        }
                    }

                    var pj = new JH_Auth_WXPJB().GetEntity(p => p.TJID == ToUserName);

                    Tencent.WXBizMsgCrypt wxcpt = new Tencent.WXBizMsgCrypt(pj.Token, pj.EncodingAESKey, ToUserName);
                    int n = wxcpt.DecryptMsg(signature, timestamp, nonce, str, ref strde);

                    string strtct         = string.Empty;
                    string strSuiteId     = string.Empty;
                    string strtAuthCorpId = string.Empty;

                    XmlDocument XmlDocument1 = new XmlDocument();
                    XmlDocument1.LoadXml(HttpContext.Current.Server.UrlDecode(strde));

                    foreach (XmlNode xn1 in XmlDocument1.ChildNodes[0].ChildNodes)
                    {
                        if (xn1.Name == "SuiteId")
                        {
                            strSuiteId = xn1.InnerText;
                        }
                        if (xn1.Name == "SuiteTicket")
                        {
                            strtct = xn1.InnerText;
                        }
                        if (xn1.Name == "InfoType")
                        {
                            strinfotype = xn1.InnerText;
                        }
                        if (xn1.Name == "AuthCorpId")
                        {
                            strtAuthCorpId = xn1.InnerText;
                        }
                    }
                    if (strinfotype == "suite_ticket")
                    {
                        pj.Ticket = strtct;

                        new JH_Auth_WXPJB().Update(pj);
                    }


                    HttpContext.Current.Response.Write("success");
                    HttpContext.Current.Response.End();
                }

                #endregion
            }

            IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
            timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            string Result = JsonConvert.SerializeObject(Model, Newtonsoft.Json.Formatting.Indented, timeConverter).Replace("null", "\"\"");
            context.Response.Write(Result);
        }
예제 #18
0
        public ActionResult <string> GetUserCodeByCode()
        {
            try
            {
                var context = _accessor.HttpContext;

                #region 获取Code
                Model.ErrorMsg = "获取Code错误,请重试";

                string strCode      = context.Request.Query["code"].ToString();
                string strCorpID    = context.Request.Query["corpid"].ToString();
                string strModelCode = context.Request.Query["funcode"].ToString();

                if (!string.IsNullOrEmpty(strCode))
                {
                    var qy = new JH_Auth_QYB().GetEntity(p => p.corpId == strCorpID);
                    if (qy != null)
                    {
                        try
                        {
                            //通过微信接口获取用户名
                            WXHelp wx       = new WXHelp(qy);
                            string username = wx.GetUserDataByCode(strCode, strModelCode);
                            if (!string.IsNullOrEmpty(username))
                            {
                                var jau = new JH_Auth_UserB().GetUserByUserName(qy.ComId, username);

                                if (jau != null)
                                {
                                    Model.ErrorMsg = "";
                                    Model.Result   = JwtHelper.CreateJWT(username, "Admin");
                                    Model.Result1  = jau.UserName;
                                    Model.Result3  = qy.FileServerUrl;
                                }
                            }
                            else
                            {
                                Model.ErrorMsg = "当前用户不存在";
                            }
                        }
                        catch (Exception ex)
                        {
                            Model.ErrorMsg = ex.ToString();
                        }
                    }
                    else
                    {
                        Model.ErrorMsg = "当前企业号未在电脑端注册";
                    }
                }
                else
                {
                    Model.ErrorMsg = "Code为空";
                }
                #endregion
            }
            catch (Exception ex)
            {
                Model.ErrorMsg = "接口调用失败,请检查日志";
                Model.Result   = ex.ToString();
                CommonHelp.WriteLOG(ex.ToString());
            }
            return(ControHelp.CovJson(Model));
        }
예제 #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                JH_Auth_QY QYMODEL = new JH_Auth_QYB().GetALLEntities().FirstOrDefault();

                if (szhlcode != "")
                {
                    if (!string.IsNullOrEmpty(FileId))//如果FileID不为空
                    {
                        string  filename = "";
                        int     fileId   = int.Parse(FileId.Split(',')[0]);
                        FT_File file     = new FT_FileB().GetEntity(d => d.ID == fileId);
                        if (type == "file") //默认下载文件
                        {
                            List <string> extends = new List <string>()
                            {
                                "jpg", "png", "gif", "jpeg"
                            };
                            if (extends.Contains(file.FileExtendName.ToLower()))
                            {
                                string width  = Request["width"] ?? "";
                                string height = Request["height"] ?? "";
                                Response.AddHeader("Content-Disposition", "attachment;filename=" + file.Name);
                                Response.ContentType = "application/octet-stream";
                                filename             = QYMODEL.FileServerUrl + "/" + QYMODEL.QYCode + "/document/" + file.zyid;
                                if (width + height != "")
                                {
                                    filename = QYMODEL.FileServerUrl + "/" + QYMODEL.QYCode + "/document/image/" + file.zyid + (width + height != "" ? ("/" + width + "/" + height) : "");
                                }
                                Response.Redirect(filename);
                            }
                            else
                            {
                                Response.AddHeader("Content-Disposition", "attachment;filename=" + Name);
                                Response.ContentType = "application/octet-stream";
                                filename             = QYMODEL.FileServerUrl + "/" + QYMODEL.QYCode + "/document/" + file.zyid;
                                Response.Redirect(filename);
                            }
                        }
                        else //返回代表类型的图片
                        {
                            Response.AddHeader("Content-Disposition", "attachment;filename=" + Name);
                            Response.ContentType = "application/octet-stream";
                            filename             = "/ViewV5/images/qywd/" + file.FileExtendName + ".png";
                            Response.Redirect(filename);
                        }
                    }
                    else
                    {
                        if (type == "folder" && MD5 != "")//下载压缩文件
                        {
                            Response.AddHeader("Content-Disposition", "attachment;filename=" + Name);
                            Response.ContentType = "application/octet-stream";
                            string filename = QYMODEL.FileServerUrl + "/zipfile/" + MD5;
                            Response.Redirect(filename);
                        }
                        if (type == "video" && MD5 != "")
                        {
                            string url   = QYMODEL.FileServerUrl + "/" + QYMODEL.QYCode + "/document/" + MD5;
                            Byte[] bytes = new WebClient().DownloadData(url);
                            Response.OutputStream.Write(bytes, 0, bytes.Length);
                        }
                        if (type == "TX" && !string.IsNullOrEmpty(userName))                           //获取用户头像
                        {
                            var userinfo = new JH_Auth_UserB().GetEntity(p => p.UserName == userName); //抓取当前用户信息
                            //JH_Auth_User userinfo = UserInfo.User;
                            if (userinfo != null)
                            {
                                string filename = "";
                                if (userinfo.UserLogoId != null)
                                {
                                    FT_File       file    = new FT_FileB().GetEntity(d => d.ID == userinfo.UserLogoId);
                                    List <string> extends = new List <string>()
                                    {
                                        "jpg", "png", "gif", "jpeg"
                                    };
                                    if (!extends.Contains(file.FileExtendName.ToLower()))//文件不是图片的不返回地址,此方法只用于图片查看
                                    {
                                        return;
                                    }
                                    filename = QYMODEL.FileServerUrl + "/" + QYMODEL.QYCode + "/document/" + file.zyid;
                                    Response.AddHeader("Content-Disposition", "attachment;filename=" + file.Name);
                                    Response.ContentType = "application/octet-stream";
                                }
                                else if (!string.IsNullOrEmpty(userinfo.txurl))
                                {
                                    Response.AddHeader("Content-Disposition", "attachment;filename=" + Name);
                                    Response.ContentType = "application/octet-stream";
                                    filename             = userinfo.txurl;
                                }
                                else
                                {
                                    Response.AddHeader("Content-Disposition", "attachment;filename=" + Name);
                                    Response.ContentType = "application/octet-stream";
                                    filename             = "/ViewV5/images/tx.png";
                                }
                                Response.Redirect(filename);
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { }
            // Response.ContentType = "application/x-zip-compressed";
        }
예제 #20
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.AddHeader("Access-Control-Allow-Origin", "*");
            context.Response.AddHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE"); //支持的http 动作
            context.Response.AddHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type,authorization");
            context.Response.AddHeader("Access-Control-Allow-Credentials", "true");
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            string strAction = context.Request["Action"] ?? "";
            string UserName  = context.Request["UserName"] ?? "";
            string strIP     = CommonHelp.getIP(context);

            Msg_Result Model = new Msg_Result()
            {
                Action = strAction.ToUpper(), ErrorMsg = ""
            };

            if (!string.IsNullOrEmpty(strAction))
            {
                #region 企业号应用callback
                if (strAction == "XXJS")
                {
                    String strCorpID = context.Request["corpid"] ?? "";
                    string strCode   = context.Request["Code"] ?? "";
                    try
                    {
                        JH_Auth_QY    jaq = new JH_Auth_QYB().GetALLEntities().FirstOrDefault();
                        JH_Auth_Model jam = new JH_Auth_ModelB().GetEntity(p => p.ModelCode == strCode);
                        //if (jaq != null && jam != null && !string.IsNullOrEmpty(jam.TJId))
                        if (jaq != null && jam != null)
                        {
                            #region POST
                            if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")
                            {
                                string signature = HttpContext.Current.Request.QueryString["msg_signature"];//企业号的 msg_signature
                                string timestamp = HttpContext.Current.Request.QueryString["timestamp"];
                                string nonce     = HttpContext.Current.Request.QueryString["nonce"];

                                // 获得客户端RAW HttpRequest
                                StreamReader srResult    = new StreamReader(context.Request.InputStream);
                                string       str         = srResult.ReadToEnd();
                                XmlDocument  XmlDocument = new XmlDocument();
                                XmlDocument.LoadXml(HttpContext.Current.Server.UrlDecode(str));
                                string ToUserName = string.Empty;
                                string strde      = string.Empty;
                                string msgtype    = string.Empty;//微信响应类型
                                foreach (XmlNode xn in XmlDocument.ChildNodes[0].ChildNodes)
                                {
                                    if (xn.Name == "ToUserName")
                                    {
                                        ToUserName = xn.InnerText;
                                    }
                                }
                                var pj = new JH_Auth_WXPJB().GetEntity(p => p.TJID == jam.TJId);
                                //Tencent.WXBizMsgCrypt wxcpt = new Tencent.WXBizMsgCrypt(pj.Token, pj.EncodingAESKey, ToUserName);
                                //int n = wxcpt.DecryptMsg(signature, timestamp, nonce, str, ref strde);
                                XmlDocument XmlDocument1 = new XmlDocument();
                                XmlDocument1.LoadXml(HttpContext.Current.Server.UrlDecode(strde));
                                foreach (XmlNode xn1 in XmlDocument1.ChildNodes[0].ChildNodes)
                                {
                                    if (xn1.Name == "MsgType")
                                    {
                                        msgtype = xn1.InnerText;
                                    }
                                    //CommonHelp.WriteLOG(XmlDocument1.OuterXml);
                                }
                                if (msgtype == "event")//处理事件
                                {
                                    //需要处理进入应用的菜单更改事件
                                    string strEvent    = XmlDocument1.ChildNodes[0]["Event"].InnerText;
                                    string strUserName = XmlDocument1.ChildNodes[0]["FromUserName"].InnerText;
                                    string strAgentID  = XmlDocument1.ChildNodes[0]["AgentID"].InnerText;
                                    string strEventKey = XmlDocument1.ChildNodes[0]["EventKey"].InnerText;

                                    if (strEvent.ToLower() == "enter_agent" || strEvent.ToLower() == "view")
                                    {
                                        //进入应用和点击菜单
                                        //JH_Auth_User jau = new JH_Auth_UserB().GetEntity(p => p.ComId == jaq.ComId && p.UserName == strUserName);
                                        //JH_Auth_QY_Model jhqm = new JH_Auth_QY_ModelB().GetEntity(p => p.ComId == jaq.ComId && p.AgentId == strAgentID);
                                        //if (jau != null && jhqm != null)
                                        //{
                                        //    JH_Auth_YYLog jay = new JH_Auth_YYLog();
                                        //    jay.ComId = jaq.ComId;
                                        //    jay.AgentID = strAgentID;
                                        //    jay.CorpID = strCorpID;
                                        //    jay.CRDate = DateTime.Now;
                                        //    jay.CRUser = strUserName;
                                        //    jay.Event = strEvent;
                                        //    jay.EventKey = strEventKey;
                                        //    jay.ModelCode = strCode;
                                        //    jay.ModelID = jhqm.ModelID;
                                        //    jay.QYName = jaq.QYName;
                                        //    jay.TJID = jam.TJId;
                                        //    jay.Type = msgtype;
                                        //    jay.UserName = strUserName;
                                        //    jay.UserRealName = jau.UserRealName;

                                        //    new JH_Auth_YYLogB().Insert(jay);

                                        //    if (strEvent.ToLower() == "enter_agent")
                                        //    {
                                        //        var jays = new JH_Auth_YYLogB().GetEntities(p => p.ComId == jaq.ComId && p.Event == "enter_agent" && p.AgentID == strAgentID && p.CRUser == strUserName);
                                        //        if (jays.Count() <= 1)
                                        //        {
                                        //        }
                                        //    }
                                        //}
                                    }
                                }
                                if (new List <string> {
                                    "text", "image", "voice", "video", "shortvideo", "link"
                                }.Contains(msgtype))                                                                               //处理消息事件
                                {
                                    if (XmlDocument1.ChildNodes.Count > 0)
                                    {
                                        JH_Auth_WXMSG wxmsgModel = new JH_Auth_WXMSG();
                                        wxmsgModel.AgentID      = int.Parse(XmlDocument1.ChildNodes[0]["AgentID"].InnerText);
                                        wxmsgModel.ComId        = jaq.ComId;
                                        wxmsgModel.ToUserName   = XmlDocument1.ChildNodes[0]["ToUserName"].InnerText;
                                        wxmsgModel.FromUserName = XmlDocument1.ChildNodes[0]["FromUserName"].InnerText;
                                        wxmsgModel.CRDate       = DateTime.Now;
                                        wxmsgModel.CRUser       = XmlDocument1.ChildNodes[0]["FromUserName"].InnerText;
                                        wxmsgModel.MsgId        = XmlDocument1.ChildNodes[0]["MsgId"].InnerText;
                                        wxmsgModel.MsgType      = msgtype;
                                        wxmsgModel.ModeCode     = strCode;
                                        wxmsgModel.Tags         = "微信收藏";

                                        switch (msgtype)
                                        {
                                        case "text":
                                            wxmsgModel.MsgContent = XmlDocument1.ChildNodes[0]["Content"].InnerText;
                                            break;

                                        case "image":
                                            wxmsgModel.PicUrl  = XmlDocument1.ChildNodes[0]["PicUrl"].InnerText;
                                            wxmsgModel.MediaId = XmlDocument1.ChildNodes[0]["MediaId"].InnerText;
                                            break;

                                        case "voice":
                                            wxmsgModel.MediaId = XmlDocument1.ChildNodes[0]["MediaId"].InnerText;
                                            wxmsgModel.Format  = XmlDocument1.ChildNodes[0]["Format"].InnerText;
                                            break;

                                        case "video":
                                            wxmsgModel.MediaId      = XmlDocument1.ChildNodes[0]["MediaId"].InnerText;
                                            wxmsgModel.ThumbMediaId = XmlDocument1.ChildNodes[0]["ThumbMediaId"].InnerText;
                                            break;

                                        case "shortvideo":
                                            wxmsgModel.MediaId      = XmlDocument1.ChildNodes[0]["MediaId"].InnerText;
                                            wxmsgModel.ThumbMediaId = XmlDocument1.ChildNodes[0]["ThumbMediaId"].InnerText;
                                            break;

                                        case "link":
                                            wxmsgModel.Description = XmlDocument1.ChildNodes[0]["Description"].InnerText;
                                            wxmsgModel.Title       = XmlDocument1.ChildNodes[0]["Title"].InnerText;
                                            wxmsgModel.URL         = XmlDocument1.ChildNodes[0]["Url"].InnerText;
                                            wxmsgModel.PicUrl      = XmlDocument1.ChildNodes[0]["PicUrl"].InnerText;
                                            break;
                                        }
                                        if (new List <string>()
                                        {
                                            "link", "text"
                                        }.Contains(msgtype))
                                        {
                                            if (msgtype == "link")
                                            {
                                                var jaw = new JH_Auth_WXMSGB().GetEntity(p => p.ComId == jaq.ComId && p.MsgId == wxmsgModel.MsgId);
                                                if (jaw == null)
                                                {
                                                    string strMedType = ".jpg";
                                                    JH_Auth_UserB.UserInfo UserInfo = new JH_Auth_UserB.UserInfo();
                                                    UserInfo = new JH_Auth_UserB().GetUserInfo(jaq.ComId, wxmsgModel.FromUserName);
                                                    //  string fileID = CommonHelp.ProcessWxIMGUrl(wxmsgModel.PicUrl, UserInfo, strMedType);

                                                    //wxmsgModel.FileId = fileID;
                                                    //new JH_Auth_WXMSGB().Insert(wxmsgModel);

                                                    //if (strCode == "TSSQ")
                                                    //{
                                                    //    SZHL_TXSX tx1 = new SZHL_TXSX();
                                                    //    tx1.ComId = jaq.ComId;
                                                    //    tx1.APIName = "TSSQ";
                                                    //    tx1.MsgID = wxmsgModel.ID.ToString();
                                                    //    tx1.FunName = "SENDWXMSG";
                                                    //    tx1.Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                                    //    tx1.CRUser = wxmsgModel.CRUser;
                                                    //    tx1.CRDate = DateTime.Now;
                                                    //    TXSX.TXSXAPI.AddALERT(tx1); //时间为发送时间
                                                    //}
                                                }
                                            }
                                            else
                                            {
                                                new JH_Auth_WXMSGB().Insert(wxmsgModel);
                                            }
                                        }
                                        if (!string.IsNullOrEmpty(wxmsgModel.MediaId))
                                        {
                                            var jaw = new JH_Auth_WXMSGB().GetEntity(p => p.ComId == jaq.ComId && p.MediaId == wxmsgModel.MediaId);
                                            if (jaw == null)
                                            {
                                                string strMedType = ".jpg";
                                                if (strCode == "QYWD" || strCode == "CRM")             //判断模块
                                                {
                                                    if (msgtype == "shortvideo" || msgtype == "video") //视频,小视频
                                                    {
                                                        strMedType = ".mp4";
                                                    }
                                                    if (new List <string>()
                                                    {
                                                        "image", "shortvideo", "video", "voice"
                                                    }.Contains(msgtype))                                                                 //下载到本地服务器
                                                    {
                                                        JH_Auth_UserB.UserInfo UserInfo = new JH_Auth_UserB.UserInfo();
                                                        UserInfo = new JH_Auth_UserB().GetUserInfo(jaq.ComId, wxmsgModel.FromUserName);
                                                        //  string fileID = CommonHelp.ProcessWxIMG(wxmsgModel.MediaId, strCode, UserInfo, strMedType);
                                                        //  wxmsgModel.FileId = fileID;
                                                        // new JH_Auth_WXMSGB().Insert(wxmsgModel);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region GET
                            if (HttpContext.Current.Request.HttpMethod.ToUpper() == "GET")
                            {
                                Auth(jam.Token, jam.EncodingAESKey, jaq.corpId);
                            }
                            #endregion
                        }
                    }
                    catch (Exception ex)
                    {
                        Model.ErrorMsg = ex.ToString();
                        CommonHelp.WriteLOG(ex.ToString());
                    }
                }
                #endregion



                #region 获取唯一code
                if (strAction.ToUpper() == "GetUserCodeByCode".ToUpper())
                {
                    #region 获取Code
                    Model.ErrorMsg = "获取Code错误,请重试";

                    string strCode      = context.Request["code"] ?? "";
                    string strCorpID    = context.Request["corpid"] ?? "";
                    string strModelCode = context.Request["funcode"] ?? "";

                    if (!string.IsNullOrEmpty(strCode))
                    {
                        var qy = new JH_Auth_QYB().GetEntity(p => p.corpId == strCorpID);
                        if (qy != null)
                        {
                            try
                            {
                                //通过微信接口获取用户名
                                WXHelp wx       = new WXHelp(qy);
                                string username = wx.GetUserDataByCode(strCode, strModelCode);
                                CommonHelp.WriteLOG(username);
                                if (!string.IsNullOrEmpty(username))
                                {
                                    var jau = new JH_Auth_UserB().GetUserByUserName(qy.ComId, username);
                                    CommonHelp.WriteLOG(JsonConvert.SerializeObject(jau));

                                    if (jau != null)
                                    {
                                        //如果PCCode为空或者超过60分钟没操作,统统重新生成PCCode,并更新最新操作时间
                                        if (jau.logindate == null)
                                        {
                                            jau.logindate = DateTime.Now;
                                        }
                                        TimeSpan ts = new TimeSpan(jau.logindate.Value.Ticks).Subtract(new TimeSpan(DateTime.Now.Ticks)).Duration();
                                        if (string.IsNullOrEmpty(jau.pccode) || ts.TotalMinutes > 60)
                                        {
                                            string strGuid = CommonHelp.CreatePCCode(jau);
                                            jau.pccode    = strGuid;
                                            jau.logindate = DateTime.Now;
                                            new JH_Auth_UserB().Update(jau);
                                        }
                                        Model.ErrorMsg = "";
                                        Model.Result   = jau.pccode;
                                        Model.Result1  = jau.UserName;
                                        Model.Result2  = ts.TotalMinutes;
                                        Model.Result3  = qy.FileServerUrl;
                                    }
                                }
                                else
                                {
                                    Model.ErrorMsg = "当前用户不存在";
                                }
                            }
                            catch (Exception ex)
                            {
                                Model.ErrorMsg = ex.ToString();
                            }
                        }
                        else
                        {
                            Model.ErrorMsg = "当前企业号未在电脑端注册";
                        }
                    }
                    else
                    {
                        Model.ErrorMsg = "Code为空";
                    }
                    #endregion
                }
                #endregion
                #region 是否存在
                if (strAction.ToUpper() == "isexist".ToUpper())
                {
                    if (context.Request["szhlcode"] != null)
                    {
                        //通过Cookies获取Code
                        //string szhlcode = "5ab470be-4988-4bb3-9658-050481b98fca";
                        string szhlcode = context.Request["szhlcode"].ToString();
                        //通过Code获取用户名,然后执行接口方法
                        var jau = new JH_Auth_UserB().GetUserByPCCode(szhlcode);
                        if (jau == null)
                        {
                            Model.Result = "NOCODE";
                        }
                    }
                }
                #endregion
                #region 发送提醒
                if (strAction.ToUpper() == "AUTOALERT")
                {
                    TXSX.TXSXAPI.AUTOALERT();
                }
                //阿里云转码通知
                if (strAction.ToUpper() == "ZMNOTICE")
                {
                    #region 转码通知


                    Stream       stream = context.Request.InputStream;
                    StreamReader reader = new StreamReader(stream);
                    string       text   = reader.ReadToEnd();
                    reader.Close();

                    if (!string.IsNullOrEmpty(text))
                    {
                        JObject jo      = JObject.Parse(text);
                        JObject message = JObject.Parse(jo["Message"].ToString());

                        string RunId = message["RunId"].ToString();
                        string State = message["State"].ToString();
                        if (State.ToUpper() == "SUCCESS")
                        {
                            JObject MediaWorkflowExecution = JObject.Parse(message["MediaWorkflowExecution"].ToString());
                            string  InputFileobject        = MediaWorkflowExecution["Input"]["InputFile"]["Object"].ToString();

                            if (MediaWorkflowExecution["State"].ToString().ToUpper() == "COMPLETED")
                            {
                                JArray ActivityList = JArray.Parse(MediaWorkflowExecution["ActivityList"].ToString());
                                foreach (var al in ActivityList)
                                {
                                    string alType = al["Type"].ToString();
                                    CommonHelp.WriteLOG("alType:" + alType);

                                    if (alType.ToUpper() == "TRANSCODE")
                                    {
                                        string alname = al["Name"].ToString();
                                        string md5    = InputFileobject.Substring(0, InputFileobject.LastIndexOf("."));

                                        var files = new FT_FileB().GetEntities(p => p.FileMD5 == md5);
                                        foreach (var v in files)
                                        {
                                            v.YLUrl = string.Format("http://chengyanout.oss-cn-beijing.aliyuncs.com/{0}/{1}/{2}", alname, RunId, InputFileobject);
                                            new FT_FileB().Update(v);
                                        }
                                    }
                                }
                            }
                        }

                        //转码成功则删除原始文件
                        //OssClient client = new OssClient("",);

                        context.Response.Write("HTTP/1.1 204 No Content");
                        //}
                    }
                    context.Response.Write("HTTP/1.1 500 No Content");

                    #endregion
                }
                if (strAction.ToUpper() == "WXAPPSIGNATURE")//上传签名
                {
                    var sign = QJY.API.BusinessCode.Signature.GetUploadSignature();
                    Model.Result = sign;
                }
                if (strAction.ToUpper() == "CHECKBINDYH")//判断是否绑定账号
                {
                    //string code = context.Request["code"] ?? "";
                    //if (string.IsNullOrEmpty(code))
                    //{
                    //    Model.ErrorMsg = "请先获取微信code";
                    //}
                    //else
                    //{
                    //    string openid = WXApp.OnLogin(code);
                    //    if (openid == "")
                    //    {
                    //        Model.ErrorMsg = "获取openid失败,请重试";
                    //    }
                    //    else
                    //    {
                    //        Model.Result = openid;
                    //        //判断是否绑定
                    //        var user = new JH_Auth_UserB().GetEntity(p => p.weixinCard == openid);
                    //        if (user != null)
                    //        {
                    //            Model.Result1 = "Y";
                    //            Model.Result2 = user;
                    //        }
                    //    }

                    //}
                }
                if (strAction.ToUpper() == "BINDYH")//绑定用户
                {
                    string password = context.Request["password"] ?? "";
                    string username = context.Request["UserName"] ?? "";
                    string wxopenid = context.Request["wxopenid"] ?? "";
                    string nickname = context.Request["nickname"] ?? "";
                    string txurl    = context.Request["txurl"] ?? "";


                    JH_Auth_QY qyModel = new JH_Auth_QYB().GetALLEntities().First();
                    password = CommonHelp.GetMD5(password);
                    JH_Auth_User userInfo = new JH_Auth_User();

                    List <JH_Auth_User> userList = new JH_Auth_UserB().GetEntities(d => (d.UserName == username || d.mobphone == username) && d.UserPass == password).ToList();
                    if (userList.Count() == 0)
                    {
                        Model.ErrorMsg = "用户名或密码不正确";
                    }
                    else
                    {
                        userInfo = userList[0];
                        if (userInfo.IsUse != "Y")
                        {
                            Model.ErrorMsg = "用户被禁用,请联系管理员";
                        }
                        if (Model.ErrorMsg == "")
                        {
                            userInfo.weixinCard = wxopenid;
                            userInfo.NickName   = nickname;
                            userInfo.txurl      = txurl;
                            new JH_Auth_UserB().Update(userInfo);
                            Model.Result  = userInfo.pccode;
                            Model.Result1 = userInfo.UserName;
                            Model.Result2 = qyModel.FileServerUrl;
                            Model.Result4 = userInfo;
                        }
                    }
                }

                if (strAction.ToUpper() == "LOGIN")
                {
                    string password = context.Request["password"] ?? "";
                    string username = context.Request["UserName"] ?? "";
                    string chkcode  = context.Request["chkcode"] ?? "";
                    Model.ErrorMsg = "";

                    if (chkcode.ToUpper() != "APP")
                    {
                        if (context.Session["chkcode"] != null)
                        {
                            if (!chkcode.ToUpper().Equals(context.Session["chkcode"].ToString()))
                            {
                                Model.ErrorMsg = "验证码不正确";
                            }
                        }
                        else
                        {
                            Model.ErrorMsg = "验证码已过期";
                        }
                    }



                    JH_Auth_QY qyModel = new JH_Auth_QYB().GetALLEntities().First();
                    password = CommonHelp.GetMD5(password);
                    JH_Auth_User userInfo = new JH_Auth_User();

                    List <JH_Auth_User> userList = new JH_Auth_UserB().GetEntities(d => (d.UserName == username || d.mobphone == username) && d.UserPass == password).ToList();
                    if (userList.Count() == 0)
                    {
                        Model.ErrorMsg = "用户名或密码不正确";
                    }
                    else
                    {
                        userInfo = userList[0];
                        if (userInfo.IsUse != "Y")
                        {
                            Model.ErrorMsg = "用户被禁用,请联系管理员";
                        }
                        if (Model.ErrorMsg == "")
                        {
                            if (string.IsNullOrEmpty(userInfo.pccode))
                            {
                                userInfo.pccode = CommonHelp.CreatePCCode(userInfo);
                            }
                            userInfo.logindate = DateTime.Now;
                            new JH_Auth_UserB().Update(userInfo);
                            CacheHelp.Remove(userInfo.pccode);//登陆时清理缓存

                            Model.Result  = userInfo.pccode;
                            Model.Result1 = userInfo.UserName;
                            Model.Result2 = qyModel.FileServerUrl;
                            Model.Result4 = userInfo;
                        }
                    }
                }

                #endregion
            }
            else
            {
                #region 获取SuiteTicket
                if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")
                {
                    string signature = HttpContext.Current.Request.QueryString["msg_signature"];//企业号的 msg_signature
                    string timestamp = HttpContext.Current.Request.QueryString["timestamp"];
                    string nonce     = HttpContext.Current.Request.QueryString["nonce"];

                    // 获得客户端RAW HttpRequest
                    StreamReader srResult = new StreamReader(context.Request.InputStream);
                    string       str      = srResult.ReadToEnd();

                    XmlDocument XmlDocument = new XmlDocument();
                    XmlDocument.LoadXml(HttpContext.Current.Server.UrlDecode(str));

                    string ToUserName = string.Empty;
                    string Encrypt    = string.Empty;

                    string strde       = string.Empty;
                    string strinfotype = string.Empty;


                    foreach (XmlNode xn in XmlDocument.ChildNodes[0].ChildNodes)
                    {
                        if (xn.Name == "ToUserName")
                        {
                            ToUserName = xn.InnerText;
                        }
                        if (xn.Name == "Encrypt")
                        {
                            Encrypt = xn.InnerText;
                        }
                    }

                    var pj = new JH_Auth_WXPJB().GetEntity(p => p.TJID == ToUserName);


                    int    n              = new WXHelp().DecryptMsg(pj.Token, pj.EncodingAESKey, ToUserName, signature, timestamp, nonce, str, ref strde);
                    string strtct         = string.Empty;
                    string strSuiteId     = string.Empty;
                    string strtAuthCorpId = string.Empty;

                    XmlDocument XmlDocument1 = new XmlDocument();
                    XmlDocument1.LoadXml(HttpContext.Current.Server.UrlDecode(strde));

                    foreach (XmlNode xn1 in XmlDocument1.ChildNodes[0].ChildNodes)
                    {
                        if (xn1.Name == "SuiteId")
                        {
                            strSuiteId = xn1.InnerText;
                        }
                        if (xn1.Name == "SuiteTicket")
                        {
                            strtct = xn1.InnerText;
                        }
                        if (xn1.Name == "InfoType")
                        {
                            strinfotype = xn1.InnerText;
                        }
                        if (xn1.Name == "AuthCorpId")
                        {
                            strtAuthCorpId = xn1.InnerText;
                        }
                    }
                    if (strinfotype == "suite_ticket")
                    {
                        pj.Ticket = strtct;

                        new JH_Auth_WXPJB().Update(pj);
                    }


                    HttpContext.Current.Response.Write("success");
                    HttpContext.Current.Response.End();
                }

                #endregion
            }

            IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
            timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            string Result = JsonConvert.SerializeObject(Model, Newtonsoft.Json.Formatting.Indented, timeConverter).Replace("null", "\"\"");
            context.Response.Write(Result);
        }