Пример #1
0
        public WX_NewsContent Get_WX_News(out string msg, string PUBLICID, string updateValue)
        {
            msg = string.Empty;
            CRMLIBASHX     obj            = JsonConvert.DeserializeObject <CRMLIBASHX>(updateValue);
            WX_NewsContent tp_newscontent = new WX_NewsContent();
            DbConnection   conn           = CyDbConnManager.GetDbConnection("CRMDB");

            try { conn.Open(); }
            catch (Exception e)
            {
                throw new MyDbException(e.Message, true);
            }
            CyQuery query = new CyQuery(conn);

            try
            {
                List <WX_NewsContentList> newscontentlist = new List <WX_NewsContentList>();
                tp_newscontent.articles = newscontentlist;
                query.SQL.Text          = "select * from WX_NEWSDY_ITEM where 1=1";
                if (obj.iJLBH != 0)
                {
                    query.SQL.Add(" and JLBH=" + obj.iJLBH);
                }
                query.Open();
                while (!query.Eof)
                {
                    WX_NewsContentList list = new WX_NewsContentList();
                    newscontentlist.Add(list);
                    list.title              = query.FieldByName("TITLE").AsString;
                    list.thumb_media_id     = query.FieldByName("THUMB_MEDIA_ID").AsString;
                    list.author             = query.FieldByName("AUTHOR").AsString;
                    list.digest             = query.FieldByName("DIGEST").AsString;
                    list.show_cover_pic     = query.FieldByName("BJ_COVER").AsInteger;
                    list.content            = query.FieldByName("CONTNET").AsString;
                    list.content_source_url = query.FieldByName("YWURL").AsString;
                    query.Next();
                }
                query.Close();
            }
            catch (Exception e)
            {
                if (e is MyDbException)
                {
                    throw e;
                }
                else
                {
                    throw new MyDbException(e.Message, query.SqlText);
                }
            }
            finally
            {
                conn.Close();
            }

            return(tp_newscontent);
        }
