コード例 #1
0
ファイル: AuthPack.cs プロジェクト: kxlcn/android-weixin
        public static object onParserNewRegPack(SessionPack sessionPack)
        {
            NewRegResponse response = NewRegResponse.ParseFrom(sessionPack.mResponseBuffer);

            if (response == null)
            {
                Log.e("Network", "new reg parse failed. ");
                return(null);
            }
            int      uin = (int)response.Uin;
            RetConst ret = (RetConst)response.BaseResponse.Ret;

            Log.d("Network", string.Concat(new object[] { "new reg parsed success. uin= ", uin, "ret =", ret }));
            NewRegRequest mRequestObject = sessionPack.mRequestObject as NewRegRequest;
            uint          regMode        = mRequestObject.RegMode;

            if ((uin != 0) && (ret == RetConst.MM_OK))
            {
                Log.i("Network", "new reg PASS");
                SessionPackMgr.setSessionKey(Util.StringToByteArray(response.SessionKey));
                SessionPackMgr.getAccount().setUin(uin);
                SessionPackMgr.setAuthStatus(2);
                return(response);
            }
            Log.e("Network", "new reg failed, ret = " + ret);
            SessionPackMgr.setSessionKey(null);
            SessionPackMgr.getAccount().reset();
            return(response);
        }
コード例 #2
0
 public void onError(PackResult ret)
 {
     Log.e("Network", string.Concat(new object[] { "pack.onError, cmd = ", (CmdConst)this.mCmdID, " seq = ", this.mSeqID, ", ret = ", ret }));
     if (this.mCompleted != null)
     {
         PackEventArgs args = new PackEventArgs
         {
             result = ret
         };
         if (this.isAutoAuthPack())
         {
             SessionPackMgr.setAuthStatus(0);
         }
         else
         {
             if (((this.mCmdID == 1) || (this.mCmdID == 0x20)) || (this.mCmdID == 0x1f) || (this.mCmdID == 0xb2))
             {
                 SessionPackMgr.setSessionKey(null);
                 SessionPackMgr.getAccount().reset();
                 SessionPackMgr.setAuthStatus(0);
             }
             //Deployment.get_Current().get_Dispatcher().BeginInvoke(new SessionPackCompletedDelegate(this.mCompleted.Invoke), new object[] { this, args });
             SessionPackCompletedDelegate spd = new SessionPackCompletedDelegate(this.mCompleted.Invoke);
             spd.BeginInvoke(this, args, null, null);
         }
     }
 }
コード例 #3
0
ファイル: Sender.cs プロジェクト: kxlcn/android-weixin
        public bool handler()
        {
            //if (!NetworkDeviceWatcher.isNetworkAvailable())
            //{
            //    return false;
            //}
            SessionPack sessionPack = SessionPackMgr.getFirstNotSended();

            if (sessionPack == null)
            {
                return(false);
            }
            if (SessionPackMgr.isAuthing())
            {
                return(false);
            }
            if (!Connector.isValidforPack(sessionPack))
            {
                return(false);
            }
            if (!this.checkSessionKey(ref sessionPack))
            {
                return(false);
            }
            if (!this.preProcessPack(sessionPack))
            {
                Log.e("Network", "Sender: Failed to PreProcess pack.");
                return(false);
            }
            if (!this.doSendPack(sessionPack))
            {
                return(false);
            }
            return(true);
        }
コード例 #4
0
ファイル: AuthPack.cs プロジェクト: kxlcn/android-weixin
        public static object onParserRegPack(SessionPack sessionPack)
        {
            RegResponse response = RegResponse.ParseFrom(sessionPack.mResponseBuffer);

            if (response == null)
            {
                Log.e("Network", "register parse failed. ");
                return(null);
            }
            Log.d("Network", "register parsed success. ");
            int      uin = (int)response.Uin;
            RetConst ret = (RetConst)response.BaseResponse.Ret;

            if ((uin != 0) && (ret == RetConst.MM_OK))
            {
                Log.i("Network", "register PASS");
                SessionPackMgr.setSessionKey(response.SessionKey.ToByteArray());
                SessionPackMgr.getAccount().setUin(uin);
                SessionPackMgr.setAuthStatus(2);
                return(response);
            }
            Log.e("Network", "register Failed, ret = " + ret);
            SessionPackMgr.setSessionKey(null);
            SessionPackMgr.getAccount().reset();
            return(response);
        }
コード例 #5
0
ファイル: LongConnector.cs プロジェクト: kxlcn/android-weixin
 public static bool checkKeepAlive()
 {
     if (mNextHelloTimestamp == 0.0)
     {
         return(false);
     }
     if (SessionPack.getNow() < mNextHelloTimestamp)
     {
         return(false);
     }
     if (!SessionPackMgr.getAccount().isValid() || !SessionPackMgr.isValidSessionKey())
     {
         stopKeepAlivePoint();
         return(false);
     }
     if (mFirstKeepAlivePointAfterConnected == mNextHelloTimestamp)
     {
         EventCenter.postEvent(EventConst.ON_NET_MM_NET_NOOP, null, null);
     }
     else
     {
         EventCenter.postEvent(EventConst.ON_NET_MM_NET_NOOP, null, null);
     }
     restartKeepAlivePoint(0xea60);
     return(true);
 }
