public string GetContent(string Content, string value, string para) { string sql = "select earth_date,sol,img_id,img_name,img_src from blue.mars where " + para + "='" + value + "' order by img_id"; DataTable dt = ms.S(sql); if (dt.Rows.Count == 0) { Content = Content + "【没有可公开照片】"; } else { Content = (Content == "") ? Content + "NASA 好奇号于公元" + dt.Rows[0]["earth_date"].ToString() + "_" + "火星" + dt.Rows[0]["sol"].ToString() + "所拍摄的部分照片\n(点击照片名称查看)\n" : Content; } foreach (DataRow dr in dt.Rows) { string Append = ""; Append = Append + "<a href=\""; Append = Append + dr["img_src"].ToString(); Append = Append + "\">"; Append = Append + dr["img_id"].ToString(); Append = Append + "-" + dr["img_name"].ToString(); Append = Append + "</a>\n"; if (System.Text.Encoding.UTF8.GetBytes(Content + Append).Length < 2048) { Content = Content + Append; } else { break; } } return(Content); }
public string Rnt(string str) { string Msg = ""; string Notice = ""; str = str.ToLower(); MySQL msql = new MySQL("stock"); string com = "select code,name from stock.300 where code like '%" + str + "%' or name like '%" + str + "%'"; DataTable dt = msql.S(com); if (dt.Rows.Count == 0) { Msg = "请检查关键词\n请回复沪深300成份股代码或名称,如000001或平安银行。\n支持模糊查询\n<a href=\"http://www.csindex.com.cn/zh-CN/indices/index-detail/000300\">点击查看关于沪深300指数</a>"; } else { foreach (DataRow dr in dt.Rows) { Msg = Msg + "<a href=\"http://www.blueyifan.tech:300/" + dr[0] + ".html\">点击查看 " + " " + dr[0].ToString().Substring(2, 6) + " " + dr[1] + "</a>\n"; } Msg = Msg + Notice; if (System.Text.Encoding.UTF8.GetBytes(Msg).Length >= 2048) { Msg = "抱歉,当前无法返回信息。因为腾讯的限制,所返回的消息不能超过2048个字节,请优化关键词。"; } } return(Msg); }
public string FundNet(string str) { string com = "select * from blue.fundnet where code like '%" + str + "%' or name like '%" + str + "%'" + "order by time desc,code"; MySQL msql = new MySQL("blue"); DataTable dt = msql.S(com); string rnt = ""; string notice = "点击基金代码和基金名称即可查看该基金的投资组合数据"; int nLength = System.Text.Encoding.UTF8.GetBytes(notice).Length; if (dt.Rows.Count == 0) { rnt = "抱歉,未查询到基金信息。请检查关键词。\n(仅支持开放式基金,专户产品等不可查。)"; return(rnt); } else { foreach (DataRow dr in dt.Rows) { rnt = rnt + "<a href=\"http://www.blueyifan.tech:9000/Fund2nd/fund/" + dr["code"].ToString() + "/" + dr["name"].ToString() + "\">" + "基金代码:" + dr["code"].ToString() + "</a>\n"; rnt = rnt + "<a href=\"http://www.blueyifan.tech:9000/Fund2nd/fund/" + dr["code"].ToString() + "/" + dr["name"].ToString() + "\">" + "基金名称:" + dr["name"].ToString() + "</a>\n"; rnt = rnt + "最新净值:" + dr["newnet"].ToString() + "\n"; rnt = rnt + "累计净值:" + dr["totalnet"].ToString() + "\n"; rnt = rnt + "日增长值:" + dr["dayincrease"].ToString() + "\n"; rnt = rnt + "日增长率:" + dr["daygrowrate"].ToString() + "\n"; rnt = rnt + "周增长率:" + dr["weekgrowrate"].ToString() + "\n"; rnt = rnt + "月增长率:" + dr["monthgrowrate"].ToString() + "\n"; rnt = rnt + "最新净值时间:" + dr["time"].ToString() + "\n"; rnt = rnt + "\n"; if (System.Text.Encoding.UTF8.GetBytes(rnt).Length >= 2048 - nLength) { rnt = "抱歉,当前无法返回信息。因为腾讯的限制,所返回的消息不能超过2048个字节,请优化关键词。"; return(rnt); } } rnt = rnt + notice; return(rnt); } }
public string RntMsg(string Content, string CounterID) { string com = "select * from blue.turing where state = '1' order by robotid"; MySQL msql = new MySQL("blue"); DataTable dt = msql.S(com); if (dt.Rows.Count == 0) { return("好累啊,明天在说吧。"); } else { string appkey = dt.Rows[0]["APIkey"].ToString(); string url = "http://www.tuling123.com/openapi/api"; var parameters = new Dictionary <string, string>(); if (Content.Length > 30) { Content = Content.Substring(0, 29); } Content = Content.ToLower().Replace("BlueYifan", "图灵机器人"); parameters.Add("key", appkey); //你申请的key parameters.Add("info", Content); //要发送给机器人的内容,不要超过30个字符 parameters.Add("userid", CounterID); //1~32位,此userid针对您自己的每一个用户,用于上下文的关联 string str = sendPost(url, parameters, "post"); JObject jo = JObject.Parse(str); string code = jo["code"].ToString(); string rnt = ""; switch (code) { case "100000": { rnt = jo["text"].ToString(); } break; case "200000": { rnt = jo["text"].ToString() + "\n"; rnt = rnt + "<a href=\"" + jo["url"].ToString() + "\">" + "点击查看" + "</a> "; } break; case "302000": { rnt = jo["text"].ToString() + "\n"; JArray ja = JArray.Parse(jo["list"].ToString()); rnt = rnt + "共" + ja.Count.ToString() + "条\n"; for (int i = 0; i < ja.Count; i++) { JObject jo_ = JObject.Parse(ja[i].ToString()); rnt = rnt + "<a href=\"" + jo_["detailurl"].ToString() + "\">" + (i + 1).ToString() + "、" + jo_["article"].ToString() + "</a> \n"; } } break; case "308000": { rnt = jo["text"].ToString() + "\n"; JArray ja = JArray.Parse(jo["list"].ToString()); rnt = rnt + "共" + ja.Count.ToString() + "条\n"; for (int i = 0; i < ja.Count; i++) { JObject jo_ = JObject.Parse(ja[i].ToString()); rnt = rnt + "<a href=\"" + jo_["detailurl"].ToString() + "\">" + (i + 1).ToString() + "、" + jo_["name"].ToString() + "</a> \n"; } } break; case "40004": { rnt = "抱歉,未能收到您发的信息,可能是因为丢包或其它原因。能再发一遍吗?"; msql.I_D_U("UPDATE blue.turing SET state = '0' where APIkey = '" + appkey + "'"); } break; case "40001": { rnt = "抱歉,我出故障了,错误代码 1 ,可以把错误代码转告给Wan Yifan吗?"; } break; case "40007": { rnt = "抱歉,我出故障了,错误代码 7 ,可以把错误代码转告给Wan Yifan吗?"; } break; case "40002": { rnt = "抱歉,我出故障了,错误代码 2 ,可以把错误代码转告给Wan Yifan吗?"; } break; } rnt = rnt.Replace("图灵机器人", "BlueYifan").Replace("亲爱的", "尊敬的用户").Replace("旧服务已下线,请迁移至 http://api.fanyi.baidu.com", "我不说了"); return(rnt); } }
public string RntMsg(string PicUrl) { WebClient wc = new WebClient(); byte[] bytes = wc.DownloadData(PicUrl); MemoryStream ms = new MemoryStream(bytes); Image img = Image.FromStream(ms); MC = Statistics.PrincipalColorAnalysis((Bitmap)img, 3, 24); MySQL msql = new MySQL("blue"); DataTable dtColor = new DataTable(); dtColor = msql.S("SELECT * FROM blue.color;"); DataTable dtRnt = new DataTable(); dtRnt.Columns.Add("name"); dtRnt.Columns.Add("amount"); for (int i = 0; i < MC.Count; i++) { string cn_name = ""; string en_name = ""; string name = ""; long sim = long.MaxValue; int X1 = MC[i].Color & 255; int X2 = (MC[i].Color & 65280) / 256; int X3 = (MC[i].Color & 16711680) / 65536; foreach (DataRow drColor in dtColor.Rows) { int Y1 = Convert.ToInt32(drColor["R"].ToString()); int Y2 = Convert.ToInt32(drColor["G"].ToString()); int Y3 = Convert.ToInt32(drColor["B"].ToString()); long result = (X1 - Y1) * (X1 - Y1) + (X2 - Y2) * (X2 - Y2) + (X3 - Y3) * (X3 - Y3); //double X = (X1 * Y1 + X2 * Y2 + X3 * Y3); //double Y = Math.Sqrt(X1 * X1 + X2 * X2 + X3 * X3) * Math.Sqrt(Y1 * Y1 + Y2 * Y2 + Y3 * Y3); //double result = X / Y; if (result <= sim) { cn_name = drColor["CN_NAME"].ToString(); en_name = drColor["EN_NAME"].ToString(); name = cn_name + "(" + en_name + ")"; sim = result; } } DataRow drNew = dtRnt.NewRow(); drNew["name"] = name; drNew["amount"] = MC[i].Amount.ToString(); dtRnt.Rows.Add(drNew); } Dictionary <string, DataRow> dict = new Dictionary <string, DataRow>(); //这个字典用于查找第一列相同的项目 List <DataRow> removeRows = new List <DataRow>(); //这个List 存储需要删除的重复行 foreach (DataRow row in dtRnt.Rows) { string key = row["name"].ToString(); DataRow dr_; if (dict.TryGetValue(key, out dr_)) { dr_["amount"] = int.Parse(dr_["amount"].ToString()) + int.Parse(row["amount"].ToString()); removeRows.Add(row); //将这一行加入要删除的行列表中 } else { dict.Add(key, row); } } //删除重复的行 foreach (DataRow row in removeRows) { dtRnt.Rows.Remove(row); } string rnt = ""; foreach (DataRow dr in dtRnt.Rows) { rnt = rnt + "颜色名称:" + dr["name"].ToString() + "\n" + "像素个数:" + dr["amount"].ToString() + "\n\n"; } return(rnt); }