Пример #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.ContentType = "text/html; charset=utf-8";

            string dir         = context.Server.MapPath("~"); //项目根目录
            string requestType = "";                          //哪个相关操作  比如 用户信息  组信息  后期用在基类中的字段代替

            if (context.Request["requestType"] != null)
            {
                requestType = context.Request["requestType"].ToString();
            }
            if (context.Request["filename"] != null)
            {
                //postData 可以在前台定义好与类对应的格式,并将URL 和 Type设置好
                filename = context.Request["filename"].ToString();
            }
            if (context.Request["localUrl"] != null)
            {
                filename = context.Request["localUrl"];
                filename = filename.Substring(filename.LastIndexOf("\\") + 1);
            }
            //返回提示
            ErrMsg NoteObject = new ErrMsg();

            if (requestType.Length > 0)
            {
                DbConnection conn       = CyDbConnManager.GetActiveDbConnection("CRMDB");
                CyQuery      query      = new CyQuery(conn);
                DateTime     serverTime = CyDbSystem.GetDbServerTime(query);
                query.SQL.Text = "select IP_NET,PSWD,IP_PUB,DIR from FTPCONFIG WHERE ID=1";
                query.Open();
                while (!query.Eof)
                {
                    saveIp = query.FieldByName("IP_PUB").AsString;
                    sPSWD  = query.FieldByName("PSWD").AsString;
                    string FTPDIR = query.FieldByName("DIR").AsString;
                    int    t      = FTPDIR.LastIndexOf("@");
                    sUSER = FTPDIR.Substring(0, t);
                    //sURL = "ftp://" + FTPDIR.Substring(t + 1, FTPDIR.Length - t - 1);
                    sURL = FTPDIR.Substring(t + 1, FTPDIR.Length - t - 1);
                    //this.ftpuser =
                    //obj.sDIR = query.FieldByName("DIR").AsString;
                    //obj.sIP_NET = query.FieldByName("IP_NET").AsString;

                    query.Next();
                }
                query.Close();
                string year        = serverTime.Year.ToString();
                string month       = (serverTime.Month.ToString().CompareTo("10") > 0) ? serverTime.Month.ToString() : 0 + serverTime.Month.ToString();
                string day         = (serverTime.Day.ToString().CompareTo("10") > 0) ? serverTime.Day.ToString() : 0 + serverTime.Day.ToString();
                string FtpsavePath = "WXFtp" + year + month + day;
                #region  此处为FTP上传
                //将文件上传到ftp
                string   savePath = dir + filename;
                FileInfo fileNew  = new FileInfo(savePath);
                string   msg      = string.Empty;
                //ftp不存在此目录
                if (!ftpIsExistsFile(out msg, FtpsavePath, sURL, sUSER, sPSWD))
                {
                    if (msg.Length == 0)
                    {
                        //创建ftp目录
                        MakeDir(out msg, FtpsavePath, sURL, sUSER, sPSWD);
                        if (msg.Length > 0)
                        {
                            NoteObject.errCode    = 1;
                            NoteObject.errMessage = "ftp目录:" + msg;
                            context.Response.Write(JsonConvert.SerializeObject(NoteObject));
                            return;
                        }
                    }
                }
                //上传文件上传不成功报错
                if (!UploadFile(out msg, fileNew, FtpsavePath, sURL, sUSER, sPSWD))
                {
                    NoteObject.errCode    = 2;
                    NoteObject.errMessage = "ftp上传文件:" + msg;
                    context.Response.Write(JsonConvert.SerializeObject(NoteObject));
                    return;
                }
                else
                {
                    NoteObject.result = "http://" + saveIp + "/" + FtpsavePath + "/" + filename.Substring(filename.LastIndexOf("/") + 1);
                    context.Response.Write(JsonConvert.SerializeObject(NoteObject));
                    return;
                }
                #endregion
            }
            else
            {
                //保存公网IP
                saveIp = context.Request.QueryString["sPath"];
                //存在服务器FTP目录
                string FtpsavePath = "FtpImg";
                //文件基础名称
                filename = context.Request.QueryString["sName"];
                //ftp地址  密码 及用户名
                sURL  = context.Request.QueryString["sURL"].ToString().Trim();
                sPSWD = context.Request.QueryString["sPSWD"].ToString().Trim();
                sUSER = context.Request.QueryString["sUSER"].ToString().Trim();
                //取出file上传文件
                HttpPostedFile file = context.Request.Files[0];
                //取本地路径,先将文件上传到服务器(程序服务器)
                string mapPath = context.Server.MapPath("~");
                string path    = mapPath + "\\FtpImg\\";
                if (file != null && file.ContentLength > 0)
                {
                    //form本地上传缓存解决了file取路径浏览器安全导致问题
                    #region  此处先上传本地缓存本地可进行预览(如加预览功能需将ftp上传和本地上传分开写)
                    int    imagesKindInx = file.FileName.LastIndexOf(".");
                    string fileNewName   = ConvertDateTimeInt(DateTime.Now) + filename + file.FileName.Substring(imagesKindInx, file.FileName.Length - imagesKindInx);
                    string savePath      = path + fileNewName;
                    //先删除本地目录及目录下文件(清除文件缓存)
                    try
                    {
                        Directory.Delete(path, true);
                    }
                    catch
                    {
                        try
                        {
                            Directory.CreateDirectory(path);
                        }
                        catch (Exception e)
                        {
                            NoteObject.errCode    = 1;
                            NoteObject.errMessage = "文件目录创建:" + e.Message;
                            context.Response.Write(JsonConvert.SerializeObject(NoteObject));
                        }
                    }
                    try
                    {
                        //本地目录不存在创建
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        //本地命名重复存在删除
                        if (File.Exists(savePath))
                        {
                            File.Delete(savePath);
                        }
                        //保存文件在本地
                        file.SaveAs(savePath);
                    }
                    catch (Exception e)
                    {
                        NoteObject.errCode    = 1;
                        NoteObject.errMessage = "文件提交本地目录:" + e.Message;
                        context.Response.Write(JsonConvert.SerializeObject(NoteObject));
                    }
                    #endregion

                    #region  此处为FTP上传
                    //将文件上传到ftp
                    FileInfo fileNew = new FileInfo(savePath);
                    string   msg     = string.Empty;
                    //ftp不存在此目录
                    if (!ftpIsExistsFile(out msg, FtpsavePath, sURL, sUSER, sPSWD))
                    {
                        if (msg.Length == 0)
                        {
                            //创建ftp目录
                            MakeDir(out msg, FtpsavePath, sURL, sUSER, sPSWD);
                            if (msg.Length > 0)
                            {
                                NoteObject.errCode    = 1;
                                NoteObject.errMessage = "ftp目录:" + msg;
                                context.Response.Write(JsonConvert.SerializeObject(NoteObject));
                                return;
                            }
                        }
                    }
                    //上传文件上传不成功报错
                    if (!UploadFile(out msg, fileNew, FtpsavePath, sURL, sUSER, sPSWD))
                    {
                        NoteObject.errCode    = 2;
                        NoteObject.errMessage = "ftp上传文件:" + msg;
                        context.Response.Write(JsonConvert.SerializeObject(NoteObject));
                        return;
                    }
                    else
                    {
                        NoteObject.result = "http://" + saveIp + "/" + FtpsavePath + "/" + fileNewName;
                        context.Response.Write(JsonConvert.SerializeObject(NoteObject));
                        return;
                    }
                    #endregion
                }
            }
        }