コード例 #6
0
ファイル: Sender.cs プロジェクト: kxlcn/android-weixin
        private bool checkSessionKey(ref SessionPack sessionPack)
        {
            if (sessionPack.mCmdID == 1 || sessionPack.mCmdID == 0xb2)
            {
                AuthPack.updateAccountInfoFromAuth(sessionPack.mRequestObject);

                return(true);
            }

            if (sessionPack.mCmdID == 0x20)
            {
                AuthPack.updateAccountInfoFromNewReg(sessionPack.mRequestObject);
                return(true);
            }
            if (sessionPack.mCmdID == 0x1f)
            {
                AuthPack.updateAccountInfoFromReg(sessionPack.mRequestObject);
                return(true);
            }
            if (sessionPack.mCmdID == 232 || sessionPack.mCmdID == 233)
            {
                return(true);
            }
            if (!this.needSessionKey(sessionPack))
            {
                return(true);
            }
            if (SessionPackMgr.isValidSessionKey())
            {
                return(true);
            }
            this.checkTryAutoAuth();
            return(false);
        }
コード例 #7
0
ファイル: Sender.cs プロジェクト: kxlcn/android-weixin
 public bool checkTryAutoAuth()
 {
     if (!SessionPackMgr.getAccount().isValid())
     {
         Log.e("Network", "cannot auto-auth without valid account.");
         this.closeSender();
         return(false);
     }
     if (mRetryAuthLeft <= 0)
     {
         if (mRetryAuthLeft == 0)
         {
             Log.e("Network", " autoAuth no retry left");
             mRetryAuthLeft = -1;
         }
         return(false);
     }
     SessionPackMgr.getPackEx(delegate(SessionPack pack)
     {
         if (pack.mCacheBodyBuffer != null)
         {
             Log.i("Network", "clearn cache body before autoauth, cmdUri = " + pack.mCmdUri);
             pack.mCacheBodyBuffer = null;
         }
         return(true);
     });
     Log.i("Network", "CMD need autoauth, autoAuthLeft:" + mRetryAuthLeft);
     mRetryAuthLeft--;
     SessionPackMgr.putToHead(AuthPack.makeAutoAuthPack(2));
     return(true);
 }
コード例 #8
0
ファイル: Receiver.cs プロジェクト: kxlcn/android-weixin
 private void updateCookie(int cmdID, int ret, byte[] cookie)
 {
     if (cmdID != 8)
     {
         bool flag = false;
         if (ret == 0)
         {
             flag = true;
         }
         if ((cmdID == 1) && ((ret == -16) || (ret == -17)))
         {
             flag = true;
         }
         if (flag)
         {
             if (cookie != null)
             {
                 SessionPackMgr.setSeverID(cookie);
             }
             else
             {
                 Log.e("Network", "updateCookie: invalid cookie");
             }
         }
     }
 }
コード例 #9
0
ファイル: Sender.cs プロジェクト: kxlcn/android-weixin
 public bool sendPack(SessionPack sessionPack)
 {
     if (sessionPack == null)
     {
         Log.e("Network", "CMD to Network: null pack");
         return(false);
     }
     Log.i("Network", string.Concat(new object[] { "CMD to Network: cmd=", (CmdConst)sessionPack.mCmdID, " seq=", sessionPack.mSeqID }));
     mRetryAuthLeft = 3;
     Connector.onPrepareSend(false);
     LongConnector.setEnable(true);
     sessionPack.timeInCmd = Util.getNowMilliseconds();
     if ((sessionPack.mCmdID == 1) && SessionPackMgr.isAuthing())
     {
         Log.e("Network", "isAuthing, don't send auth request");
         return(false);
     }
     if (sessionPack.mCmdID == 1 || sessionPack.mCmdID == 0xb2)
     {
         SessionPackMgr.putToHead(sessionPack);
     }
     else
     {
         SessionPackMgr.putToTail(sessionPack);
     }
     NetHandler.wakeUp();
     return(true);
 }
コード例 #10
0
ファイル: Sender.cs プロジェクト: kxlcn/android-weixin
 public void closeSender()
 {
     Log.i("Network", "close sender , clearn all.");
     LongConnector.setEnable(false);
     Connector.close();
     SessionPackMgr.cancelAllPacket();
     SessionPackMgr.getAccount().reset();
     SessionPackMgr.setAuthStatus(0);
 }
コード例 #11
0
 public static void onAllError(PackResult ret)
 {
     Log.e("Network", "onAllError");
     SessionPackMgr.cleanAllTimeoutPoint(3);
     SessionPackMgr.markAllToNotSended(3);
     for (SessionPack pack = SessionPackMgr.getFirstNotSended(); pack != null; pack = SessionPackMgr.getFirstNotSended())
     {
         pack.mSendStatus = 6;
         onError(pack, ret);
     }
 }
