예제 #1
0
 public static void Un_Pack_ErrMsg(int errorType, byte[] bytes)
 {
     try
     {
         bytes = bytes.Skip(2).ToArray();
         bytes = bytes.Skip(1).ToArray();
         bytes = bytes.Skip(4).ToArray();
         bytes = bytes.Skip(2).ToArray();
         var errType = BitConverter.ToInt32(bytes.Take(4).ToArray().Reverse().ToArray(), 0);
         bytes = bytes.Skip(4).ToArray();
         var titleLen = Convert.ToInt32(BitConverter.ToInt16(bytes.Take(2).ToArray().Reverse().ToArray(), 0));
         bytes = bytes.Skip(2).ToArray();
         var title      = Encoding.UTF8.GetString(bytes, 0, titleLen);
         var messageLen = Convert.ToInt32(BitConverter.ToInt16(bytes.Skip(titleLen).Take(2).ToArray().Reverse().ToArray(), 0));
         var message    = Encoding.UTF8.GetString(bytes.Skip(titleLen + 2).ToArray(), 0, messageLen);
         API.last_error = title + ":" + errorType.ToString() + " " + message;
         Debug.Print(API.last_error);
         SDK.GetLog(API.last_error);
     }
     catch (Exception ex)
     {
     }
 }
예제 #2
0
 public static void GetSimpleInfo(byte[] BytesIn)
 {
     BytesIn = BytesIn.Skip(4).ToArray();
     JceStruct.StartDecode(BytesIn);
     if (JceStruct.DicSimpleList.Count > 0)
     {
         var hex = JceStruct.DicSimpleList[0].ElementAt(0).Value;
         JceStruct.StartDecode(API.HexStrToByteArray(hex));
         if (JceStruct.DicMAP.Count > 0)
         {
             hex = JceStruct.DicMAP[0].ElementAt(0).Value.Item2;
             JceStruct.StartDecode(API.HexStrToByteArray(hex));
             if (JceStruct.DicList.Count > 0)
             {
                 var info = JceStruct.DicList[0].ElementAt(0).Value.Trim().Split('/');
                 API.NickName = info[4];
                 List <string> list = new List <string> {
                     info[0], info[4], info[3], (info[5] == "0")?"女":"男", info[12], info[14]
                 };
                 SDK.GetValue(list);
             }
         }
     }
 }
