Exemple #1
0
 static void Main(string[] args)
 {
     //创建Sqlserver对象
     AbstractDbHelper sqldb = CreateDatabase.GetDatabase("SqlServer", "Data Source=192.168.22.42;Initial Catalog=CPSysDB;User ID=sa;pwd=1;");
     object           obj   = sqldb.GetDataResult("select count(*) from base_user");
     //创建DB2对象
     AbstractDbHelper oledb = CreateDatabase.GetDatabase("IbmDb2", "Provider=IBMDADB2;Database=CPSysDB;Hostname=192.168.22.176;Protocol=TCPIP;Port=50000; Uid=db2inst1;Pwd=db2inst1;");
     object           obj2  = oledb.GetDataResult("select count(*) from base_user");
 }
        private AbstractDbHelper CreateDb()
        {
            ConnectionStringSettings aSett    = System.Configuration.ConfigurationManager.ConnectionStrings["efwplusWebSite"];
            AbstractDbHelper         DbHelper = miniCoreFrame.DbProvider.CreateDatabase.GetDatabase("SqlServer", aSett.ConnectionString);

            miniCoreFrame.Common.Log.Info("连接数据库成功!");
            //miniCoreFrame.Common.Log.Info(GlobalAPP.RunState);
            return(DbHelper);
        }
        //文本处理
        private void TextHandle(string postString)
        {
            string           searchKey = ParserPostXML(postString, "Content");
            AbstractDbHelper DbHelper  = CreateDb();
            string           strsql    = @"SELECT top 10 a.title,a.linkurl FROM ews_ArticleList a";

            strsql += @" WHERE isshow=1 and (title like '%" + searchKey + "%' or intro like '%" + searchKey + "%') order by toplevel DESC, createdate desc";
            DataTable dtAL = DbHelper.GetDataTable(strsql);
            Dictionary <string, string> articleList = new Dictionary <string, string>();

            for (int i = 0; i < dtAL.Rows.Count; i++)
            {
                articleList.Add(dtAL.Rows[i]["title"].ToString(), dtAL.Rows[i]["linkurl"].ToString());
            }
            string tpl  = ContextTemplate(contextType.搜索, articleList);
            string text = BuildOutText(postString, tpl);

            WriteContent(text);
        }
        //微信群发
        public static void SendAll()
        {
            //获取待群发的文章
            AbstractDbHelper            DbHelper    = CreateDb();
            string                      strsql      = @"SELECT top 10 a.ID,a.title,a.linkurl FROM ews_ArticleList a
                                WHERE isshow=1 AND wxflag=0 order by createdate";
            DataTable                   dtAL        = DbHelper.GetDataTable(strsql);
            Dictionary <string, string> articleList = new Dictionary <string, string>();

            for (int i = 0; i < dtAL.Rows.Count; i++)
            {
                articleList.Add(dtAL.Rows[i]["title"].ToString(), dtAL.Rows[i]["linkurl"].ToString());
                strsql = @"UPDATE ews_ArticleList SET wxflag=1 WHERE ID=" + dtAL.Rows[i]["ID"].ToString();
                DbHelper.DoCommand(strsql);
            }
            //微信获取access_token
            string         wxurl_getaccecsstoken = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret;
            string         retJson = HttpHelper.GetResponseString(HttpHelper.CreateGetHttpResponse(wxurl_getaccecsstoken));
            wx_accesstoken wx_at   = Newtonsoft.Json.JsonConvert.DeserializeObject <wx_accesstoken>(retJson);
            //微信群发(需要认证)
            string wxurl_sendall = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=" + wx_at.access_token;
            string tpl           = ContextTemplate(contextType.群发, articleList);
            string text          = @"{
                           \""filter\"":{
                              \""is_to_all\"":false,
                              \""tag_id\"":2
                           },
                           \""text\"":{
                              \""content\"":\""" + tpl + @"\""
                           },
                            \""msgtype\"":\""text\""
                        }";

            retJson = HttpHelper.GetResponseString(HttpHelper.CreatePostHttpResponse(wxurl_sendall, text));
            miniCoreFrame.Common.Log.Info(retJson);
        }