コード例 #12
0
ファイル: LongConnector.cs プロジェクト: kxlcn/android-weixin
        public static void sendHelloPack()
        {
            Log.i("Network", "send hello pack... ");
            SessionPack sessionPack = new SessionPack {
                mCmdID           = 6,
                mCacheBodyBuffer = new byte[0],
                mRetryLeft       = 1
            };

            SessionPackMgr.putToTail(sessionPack);
        }
コード例 #13
0
ファイル: Sender.cs プロジェクト: kxlcn/android-weixin
 public void onSendPackFailed(bool needReconnect, SessionPack sessionPack)
 {
     Log.e("Network", string.Concat(new object[] { "sender:onSendPackFailed, seq =", sessionPack.mSeqID, ", cmd =", sessionPack.mCmdID }));
     SessionPackMgr.cleanAllTimeoutPoint(sessionPack.mConnectMode);
     SessionPackMgr.markAllToNotSended(sessionPack.mConnectMode);
     if (SessionPackMgr.getAuthStatus() == 1)
     {
         SessionPackMgr.setAuthStatus(0);
     }
     Connector.onSendFailed(needReconnect, sessionPack.mConnectMode);
 }
コード例 #14
0
ファイル: NetHandler.cs プロジェクト: kxlcn/android-weixin
 public static void onApplicationActivated()
 {
     if (mRunStatus == 2)
     {
         SessionPackMgr.cleanAllTimeoutPoint(3);
         SessionPackMgr.markAllToNotSended(3);
         if (SessionPackMgr.getAuthStatus() == 1)
         {
             SessionPackMgr.setAuthStatus(0);
         }
         Connector.onPrepareSend(true);
         mRunStatus = 1;
     }
 }
コード例 #15
0
        public byte[] getSessionKey(bool encode)
        {
            switch (this.mCmdID)
            {
            case 0:
                return(this.getSessionKeyForInvalidCmd(encode));

            case 1:
                if (!encode)
                {
                    return(Util.StringToByteArray(SessionPackMgr.getAccount().getPassword()));
                }
                return(null);

            case 0x1f:
            case 0x20:
                if (!encode)
                {
                    return(Util.StringToByteArray(SessionPackMgr.getAccount().getPassword()));
                }
                return(null);

            case 0x21:
                //if (!encode)
                //{
                //    return Util.StringToByteArray(((GetUserNameRequest) this.mRequestObject).Pwd);
                //}
                return(null);

            case 0x30:
                if (encode)
                {
                    return(null);
                }
                return(null);

            //return Util.StringToByteArray(((GetVerifyImgRequest) this.mRequestObject).Pwd.String);
            case 232:
            case 233:
            case 0xb2:
                if (encode)
                {
                    return(null);
                }
                return(RandomKey);
            }
            return(SessionPackMgr.getSessionKey());
        }
コード例 #16
0
ファイル: AuthPack.cs プロジェクト: kxlcn/android-weixin
        public static void updateAccountInfoFromAuth(object request)
        {
            switch (request.GetType().Name)
            {
            case "AuthRequest":
                AuthRequest request2 = request as AuthRequest;
                SessionPackMgr.getAccount().setAuthInfo(request2.UserName.String, request2.Pwd.String, request2.Pwd2);
                break;

            case "NewAuthRequest":
                NewAuthRequest request3 = request as NewAuthRequest;
                SessionPackMgr.getAccount().setAuthInfo(request3.UserName.String, request3.Pwd.String, request3.Pwd2);

                break;
            }
        }