예제 #3
0
        public static API.FriendWithdrawInfo ParsingFriendMsg(byte[] byteIn)
        {
            string TextMsg   = "";
            string FaceMsg   = "";
            string HotPicMsg = "";
            string PicMsg    = "";
            string AudioMsg  = "";
            string VideoMsg  = "";
            string ReplyMsg  = "";
            string XmlMsg    = "";

            byteIn = byteIn.Skip(4).ToArray();
            using (MemoryStream ms = new MemoryStream(byteIn))
            {
                try
                {
                    var  result   = Serializer.Deserialize <FriendMsgStuct>(ms);
                    long qqid     = result.MessageInfo[0].QQInfo.QQFromInfo.QQId;
                    long qqfromid = result.MessageInfo[0].QQInfo.QQFromInfo.QQFromId;
                    API.FriendWithdraw.MsgReqId     = result.MessageInfo[0].QQInfo.QQFromInfo.fromReq;
                    API.FriendWithdraw.MsgTimeStamp = result.MessageInfo[0].QQInfo.QQFromInfo.RecvTime;
                    if (result.MessageInfo[0].QQInfo.MsgInfo.FileUploadInfo != null)                     //文件上传消息
                    {
                        Debug.Print("朋友文件上传:" + "\r\n" + BitConverter.ToString(result.MessageInfo[0].QQInfo.MsgInfo.FileUploadInfo).Replace("-", " "));
                        using (MemoryStream mStream = new MemoryStream(result.MessageInfo[0].QQInfo.MsgInfo.FileUploadInfo))
                        {
                            var MsgResult = Serializer.Deserialize <FileMessageStruct>(mStream);
                            var fileName  = MsgResult.FileInfo.FileName;
                            var fileSize  = MsgResult.FileInfo.FileSize;
                            API.FriendWithdraw.MsgRandomId = MsgResult.FileInfo.FileRandId;
                        }
                    }
                    if (result.MessageInfo[0].QQInfo.MsgInfo.MsgTextInfo.fonts != null)
                    {
                        API.FriendWithdraw.MsgRandomId = result.MessageInfo[0].QQInfo.MsgInfo.MsgTextInfo.fonts.fromRandom;
                    }
                    if (result.MessageInfo[0].QQInfo.MsgInfo.MsgTextInfo.MsgContent != null)
                    {
                        var msgByte = result.MessageInfo[0].QQInfo.MsgInfo.MsgTextInfo.MsgContent;
                        Debug.Print("朋友消息内容:" + "\r\n" + BitConverter.ToString(msgByte).Replace("-", " "));
                        using (MemoryStream mStream = new MemoryStream(msgByte))
                        {
                            var MsgResult = Serializer.Deserialize <MessageStruct>(mStream);
                            if (MsgResult.ReplyMessage != null)                             //是带回复的消息
                            {
                                string replyContent = "";
                                for (var i = 0; i < MsgResult.ReplyMessage.OldMsgContent.Count; i++)
                                {
                                    replyContent = replyContent + MsgResult.ReplyMessage.OldMsgContent[i].content.Replace("\n", "").Replace("\r", "").Replace("\r\n", "");
                                }
                                ReplyMsg = " [Reply=@" + MsgResult.ReplyMessage.thisQQId.ToString() + "内容:" + replyContent + "]";
                            }
                            if (MsgResult.TextMessageContent != null)                             //有文本或小表情或热图内容
                            {
                                for (var i = 0; i < MsgResult.TextMessageContent.Count; i++)
                                {
                                    TextMsg = TextMsg + MsgResult.TextMessageContent[i].content;
                                }
                            }
                            if (MsgResult.BigFace != null)                             //有大表情内容
                            {
                                for (var i = 0; i < MsgResult.BigFace.Count; i++)
                                {
                                    var FaceId = MsgResult.BigFace[i].FaceId;
                                    FaceMsg = FaceMsg + " [BigFaceId=" + FaceId.ToString() + "]";
                                }
                            }
                            if (MsgResult.PicMessageContent != null)                             //有图片内容
                            {
                                for (var i = 0; i < MsgResult.PicMessageContent.Count; i++)
                                {
                                    PicMsg = PicMsg + "https://c2cpicdw.qpic.cn/offpic_new/" + MsgResult.PicMessageContent[i].PicGuid + "/0 ";
                                }
                                PicMsg = "[pic,link=" + PicMsg + "]";
                            }
                            //If Not MsgResult.XMLMessage Is Nothing Then '有XML内容
                            //    Dim xmlByte = MsgResult.XMLMessage
                            //    XmlMsg = Encoding.UTF8.GetString(xmlByte)
                            //End If
                            if (result.MessageInfo[0].QQInfo.MsgInfo.MsgTextInfo.AudioContent != null)                             //有语音内容
                            {
                                using (MemoryStream msStream = new MemoryStream(result.MessageInfo[0].QQInfo.MsgInfo.MsgTextInfo.AudioContent))
                                {
                                    var Ret = Serializer.Deserialize <AudioMessageStruct>(msStream);
                                    AudioMsg = Ret.AudioUrl;
                                }
                            }
                            if (MsgResult.VideoMessageContent != null)                             //有视频内容
                            {
                                for (var i = 0; i < MsgResult.VideoMessageContent.Count; i++)
                                {
                                    VideoMsg = VideoMsg + "[video,guid=" + MsgResult.VideoMessageContent[i].VideoGuid + "]";
                                }
                            }
                            SDK.GetResult(qqfromid.ToString(), qqfromid.ToString(), ReplyMsg + FaceMsg + HotPicMsg + TextMsg + PicMsg + AudioMsg + VideoMsg);
                        }
                    }
                    var MsgTimeStamp = result.MessageInfo[0].QQInfo.QQFromInfo.RecvTime;
                    using (var mMemoryStream = new MemoryStream())
                    {
                        Serializer.Serialize(mMemoryStream, result.SyncCoookie);
                        MakeReadedFriendMsg(qqfromid, mMemoryStream.ToArray(), MsgTimeStamp);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.Message.ToString());
                }
            }
            return(API.FriendWithdraw);
        }
