dotNet QQ大法[原创]

昨天下了个qqlite03,研究了一番不算太好用。不过还是从中挖出了一些宝贝。

qqlite03是用JS去做的,在我这边表现不太好(有可能是防火墙的原因)。我把它用dotNet写了个类,表现还算可以。不过在asp.net 2.0里就不能用了,只能在1.1中用,不知其解。拿去来与大家分享。
None.gif using  System;
None.gif
using  System.IO;
None.gif
using  System.Text;
None.gif
using  System.Net;
None.gif
using  System.Data;
None.gif
using  System.Collections;
None.gif
None.gif
None.gif
namespace  Goodspeed.IM
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//// <summary>
InBlock.gif
/// Summary description for QQ
ExpandedSubBlockEnd.gif
/// </summary>

InBlock.gif    public class QQ
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
- 属性 -#region - 属性 -
InBlock.gif        
private string _uid = string.Empty;
InBlock.gif        
private string _password = string.Empty;
InBlock.gif
InBlock.gif        
public string UID
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _uid; }
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
- 构造 -#region - 构造 -
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public QQ()dot.gif{}
InBlock.gif
InBlock.gif        
public QQ(string UID, string PS)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            PS 
= System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(PS, "md5");
InBlock.gif            _password 
= PS;
InBlock.gif            _uid 
= UID;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
- 方法 -#region - 方法 -
InBlock.gif        
//登录
InBlock.gif
        public bool Login()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string sData = "VER=1.0&CMD=Login&SEQ=" + GetTickCount() + "&UIN="+_uid+"&PS=" + _password + "&M5=1&LC=9326B87B234E7235";