Пример #3
0
        //上传文件(1、读取文件,将文件转换成流写入到请求流当中。2、发送请求,获得FTP服务器的返回信息)
        public bool UploadFileToFTP(out string msg, HttpContext context = null)
        {
            msg = "";
            bool result = false;

            try
            {
                if (GetBuffer(out msg, context))
                {
                    string name = saveFileResource(out msg);

                    ;//写到程序所指定的文件夹当中
                    DbConnection conn       = CyDbConnManager.GetActiveDbConnection("CRMDB");
                    CyQuery      query      = new CyQuery(conn);
                    DateTime     serverTime = CyDbSystem.GetDbServerTime(query);
                    query.SQL.Text = "select IP_NET,PSWD,IP_PUB,DIR from FTPCONFIG WHERE ID=1";
                    query.Open();
                    while (!query.Eof)
                    {
                        wxserverurl = query.FieldByName("IP_PUB").AsString;
                        this.ftppwd = query.FieldByName("PSWD").AsString;
                        string FTPDIR = query.FieldByName("DIR").AsString;
                        int    t      = FTPDIR.LastIndexOf("@");
                        this.ftpuser = FTPDIR.Substring(0, t);
                        this.ftpurl  = "ftp://" + FTPDIR.Substring(t + 1, FTPDIR.Length - t - 1);
                        //this.ftpuser =
                        //obj.sDIR = query.FieldByName("DIR").AsString;
                        //obj.sIP_NET = query.FieldByName("IP_NET").AsString;

                        query.Next();
                    }
                    query.Close();
                    //wxserverurl = ConfigurationManager.AppSettings["WXServerIP"].ToString();
                    //this.ftpurl = ConfigurationManager.AppSettings["WXServerFTP"].ToString();
                    //this.ftpuser = ConfigurationManager.AppSettings["ftpuser"].ToString();
                    //this.ftppwd = ConfigurationManager.AppSettings["ftppwd"].ToString();

                    string year  = serverTime.Year.ToString();
                    string month = (serverTime.Month.ToString().CompareTo("10") > 0) ? serverTime.Month.ToString() : 0 + serverTime.Month.ToString();
                    string day   = (serverTime.Day.ToString().CompareTo("10") > 0) ? serverTime.Day.ToString() : 0 + serverTime.Day.ToString();
                    dirname = "WXFtp//" + year + month + day;
                    FtpMakeDir("WXFtp");
                    FtpMakeDir(dirname);

                    Url = ftpurl + "//" + dirname + "//" + filename.Substring(filename.LastIndexOf("/") + 1);

                    Uri           uri        = new Uri(Url);
                    FtpWebRequest ftprequest = (FtpWebRequest)FtpWebRequest.Create(uri);
                    ftprequest.Method = WebRequestMethods.Ftp.UploadFile;//设置操作类型
                    //STOR <filename>储存(复制)文件到服务器上
                    //STOU <filename>储存文件到服务器名称上
                    ftprequest.Credentials = new NetworkCredential(ftpuser, ftppwd);//设置验证

                    //与FTP交互有关的类
                    FtpState state = new FtpState();
                    if (name == "")//属于只传了个文件绝对路径过来
                    {
                        state.FileName = this.dir + this.filename;
                    }
                    else//传的是文件流,并且已经保存到了本地
                    {
                        state.FileName = fullFileName;
                    }
                    //state.FileName = fullFileName;

                    state.Request = ftprequest;

                    // Asynchronously get the stream for the file contents.  //将要上传的内容写到请求流当中
                    ftprequest.BeginGetRequestStream(
                        new AsyncCallback(EndGetStreamCallback),//委托  ,相当于事件处理函数
                        state);


                    waitObject = state.OperationComplete;//用于线程控制

                    // Block the current thread until all operations are complete.

                    waitObject.WaitOne();//直接收到信号,才开始进程

                    // The operations either completed or threw an exception.
                    if (state.OperationException != null)
                    {
                        msg    = state.OperationException.Message;
                        result = false;
                    }
                    result = true;
                }
                else if (msg != "")
                {
                    msg    = "上传到服务器失败";
                    result = false;
                }
                else if (msg == "")
                {
                    result = true;
                }
            }
            catch (Exception e)
            {
                msg    = e.Message;
                result = false;
            }
            return(result);
        }