コード例 #17
0
ファイル: AuthPack.cs プロジェクト: kxlcn/android-weixin
        //¶þ´ÎµÇ½
        private static NewAuthRequest makeAuthRequest(int scene)
        {
            if (!SessionPackMgr.getAccount().isValid())
            {
                return(null);
            }
            BaseRequest defaultInstance = BaseRequest.DefaultInstance;

            BaseRequest.Builder builder = BaseRequest.CreateBuilder();
            //builder.SessionKey = ByteString.CopyFrom(SessionPackMgr.getSessionKeyEx());
            builder.SessionKey    = ByteString.CopyFrom(SessionPackMgr.getAccount().SessionKey);
            builder.Uin           = (uint)SessionPackMgr.getAccount().getUin();
            builder.DeviceID      = ByteString.CopyFromUtf8(Util.getDeviceUniqueId());
            builder.ClientVersion = (int)ConstantsProtocol.CLIENT_MIN_VERSION;
            builder.DeviceType    = ByteString.CopyFromUtf8(ConstantsProtocol.DEVICE_TYPE);
            builder.Scene         = (uint)scene;
            defaultInstance       = builder.Build();

            NewAuthRequest.Builder builder2 = NewAuthRequest.CreateBuilder();
            builder2.BaseRequest = defaultInstance;
            builder2.UserName    = Util.toSKString(SessionPackMgr.getAccount().getUsername());
            builder2.Pwd         = Util.toSKString(SessionPackMgr.getAccount().getPassword());
            // builder2.Pwd2 = Util.NullAsNil("");
            builder2.ImgSid       = Util.toSKString("");
            builder2.ImgCode      = Util.toSKString("");
            builder2.Channel      = 0;// AppInfoHelper.ChannelId;
            builder2.InputType    = 0;
            builder2.TimeStamp    = Convert.ToUInt32(Util.getNowSeconds().ToString().Substring(0, 10));
            builder2.BuiltinIPSeq = 0;
            //builder2.WTLoginReqBuff = Util.toSKBuffer("");
            //builder2.BundleID = "com.tencent.xin";
            builder2.DeviceName = "Apple Watch";

            builder2.DeviceType     = ConstantsProtocol.DEVICE_TYPE;
            builder2.AutoAuthTicket = SessionPackMgr.getAccount().AutoAuthKey;
            builder2.Language       = "zh_CN"; //AccountMgr.GetCurrentLanguage();
            builder2.DeviceBrand    = "Apple"; //DeviceStatus.get_DeviceManufacturer() ?? "";
            builder2.RealCountry    = "CN";    //DeviceStatus.get_DeviceManufacturer() ?? "";
            builder2.DeviceModel    = "";      //DeviceStatus.get_DeviceName() ?? "";
            builder2.RandomEncryKey = Util.toSKBuffer(new byte[] { 104, 84, 125, 199, 142, 226, 48, 218, 83, 195, 3, 84, 3, 123, 208, 162 });
            builder2.OSType         = "8.10.12393.0";
            builder2.TimeZone       = "8.00";

            Log.i("Network", "Old AutoAuthTicket = " + SessionPackMgr.getAccount().AutoAuthKey);
            Util.WriteLog("Old AutoAuthTicket = " + SessionPackMgr.getAccount().AutoAuthKey);
            return(builder2.Build());
        }
コード例 #18
0
ファイル: Receiver.cs プロジェクト: kxlcn/android-weixin
        private void decodeNotifyData(byte[] encryptData)
        {
            uint encryptAlgo  = Util.ReadProtoInt(encryptData, 1);
            uint compressAlgo = Util.ReadProtoInt(encryptData, 4);

            byte[] cipherText = Util.ReadProtoRawData(encryptData, 8);
            if (encryptAlgo == 5)
            {
                int    Salt         = (int)Util.ReadProtoInt(encryptData, 3);
                byte[] sencryptSalt = TLVUtil.int2byte(Salt, 4, false);
                byte[] sessionKey   = SessionPackMgr.getAccount().SessionKey;
                byte[] decodeKey    = new byte[20];

                Buffer.BlockCopy(sessionKey, 0, decodeKey, 0, 16);
                Buffer.BlockCopy(sencryptSalt, 0, decodeKey, 16, sencryptSalt.Length);

                byte[] decodeAesKey = MD5Core.GetHash(decodeKey);
                // Log.w("Network", string.Concat(new object[] { "encode notify salt ", Util.byteToHexStr(sencryptSalt), "SessionKey ", Util.byteToHexStr(sessionKey), "decode Key ", Util.byteToHexStr(decodeAesKey) }));
                byte[] decryptedData = Util.AESDecrypt(cipherText, decodeAesKey);

                if (compressAlgo == 1)
                {
                    Zlib.Decompress(decryptedData, decryptedData.Length, ref decryptedData);
                }

                Log.w("Network", string.Concat(new object[] { "decode notify result ", Util.byteToHexStr(decryptedData) }));

                cipherText = Util.ReadProtoRawData(decryptedData, 1);
                cipherText = Util.ReadProtoRawData(cipherText, 1);
                string ChatRoomId = Encoding.UTF8.GetString(cipherText);
                //  uint newMsgid = Util.ReadProtoInt(decryptedData, 2);

                uint newMsgSeq = Util.ReadProtoInt(decryptedData, 3);
                cipherText = Util.ReadProtoRawData(decryptedData, 6);
                cipherText = Util.ReadProtoRawData(cipherText, 1);
                string Contact = Encoding.UTF8.GetString(cipherText);

                uint msgType = Util.ReadProtoInt(decryptedData, 8);


                Log.w("Network", string.Concat(new object[] { "decode notify data ", " ChatRoomId ", ChatRoomId, " newMsgSeq ", newMsgSeq, "MsgType ", msgType, " Contact ", Contact }));


                new NetSceneGetChatRoomMsg().doScene(ChatRoomId, newMsgSeq);
            }
        }
