关于QQ一些功能的实现(二)

关于QQ一些功能的实现(二)

  上周已经写了一篇关于QQ一些功能的实现, 感谢大家的支持. 但评论到70层的时候, 我再也坐不住

了, 因为几乎100%的同学表示自己的QQ号码测试不成功.

  近两万人看过上篇, 不能让这么多同学失望啊! 因此我又加了把劲, 现在只要你按照我的要求做, 就一定

能成功. 晚上又抽空写了个DEMO给大家参考使用. 这个DEMO很给力的哦!!!嘿嘿

  其实正如我在上篇的评论中所说的那样, 我的QQ开通了一个服务的, 只是那几天并没有找到那个网址.

今天早了很久终于让我找到了!! http://wp.qq.com/ 就是这个网址, 大家先要去这个网址登陆一下QQ.

然后就能成功测试我的Demo了 :-)

  我新注册了一个QQ号码测试都是通过的! 因此我觉得这个方法可行, 如果你还是不能登上去, 那真的Soory

了, 我真没辙了...

  目前写了这么几个功能: 查询在线好友  查询某QQ号信息  给某QQ好友发送消息  查看收到的消息  退出登陆

  每个功能我都测试不少遍了, 应该没有多么大的问题的. 欢迎大家下载把玩

  DEMO下载地址: http://cid-07452800dc0167da.office.live.com/self.aspx/.Public/Contact/QQ%5E_DEMO%5E_.zip

  DEMO Project: http://cid-07452800dc0167da.office.live.com/self.aspx/.Public/Contact/QQ%5E_DEMO.zip

  转载请注明: http://www.cnblogs.com/technology/

  DEMO的测试代码部分, 主要测试的就是上一篇中提到的类:

   
   
using System;
using System.Text.RegularExpressions;