InBlock.gif            
string r =SentMsg(sData);
InBlock.gif
InBlock.gif            
return (r.IndexOf("密码错误"== -1);
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//在线好友列表
InBlock.gif
        public DataTable getOnlineList()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string sData = "VER=1.0&CMD=Query_Stat&SEQ=" + GetTickCount() + "&UIN="+_uid+"&TN=300&UN=0";
InBlock.gif            
string r = SentMsg(sData);
InBlock.gif            
//string r = "VER=1.0&SEQ=4688&CMD=QUERY_STAT&UIN=4480911&RES=0&SN=17&FN=1&UN=364121,503894,963947,4874923,5130883,11273626,11845218,17197891,22566157,22882044,26819204,32746072,37245281,59535722,86755989,253466760,258259468&FC=141,108,141,30,168,96,237,3,36,57,255,141,195,57,168,33,180&ST=30,10,30,10,10,10,30,10,10,10,10,10,10,10,10,10,10&NK=%20%20%20奎狼,山鹰,阿鱼,名山工作室,%20情结,billy,天骄,%20%20%20%20jordan,快乐宝贝,阿不,十二月的某天,飞羊习习鸟,green,**~田心,殷若离,冰狐%0a,%20%20移动通道";
InBlock.gif
            string[] my = r.Split('&');
InBlock.gif
InBlock.gif            Hashtable ht 
= getParameter(my);
InBlock.gif
InBlock.gif            
string[] QQnum = (ht["UN"].ToString()).Split(',');
InBlock.gif            
string[] QQface = (ht["FC"].ToString()).Split(',');
InBlock.gif            
string[] QQnick = (ht["NK"].ToString()).Split(',');
InBlock.gif
InBlock.gif            DataTable objTable 
= new DataTable();
InBlock.gif            DataColumn myDataColumn;
InBlock.gif            DataRow myDataRow;
InBlock.gif
InBlock.gif            myDataColumn 
= new DataColumn();
InBlock.gif            myDataColumn.DataType 
= System.Type.GetType("System.String");
InBlock.gif            myDataColumn.ColumnName 
= "num";
InBlock.gif            objTable.Columns.Add(myDataColumn);
InBlock.gif
InBlock.gif            myDataColumn 
= new DataColumn();
InBlock.gif            myDataColumn.DataType 
= System.Type.GetType("System.String");
InBlock.gif            myDataColumn.ColumnName 
= "face";
InBlock.gif            objTable.Columns.Add(myDataColumn);
InBlock.gif
InBlock.gif            myDataColumn 
= new DataColumn();
InBlock.gif            myDataColumn.DataType 
= System.Type.GetType("System.String");
InBlock.gif            myDataColumn.ColumnName 
= "nick";
InBlock.gif            objTable.Columns.Add(myDataColumn);
InBlock.gif
InBlock.gif
InBlock.gif            
for (int i = 0; i < QQnum.Length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                myDataRow 
= objTable.NewRow();
InBlock.gif                myDataRow[
"num"= QQnum[i];
InBlock.gif                myDataRow[
"face"= QQface[i];
InBlock.gif                myDataRow[
"nick"= QQnick[i].Replace("%20""&nbsp;");
InBlock.gif                objTable.Rows.Add(myDataRow);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return objTable;
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//好友列表
InBlock.gif
        public DataTable getList()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string sData = "VER=1.0&CMD=List&SEQ="+GetTickCount()+"&UIN="+_uid+"&TN=300&UN=0";
InBlock.gif            
string r = SentMsg(sData);
InBlock.gif            
//VER=1.0&SEQ=6984&CMD=LIST&UIN=4480911&RES=0&SN=77&FN=1&UN=209433,276938,286066,329085,342780,364121
InBlock.gif
            string[] my = r.Split('&');
InBlock.gif
InBlock.gif            Hashtable ht 
= getParameter(my);
InBlock.gif
InBlock.gif            
string[] QQnum = (ht["UN"].ToString()).Split(',');
InBlock.gif
InBlock.gif            DataTable objTable 
= new DataTable();
InBlock.gif            DataColumn myDataColumn;
InBlock.gif            DataRow myDataRow;            
InBlock.gif
InBlock.gif            myDataColumn 
= new DataColumn();
InBlock.gif            myDataColumn.DataType 
= System.Type.GetType("System.String");
InBlock.gif            myDataColumn.ColumnName 
= "num";
InBlock.gif            objTable.Columns.Add(myDataColumn);
InBlock.gif
InBlock.gif            
for (int i = 0; i < QQnum.Length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                myDataRow 
= objTable.NewRow();
InBlock.gif                myDataRow[
"num"= QQnum[i];
InBlock.gif                objTable.Rows.Add(myDataRow);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return objTable;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//好友信息
InBlock.gif
        public QQFriendInfo getInfo(int UN)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return getInfo(UN.ToString());
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public QQFriendInfo getInfo(string UN)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string sData = "VER=1.0&CMD=GetInfo&SEQ=" + GetTickCount() + "&UIN=" + _uid + "&UN=" + UN;
InBlock.gif            
string r = SentMsg(sData);
InBlock.gif            
string[] my = r.Split('&');
InBlock.gif
InBlock.gif            Hashtable ht 
= getParameter(my);
InBlock.gif            QQFriendInfo qq 
= new QQFriendInfo(ht);
InBlock.gif            
return qq;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//接收消息
InBlock.gif
        public string GetMsg()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string sData = "VER=1.0&CMD=GetMsg&SEQ="+GetTickCount()+"&UIN="+_uid;
InBlock.gif            
//VER=1.0&SEQ=6984&CMD=GETMSG&UIN=4480911&RES=0&MT=9&UN=63027896&MG=好,你来了~~ 
InBlock.gif
            string r = SentMsg(sData);
InBlock.gif            
string[] my = r.Split('&');
InBlock.gif
InBlock.gif            Hashtable ht 
= getParameter(my);
InBlock.gif            
string UN = ht["UN"].ToString();
InBlock.gif            
if (UN == "0"return "";
InBlock.gif            QQFriendInfo qq 
= getInfo(UN);
InBlock.gif            
return qq.NickName + "(" + UN + "):" + ht["MG"].ToString();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//发送消息
InBlock.gif
        public void SendMessage(int UN, string msg)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            SendMessage(UN.ToString(), msg);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void SendMessage(string UN, string msg)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string sData = "VER=1.0&CMD=CLTMSG&SEQ=1091071257750&UIN=4480911&UN=" + UN + "&MG=" + msg;
InBlock.gif            SentMsg(sData);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//登出
InBlock.gif
        public void Logout()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string sData = "VER=1.0&CMD=Logout&SEQ=" + GetTickCount() + "&UIN=" + _uid;
InBlock.gif            SentMsg(sData);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
私有方法#region 私有方法
InBlock.gif        
//方法返回一个整数值,这个整数代表了从 1970 年 1 月 1 日开始计算到 Date 对象中的时间之间的毫秒数
InBlock.gif
        private string GetTickCount()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DateTime o 
= new DateTime(197011);
InBlock.gif            TimeSpan ts 
= DateTime.Now - o;
InBlock.gif
InBlock.gif            
return ts.TotalMilliseconds.ToString("0");
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private string SentMsg(string sData)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string g_qqServer = "http://127.0.0.1:8000/";
InBlock.gif            
// string g_qqServer ="http://tqq.tencent.com:8000/";
InBlock.gif
            ASCIIEncoding encoding = new ASCIIEncoding();
InBlock.gif            
byte[] data = encoding.GetBytes(sData);
InBlock.gif
InBlock.gif            HttpWebRequest myRequest 
= (HttpWebRequest)WebRequest.Create(g_qqServer);
InBlock.gif            myRequest.Method 
= "POST";
InBlock.gif            myRequest.ContentType 
= "application/x-www-form-urlencoded";
InBlock.gif            myRequest.ContentLength 
= data.Length;
InBlock.gif            Stream newStream 
= myRequest.GetRequestStream();
InBlock.gif            newStream.Write(data, 
0, data.Length);
InBlock.gif            newStream.Close();
InBlock.gif
InBlock.gif            HttpWebResponse res 
= (HttpWebResponse)myRequest.GetResponse();
InBlock.gif            StreamReader sr 
= new StreamReader(res.GetResponseStream());
InBlock.gif            
string sHtml = sr.ReadToEnd();
InBlock.gif            sr.Close();
InBlock.gif            res.Close();
InBlock.gif
InBlock.gif            
return sHtml;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private Hashtable getParameter(string[] my)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Hashtable ht 
= new Hashtable();
InBlock.gif
InBlock.gif            
foreach (string si in my)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string[] sArray = si.Split('=');
InBlock.gif                ht.Add(sArray[
0], sArray[1]);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
return ht;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
public class QQFriendInfo
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
- 属性 -#region - 属性 -
InBlock.gif       
InBlock.gif        
private string _qqnum = string.Empty;
InBlock.gif        
private string _nickname = string.Empty;
InBlock.gif        
private string _face = string.Empty;
InBlock.gif        
private string _age = string.Empty;
InBlock.gif        
private string _sex = string.Empty;
InBlock.gif        
private string _province = string.Empty;
InBlock.gif        
private string _email = string.Empty;
InBlock.gif        
private string _address = string.Empty;
InBlock.gif        
private string _postcode = string.Empty;
InBlock.gif        
private string _phone = string.Empty;
InBlock.gif        
private string _job = string.Empty;
InBlock.gif        
private string _homepage = string.Empty;
InBlock.gif        
private string _remark = string.Empty;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string QQNumdot.gif{get dot.gifreturn QQNum; }}
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string NickName dot.gifget dot.gifreturn _nickname; } }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string Face dot.gifget dot.gifreturn _face; } }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string Age dot.gifget dot.gifreturn _age; } }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string Sex dot.gifget dot.gifreturn _sex; } }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string Province dot.gifget dot.gifreturn _province; } }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string Email dot.gifget dot.gifreturn _email; } }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string Address dot.gifget dot.gifreturn _address; } }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string Postcode dot.gifget dot.gifreturn _postcode; } }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string Phone dot.gifget dot.gifreturn _phone; } }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string Job dot.gifget dot.gifreturn _job; } }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string HomePage dot.gifget dot.gifreturn _homepage; } }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string Rremark dot.gifget dot.gifreturn _remark; } }
InBlock.gif
InBlock.gif        
public QQFriendInfo(Hashtable ht)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif             
/**//*
InBlock.gif        UIN=4480911
InBlock.gifFC=156
InBlock.gifAG=0
InBlock.gifSX=0
InBlock.gif
InBlock.gifPV=湖北省
InBlock.gifEM=goodspeed@21cn.com
InBlock.gifAD=湖北省武汉市63612264邮政信箱
InBlock.gifPC=430063
InBlock.gifPH=
InBlock.gifRN=什么都没有
InBlock.gifPR=VIM:30028181149%0d%0aUC:279163%0d%0a搜Q:good2speed@sohu.com
InBlock.gifJB=失业中
InBlock.gifSC=-
InBlock.gifHP=
http://www.cnblogs.com/goodspeed 
ExpandedSubBlockEnd.gif        
*/

InBlock.gif            _qqnum 
= ht["UIN"].ToString();
InBlock.gif            _nickname 
= ht["NK"].ToString().Replace("%20""&nbsp;");
InBlock.gif            _address 
= ht["AD"].ToString();
InBlock.gif            _age 
= ht["AG"].ToString();
InBlock.gif            _email 
= ht["EM"].ToString();
InBlock.gif            _face 
= ht["FC"].ToString();
InBlock.gif            _homepage 
= ht["HP"].ToString();
InBlock.gif            _job 
= ht["JB"].ToString();
InBlock.gif            _phone 
= ht["PH"].ToString();
InBlock.gif            _postcode 
= ht["PC"].ToString();
InBlock.gif            _province 
= ht["PV"].ToString();
InBlock.gif            _remark 
= ht["PR"].ToString();
InBlock.gif            _sex 
= (ht["SX"].ToString() == "0"? "" : "";
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值