private static byte[] authRequestToByteArray(object obj) { NewAuthRequest request = obj as NewAuthRequest; Console.WriteLine(Util.byteToHexStr(request.ToByteArray())); return(request.ToByteArray()); }
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; } }
//¶þ´ÎµÇ½ 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()); }
public static SessionPack makeAutoAuthPack(int scene) { NewAuthRequest request = makeAuthRequest(scene); if (request == null) { return(null); } SessionPack pack = new SessionPack { mCmdID = 0xb2, mRequestObject = request, mCmdUri = "/cgi-bin/micromsg-bin/newauth", mNeedAutoAuth = true }; pack.mProcRequestToByteArray += new RequestToByteArrayDelegate(AuthPack.authRequestToByteArray); pack.mCompleted += new SessionPackCompletedDelegate(AuthPack.onAutoAuthCompleted); return(pack); }
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); } } }