3.模拟登陆后会获得一个token(令牌)和cookie。
5.知道对方的fakeid就可以进行数据的发送了。
不过里面还有一些小问题,希望有人继续修改和讨论!也有人说这样会被封号,所以请谨慎操作
讲一下我项目里面的主要内容
staticstringGetMd5Str32(stringstr){MD5CryptoServiceProvidermd5Hasher=newMD5CryptoServiceProvider();//Converttheinputstringtoabytearrayandcomputethehash.char[]temp=str.ToCharArray();byte[]buf=newbyte[temp.Length];for(inti=0;i //此处用到了newtonsoft来序列化WeiXinRetInforetinfo=Newtonsoft.Json.JsonConvert.DeserializeObject } 2.在WeiXin.cs类中实现发送数据publicstaticboolSendMessage(stringMessage,stringfakeid){boolresult=false;CookieContainercookie=null;stringtoken=null;cookie=WeiXinLogin.LoginInfo.LoginCookie;//取得cookietoken=WeiXinLogin.LoginInfo.Token;//取得token byte[]byteArray=Encoding.UTF8.GetBytes(padate);//转化 HttpWebRequestwebRequest2=(HttpWebRequest)WebRequest.Create(url); webRequest2.Method="POST"; webRequest2.UserAgent="Mozilla/5.0(WindowsNT5.1;rv:2.0.1)Gecko/20100101Firefox/4.0.1"; webRequest2.ContentType="application/x-www-form-urlencoded"; webRequest2.ContentLength=byteArray.Length; StreamnewStream=webRequest2.GetRequestStream(); //Sendthedata.newStream.Write(byteArray,0,byteArray.Length);//写入参数 newStream.Close(); HttpWebResponseresponse2=(HttpWebResponse)webRequest2.GetResponse(); StreamReadersr2=newStreamReader(response2.GetResponseStream(),Encoding.Default); stringtext2=sr2.ReadToEnd();if(text2.Contains("ok")){result=true;}returnresult;} cookie=WeiXinLogin.LoginInfo.LoginCookie;//取得cookietoken=WeiXinLogin.LoginInfo.Token;//取得token /*获取用户信息的url,这里有几个参数给大家讲一下,1.token此参数为上面的token2.pagesize此参数为每一页显示的记录条数 StreamReadersr2=newStreamReader(response2.GetResponseStream(),Encoding.Default);stringtext2=sr2.ReadToEnd();MatchCollectionmc; //由于此方法获取过来的信息是一个html网页所以此处使用了正则表达式,注意:(此正则表达式只是获取了fakeid的信息如果想获得一些其他的信息修改此处的正则表达式就可以了。)Regexr=newRegex("\"fakeId\"\\s\\:\\s\"\\d+\"");//定义一个Regex对象实例mc=r.Matches(text2);Int32friendSum=mc.Count;//好友总数 stringfackID=""; ArrayListfackID1=newArrayList(); for(inti=0;i returnfackID1;}catch(Exceptionex){thrownewException(ex.StackTrace);}}