public override WechatAccountInfo GetWechatInfoWithSearchInfo(WechatSearchInfo searchInfo) { var newAccountInfo = new WechatAccountInfo(); var startFileContent = File.ReadAllText(searchInfo.StartFile).ReplaceNoNeedSymbols(); var infoMatch = Regex.Match(startFileContent, @"帐号信息\(\d*\)</a></th></tr></table></div><table.{0,200}?<td>微信号(.{0,400}?" + searchInfo.Account + @".*?)</table>\s<div").Groups[1].Value; var rowMatch = Regex.Matches(infoMatch, @"<tr\S.*?>(.*?</table>)")[0].Groups[1].Value; newAccountInfo.Account = Regex.Match(rowMatch, @"</td><td>(.*?)</td><td .*?><div").Groups[1].Value; var matches = Regex.Matches(Regex.Match(rowMatch, @"<table.*?>(.*?)</table>").Groups[1].Value, @"<tr><td> .*?</td><td> (.*?)</td></tr>"); newAccountInfo.Name = matches[0].Groups[1].Value.FilterHtmlSpecialSymbols(); newAccountInfo.Id = matches[1].Groups[1].Value.FilterHtmlSpecialSymbols(); newAccountInfo.BindQQ = matches[2].Groups[1].Value.FilterHtmlSpecialSymbols(); //newAccountInfo.Account = matches[3].Groups[1].Value.FilterHtmlSpecialSymbols(); newAccountInfo.Sex = matches[4].Groups[1].Value.FilterHtmlSpecialSymbols(); newAccountInfo.Description = matches[5].Groups[1].Value.FilterHtmlSpecialSymbols(); newAccountInfo.Remark = matches[6].Groups[1].Value.FilterHtmlSpecialSymbols(); //newAccountInfo.Account = matches[7].Groups[1].Value.FilterHtmlSpecialSymbols(); //newAccountInfo.Account = matches[8].Groups[1].Value.FilterHtmlSpecialSymbols(); //newAccountInfo.Account = matches[9].Groups[1].Value.FilterHtmlSpecialSymbols(); newAccountInfo.Email = matches[10].Groups[1].Value.FilterHtmlSpecialSymbols(); //newAccountInfo.Email = matches[11].Groups[1].Value.FilterHtmlSpecialSymbols(); //newAccountInfo.Email = matches[12].Groups[1].Value.FilterHtmlSpecialSymbols(); newAccountInfo.Mobile = matches[13].Groups[1].Value.FilterHtmlSpecialSymbols(); return(newAccountInfo); }
private static void GetWeChatInfo() { string _RandomStr = WeChatTools.GetRandomStr(43); using (SmartBindUtil smartBind = new SmartBindUtil("*****@*****.**", "shizhongxiao93")) { //登录成功后,在开发者中心获取开发者信息 WechatDevInfo devInfo = smartBind.GetWechatDev(); WechatAccountInfo accountInfo = smartBind.GetAccount(); //无法获取用户信息,结束操作并跳出 if (accountInfo == null) { return; } //下载头像 if (!string.IsNullOrWhiteSpace(accountInfo.HeadImage)) { string fileName = AppDomain.CurrentDomain.BaseDirectory + "img\\headImg.jpg"; int downStatus = smartBind.DownloadImg(accountInfo.HeadImage, fileName, true); } //下载二维码 if (!string.IsNullOrWhiteSpace(accountInfo.HeadImage)) { string fileName = AppDomain.CurrentDomain.BaseDirectory + "img\\qrCode.jpg"; int downStatus = smartBind.DownloadImg(accountInfo.QRCode, fileName, true); } //设置启用开发模式 int status = smartBind.EnabledDev(1, 2); //启用开发模式失败,结束操作并跳出 if (status != 0) { return; } // 验证服务器接口回调,此处修改服务器配置中的URL和Token int i = 2; while (i > 0) { status = smartBind.SetDevServiceUrl( "http://sjianshang.xicp.net/seekask.ui/weixin", "SeekAsk2015WeiXin", "T9538lolqhzjEQokpni6xSfYQ0LpJChwLvJiohLu4oV", ((int)EncodingAESType.安全模式).ToString()); if (status == 0) { break; } Thread.Sleep(2000); i--; } if (status == 0) { //修改成功! } }; }
public override List <WechatAccountInfo> GetFriendsInOneFile(string filePath, FileOrder order) { var wechatAccountInfoList = new List <WechatAccountInfo>(); var regexString = @"好友列表\(\d*\)</a></th></tr></table></div><table.*?</table>((\s<div)|(<br>))"; if (order == FileOrder.Normal) { regexString = @"<table.*?</table>(<br>|\s</body>)"; } else if (order == FileOrder.Last) { regexString = @"<table.*?</table>\s<div"; } var fileContent = File.ReadAllText(filePath).ReplaceNoNeedSymbols(); var friendContent = Regex.Match(fileContent, regexString).Value; // check if it is public account if (order == FileOrder.Last) { var paIndex = GetWechatPublicAccountIndex(fileContent); if (paIndex > 0 && fileContent.IndexOf(friendContent) >= paIndex) { return(wechatAccountInfoList); } } var friendMatches = Regex.Matches(friendContent, @"<tr\S.*?>(.*?)</table>"); foreach (Match aMatch in friendMatches) { var newWechatAccountInfo = new WechatAccountInfo(); newWechatAccountInfo.Id = Regex.Match(aMatch.Value, @"</td><td>(.*?)</td><td .*?><div").Groups[1].Value; var matches = Regex.Matches(Regex.Match(aMatch.Value, @"<table.*?>(.*?)</table>").Groups[1].Value, @"<tr><td> .*?</td><td> (.*?)</td></tr>"); if (matches.Count < 2) { continue; } newWechatAccountInfo.Account = matches[0].Groups[1].Value.FilterHtmlSpecialSymbols(); newWechatAccountInfo.Name = matches[1].Groups[1].Value.FilterHtmlSpecialSymbols(); newWechatAccountInfo.Mobile = matches[2].Groups[1].Value.FilterHtmlSpecialSymbols(); newWechatAccountInfo.Sex = matches[3].Groups[1].Value.FilterHtmlSpecialSymbols(); newWechatAccountInfo.Description = matches[4].Groups[1].Value.FilterHtmlSpecialSymbols(); newWechatAccountInfo.Remark = matches[5].Groups[1].Value.FilterHtmlSpecialSymbols(); newWechatAccountInfo.Location = matches[6].Groups[1].Value.FilterHtmlSpecialSymbols(); // newWechatAccountInfo. = matches[7].Groups[1].Value.FilterHtmlSpecialSymbols(); 头像 newWechatAccountInfo.BindQQ = matches[8].Groups[1].Value.FilterHtmlSpecialSymbols(); newWechatAccountInfo.BindQQName = matches[9].Groups[1].Value.FilterHtmlSpecialSymbols(); newWechatAccountInfo.Email = matches[10].Groups[1].Value.FilterHtmlSpecialSymbols(); newWechatAccountInfo.BindQQDescription = matches[11].Groups[1].Value.FilterHtmlSpecialSymbols(); newWechatAccountInfo.BindQQTip = matches[12].Groups[1].Value.FilterHtmlSpecialSymbols(); wechatAccountInfoList.Add(newWechatAccountInfo); } return(wechatAccountInfoList); }
public override List <WechatAccountInfo> GetFriendsInOneFile(string filePath, FileOrder order) { var regexString = @"好友统计\(\d*\)</a>[\s\S]*?<table[\s\S]*?>[\s\S]*?</table>"; if (order == FileOrder.Normal) { regexString = "<table.*?abbr=\"真实姓名\".*?</table>"; } else if (order == FileOrder.Last) { regexString = "<table.*?abbr=\"真实姓名\".*?</table>"; } var fileContent = File.ReadAllText(filePath).ReplaceNoNeedSymbols(); var friendContent = Regex.Match(fileContent, regexString).Value; var friendMatches = Regex.Matches(friendContent, @"<tr .*?>(.*?)</tr>"); var wechatAccountInfoList = new List <WechatAccountInfo>(); foreach (Match aMatch in friendMatches) { var newWechatAccountInfo = new WechatAccountInfo(); var matches = Regex.Matches(aMatch.Value, @"<td>.*?</td>"); if (matches.Count > 1) { newWechatAccountInfo.Id = Regex.Match(matches[1].Value, "<td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); } if (matches.Count > 2) { newWechatAccountInfo.Account = Regex.Match(matches[2].Value, "<td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); } if (matches.Count > 3) { newWechatAccountInfo.Name = Regex.Match(matches[3].Value, "<td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); } // newWechatAccountInfo.Name = Regex.Match(matches[4].Value, "<td>(.*) <br/></td>").Groups[1].Value; 真实姓名 if (matches.Count > 5) { newWechatAccountInfo.Mobile = Regex.Match(matches[5].Value, "<td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); } if (matches.Count > 6) { newWechatAccountInfo.Email = Regex.Match(matches[6].Value, "<td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); } if (matches.Count > 7) { newWechatAccountInfo.Count = Regex.Match(matches[7].Value, "<td>(.*) <br/></td>").Groups[1].Value; } wechatAccountInfoList.Add(newWechatAccountInfo); } return(wechatAccountInfoList); }
public override WechatAccountInfo GetWechatInfoWithSearchInfo(WechatSearchInfo searchInfo) { var newAccountInfo = new WechatAccountInfo(); var startFileContent = File.ReadAllText(searchInfo.StartFile); newAccountInfo.Account = Regex.Match(startFileContent, @"账号 <br/></td><td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); newAccountInfo.Name = Regex.Match(startFileContent, @"昵称 <br/></td><td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); //newAccountInfo.pa = Regex.Match(startFileContent, @"密码 <br/></td><td>(.*) <br/></td>").Groups[1].Value; newAccountInfo.Email = Regex.Match(startFileContent, @"邮箱 <br/></td><td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); newAccountInfo.Sex = Regex.Match(startFileContent, @"性别 <br/></td><td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); newAccountInfo.Location = Regex.Match(startFileContent, @"地址 <br/></td><td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); return(newAccountInfo); }
public override List <WechatGroup> GetGroupsInOneFile(string filePath, FileOrder order) { var fileContent = File.ReadAllText(filePath).ReplaceNoNeedSymbols(); // </div><a class = 'subtitle4'.*?>(.*?)\\(\\d*\\) var tableMatches = Regex.Matches(fileContent, "<a class = 'subtitle4'.{0,100}<table(.{0,200}?)abbr=\"群账号\"(.*?)</table>"); var qqIndex = GetQQIndex(fileContent); var groupList = new List <WechatGroup>(); foreach (Match aMatch in tableMatches) { if (qqIndex > 0 && order == FileOrder.Last && fileContent.IndexOf(aMatch.Value) > qqIndex) { continue; } var memberMatches = Regex.Matches(aMatch.Value, @"<tr .*?>(.*?)</tr>"); var newGroup = new WechatGroup(); newGroup.Members = new List <WechatAccountInfo>(); foreach (Match aMembenMatch in memberMatches) { var aNewMember = new WechatAccountInfo(); var memberInfoMatch = Regex.Matches(aMembenMatch.Value, "<td>.*?</td>"); if (string.IsNullOrEmpty(newGroup.Account)) { newGroup.Account = Regex.Match(memberInfoMatch[1].Value, "<td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); } if (string.IsNullOrEmpty(newGroup.Name)) { newGroup.Name = Regex.Match(memberInfoMatch[2].Value, "<td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); } aNewMember.Account = Regex.Match(memberInfoMatch[3].Value, "<td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); aNewMember.Name = Regex.Match(memberInfoMatch[4].Value, "<td>(.*) <br/></td>").Groups[1].Value.FilterHtmlSpecialSymbols(); newGroup.Members.Add(aNewMember); } groupList.Add(newGroup); } return(groupList); }
public override List <WechatGroup> GetGroupsInOneFile(string filePath, FileOrder order) { var fileContent = File.ReadAllText(filePath).ReplaceNoNeedSymbols(); var tableMatches = Regex.Matches(fileContent, @"<table .{0,350}?成员(帐|账)号</td>.*?</table>((\s<div)|(<br>)|(\s</body>))"); var groupList = new List <WechatGroup>(); foreach (Match aMatch in tableMatches) { var newGroup = new WechatGroup(); newGroup.Members = new List <WechatAccountInfo>(); var memberMatches = Regex.Matches(aMatch.Value, @"<tr\S.*?>(.*?)</table></div></td></tr>"); foreach (Match aMembenMatch in memberMatches) { var aNewMember = new WechatAccountInfo(); newGroup.Account = Regex.Match(aMembenMatch.Value, @"</td><td>(.*?)</td><td .*?><div").Groups[1].Value; var memberInfoMatch = Regex.Matches(aMembenMatch.Value, @"<tr><td> .*?</td><td> (.*?)</td></tr>"); if (string.IsNullOrEmpty(newGroup.Name)) { newGroup.Name = memberInfoMatch[0].Groups[1].Value.FilterHtmlSpecialSymbols(); } aNewMember.Name = memberInfoMatch[1].Groups[1].Value.FilterHtmlSpecialSymbols(); aNewMember.Account = memberInfoMatch[2].Groups[1].Value.FilterHtmlSpecialSymbols(); aNewMember.Description = memberInfoMatch[3].Groups[1].Value.FilterHtmlSpecialSymbols(); aNewMember.Location = memberInfoMatch[4].Groups[1].Value.FilterHtmlSpecialSymbols(); // aNewMember.Account = memberInfoMatch[5].Groups[1].Value.FilterHtmlSpecialSymbols(); 头像 if (memberInfoMatch.Count > 6) { aNewMember.Inway = memberInfoMatch[6].Groups[1].Value.FilterHtmlSpecialSymbols(); } newGroup.Members.Add(aNewMember); } groupList.Add(newGroup); } return(groupList); }
/// <summary> /// 得到微信公众平台个人信息 /// </summary> /// <returns></returns> public WechatAccountInfo GetAccount() { WechatAccountInfo account = null; HttpResponseMessage response = null; try { _httpClient = new HttpClient(handler); SetHeader(); response = _httpClient.GetAsync(WeChatUrl.ACCOUNT_INFO_URL + token).Result; if (response.StatusCode == HttpStatusCode.OK) { //已经连接,正在接收数据 string result = response.Content.ReadAsStringAsync().Result; var parser = new JumonyParser(); var htmlDoc = parser.Parse(result); var htmlEles = htmlDoc.Find(".account_setting_area .account_setting_item .meta_content"); if (htmlEles != null && htmlEles.Count() > 0) { var setting = htmlEles.ToList(); account = new WechatAccountInfo(); #region 解析html获取相关文本信息 for (int i = 0; i < setting.Count; i++) { try { var infoText = setting[i].InnerText().Trim(); if (i > 1 && string.IsNullOrWhiteSpace(infoText)) { continue; } switch (i) { case 0: account.HeadImage = setting[0].Find("img").FirstOrDefault() .Attribute("src").AttributeValue; break; case 1: account.QRCode = setting[1].Find("img").FirstOrDefault() .Attribute("src").AttributeValue; break; case 2: account.AccountName = infoText; break; case 3: account.WechatNumber = infoText; break; case 4: SetWechatType(account.WechatType, infoText); break; case 5: account.Introduces = infoText; break; case 6: SetAuthenticate(account.Authenticate, infoText); break; case 7: account.PlaceAddress = infoText; break; case 8: account.SubjectInfo = infoText; break; case 9: account.LoginEmail = infoText; break; case 10: account.AccountId = infoText; break; default: break; } } catch (Exception) { } } #endregion } } } catch (Exception) { } finally { if (response != null) { response.Dispose(); } } return(account); }
public ActionResult BindWeiXinByAccount(string wxUserID, string wxUserPwd) { StatusBackModel errBack = new StatusBackModel(); try { using (SmartBindUtil smartBind = new SmartBindUtil(wxUserID, wxUserPwd)) { //登录成功后,在开发者中心获取开发者信息 WechatDevInfo devInfo = smartBind.GetWechatDev(); WechatAccountInfo accountInfo = smartBind.GetAccount(); //无法获取用户信息,结束操作并跳出 if (accountInfo == null) { errBack.ErrMsg = "无法获取用户信息,结束操作并跳出"; return(Json(errBack)); } if (devInfo != null && !string.IsNullOrWhiteSpace(devInfo.AppSecret)) { devInfo.AppSecret = devInfo.AppSecret.Replace("重置", "").Trim(); if (devInfo.AppSecret.Contains("显示密钥")) { devInfo.AppSecret = null; } } Weixin_Sys_Info info = null; using (SeekAskContext context = new SeekAskContext()) { #region 更新微信号管理 info = context.Weixin_Sys_Info.FirstOrDefault(p => p.Wx_AccountId == accountInfo.AccountId && p.Wx_WechatNumber == accountInfo.WechatNumber && p.Wx_AppId == devInfo.AppId); if (info == null) { info = new Weixin_Sys_Info(); info.Create_Id = "Sys"; info.Create_Name = "系统管理员"; info.Create_IP = WebSiteTools.GetRequestIP(); info.Create_Time = DateTime.Now; info = context.Weixin_Sys_Info.Add(info); } info.Wx_Status = 0; info.Wx_AccountId = accountInfo.AccountId; info.Wx_AccountName = accountInfo.AccountName; info.Wx_WechatNumber = accountInfo.WechatNumber; info.Wx_WechatType = (int)accountInfo.WechatType; info.Wx_Introduces = accountInfo.Introduces; info.Wx_Authenticate = (int)accountInfo.Authenticate; info.Wx_PlaceAddress = accountInfo.PlaceAddress; info.Wx_SubjectInfo = accountInfo.SubjectInfo; info.Wx_LoginEmail = accountInfo.LoginEmail; info.Wx_AppId = devInfo.AppId; if (!string.IsNullOrWhiteSpace(devInfo.AppSecret)) { info.Wx_AppSecret = devInfo.AppSecret; } info.Wx_URL = devInfo.URL; info.Wx_EncodingAESKey = devInfo.EncodingAESKey; info.Wx_EncodingAESType = (int)devInfo.EncodingAESType; info.Modify_Id = "Sys"; info.Modify_Name = "系统管理员"; info.Modify_IP = WebSiteTools.GetRequestIP(); info.Modify_Time = DateTime.Now; info.Is_Deleted = false; context.SaveChanges(); #endregion #region 载头像及设置开发模式 //下载头像 if (!string.IsNullOrWhiteSpace(accountInfo.HeadImage)) { string fileName = "weixinImg/headImg_" + info.WxId + ".jpg"; int downStatus = smartBind.DownloadImg(accountInfo.HeadImage, Server.MapPath("~/") + fileName, true); if (downStatus == (int)HttpStatusCode.OK) { info.Wx_HeadImage = "/" + fileName; } } //下载二维码 if (!string.IsNullOrWhiteSpace(accountInfo.HeadImage)) { string fileName = "weixinImg/qrCode_" + info.WxId + ".jpg"; int downStatus = smartBind.DownloadImg(accountInfo.QRCode, Server.MapPath("~/") + fileName, true); if (downStatus == (int)HttpStatusCode.OK) { info.Wx_QRCode = "/" + fileName; } } //info.Wx_URL = "http://sjianshang.xicp.net/seekask.ui/weixin?appid=" + info.WxId; info.Wx_URL = "http://wx.seekask.cn/weixin?appid=" + info.WxId; info.Wx_Token = WeChatTools.GetRandomStr(20); info.Wx_EncodingAESKey = WeChatTools.GetRandomStr(43); info.Wx_EncodingAESType = 2; context.SaveChanges(); //设置启用开发模式 int status = smartBind.EnabledDev(1, 2); //启用开发模式失败,结束操作并跳出 if (status != 0) { return(Content("启用开发模式失败,结束操作并跳出")); } // 验证服务器接口回调,此处修改服务器配置中的URL和Token status = smartBind.SetDevServiceUrl( info.Wx_URL, info.Wx_Token, info.Wx_EncodingAESKey, info.Wx_EncodingAESType.ToString()); #endregion errBack.BackData = info.WxId; if (status == 0) { errBack.ErrCode = 1; errBack.ErrMsg = "接入成功!"; } else { errBack.ErrMsg = "用户信息获取成功,接入失败!"; } } }; } catch (Exception) { errBack.ErrMsg = "执行异常"; } return(Json(errBack)); }