[C#] 纯文本查看 复制代码 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using DotNet4.Utilities;
using System.Runtime.InteropServices;
using System.Net;
using System.Security;
using System.Security.Permissions;
using System.ComponentModel;
namespace AutoMoney
{
public class JPay
{
HttpHelper http = new HttpHelper();
public CookieCollection Cookie;
public bool Login(string name, string pwd)
{
#region 打开登录页面
HttpItem item = new HttpItem();
item.URL = "http://weike.j-pay.cn/v3/user/login";
item.ResultCookieType = ResultCookieType.CookieCollection;
HttpResult result = http.GetHtml(item);
#endregion
#region 截取需要的参数
string html = result.Html;
int start = html.IndexOf("value=", html.IndexOf("看不清")) + 7;
int len = html.IndexOf("\" />", start) - start;
string _tokenName_ = html.Substring(start, len);
start = html.IndexOf("CaptchaDeText");
len = html.IndexOf("\"", start) - start;
string captchaDeText = html.Substring(start, len);
start = html.IndexOf("value=", html.IndexOf("__Request")) + 7;
len = html.IndexOf("\" />", start) - start;
string __RequestVerificationToken = html.Substring(start, len);
#endregion
#region 获取验证码
item = new HttpItem();
item.URL = "http://weike.j-pay.cn/DefaultCaptcha/Generate?t=" + _tokenName_;
item.ResultType = ResultType.Byte;
item.CookieCollection=result.CookieCollection;
item.ResultCookieType = ResultCookieType.CookieCollection;
item.Accept = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5";
item.Referer = "http://weike.j-pay.cn/v3/user/login";
result = http.GetHtml(item);
#endregion
#region 验证码破解
IntPtr re = Dc.RecByte_A(result.ResultByte, result.ResultByte.Length, G.USER_ID, G.USER_PWD, "5134");
string returnMess = Marshal.PtrToStringAnsi(re);
string code = "";
if (returnMess.IndexOf("|") > -1)
{
code = returnMess.Split('|')[0];
if (code.Length != 5)
{
Dc.ReportError_A(G.USER_ID, returnMess.Split('|')[2]);
return false;
}
}
else
{
return false;
}
#endregion
#region 提交登录请求
item = new HttpItem();
item.Encoding = Encoding.UTF8;
item.URL = "http://weike.j-pay.cn/V3/user/Login";
item.Method = "post";
item.CookieCollection = result.CookieCollection;
item.ResultCookieType = ResultCookieType.CookieCollection;
item.Postdata = string.Format("CaptchaFormElementId=form0&ResetFormElementId=form0&SuccessSummaryContainerElementId=operator-LoginModel-success-div&ValidationSummaryContainerElementId=operator-LoginModel-validation-div&X-Requested-With=XMLHttpRequest&UserName={0}&Password={1}&CaptchaInputText={2}&_tokenName_={3}&{3}={4}&__RequestVerificationToken={5}", name, pwd, code, captchaDeText, _tokenName_, __RequestVerificationToken);
item.ResultType = ResultType.String;
item.Accept = "*/*";
item.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
item.Host = "weike.j-pay.cn";
item.Referer = "http://weike.j-pay.cn/v3/user/login";
result = http.GetHtml(item);
#endregion
html = result.Html;
Cookie = result.CookieCollection;
return false;
}
}
} |