예제 #4
0
        public static byte[] UnPackReceiveData(byte[] ReceiveData)
        {
            if (ReceiveData.Length == 0)
            {
                return(null);
            }
            byte[] teaBytes = null;
            try
            {
                UpdateSyncCoookies();
                Debug.Print("收到包:" + ReceiveData.Length.ToString() + "\r\n" + BitConverter.ToString(ReceiveData).Replace("-", " "));
                var packType   = ReceiveData.Skip(7).Take(1).ToArray()[0];
                var encrptType = ReceiveData.Skip(8).Take(1).ToArray()[0];
                int pos        = API.SearchBytes(ReceiveData, API.QQ.UTF8);

                var bytes = ReceiveData.Skip(pos + API.QQ.UTF8.Length).ToArray();
                teaBytes = bytes;
                HashTea Hash = new HashTea();

                if (packType == 0xB && packType == 9)
                {
                    if (encrptType == 1)
                    {
                        bytes = Hash.UNHashTEA(bytes, API.QQ.key, 0, true);
                    }
                    else if (encrptType == 2)
                    {
                        bytes = Hash.UNHashTEA(bytes, API.QQ.shareKey, 0, true);
                    }
                }
                else if (packType == 0xA && packType == 8)
                {
                    if (encrptType == 1)
                    {
                        bytes = Hash.UNHashTEA(bytes, API.QQ.shareKey, 0, true);
                    }
                    else if (encrptType == 2)
                    {
                        bytes = Hash.UNHashTEA(bytes, API.QQ.key, 0, true);
                    }
                }
                else if (packType == 0xA && packType == 10)
                {
                    if (encrptType == 1)
                    {
                        bytes = Hash.UNHashTEA(bytes, API.UN_Tlv.T305_SessionKey, 0, true);
                    }
                    else if (encrptType == 2)
                    {
                        bytes = Hash.UNHashTEA(bytes, API.QQ.key, 0, true);
                    }
                }
                else
                {
                    bytes = Hash.UNHashTEA(bytes, API.UN_Tlv.T305_SessionKey, 0, true);
                }

                Debug.Print("解密后:" + bytes.Length.ToString() + "\r\n" + BitConverter.ToString(bytes).Replace("-", " "));

                //取出第一层包头中的包长度值
                if (BitConverter.ToInt16(bytes.Take(2).ToArray(), 0) != 0)
                {
                    Debug.Print("未解析" + "\r\n" + BitConverter.ToString(teaBytes).Replace("-", " "));
                    Debug.Print("ShareKey" + "\r\n" + BitConverter.ToString(API.QQ.shareKey).Replace("-", " "));
                    Debug.Print("SessionKey" + "\r\n" + BitConverter.ToString(API.UN_Tlv.T305_SessionKey).Replace("-", " "));
                    return(null);
                }
                var    head1_len = BitConverter.ToInt32(bytes.Take(4).ToArray().Reverse().ToArray(), 0);
                byte[] bodyBytes = bytes.Skip(head1_len).ToArray();
                Debug.Print("主包体:" + bodyBytes.Length.ToString() + "\r\n" + BitConverter.ToString(bodyBytes).Replace("-", " "));
                if (head1_len > 4)
                {
                    bytes = bytes.Skip(4).Take(head1_len - 4).ToArray();
                    bytes = bytes.Skip(4).ToArray();
                    if (bytes.Skip(4).Take(4).ToArray() == new byte[] { 0, 0, 0, 0 })
                    {
                        bytes = bytes.Skip(4).ToArray();
                    }
                    else
                    {
                        var head3_len = BitConverter.ToInt32(bytes.Skip(4).Take(4).ToArray().Reverse().ToArray(), 0);
                        bytes = bytes.Skip(head3_len + 4).ToArray();
                    }
                    var str_len = BitConverter.ToInt32(bytes.Take(4).ToArray().Reverse().ToArray(), 0);
                    if (str_len > 4)
                    {
                        var serviceCmd = Encoding.UTF8.GetString(bytes.Skip(4).ToArray(), 0, str_len - 4);
                        if (serviceCmd.Contains("wtlogin.login"))
                        {
                            Debug.Print("收到命令:wtlogin.login");
                            //解析登录包体
                            var status = Un_Pack_Login(bodyBytes);
                            Debug.Print("status:" + status.ToString());
                            if (status == 1)
                            {
                                Debug.Print("wtlogin.login");
                                SDK.GetLog("登录成功");
                                //发上线包
                                API.TClient.SendData(Pack.PackOnlineStatus("StatSvc.register", 0));
                            }
                            else if (status == 0)
                            {
                                Microsoft.VisualBasic.Interaction.MsgBox(API.getLastError(), (Microsoft.VisualBasic.MsgBoxStyle)((int)Microsoft.VisualBasic.Constants.vbInformation + (int)Microsoft.VisualBasic.Constants.vbMsgBoxSetForeground + (int)Microsoft.VisualBasic.Constants.vbSystemModal + (int)Microsoft.VisualBasic.Constants.vbCritical + (int)Microsoft.VisualBasic.Constants.vbInformation), "登录失败");
                            }
                            else if (status == 2)
                            {
                                API.QQ.loginState = (int)API.LoginState.Logining;
                                if (API.UN_Tlv.T143_token_A2 != null && API.QQ.shareKey != null && API.UN_Tlv.T10A_token_A4 != null)
                                {
                                    API.TClient.SendData(Pack.PackOnlineStatus("StatSvc.register", 1));
                                }
                            }
                        }
                        else if (serviceCmd.Contains("PushService.register"))
                        {
                            Debug.Print("服务器注册成功:PushService.register");
                        }
                        else if (serviceCmd.Contains("RegPrxySvc.PushParam"))
                        {
                            Debug.Print("RegPrxySvc.PushParam命令");
                        }
                        else if (serviceCmd.Contains("ConfigPushSvc.PushDomain"))
                        {
                            Debug.Print("成功登录服务器:ConfigPushSvc.PushDomain");
                            SDK.GetLog("上线成功");
                        }
                        else if (serviceCmd.Contains("OnlinePush.ReqPush"))
                        {
                            Debug.Print("OnlinePush.ReqPush系统推送消息、撤回、加好友等");
                        }
                        else if (serviceCmd.Contains("ConfigPushSvc.PushReq"))
                        {
                            Debug.Print("回执ConfigPushSvc.PushReq");
                            JceStructSDK.ReplyConfigPushSvc(bodyBytes, API.QQ.mRequestID);
                        }
                        else if (serviceCmd.Contains("StatSvc.SimpleGet"))
                        {
                            Debug.Print("收到心跳包");
                            SDK.GetHeartBeatResult(true);
                        }
                        else if (serviceCmd.Contains("MessageSvc.PushNotify"))
                        {
                            Debug.Print("通知好友消息:" + bytes.Length.ToString() + "\r\n" + BitConverter.ToString(bytes).Replace("-", " "));
                            bytes = bytes.Reverse().ToArray();
                            var code     = bytes.Skip(15).Take(4).ToArray().Reverse().ToArray();
                            var sendByte = Pack.PackFriendMsg(code);                             //组包获取好友消息
                            API.TClient.SendData(sendByte);
                        }
                        else if (serviceCmd.Contains("MessageSvc.PbGetMsg"))
                        {
                            Debug.Print("收到好友消息");
                            FriendMsg.ParsingFriendMsg(bodyBytes);
                        }
                        else if (serviceCmd.Contains("OnlinePush.PbPushGroupMsg"))
                        {
                            Debug.Print("群聊消息");
                            GroupMsg.ParsingGroupMsg(bodyBytes);
                        }
                        else if (serviceCmd.Contains("MessageSvc.RequestPushStatus"))
                        {
                            Debug.Print("上线下线状态改变");
                        }
                        else if (serviceCmd.Contains("MessageSvc.PushReaded"))
                        {
                            Debug.Print("已读私人消息");
                        }
                        else if (serviceCmd.Contains("OnlinePush.PbC2CMsgSync"))
                        {
                            Debug.Print("发私人消息");
                        }
                        else if (serviceCmd.Contains("RegPrxySvc.PbGetGroupMsg"))
                        {
                            Debug.Print("群消息");
                        }
                        else if (serviceCmd.Contains("RegPrxySvc.PullGroupMsgSeq"))
                        {
                            Debug.Print("拉取群消息Seq");
                        }
                        else if (serviceCmd.Contains("MessageSvc.PbGetOneDayRoamMsg"))
                        {
                            Debug.Print("解析漫游消息");
                        }
                        else if (serviceCmd.Contains("RegPrxySvc.PbSyncMsg"))
                        {
                            Debug.Print("同步历史消息");
                        }
                        else if (serviceCmd.Contains("SSO.HelloPush"))
                        {
                            Debug.Print("回执SSO.HelloPush");
                            Pack.ReplySSOHelloPush(bodyBytes, API.QQ.mRequestID);
                        }
                        else if (serviceCmd.Contains("StatSvc.SvcReqMSFLoginNotify"))
                        {
                            Debug.Print("平板上/下线通知");
                        }
                        else if (serviceCmd.Contains("MessageSvc.RequestPushStatus"))
                        {
                            Debug.Print("电脑上/下线通知");
                        }
                        else if (serviceCmd.Contains("StatSvc.ReqMSFOffline"))
                        {
                            Debug.Print("异常提醒");
                        }
                        else if (serviceCmd.Contains("StatSvc.QueryHB"))
                        {
                            Debug.Print("StatSvc.QueryHB");
                        }
                        else if (serviceCmd.Contains("MessageSvc.PushForceOffline"))
                        {
                            Debug.Print("被顶下线");
                            SDK.GetLog("被顶下线");
                        }
                        else if (serviceCmd.Contains("MessageSvc.PbSendMsg"))
                        {
                            Debug.Print("递增发送信息");
                            API.QQ.mRequestID = API.QQ.mRequestID + 1;
                        }
                        else if (serviceCmd.Contains("OnlinePush.PbC2CMsgSync"))
                        {
                            Debug.Print("同步递增发送信息");
                        }
                        else if (serviceCmd.Contains("OnlinePush.PbPushDisMsg"))
                        {
                            Debug.Print("讨论组消息");
                        }
                        else if (serviceCmd.Contains("OnlinePush.PbPushTransMsg"))
                        {
                            Debug.Print("管理员变动");
                        }
                        else if (serviceCmd.Contains("friendlist.GetTroopListReqV2"))
                        {
                            Debug.Print("群列表");
                            JceStructSDK.GetGrouplist(bodyBytes);
                        }
                        else if (serviceCmd.Contains("friendlist.getFriendGroupList"))
                        {
                            Debug.Print("好友列表");
                            JceStructSDK.GetFriendlist(bodyBytes);
                        }
                        else if (serviceCmd.Contains("friendlist.GetTroopMemberList"))
                        {
                            Debug.Print("群成员列表");
                            JceStructSDK.GetGroupMemberlist(bodyBytes);
                        }
                        else if (serviceCmd.Contains("OidbSvc.0x899_0"))
                        {
                            Debug.Print("群管理列表");
                            ProtoSDK.GetGroupAdminlist(bodyBytes);
                        }
                        else if (serviceCmd.Contains("ProfileService.Pb.ReqSystemMsgNew.Friend"))
                        {
                            Debug.Print("新好友提醒");
                        }
                        else if (serviceCmd.Contains("ProfileService.Pb.ReqNextSystemMsg.Friend"))
                        {
                            Debug.Print("加好友消息提醒");
                        }
                        else if (serviceCmd.Contains("ProfileService.Pb.ReqSystemMsgNew.Group"))
                        {
                            Debug.Print("新群提醒");
                        }
                        else if (serviceCmd.Contains("QualityTest.PushList"))
                        {
                            Debug.Print("回执QualityTest.PushList");
                            Pack.ReplyQualityTest(API.QQ.mRequestID + 1);
                        }
                        else if (serviceCmd.Contains("OnlinePush.SidTicketExpired"))
                        {
                            Debug.Print("回执门票过期");
                        }
                        else if (serviceCmd.Contains("PubAccountSvc.get_follow_list"))
                        {
                            Debug.Print("获取列表");
                        }
                        else if (serviceCmd.Contains("account.RequestQueryQQMobileContactsV3"))
                        {
                            Debug.Print("查询内容");
                        }
                        else if (serviceCmd.Contains("ProfileService.GetSimpleInfo"))
                        {
                            Debug.Print("获取QQ资料信息");
                            JceStructSDK.GetSimpleInfo(bodyBytes);
                        }
                        else if (serviceCmd.Contains("StatSvc.register"))
                        {
                            Debug.Print("注册上线:StatSvc.register");
                        }
                        else if (serviceCmd.Contains("PbMessageSvc.PbMsgReadedReport"))
                        {
                            Debug.Print("已读消息");
                        }
                        else if (serviceCmd.Contains("OidbSvc.0x59f"))
                        {
                            Debug.Print("OidbSvc.0x59f命令");
                            JceStructSDK.GetRegSync_Info();
                        }
                        else if (serviceCmd.Contains("RegPrxySvc.infoSync"))
                        {
                            Debug.Print("RegPrxySvc.infoSync命令");
                        }
                        else if (serviceCmd.Contains("RegPrxySvc.GetMsgV2"))
                        {
                            Debug.Print("RegPrxySvc.GetMsgV2命令");
                        }
                        else if (serviceCmd.Contains("LongConn.OffPicUp"))
                        {
                            Debug.Print("收到图片反馈LongConn.OffPicUp");
                            FriendMsg.SendFriendMsg(API.ThisQQ, API.SendQQ, bodyBytes, API.MsgType.PicMsg);
                        }
                        else if (serviceCmd.Contains("ImgStore.GroupPicUp"))
                        {
                            Debug.Print("收到群图片反馈ImgStore.GroupPicUp");
                            GroupMsg.SendGroupMsg(API.ThisQQ, API.GroupId, bodyBytes, API.MsgType.PicMsg, API.SendQQ);
                        }
                        else if (serviceCmd.Contains("PttStore.GroupPttUp"))
                        {
                            Debug.Print("收到群语音反馈PttStore.GroupPttUp");
                            GroupMsg.SendGroupAudio(bodyBytes, API.FileHash);
                        }
                        else if (serviceCmd.Contains("PttCenterSvr.pb_pttCenter_CMD_REQ_APPLY_UPLOAD-500"))
                        {
                            Debug.Print("收到好友语音反馈PttCenterSvr.pb_pttCenter_CMD_REQ_APPLY_UPLOAD-500");
                            FriendMsg.SendFriendAudio(API.ThisQQ, API.SendQQ, bodyBytes, API.FileHash);
                        }
                        else if (serviceCmd.Contains("PttCenterSvr.pb_pttCenter_CMD_REQ_APPLY_DOWNLOAD-1200"))
                        {
                            Debug.Print("取语音下载地址PttCenterSvr.pb_pttCenter_CMD_REQ_APPLY_DOWNLOAD-1200");
                            //FriendMsg.GetFriendAudioUrl(bodyBytes)
                        }
                        else if (serviceCmd.Contains("PbMessageSvc.PbMsgWithDraw"))
                        {
                            Debug.Print("撤回消息反馈PbMessageSvc.PbMsgWithDraw");
                        }
                        else if (serviceCmd.Contains("SharpSvr.s2c"))
                        {
                            Debug.Print("语音视频电话SharpSvr.s2c");
                        }
                        else
                        {
                            Debug.Print("其他命令" + serviceCmd);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message.ToString());
            }

            return(null);
        }
예제 #5
0
        public static int Un_Pack_Login(byte[] bytes)
        {
            var head1_len = BitConverter.ToInt32(bytes.Take(4).ToArray().Reverse().ToArray(), 0);

            bytes = bytes.Skip(4).ToArray();
            bytes = bytes.Skip(1).ToArray();
            var head2_len = Convert.ToInt32(BitConverter.ToInt16(bytes.Take(2).ToArray().Reverse().ToArray(), 0));

            bytes = bytes.Skip(14).ToArray();
            int result = bytes[0];

            Debug.Print("验证类型码:" + result.ToString());
            bytes = bytes.Skip(1).Take(head2_len - 16 - 1).ToArray();
            HashTea Hash = new HashTea();

            bytes = Hash.UNHashTEA(bytes, API.QQ.shareKey, 0, true);
            Debug.Print("Un_Pack_Login:"******"-", " "));
            if (bytes.Take(2).ToArray()[1] == 25)
            {
                var len = BitConverter.ToInt16(bytes.Take(2).ToArray().Reverse().ToArray(), 0);
                bytes = bytes.Skip(2).ToArray();
                var publickey = bytes.Take(len).ToArray();
                bytes = bytes.Skip(len).ToArray();
                var sharekey = ECDH.GetECDHKeysEx(publickey, API.QQ.pub_key, API.QQ.prikey);
                bytes = Hash.UNHashTEA(bytes, sharekey, 0, true);
            }
            if (result == 0)
            {
                bytes = bytes.Skip(7).ToArray();
                var len = Convert.ToInt32(BitConverter.ToInt16(bytes.Take(2).ToArray().Reverse().ToArray(), 0));
                bytes = bytes.Skip(2).Take(len).ToArray();
                bytes = Hash.UNHashTEA(bytes, API.QQ.TGTKey, 0, true);
                Debug.Print("解密后登录成功数组:" + Environment.NewLine + BitConverter.ToString(bytes).Replace("-", " "));
                DecodeTlv(bytes);
                API.QQ.key        = API.UN_Tlv.T305_SessionKey;
                API.QQ.loginState = (int)API.LoginState.LoginSccess;
                return(1);
            }
            if (result == 2)
            {
                DecodeTlv(bytes.Skip(3).ToArray());
                if (API.UN_Tlv.T192_captcha != null)
                {
                    WebForm.Url = API.UN_Tlv.T192_captcha;
                    WebForm f1 = new WebForm();
                    f1.ShowDialog();
                    API.QQ.loginState = (int)API.LoginState.Logining;
                    if (API.QQ.Ticket != null)
                    {
                        API.TClient.SendData(Pack.VieryTicket(API.QQ.Ticket));
                    }
                }
                API.QQ.loginState = (int)API.LoginState.LoginFaild;
                return(2);
            }
            else if (result == 3)
            {
                Debug.Print("接收异常");
                API.QQ.loginState = (int)API.LoginState.LoginFaild;
            }
            else if (result == 1)
            {
                Debug.Print("登录账号或密码错误");
                API.QQ.loginState = (int)API.LoginState.LoginFaild;
            }
            else if (result == 40)
            {
                Debug.Print("账号被回收或无此账号");
                API.QQ.loginState = (int)API.LoginState.LoginFaild;
            }
            else if (result == 40)
            {
                Debug.Print("账号被冻结,或者账号密码已泄漏,存在被盗风险");
                API.QQ.loginState = (int)API.LoginState.LoginFaild;
            }
            else if (result == 160)
            {
                Debug.Print(result.ToString() + ":" + "\r\n" + BitConverter.ToString(bytes).Replace("-", " "));
                DecodeTlv(bytes.Skip(3).ToArray());
                SDK.GetLog(API.UN_Tlv.T17E_message);
                Debug.Print(API.UN_Tlv.T17E_message);
                if (API.UN_Tlv.T204_url_safeVerify != null)
                {
                    WebForm2.Url = API.UN_Tlv.T204_url_safeVerify;
                    WebForm2 f1 = new WebForm2();
                    f1.ShowDialog();
                    ClearWebDate();
                }
                else
                {
                    API.TClient.SendData(Pack.VieryPhoneCode());
                    string Answer = Microsoft.VisualBasic.Interaction.InputBox("请输入手机验证码");
                    if (!string.IsNullOrEmpty(Answer))
                    {
                        Pack.SubmitVertificationCode(Answer);
                    }
                }
                API.QQ.loginState = (int)API.LoginState.LoginVertify;
                return(2);
            }
            else if (result == 161)
            {
                Debug.Print("今日操作次数过多,请等待一天后再试");
                DecodeTlv(bytes.Skip(3).ToArray());
                WebForm2.Url = API.UN_Tlv.T204_url_safeVerify;
                WebForm f1 = new WebForm();
                f1.ShowDialog();
                ClearWebDate();
                API.QQ.loginState = (int)API.LoginState.LoginVertify;
                return(2);
            }
            else if (result == 162)
            {
                Debug.Print("验证码获取频繁,60s后重试");
                DecodeTlv(bytes.Skip(3).ToArray());
                WebForm2.Url = API.UN_Tlv.T204_url_safeVerify;
                WebForm2 f1 = new WebForm2();
                f1.ShowDialog();
                ClearWebDate();
                SendMobile = 3;
                //Thread.Sleep(60 * 1000)
                API.QQ.loginState = (int)API.LoginState.LoginVertify;
                return(2);
            }
            else if (result == 180)
            {
                Debug.Print("腾讯服务器繁忙,请重启框架重试");
                SDK.GetLog("腾讯服务器繁忙,请重启框架重试.");
                API.QQ.loginState = (int)API.LoginState.LoginVertify;
                return(2);
            }
            else if (result == 204)
            {
                if (API.UN_Tlv.T104 == null)
                {
                    Debug.Print("正在验证设备锁...");
                    //SDK.GetLog("正在验证设备锁...");
                    DecodeTlv(bytes.Skip(3).ToArray());
                    API.TClient.SendData(Pack.VieryLock());
                    API.QQ.loginState = (int)API.LoginState.LoginVertify;
                }
                return(2);
            }
            else if (result == 235)
            {
                Debug.Print("账号密码错误");
                API.QQ.loginState = (int)API.LoginState.LoginVertify;
            }
            else if (result == 237)
            {
                Debug.Print("验证ticket输入错误或环境异常");
                API.QQ.loginState = (int)API.LoginState.LoginVertify;
            }
            else if (result == 239)
            {
                Debug.Print(result.ToString() + ":" + "\r\n" + BitConverter.ToString(bytes).Replace("-", " "));
                DecodeTlv(bytes.Skip(3).ToArray());
                SDK.GetLog(API.UN_Tlv.T17E_message);
                Debug.Print(API.UN_Tlv.T17E_message);
                if (API.UN_Tlv.T204_url_safeVerify != null)
                {
                    WebForm2.Url = API.UN_Tlv.T204_url_safeVerify;
                    WebForm2 f1 = new WebForm2();
                    f1.ShowDialog();
                    ClearWebDate();
                }
                else
                {
                    API.TClient.SendData(Pack.VieryPhoneCode());
                    string Answer = Microsoft.VisualBasic.Interaction.InputBox("请输入手机验证码");
                    if (!string.IsNullOrEmpty(Answer))
                    {
                        Pack.SubmitVertificationCode(Answer);
                    }
                }
                API.QQ.loginState = (int)API.LoginState.LoginVertify;
                return(2);
            }
            else
            {
                Debug.Print("错误的验证类型:" + result.ToString());
                API.QQ.loginState = (int)API.LoginState.LoginVertify;
            }
            Un_Pack_ErrMsg(result, bytes);
            return(3);
        }
예제 #6
0
        public static API.GroupWithdrawInfo ParsingGroupMsg(byte[] byteIn)
        {
            string TextMsg   = "";
            string FaceMsg   = "";
            string HotPicMsg = "";
            string PicMsg    = "";
            string AudioMsg  = "";
            string VideoMsg  = "";
            string ReplyMsg  = "";
            var    byteLen   = BitConverter.ToInt32(byteIn.Take(4).ToArray().Reverse().ToArray(), 0);

            byteIn = byteIn.Skip(4).ToArray();
            using (MemoryStream ms = new MemoryStream(byteIn))
            {
                try
                {
                    var    result    = Serializer.Deserialize <GroupMsgStuct>(ms);
                    long   QQId      = result.GroupInfo.GroupQQInfo.thisQQId;
                    long   QQFromId  = result.GroupInfo.GroupQQInfo.QQFromId;
                    long   GroupId   = result.GroupInfo.GroupQQInfo.GroupInfo.GroupId;
                    string GroupName = result.GroupInfo.GroupQQInfo.GroupInfo.GroupName;
                    API.GroupWithdraw.MsgReqId    = result.GroupInfo.GroupQQInfo.fromReq;
                    API.GroupWithdraw.MsgRandomId = result.GroupInfo.GroupMessageInfo.GroupMsgInfo.FontInfo.fromRandom;
                    if (QQId == QQFromId)
                    {
                        return(API.GroupWithdraw);
                    }
                    var msgByte = result.GroupInfo.GroupMessageInfo.GroupMsgInfo.GroupMsgContent;
                    Debug.Print("群消息内容:" + "\r\n" + BitConverter.ToString(msgByte).Replace("-", " "));
                    using (MemoryStream mStream = new MemoryStream(msgByte))
                    {
                        var MsgResult = Serializer.Deserialize <GroupMessageStruct>(mStream);
                        API.NickName = MsgResult.SendNick.NickName;
                        if (MsgResult.GroupFileMessage != null)                         //有文件上传的消息
                        {
                            var FileHash = MsgResult.GroupFileMessage.FileHash;
                        }
                        if (MsgResult.GroupReplyMessage != null)                         //是带回复的消息
                        {
                            string replyContent = "";
                            for (var i = 0; i < MsgResult.GroupReplyMessage.OldMsgContent.Count; i++)
                            {
                                replyContent = replyContent + MsgResult.GroupReplyMessage.OldMsgContent[i].content.Replace("\n", "").Replace("\r", "").Replace("\r\n", "");
                            }
                            ReplyMsg = " [Reply=@" + MsgResult.GroupReplyMessage.thisQQId.ToString() + "内容:" + replyContent + "]";
                        }
                        if (MsgResult.GroupTextMsgContent != null)                         //有文本或小表情或热图内容
                        {
                            for (var i = 0; i < MsgResult.GroupTextMsgContent.Count; i++)
                            {
                                TextMsg = TextMsg + MsgResult.GroupTextMsgContent[i].content;
                            }
                        }
                        if (MsgResult.BigFace != null)                         //有大表情内容
                        {
                            for (var i = 0; i <= MsgResult.BigFace.Count; i++)
                            {
                                var FaceId = MsgResult.BigFace[i].FaceId;
                                FaceMsg = FaceMsg + " [BigFaceId=" + FaceId.ToString() + "]";
                            }
                        }
                        if (MsgResult.GroupPicMessageContent != null)                         //有图片内容
                        {
                            for (var i = 0; i < MsgResult.GroupPicMessageContent.Count; i++)
                            {
                                PicMsg = PicMsg + "https://gchat.qpic.cn" + MsgResult.GroupPicMessageContent[i].PicAddr1.Substring(0, MsgResult.GroupPicMessageContent[i].PicAddr1.LastIndexOf("/")) + "/0 ";
                            }
                            PicMsg = "[pic,link=" + PicMsg + "]";
                        }
                        if (result.GroupInfo.GroupMessageInfo.GroupMsgInfo.GroupAudioMsgContent != null)                         //有语音内容
                        {
                            using (MemoryStream msStream = new MemoryStream(result.GroupInfo.GroupMessageInfo.GroupMsgInfo.GroupAudioMsgContent))
                            {
                                var Ret = Serializer.Deserialize <AudioMessageStruct>(msStream);
                                AudioMsg = "[Audio,link=" + "http://grouptalk.c2c.qq.com" + Ret.AudioUrl;
                            }
                        }
                        if (MsgResult.GroupVideoMessageContent != null)                         //有视频内容
                        {
                            for (var i = 0; i < MsgResult.GroupVideoMessageContent.Count; i++)
                            {
                                VideoMsg = VideoMsg + "[video,guid=" + MsgResult.GroupVideoMessageContent[i].VideoGuid + "]";
                            }
                        }
                    }
                    SDK.GetResult(GroupId.ToString(), QQFromId.ToString(), "[" + GroupName + "]" + ReplyMsg + FaceMsg + HotPicMsg + TextMsg + PicMsg + AudioMsg + VideoMsg);
                    var MsgSeq = result.GroupInfo.GroupQQInfo.fromReq;
                    MakeReadedGroupMsg(GroupId, MsgSeq);
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.Message.ToString());
                }
            }
            return(API.GroupWithdraw);
        }