Пример #4
0
        //批量打标签
        public override TagJsonBJ PLDBQTag(out string msg, string PUBLICID, string PUBLICIF, string updateValue, string iDJR, string sDJRMC, HttpContext context = null)
        {
            msg    = string.Empty;
            method = "POST";
            //var PUBLICIF1 = "http://wx.changyi.com/SaveWeChatData.ashx";
            //Token = (new WX_Token()).getToken(PUBLICIF1);
            Token = (new WX_Token()).getToken(PUBLICIF);
            Token1 oToken = new Token1();

            oToken = JsonConvert.DeserializeObject <Token1>(Token);

            Url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=" + oToken.result;


            string str = updateValue;

            JObject o     = JObject.Parse(str);
            var     tagid = o["tagid"].ToString();

            var openid_LS = o["openid_list"];



            string str_LS = openid_LS.ToString();



            int count = str_LS.Split(',').Length;



            DbConnection conn  = CyDbConnManager.GetActiveDbConnection("CRMDB");
            CyQuery      query = new CyQuery(conn);


            for (var i = 0; i < count; i++)
            {
                var openid = o["openid_list"][i].ToString();

                int iJLBH = SeqGenerator.GetSeq("WX_HYBQJL");
                query.SQL.Text = "insert into WX_HYBQJL(JLBH,TAGID,OPENID,DJR,DJRMC,DJSJ,CZLX,PUBLICID)";
                query.SQL.Add(" values(:JLBH,:TAGID,:OPENID,:DJR,:DJRMC,:DJSJ,:CZLX,:PUBLICID)");
                query.ParamByName("JLBH").AsInteger     = iJLBH;
                query.ParamByName("DJR").AsInteger      = int.Parse(iDJR);
                query.ParamByName("DJRMC").AsString     = sDJRMC;
                query.ParamByName("OPENID").AsString    = openid;
                query.ParamByName("TAGID").AsInteger    = int.Parse(tagid);
                query.ParamByName("CZLX").AsInteger     = 0;
                query.ParamByName("DJSJ").AsDateTime    = DateTime.Now;
                query.ParamByName("PUBLICID").AsInteger = int.Parse(PUBLICID);
                query.ExecSQL();
            }

            var result = JsonHelper <TagJsonBJ> .ConvertJson(Url, updateValue);

            if (result.errmsg == "ok")
            {
                for (var i = 0; i < count; i++)
                {
                    var openid = o["openid_list"][i].ToString();
                    query.SQL.Text = "update WX_HYBQJL set CZLX=1";
                    query.SQL.Add(" where OPENID=:OPENID AND TAGID=:TAGID ");
                    query.ParamByName("TAGID").AsInteger = int.Parse(tagid);
                    query.ParamByName("OPENID").AsString = openid;
                    query.ExecSQL();


                    query.SQL.Text = "select * FROM WX_HYBQ where TAGID=" + int.Parse(tagid) + "and OPENID=" + "'" + openid + "'";
                    query.Open();
                    if (query.IsEmpty)
                    {
                        query.SQL.Text = "insert into WX_HYBQ(TAGID,OPENID,CREATETIME,PUBLICID)";
                        query.SQL.Add(" values(:TAGID,:OPENID,:CREATETIME,:PUBLICID)");
                        query.ParamByName("TAGID").AsInteger       = int.Parse(tagid);
                        query.ParamByName("OPENID").AsString       = openid;
                        query.ParamByName("CREATETIME").AsDateTime = DateTime.Now;
                        query.ParamByName("PUBLICID").AsInteger    = int.Parse(PUBLICID);

                        query.ExecSQL();
                    }
                }
            }
            else

            {
                for (var i = 0; i < count; i++)
                {
                    var openid = o["openid_list"][i].ToString();
                    query.SQL.Text = "update WX_HYBQJL set CZLX=2";
                    query.SQL.Add(" where OPENID=:OPENID AND TAGID=:TAGID ");
                    query.ParamByName("TAGID").AsInteger = int.Parse(tagid);
                    query.ParamByName("OPENID").AsString = openid;
                    query.ExecSQL();
                }
            }



            return(result);
        }