namespace QQ_DOMO
{
class Program
{
private static QQ myQQ;
// 输出居中的文本
private static void ConsoleWriteCenter( string s, ConsoleColor color)
{
Console.ForegroundColor
= color;
for ( int i = 0 ; i < Console.BufferWidth / 2 - s.Length / 2 ; i ++ )
Console.Write(
" " );
Console.Write(s);
Console.WriteLine();
Console.ResetColor();
}
// 输入一些文本
private static void ConsoleWrite( string s)
{
Console.Write(s);
}
// 画出=号组成的边界
private static void WriteBorder()
{
Console.ForegroundColor
= ConsoleColor.Blue;
for ( int i = 0 ; i < Console.BufferWidth; i ++ )
Console.Write(
" = " );
Console.ResetColor();
}
// 输入一行文本
private static void ConsoleWriteLine( string s)
{
Console.ForegroundColor
= ConsoleColor.Green;
Console.WriteLine(s);
Console.ResetColor();
}
// 选择Y或者N
private static bool ConsoleSelectYN()
{
Console.ForegroundColor
= ConsoleColor.Yellow;
string s = Console.ReadLine();
if (s.ToUpper() == " Y " )
{
Console.ResetColor();
return true ;
}
if (s.ToUpper() == " N " )
{
Console.ResetColor();
return false ;
}
else
{
Console.WriteLine(
" No Opinion Matches: " + s);
Console.ResetColor();
return false ;
}
}
// 判断是否是一个QQ号码
private static bool regexQQ( string s)
{
Match match
= Regex.Match(s, " [1-9][0-9]{4,} " );
if ( string .IsNullOrEmpty(match.Value.ToString()))
{
Console.WriteLine(
" 你个家伙, " + s + " 根本不是QQ号码! " );
return false ;
}
else
return true ;
}
// 控制台读一行文字
private static string ConsoleReadLine()
{
Console.ForegroundColor
= ConsoleColor.Yellow;
string s = Console.ReadLine();
Console.ResetColor();
return s;
}
// 控制台输出有哪些功能
private static int writeFunc()
{
Console.WriteLine(
" 欢迎选择以下功能[1/2/3/4/5]: " );
ConsoleWriteLine(
" 1. 查询在线好友 " + " /t/t " + " 2. 查询某QQ号信息 " );
ConsoleWriteLine(
" 3. 给某QQ好友发送消息 " + " /t " + " 4. 查看消息 " );
ConsoleWriteLine(
" 5. 退出QQ " );
ConsoleWrite(
" 请您选择一个功能:/t " );
string s = ConsoleReadLine();
int selectNum;
try
{
selectNum
= Convert.ToInt32(s);
if ( 0 < selectNum && selectNum < 6 )
{
WriteBorder();
return selectNum;
}
else
{
Console.WriteLine(
" No Opinion Matches:/t " + selectNum);
WriteBorder();
return 0 ;
}
}
catch
{
Console.WriteLine(
" 您输入了错误的选项! " );
WriteBorder();
return 0 ;
}
}
// 登陆
private static void myQQLogin()
{
ConsoleWriteLine(
" 正在登陆...需要大概10秒钟时间... " );
if (myQQ.QQ_Login() == true )
ConsoleWriteLine(
" 登陆成功... " );
else
ConsoleWriteLine(
@" 登陆失败...您还没有去http://wp.qq.com开通QQ在线状态功能 " );
}
// 获取在线好友
private static void myQQOnLine()
{
ConsoleWriteLine(
" 正在查询在线好友列表, 请稍等... " );
myQQ.QQ_Query_Stat();
ConsoleWriteLine(
" 状态 " + " /t " + " 号码 " + " /t/t " + " 昵称 " );
for ( int i = 0 ; i < myQQ.online_NameK.Length; i ++ )
{
string station;
if (myQQ.online_Station[i] == " 10 " )
station
= " 在线 " ;
if (myQQ.online_Station[i] == " 20 " )
station
= " 离开 " ;
if (myQQ.online_Station[i] == " 30 " )
station
= " 忙碌 " ;
else
station
= " 在线 " ;
if ( ! string .IsNullOrEmpty(myQQ.online_Number[i]))
ConsoleWriteLine(station
+ " /t " + myQQ.online_Number[i] + " /t " + myQQ.online_NameK[i]);
}
WriteBorder();
}
// 查询某人信息
private static void myQQQuery( string num)
{
string [] information = myQQ.QQ_GetInfo(num);
ConsoleWriteLine(
" 联系地址: " + information[ 0 ] + " /t " + " 用户年龄: " + information[ 1 ] + " /t " + " 用户邮箱: " + information[ 2 ]);
ConsoleWriteLine(
" 个人网站: " + information[ 4 ] + " /t " + " 职业: " + information[ 5 ] + " /t " + " 邮编: " + information[ 6 ]);
ConsoleWriteLine(
" 联系电话: " + information[ 7 ] + " /t " + " 简介: " + information[ 8 ]);
ConsoleWriteLine(
" 省份: " + information[ 9 ] + " /t " + " 真实姓名: " + information[ 10 ] + " /t " + " 毕业院校: " + information[ 11 ]);
ConsoleWriteLine(
" 性别: " + information[ 12 ] + " /t/t " + " QQ号: " + information[ 13 ] + " /t " + " 昵称: " + information[ 14 ]);
WriteBorder();
}
// 发送消息
private static void myQQSend( string num, string msg)
{
if (myQQ.QQ_SendMsg(num, msg) == true )
{
ConsoleWriteLine(
" 发送成功... " );
}
else
{
ConsoleWriteLine(
" 发送失败... " );
}
}
// 接受消息
private static void myQQGet()
{
myQQ.GetMsgEx();
if (myQQ.MT != null )
{
for ( int i = 0 ; i < myQQ.MG.Length; i ++ )
{
if (myQQ.MT[i] == " 9 " )
ConsoleWriteLine(myQQ.UN[i]
+ " 说:/t " + myQQ.MG[i]);
}
}
else
{
ConsoleWriteLine(
" 您现在还没有收到信息... " );
}
WriteBorder();
}
static void Main( string [] args)
{
#region test
WriteBorder();
ConsoleWriteCenter(
" MY NAME IS CHEN HUA I MADE THIS JUST FOR FUN " , ConsoleColor.Green);
ConsoleWriteCenter(
" THIS IDEA'S COPYRIGHT IS RESERVED BY CHEN HUA " , ConsoleColor.Green);
ConsoleWriteCenter(
@" PLEASE ATTENTION ME AT www.cnblogs.com/technology " , ConsoleColor.Cyan);
ConsoleWriteCenter(
" DO NOT DO ANYTHING ILLEGAL WITH THIS DEMO OR IDEA " , ConsoleColor.Red);
WriteBorder();
bool agreeOrNot;
do
{
ConsoleWrite(
" 同意作者上面的内容? [Y/N] " + " /t " );
agreeOrNot
= ConsoleSelectYN();
}
while (agreeOrNot == false );
WriteBorder();
Begin:
// 输入QQ号码
string sQQNum;
do
{
ConsoleWrite(
" 赶紧输入你的QQ号码: " + " /t " );
sQQNum
= ConsoleReadLine().Trim();
agreeOrNot
= regexQQ(sQQNum);
}
while (agreeOrNot == false );
string sQQPwd;
do
{
ConsoleWrite(
" 再输入 " + sQQNum + " 的密码: " + " /t " );
sQQPwd
= ConsoleReadLine().Trim();
}
while (agreeOrNot == false );
WriteBorder();
// 开始一些功能
myQQ = new QQ(sQQNum, sQQPwd); // 构造QQ
myQQLogin();
WriteBorder();
#endregion
// 进入死循环执行功能
do
{
// 获取宣传哪一项功能
int selectNum;
do
{
selectNum
= writeFunc(); // 写出QQDemo目前支持的一些功能
if (selectNum == 0 )
agreeOrNot
= false ;
else
agreeOrNot
= true ;
if (selectNum == 1 )
myQQOnLine();
if (selectNum == 2 )
{
ConsoleWrite(
" 输入你要查询哪个QQ号码: " + " /t " );
string num = ConsoleReadLine();
if (regexQQ(num))
{
myQQQuery(num);
}
}
if (selectNum == 3 )
{
ConsoleWrite(
" 请输入收消息的QQ好友:/t " );
string num = ConsoleReadLine();
string msg;
if (regexQQ(num) == true )
{
ConsoleWrite(
" 请输入消息内容:/t/t " );
msg
= ConsoleReadLine();
myQQ.QQ_SendMsg(num, msg);
WriteBorder();
}
}
if (selectNum == 4 )
{
myQQGet();
}
if (selectNum == 5 )
{
myQQ.QQ_Logout();
ConsoleWriteLine(
" 成功退出... " );
WriteBorder();
goto Begin;
}
}
while (agreeOrNot == false );
}
while ( true );
}
}
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值