コード例 #19
0
        private byte[] getSessionKeyForInvalidCmd(bool encode)
        {
            switch (this.mCmdUri)
            {
            //case "/cgi-bin/micromsg-bin/getresetpwdurl":
            //    if (encode)
            //    {
            //        return null;
            //    }
            //    return Util.StringToByteArray(((ResetPwdRequest)this.mRequestObject).Pwd);

            case "/cgi-bin/micromsg-bin/bindopmobileforreg":
                if (encode)
                {
                    return(null);
                }
                return(Util.StringToByteArray(((BindOpMobileRequest)this.mRequestObject).Mobile));
            }
            return(SessionPackMgr.getSessionKey());
        }
コード例 #20
0
 public static bool receiveList(List <Connector.RawPackBody> listPack)
 {
     SessionPackMgr.getPackWithHttpClient(delegate(SessionPack sessionPack) {
         int seq           = 0;
         byte[] outBuf     = null;
         string cmdUri     = null;
         SocketError error = sessionPack.mHttpClient.receive(ref outBuf, ref seq, ref cmdUri);
         if (error == ((SocketError)((int)SocketError.NoData)))
         {
             return(false);
         }
         if (error == ((SocketError)((int)SocketError.SocketError)))
         {
             sessionPack.mHttpClient.close();
             sessionPack.mHttpClient = null;
             return(false);
         }
         if (((outBuf == null) || (outBuf.Length < 2)))
         {
             Log.e("Network", "received invalid reponse body, seq = " + seq);
             sessionPack.mHttpClient.close();
             sessionPack.mHttpClient = null;
             return(false);
         }
         Connector.RawPackBody item = new Connector.RawPackBody {
             body = outBuf,
             cmd  = sessionPack.mCmdID,
             seq  = seq
         };
         listPack.Add(item);
         mFailedCount = 0;
         sessionPack.mHttpClient.close();
         sessionPack.mHttpClient = null;
         HostService.mShortConnHosts.onCurrentHostSuccess();
         return(true);
     });
     return(true);
 }
コード例 #21
0
ファイル: AuthPack.cs プロジェクト: kxlcn/android-weixin
        public static object onParserGetUserNamePack(SessionPack sessionPack)
        {
            GetUserNameResponse response = GetUserNameResponse.ParseFrom(sessionPack.mResponseBuffer);

            if (response == null)
            {
                Log.e("Network", "getusername parse failed. ");
                return(null);
            }
            Connector.close();
            Log.d("Network", "getUserName parsed success. ");
            RetConst ret = (RetConst)response.BaseResponse.Ret;

            if (ret != RetConst.MM_OK)
            {
                Log.e("Network", "NetSceneGetUserName: failed. ret = " + ret);
                return(response);
            }
            Log.i("Network", "NetSceneGetUserName: success.name = " + response.UserName);
            SessionPackMgr.getAccount().setUsername(response.UserName);
            SessionPackMgr.mAuthTicket2 = response.Ticket;
            return(response);
        }
コード例 #22
0
ファイル: Sender.cs プロジェクト: kxlcn/android-weixin
        private bool doSendPack(SessionPack sessionPack)
        {
            sessionPack.mSendStatus = 2;
            if (sessionPack.mCmdID == 1)
            {
                Log.i("Network", "auth now...user = "******"Network", "auth now...user = " + SessionPackMgr.getAccount().getUsername());
                SessionPackMgr.setAuthStatus(1);
            }
            if (sessionPack.mCmdID == 8)
            {
                sessionPack.mSendStatus = 4;
            }
            else
            {
                sessionPack.setTimeoutPoint();
            }
            if (!Connector.sendPack(sessionPack))
            {
                this.onSendPackFailed(true, sessionPack);
                return(false);
            }
            if ((sessionPack.mCmdID == 6) || (sessionPack.mCmdID == 8))
            {
                sessionPack.mSendStatus = 5;
            }
            else
            {
                sessionPack.mSendStatus = 3;
            }
            return(true);
        }
コード例 #23
0
ファイル: NetHandler.cs プロジェクト: kxlcn/android-weixin
        public static void run()
        {
            int millisecondsTimeout = 100;

            HostService.init();
            //NetworkDeviceWatcher.initWatcher();
            while (mRunStatus != 0)
            {
                idleEvent.WaitOne(millisecondsTimeout);
                if (mRunStatus == 1)
                {
                    //Sender.getInstance().checkSender();
                    SessionPackMgr.checkPackTimeout();
                    SessionPackMgr.clearCompletedOrCancel();
                    SessionPackMgr.checkSendTimeout();
                    Connector.checkReady();
                    Sender.getInstance().handler();
                    Receiver.getInstance().handler();
                    millisecondsTimeout = getIdleTime();
                }
            }
            mThread      = null;
            mThreadStart = null;
        }
コード例 #24
0
 public static void close()
 {
     SessionPackMgr.closeAllHttpClientInPacks();
 }
