發現 QQ 支援命令列登入:`QQ路徑 /start QQUIN:帳號 PWDHASH:MD5+Base64密碼 /stat:模式`。嘗試有效,遂開發圖形化登入器,採序列化持久化用戶資訊。
private void button1_Click(object sender, EventArgs e)
{
if (_ui == null) _ui = new UserInfo();
_ui.Username = txtUser.Text.Trim();
_ui.PassWord = txtPwd.Text;
_ui.Type = cboType.Text == "正常" ? "41" : "40";
if (!ValidateInput()) return;
if (string.IsNullOrEmpty(_ui.Path))
{
if (opfQQ.ShowDialog() == DialogResult.OK)
_ui.Path = opfQQ.FileName;
else return;
}
LoginQQ(_ui.Username, _ui.PassWord, _ui.Type, _ui.Path);
SerializeHelper.SerializeUserInfo(_ui); // 每次登入自動儲存
}
private void LoginQQ(string user, string pwd, string type, string path)
{
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};
proc.Start();
proc.StandardInput.WriteLine($"{path} /start QQUIN:{user} PWDHASH:{EncodeHash.PwdHash(pwd)} /stat:{type}");
proc.StandardInput.WriteLine("exit");
}
private void txtUser_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b')
e.Handled = true; // 忽略非數字/退格鍵
}
private void QQLoginForm_Load(object sender, EventArgs e) => LoadInfo();
private void LoadInfo()
{
_ui = SerializeHelper.DeserializeUserInfo();
if (_ui != null)
{
txtUser.Text = _ui.Username;
txtPwd.Text = _ui.PassWord;
cboType.SelectedIndex = _ui.Type == "41" ? 0 : 1;
}
else cboType.SelectedIndex = 0;
}
private void btnConfig_Click(object sender, EventArgs e)
{
new ConfigForm().ShowDialog();
LoadInfo(); // 同步可能被修改的路徑/模式
}