C # simulate Baidu login and reply to the specified website comment (4 ),

Source: Internet
Author: User

C # simulate Baidu login and reply to the specified website comment (4 ),

All the basic implementation functions have been completed. You can copy and paste them to log on to Baidu.

This post today tells us how to obtain Baidu's verification code.

Review: Do you still remember what I mentioned in the first post? If an exception occurs during login, Will Baidu send two values back? Yes, it is the codeType and codeString values, which can be obtained separately by parsing the preceding JSON data.

As mentioned above, codeType remains unchanged (at least the same request remains unchanged ). This parameter is required when you request a verification code. Therefore, if you want to obtain the correct verification code, this parameter is required. Otherwise, the number of requests is an incorrect verification code!

Code:

// Encapsulate the replacement Verification Code
Public void ReGetCode ()
{
String reSet_code = string. Format ("https://passport.baidu.com/v2? Reggetcodestr & token = {0} & tpl = zongheng & apiver = v3 & tt = {1} & fr = login & vcodetype = {2} & callback = bd _ cbs __ ta1xss ", token, Utility. getTimeStamp (), vcodeType );
String codeContent = helper. GetPageResponse_Get (reSet_code, Utility. UrlDecode ("http://passport.zongheng.com /? Location = http % 3A % 2F % 2Fwww.zongheng.com % 2F "),"*/*");
If (_ regex. IsMatch (codeContent ))
CodeContent = _ regex. Match (codeContent). Value;
Var codeResult = JsonConvert. DeserializeObject <Reget_Code> (codeContent );
_ Codestring = codeResult. Data_Code.VerifyStr;
String url_NewCode = string. Format ("https://passport.baidu.com/cgi-bin/genimage? {0} ", _ codestring );
Bitmap bp = helper. GetCode (url_NewCode, Utility. UrlDecode ("http://passport.zongheng.com /? Location = http % 3A % 2F % 2Fwww.zongheng.com % 2F "));
PictureBox1.Image = bp;
}

 

Some people may not understand what it means. Let's comment it out here.

ReSet_code indicates the webpage that obtains codestring. The following parameters are the token obtained, the generated timestamp, And the codeType respectively.

CodeContent indicates the content returned after the request webpage. The parameter is the parameter that needs to be provided by the Post method of the HTTPHelper class.

The next step is to analyze the content, get codestring, and then re-initiate a request to the image webpage of the verification code to display the verification code back to picturebox.

As for how codeType came from, this will return if an exception occurs during login request.

 

The following is a method to check whether the verification code is correct. after entering the verification code in the text box, press Enter.

Private void txtcode_KeyDown (object sender, KeyEventArgs e)
{

If (e. KeyCode = Keys. Enter)
{

Thread th_2 = null;
If (e. KeyCode = Keys. Enter)
{
Th_2 = new Thread () =>
{
Verifycode = txtcode. Text;
// Access the verification code verification page to check whether the verification code is correct.
String url_checkCode = string. Format ("https://passport.baidu.com/v2? Checkvcode & token = {0} & tpl = zongheng & apiver = v3 & tt = {1} & verifycode = {2} & codestring = {3} & callback = bd _ cbs _ nm74kc ", token, Utility. getTimeStamp (), verifycode, _ codestring );
String checkcode = helper. GetPageResponse_Get (url_checkCode, Utility. UrlDecode ("http://passport.zongheng.com /? Location = http % 3A % 2F % 2Fwww.zongheng.com % 2F "),"*/*");
If (_ regex. IsMatch (checkcode ))
Checkcode = _ regex. Match (checkcode). Value;
Var code_msg = JsonConvert. DeserializeObject <CheckvCode> (checkcode );
CodeMsg (code_msg.ErrInfo.No );
If (code_msg.ErrInfo.No! = "0 ")
Return;
LoginStatus status = Login (verifycode, _ codestring, token, raskey, userIndex );
GoComment_Page (status );
Th_2.Abort ();
});
Th_2.Start ();
Th_2.IsBackground = true;

}

}

 

Now, we will be here today. If you have any questions, please comments ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.