Пример #5
0
        //public class WX_MenuContentList
        //{
        //    public string name { get; set; }
        //    public string type { get; set; }
        //    public string nbdm { get; set; }
        //    public string url { get; set; }
        //    public string dm;
        //    public List<WX_MenuContentListItem> sub_button { get; set; }
        //}
        //public class WX_MenuContentListItem
        //{
        //    public string type { get; set; }
        //    public string name { get; set; }
        //    public string nbdm { get; set; }
        //    public string url { get; set; }
        //}
        public WX_MenuContent Get_WX_PostMenu(out string msg, string PUBLICID)
        {
            msg = string.Empty;
            WX_MenuContent tp_menucontent = new WX_MenuContent();

            DbConnection conn = CyDbConnManager.GetDbConnection("CRMDB");

            try { conn.Open(); }
            catch (Exception e)
            {
                throw new MyDbException(e.Message, true);
            }
            try
            {
                CyQuery query = new CyQuery(conn);
                List <WX_MenuContentList> menucontentlist = new List <WX_MenuContentList>();
                tp_menucontent.button = menucontentlist;
                List <WX_MenuMiddle> menu = new List <WX_MenuMiddle>();
                try
                {
                    string DbSystemName = CyDbSystem.GetDbSystemName(query.Connection);
                    query.SQL.Clear();
                    query.Params.Clear();
                    query.SQL.Add("select NAME,ASKID,DM,TYPE,URL,PUBLICID from WX_MENU where ").Add(CyDbSystem.GetDataLengthFuncName(conn)).Add("(DM)=2 and PUBLICID='" + PUBLICID + "' order by DM");
                    //query.ParamByName("PUBLICID").AsInteger = Convert.ToInt32(PUBLICID);
                    query.Open();
                    while (!query.Eof)
                    {
                        WX_MenuMiddle tp_menu = new WX_MenuMiddle();
                        menu.Add(tp_menu);

                        tp_menu.key      = Convert.ToString(query.FieldByName("ASKID").AsInteger);
                        tp_menu.dm       = query.FieldByName("DM").AsString;
                        tp_menu.type     = query.FieldByName("TYPE").AsInteger;
                        tp_menu.url      = query.FieldByName("URL").AsString;
                        tp_menu.PUBLICID = query.FieldByName("PUBLICID").AsInteger;
                        if (DbSystemName == "ORACLE")
                        {
                            tp_menu.name = query.FieldByName("NAME").AsString;
                        }
                        else if (DbSystemName == "SYBASE")
                        {
                            tp_menu.name = query.FieldByName("NAME").GetChineseString(200);
                        }
                        query.Next();
                    }
                    query.Close();
                    query.Params.Clear();
                    for (int i = 0; i < menu.Count; i++)
                    {
                        WX_MenuContentList tp_menucontentlist = new WX_MenuContentList();
                        menucontentlist.Add(tp_menucontentlist);
                        tp_menucontentlist.name = menu[i].name;
                        if (menu[i].type == 0)
                        {
                            List <WX_MenuContentListItem> list_menucontentlistitem = new List <WX_MenuContentListItem>();
                            tp_menucontentlist.sub_button = list_menucontentlistitem;
                            query.Params.Clear();
                            query.SQL.Clear();
                            query.SQL.Add("select NAME,TYPE,ASKID,DM,URL,PUBLICID from WX_MENU where " + CyDbSystem.GetDataLengthFuncName(conn) + "(DM)=4 and DM LIKE '" + menu[i].dm + "%" + "' and PUBLICID='" + PUBLICID + "'  order by DM");
                            //query.ParamByName("PUBLICID").AsInteger = Convert.ToInt32(PUBLICID);
                            query.Open();
                            while (!query.Eof)
                            {
                                WX_MenuContentListItem tp_menucontentlistitem = new WX_MenuContentListItem();
                                list_menucontentlistitem.Add(tp_menucontentlistitem);
                                int itemtype = query.FieldByName("TYPE").AsInteger;
                                tp_menucontentlistitem.PUBLICID = query.FieldByName("PUBLICID").AsInteger;
                                if (DbSystemName == "ORACLE")
                                {
                                    tp_menucontentlistitem.name = query.FieldByName("NAME").AsString;
                                }
                                else if (DbSystemName == "SYBASE")
                                {
                                    tp_menucontentlistitem.name = query.FieldByName("NAME").GetChineseString(200);
                                }
                                if (itemtype == 2)
                                {
                                    tp_menucontentlistitem.type = "view";
                                    tp_menucontentlistitem.url  = query.FieldByName("URL").AsString;
                                }
                                if (itemtype == 1)
                                {
                                    tp_menucontentlistitem.type = "click";
                                    tp_menucontentlistitem.key  = Convert.ToString(query.FieldByName("ASKID").AsInteger);
                                }
                                query.Next();
                            }
                            query.Close();
                        }
                        else if (menu[i].type == 1)
                        {
                            tp_menucontentlist.type = "click";
                            tp_menucontentlist.key  = menu[i].key;
                        }
                        else if (menu[i].type == 2)
                        {
                            tp_menucontentlist.type = "view";
                            tp_menucontentlist.url  = menu[i].url;
                        }
                    }
                }
                catch (Exception e)
                {
                    if (e is MyDbException)
                    {
                        throw e;
                    }
                    else
                    {
                        throw new MyDbException(e.Message, query.SqlText);
                    }
                }
            }
            finally
            {
                conn.Close();
            }
            return(tp_menucontent);
        }