private string GetRandHostUrl() { Random ran = new Random(); string randUrl = ""; bool isBlacklist = true; // int xx = 0;//没有做剔除操作,暂时限制循环次数。 while (isBlacklist) { try { string hosturl = ConfigTool.ReadVerifyConfig("HostHttp", "HostUrl");//这些域名都需要指向用户最终要访问的站点 string[] sArray = hosturl.Split(','); int RandKey1 = ran.Next(0, sArray.Length);//随机选中域名 randUrl = sArray[RandKey1]; wxCheckApi = ConfigTool.ReadVerifyConfig("wxCheckApi", "WeiXin");; wxCheckApiKey = ConfigTool.ReadVerifyConfig("wxCheckApiKey", "WeiXin"); WebRequest wr = (HttpWebRequest)WebRequest.Create(wxCheckApi + "?key=" + wxCheckApiKey + "&url=http://" + randUrl); var stream = wr.GetResponse().GetResponseStream(); var sr = new StreamReader(stream, Encoding.GetEncoding("UTF-8")); var all = sr.ReadToEnd(); sr.Close(); stream.Close(); //读取网站的数据 if (all.Contains("屏蔽")) { //剔除域名 if (hosturl.Contains(sArray[RandKey1] + ",")) { hosturl = hosturl.Replace(sArray[RandKey1] + ",", ""); } if (hosturl.Contains("," + sArray[RandKey1])) { hosturl = hosturl.Replace("," + sArray[RandKey1], ""); } ConfigTool.WriteVerifyConfig("Host", hosturl, "HostUrl");//剔除黑名单域名 } else { isBlacklist = false; return(randUrl); } } catch (Exception ex) { randUrl = ""; //randUrl = ex.Message.ToString(); return(randUrl); } } return(randUrl); }
public void ProcessRequest(HttpContext context) { //GET /index.php?g=Wap&m=Vote&a=index&token=uDSrEHNs9CFGcTSC&wecha_id=ocMqvwRjzPH9eseHRc_Z9nlP-DSM&id=25&iMicms=mp.weixin.qq.com HTTP/1.1 context.Response.ContentType = "text/plain"; pToken = QueryString("token"); pWecha_id = QueryString("wecha_id"); pId = QueryString("id"); iMicms = QueryString("iMicms"); stateUrl = ConfigTool.ReadVerifyConfig("state", "Other"); if (stateUrl.Equals("true")) { string tokens = ConfigTool.ReadVerifyConfig("tokens", "Other"); if (tokens.Contains(pToken)) { string pRedirectUrl = "http://" + GetRandHostUrl() + "/index.php?g=Wap&m=Vote&a=index&id=" + pId + "&token=" + pToken + "&wecha_id=" + pWecha_id + "&iMicms=" + iMicms; string json = "{\"Mode\": \"WXCheckUrl\", \"Param\": \"{\'CheckUrl\':\'" + pRedirectUrl + "\'}\"}"; _service = new ServiceApi(); string resultCheck = _service.Api(json); if (!resultCheck.Contains("屏蔽")) { //域名未被微信封号 hmdOpenid = ConfigTool.ReadVerifyConfig("hmdOpenid", "Other"); if (!hmdOpenid.Contains(pWecha_id)) { //当前访问的用户不在黑名单 redirectUrl = pRedirectUrl; Logger.WriteLoggger("openid:" + pWecha_id); //后续可以扩展,可以屏蔽一些恶意投诉的微信号 } } else { //修改投票状态 ConfigTool.WriteVerifyConfig("state", "false", "Other"); Logger.WriteLoggger("恶意的openid:" + pWecha_id); //后续可以扩展,可以屏蔽一些恶意投诉的微信号 } } } context.Response.Redirect(redirectUrl); // context.Response.Write(redirectUrl); context.Response.End(); }