發送 poll包 public static void Login_PostPoll() { try { string url = "http://d1.web2.qq.com/channel/poll2"; string dat = "{\"ptwebqq\":\"#{ptwebqq}\",\"c ...
發送 poll包
public static void Login_PostPoll()
{
try
{
string url = "http://d1.web2.qq.com/channel/poll2";
string dat = "{\"ptwebqq\":\"#{ptwebqq}\",\"clientid\":53999199,\"psessionid\":\"#{psessionid}\",\"key\":\"\"}";
dat = dat.Replace("#{ptwebqq}", Login_ptwebqq).Replace("#{psessionid}", Login_Psessionid);
dat = "r=" + HttpUtility.UrlEncode(dat);
HTTP.Post_Async_Action action = Message_Get;
HTTP.Post_Async(url, dat, action);
}
catch (Exception) { Login_PostPoll(); }
}
#endregion
#region 接收到消息的回調函數
/// <summary>
/// 接收到消息的回調函數
/// </summary>
/// <param name="data">接收到的數據(json)</param>
private static bool Running = true;
public static void Message_Get(string data)
{
Task.Run(() => Login_PostPoll());
if (Running)
Task.Run(() => Message_Process(data));//這個是處理收到信息的另外一個方法具體處理 在源碼
}
以上就是poll包的處理以及 收到的信息處理
接下來是 發送的
上面是發送的連接以及 發送後返回的 poll包信息。代碼如下
/// <summary>
///
/// </summary>
/// <param name="type">私聊0 群聊1 討論組2</param>
/// <param name="uin">uin</param>
/// <param name="messageToSend">消息</param>
/// <param name="auto"></param>
/// <returns></returns>
public static bool Login_Postsend_buddy_msg(int type, string uin, string messageToSend)
{
if (messageToSend.Equals("") || uin.Equals(""))
return false;
string[] tmp = messageToSend.Split("{}".ToCharArray());
messageToSend = "";
for (int i = 0; i < tmp.Length; i++)
if (!tmp[i].Trim().StartsWith("..[face") || !tmp[i].Trim().EndsWith("].."))
messageToSend += "\\\"" + tmp[i] + "\\\",";
else
messageToSend += tmp[i].Replace("..[face", "[\\\"face\\\",").Replace("]..", "],");
messageToSend = messageToSend.Remove(messageToSend.LastIndexOf(','));
messageToSend = messageToSend.Replace("\r\n", "\n").Replace("\n\r", "\n").Replace("\r", "\n").Replace("\n", Environment.NewLine);
try
{
string to_groupuin_did, url;
switch (type)
{
case 0:
to_groupuin_did = "to";
url = "http://d1.web2.qq.com/channel/send_buddy_msg2";
break;
case 1:
to_groupuin_did = "group_uin";
url = "http://d1.web2.qq.com/channel/send_qun_msg2";
break;
case 2:
to_groupuin_did = "did";
url = "http://d1.web2.qq.com/channel/send_discu_msg2";
break;
default:
return false;
}
string postData = "{\"#{type}\":#{id},\"content\":\"[#{msg},[\\\"font\\\",{\\\"name\\\":\\\"繁體\\\",\\\"size\\\":10,\\\"style\\\":[0,0,0],\\\"color\\\":\\\"000000\\\"}]]\",\"face\":#{face},\"clientid\":53999199,\"msg_id\":#{msg_id},\"psessionid\":\"#{psessionid}\"}";
postData = "r=" + HttpUtility.UrlEncode(postData.Replace("#{type}", to_groupuin_did).Replace("#{id}", uin).Replace("#{msg}", messageToSend).Replace("#{face}", SelfInfo.face.ToString()).Replace("#{msg_id}", rand.Next(10000000, 99999999).ToString()).Replace("#{psessionid}", Login_Psessionid));
string dat = HTTP.Post(url, postData, "http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2");
return dat.Equals("{\"errCode\":0,\"msg\":\"send ok\"}");
}
catch (Exception)
{
return false;
}
}
這一講費了很多時間,中間又去查了資料。特別是處理返回的 包的json ,不知道怎麼格式化,只能替換出來,拿到想要的數據。
到現在為止,整個新手smart qq http 協議的教程 已經可以說完成了,因為這個協議的功能非常單一,並且很多都已經被TX去掉的,就像獲取好友的 真實QQ也已經是報錯的。接下來就可以做圖形界面,還有部分業務了(qq機器人自動回覆等)