コード例 #25
0
ファイル: Sender.cs プロジェクト: kxlcn/android-weixin
        private bool preProcessPack(SessionPack sessionPack)
        {
            if (sessionPack.mRetryLeft <= 0)
            {
                Log.e("Network", "sender: retryLeft =0,cmd =:" + ((CmdConst)sessionPack.mCmdID));
                sessionPack.mSendStatus = 6;
                OnCallback.onError(sessionPack, PackResult.RETRY_LIMIT);
                return(false);
            }
            if (sessionPack.mCanceled)
            {
                Log.e("Network", "not send packet been cancelled.)");
                return(false);
            }
            if ((sessionPack.mCmdID != 6) && (sessionPack.mRetryLeft != 3))
            {
                int newSeq = SessionPack.getSeqID();
                Log.d("Network", string.Concat(new object[] { "resend pack, change seq ", sessionPack.mSeqID, " to new seq ", newSeq }));
                SessionPackMgr.changeSessionPackSeq(sessionPack.mSeqID, newSeq);
                sessionPack.mSeqID = newSeq;
            }
            sessionPack.mRetryLeft--;
            sessionPack.mSendStatus = 1;
            if (sessionPack.mCacheBodyBuffer == null)
            {
                //   if ((sessionPack.mCmdID == 8) || (sessionPack.mCmdID == 0x19) || (sessionPack.mCmdID == 232 || (sessionPack.mCmdID == 233)))
                //  {
                //sessionPack.mCacheBodyBuffer = sessionPack.requestToByteArray();


                ////Log.e("Network", "mCacheBodyBuffer:"+);
                //if (sessionPack.mCacheBodyBuffer == null)
                //{
                //    Log.e("Network", "newsync check got bytearray failed.");
                //    sessionPack.mSendStatus = 6;
                //    OnCallback.onError(sessionPack, PackResult.PACK_ERROR);
                //    return false;
                //}

                //if (sessionPack.mCmdID == 232 || sessionPack.mCmdID == 233)
                //{
                //    if (!MMPack.EncodePackMini(sessionPack))
                //    //if (!MMPack.EncodePack(sessionPack))
                //    {
                //        Log.e("Network", "sender.encodePack failed,cmd= " + ((CmdConst)sessionPack.mCmdID));
                //        sessionPack.mCacheBodyBuffer = null;
                //        sessionPack.mSendStatus = 6;
                //        OnCallback.onError(sessionPack, PackResult.PACK_ERROR);
                //        return false;
                //    }
                //}

                //return true;
                //  }

                if (!MMPack.EncodePackMini(sessionPack))
                // if (!MMPack.EncodePack(sessionPack))
                {
                    Log.e("Network", "sender.encodePack failed,cmd= " + ((CmdConst)sessionPack.mCmdID));
                    sessionPack.mCacheBodyBuffer = null;
                    sessionPack.mSendStatus      = 6;
                    OnCallback.onError(sessionPack, PackResult.PACK_ERROR);
                    return(false);
                }
            }
            return(true);
        }
コード例 #26
0
ファイル: AuthPack.cs プロジェクト: kxlcn/android-weixin
        public static object onParserNewAuthPack(SessionPack sessionPack)
        {
            NewAuthResponse response = NewAuthResponse.ParseFrom(sessionPack.mResponseBuffer);

            if (response == null)
            {
                Log.e("Network", "auth parse failed. ");
                return(null);
            }
            int      uin = (int)response.Uin;
            RetConst ret = (RetConst)response.BaseResponse.Ret;

            Log.d("Network", "auth parsed success. ");
            if ((uin != 0) && (((ret == RetConst.MM_OK) || (ret == RetConst.MM_ERR_CRITICALUPDATE)) || (ret == RetConst.MM_ERR_RECOMMENDEDUPDATE)))
            {
                Log.i("Network", "auth PASS, uin= " + uin);

                HostService.updateAuthBuiltinIP(response.BuiltinIPList);
                SessionPackMgr.setSessionKey(response.SessionKey.ToByteArray());
                SessionPackMgr.getAccount().AutoAuthKey = response.AutoAuthTicket;
                SessionPackMgr.getAccount().setUin(uin);
                SessionPackMgr.getAccount().Nickname = response.NickName.String;
                //SessionPackMgr.getAccount().Headimg=response.WTLoginRspBuff
                SessionPackMgr.setAuthStatus(2);
                return(response);
            }
            Log.e("Network", "auth Failed,ret = " + ret);
            switch (ret)
            {
            case RetConst.MM_ERR_NEEDREG:
                Log.i("Network", "auth result: need register");
                SessionPackMgr.mAuthTicket1 = response.Ticket;
                Connector.close();
                return(response);

            case RetConst.MM_ERR_IDC_REDIRECT:
                Log.i("Network", "Need to redirect IDC for auth ...");
                HostService.updateAuthIDCHost(response.NewHostList);
                HostService.updateAuthBuiltinIP(response.BuiltinIPList);
                Connector.close();
                return(response);

            case RetConst.MM_ERR_QQ_OK_NEED_MOBILE:
                SessionPackMgr.setSessionKey(null);
                return(response);

            default:
                SessionPackMgr.setSessionKey(null);
                SessionPackMgr.getAccount().reset();
                switch (ret)
                {
                case RetConst.MM_ERR_RECOMMENDEDUPDATE:
                    Log.e("Network", "Auth Failed: MM_ERR_RECOMMENDEDUPDATE ");
                    goto Label_022B;

                case RetConst.MM_ERR_CRITICALUPDATE:
                    Log.e("Network", "Auth Failed: MM_ERR_CRITICALUPDATE ");
                    goto Label_022B;

                case RetConst.MM_ERR_AUTH_ANOTHERPLACE:
                    Log.e("Network", "Auth Failed: MM_ERR_AUTH_ANOTHERPLACE ");
                    mKickMessage = response.KickResponse;
                    Sender.getInstance().closeSender();
                    goto Label_022B;

                case RetConst.MM_ERR_NEED_VERIFY:
                    Log.e("Network", "Auth Failed: MM_ERR_NEED_VERIFY ");
                    goto Label_022B;

                case RetConst.MM_ERR_NOUSER:
                    Log.e("Network", "Auth Failed: MM_ERR_NOUSER ");
                    goto Label_022B;

                case RetConst.MM_ERR_PASSWORD:
                    Log.e("Network", "Auth Failed: MM_ERR_PASSWORD ");
                    goto Label_022B;
                }
                break;
            }
Label_022B:
            Connector.close();
            return(response);
        }
コード例 #27
0
ファイル: Receiver.cs プロジェクト: kxlcn/android-weixin
        private void onReceivedResponsePack(byte[] body, int seq, int cmd, string cmdUri)
        {
            Log.i("Network", string.Concat(new object[] { "receive a packet , cmd = ", (CmdConst)cmd, ",seq = ", seq, " , len = ", body.Length }));
            SessionPack sessionPack = SessionPackMgr.getSessionPackBySeq(seq);

            if (sessionPack == null)
            {
                //FlowControl.onReceive(cmd, "", (uint) body.Length);
                this.onReceivedNotify(seq, cmd, body);
            }
            else
            {
                sessionPack.timeInRecvEnd = Util.getNowMilliseconds();
                sessionPack.cancelTimeoutPoint();
                sessionPack.mSendStatus = 4;
                if (sessionPack.mCmdID == 6)
                {
                    sessionPack.mSendStatus = 5;
                }
                else if (sessionPack.mCmdID == 0x19)
                {
                    sessionPack.mSendStatus     = 5;
                    sessionPack.mResponseBuffer = body;
                    OnCallback.onSuccess(sessionPack);
                }
                else
                {
                    if (sessionPack.mCmdID == 1 || sessionPack.mCmdID == 0xb2)
                    {
                        SessionPackMgr.setAuthStatus(0);
                    }
                    if (sessionPack.mCanceled)
                    {
                        Log.i("Network", "receive a packet been cancelled.");
                    }
                    else
                    {
                        byte[] key = sessionPack.getSessionKey(false);
                        if (key == null)
                        {
                            Log.e("Network", "recv a packet without valid key, resend later.");
                            sessionPack.mCacheBodyBuffer = null;
                            sessionPack.mSendStatus      = 0;
                        }
                        else
                        {
                            byte[] serverId      = null;
                            byte[] decryptedData = null;
                            int    ret           = 0;
                            if (!MMPack.DecodePack(ref decryptedData, body, key, ref serverId, ref ret))
                            {
                                Log.e("Network", string.Concat(new object[] { "unpack error! cmd=", (CmdConst)cmd, " seq=", seq }));
                                Connector.close();
                                if (ret == -13)
                                {
                                    Log.e("Network", "session timeout");
                                    SessionPackMgr.setSessionKey(null);
                                }
                                if (sessionPack.mRetryLeft > 0)
                                {
                                    sessionPack.mCacheBodyBuffer = null;
                                    sessionPack.cancelTimeoutPoint();
                                    sessionPack.mSendStatus = 0;
                                }
                                else
                                {
                                    sessionPack.mSendStatus = 6;
                                    OnCallback.onError(sessionPack, PackResult.UNPACK_ERROR);
                                }
                            }
                            else
                            {
                                sessionPack.mSendStatus     = 5;
                                sessionPack.mResponseBuffer = decryptedData;
                                // string a = Util.byteToHexStr(decryptedData);
                                object responseObject = null;
                                if (!AuthPack.preProcessAuthPack(sessionPack, ref responseObject))
                                {
                                    sessionPack.mSendStatus = 6;
                                    OnCallback.onAllError(PackResult.AUTH_ERROR);
                                    Connector.onSendFailed(false, 3);
                                }
                                else
                                {
                                    this.updateCookie(sessionPack.mCmdID, ret, serverId);
                                    if (responseObject != null)
                                    {
                                        sessionPack.mResponseObject = responseObject;
                                    }
                                    else
                                    {
                                        try
                                        {
                                            sessionPack.mResponseObject = sessionPack.onResponseParser();
                                        }
                                        catch (Exception exception)
                                        {
                                            Log.e("Network", "onResponseParser failed," + exception.ToString());
                                            OnCallback.onError(sessionPack, PackResult.PARSER_ERROR);
                                            return;
                                        }
                                        if (sessionPack.mResponseObject == null)
                                        {
                                            Log.e("Network", "onResponseParser failed");
                                            OnCallback.onError(sessionPack, PackResult.PARSER_ERROR);
                                            return;
                                        }
                                    }
                                    OnCallback.onSuccess(sessionPack);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #28
0
ファイル: AuthPack.cs プロジェクト: kxlcn/android-weixin
 private static void onAutoAuthCompleted(object sender, PackEventArgs e)
 {
     if (!e.isSuccess())
     {
         Log.e("Network", "auto auth failed .");
     }
     else
     {
         SessionPack     pack            = sender as SessionPack;
         NewAuthResponse mResponseObject = (NewAuthResponse)pack.mResponseObject;
         NewAuthRequest  mRequestObject  = (NewAuthRequest)pack.mRequestObject;
         RetConst        ret             = (RetConst)mResponseObject.BaseResponse.Ret;
         if (ret == RetConst.MM_ERR_IDC_REDIRECT)
         {
             if (mIDCAutoAuthCount < 3)
             {
                 mIDCAutoAuthCount++;
                 SessionPackMgr.putToHead(makeAutoAuthPack(2));
                 return;
             }
             Log.e("Network", "Redirect IDC too much, auto auth failed!");
         }
         mIDCAutoAuthCount = 0;
         switch (ret)
         {
         case RetConst.MM_OK:
         case RetConst.MM_ERR_CRITICALUPDATE:
         case RetConst.MM_ERR_RECOMMENDEDUPDATE:
         {
             Log.i("Network", "auto auth success. ");
             Log.i("Network", "New AutoAuthTicket = " + SessionPackMgr.getAccount().AutoAuthKey);
             Util.WriteLog("New AutoAuthTicket = " + SessionPackMgr.getAccount().AutoAuthKey);
             // Account account = AccountMgr.getCurAccount();
             // account.bytesSessionkey = mResponseObject.SessionKey.ToByteArray();
             // account.nUin = mResponseObject.Uin;
             //  account.dbLastSessionKeyTimeStamp = Util.getNowSeconds();
             //  account.bytesA2Key = mResponseObject.A2Key.Buffer.ToByteArray();
             SessionPackMgr.getAccount().SessionKey = mResponseObject.SessionKey.ToByteArray();
             AccountMgr.updateAccount();
             EventCenter.postEvent(EventConst.ON_NETSCENE_AUTOAUTH_SUCCESS, mResponseObject, null);
             return;
         }
         }
         if (ret == RetConst.MM_ERR_NEED_VERIFY)
         {
             if ((mResponseObject.ImgBuf == null) || (mResponseObject.ImgSid == null))
             {
                 Log.e("Network", "NEED_VERIFY_USER, but ImgSid or ImgBuf is null");
                 EventCenter.postEvent(EventConst.ON_NETSCENE_AUTOAUTH_ERR, ret, null);
             }
             else
             {
                 //VerifyCodeArgs args = new VerifyCodeArgs {
                 //    mImageSid = mResponseObject.ImgSid.String,
                 //    mImageBuf = mResponseObject.ImgBuf.Buffer.ToByteArray()
                 //};
                 Log.e("Network", "auto auth failed, need verify,  sid = " + "args.mImageSid");
                 //EventCenter.postEvent(EventConst.ON_NETSCENE_AUTH_NEEDVERIFY, args, null);
             }
         }
         else if (ret == RetConst.MM_ERR_QQ_OK_NEED_MOBILE)
         {
             Log.i("Network", "autoAuth Need Mobile veryfy ret = " + ret.ToString());
             EventCenter.postEvent(EventConst.ON_NETSCENE_AUTOAUTH_ERR, ret, mResponseObject.BindMobile.String);
         }
         else
         {
             Log.e("Network", "auto auth failed, result = " + mResponseObject.BaseResponse.ErrMsg.String);
             EventCenter.postEvent(EventConst.ON_NETSCENE_AUTOAUTH_ERR, ret, null);
         }
     }
 }
コード例 #29
0
ファイル: AuthPack.cs プロジェクト: kxlcn/android-weixin
        public static void updateAccountInfoFromReg(object request)
        {
            RegRequest request2 = request as RegRequest;

            SessionPackMgr.getAccount().setAuthInfo(request2.UserName.String, request2.Pwd.String, request2.Pwd2);
        }
コード例 #30
0
ファイル: AuthPack.cs プロジェクト: kxlcn/android-weixin
        public static void updateAccountInfoFromNewReg(object request)
        {
            NewRegRequest request2 = request as NewRegRequest;

            SessionPackMgr.getAccount().setAuthInfo(request2.UserName, request2.Pwd, "");
        }