Welcome to Yumao′s Blog.
其實登錄支付寶的方式有很多種
最簡單的就是搞清楚支付寶的
3DES加密方式
直接在主頁登錄
這邊當然講的就是如何繞過支付寶加密
然後登入到支付寶內拉
方式有很多種
這裏先講下淘寶接口好了
衆所周知
登入淘寶帳號之後
在我的淘寶中是有支付寶的跳轉接口的
還有就是淘寶的登錄並不一定需要加密
僞裝成Linux+Chrome客戶端的話
只需要提供 帳號 密碼 驗證碼
即可登入淘寶系統
以下是實現code
public static void main(String[] args) throws Exception {
//獲取checkcode
HttpGet get = new HttpGet("https://login.taobao.com/member/login.jhtml");
HttpClient http = new DefaultHttpClient();
http.getParams().setParameter(ClientPNames.COOKIE_POLICY,CookiePolicy.BEST_MATCH);
HttpResponse response = http.execute(get);
if (response.getStatusLine().getStatusCode() == 200) {
List<Cookie> cookies = ((AbstractHttpClient) http).getCookieStore().getCookies();
for (int i = 0; i < cookies.size(); i++) {
if(cookies.get(i).getName().contains("cookie2"))
System.out.println("checkcode url:\nhttps://regcheckcode.taobao.com/auction/checkcode?sessionID="+cookies.get(i).getValue());
}
}
//釋放連接
get.abort();
//手動輸入checkcode
System.out.println("input checkcode:");
Scanner scan=new Scanner(System.in);
String checkcode=scan.nextLine().trim();
String tbcUsername="<username>";
String tbcPassword="<password>";
//登入環境設置爲Chrom+Linux 不會有控件加密
HttpPost post = new HttpPost("https://login.taobao.com/member/login.jhtml");
post.setHeader("Content-Type","application/x-www-form-urlencoded");
post.setHeader("Connection","keep-alive");
//Linux+Chrome
post.setHeader("User-Agent", "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.79 Safari/537.1");
//NT5+IE
// post.setHeader("User-Agent","User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)");
post.setHeader("Accept-Encoding", "deflate,sdch");
post.setHeader("Accept-Language", "zh-CN,zh;q=0.8");
post.setHeader("Accept-Charset", "UTF-8,*;q=0.5");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("TPL_username", tbcUsername));
params.add(new BasicNameValuePair("TPL_password", tbcPassword));
params.add(new BasicNameValuePair("TPL_checkcode", checkcode));
params.add(new BasicNameValuePair("TPL_redirect_url", "http://www.taobao.com/"));
params.add(new BasicNameValuePair("need_check_code", "false"));
params.add(new BasicNameValuePair("action", "Authenticator"));
params.add(new BasicNameValuePair("event_submit_do_login", "anything"));
params.add(new BasicNameValuePair("from", "tbTop"));
params.add(new BasicNameValuePair("fc", "default"));
params.add(new BasicNameValuePair("style", "default"));
params.add(new BasicNameValuePair("support", "000001"));
params.add(new BasicNameValuePair("CtrlVersion", "1,0,0,7"));
params.add(new BasicNameValuePair("loginType", "3"));
post.setEntity(new UrlEncodedFormEntity(params,"GBK"));
//發送請求
response = http.execute(post);
System.out.println(response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() == 302||response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
post.abort();
//獲取支付寶跳轉連接
String jumpAlipayUrl = "";
get=new HttpGet("http://member1.taobao.com/member/fresh/account_management.htm");
response=http.execute(get);
if (response.getStatusLine().getStatusCode() == 200) {
entity = response.getEntity();
String htmlCode = EntityUtils.toString(entity);
jumpAlipayUrl = htmlCode.substring(htmlCode.indexOf("https://lab.alipay.com/user/i.htm?"));
jumpAlipayUrl = jumpAlipayUrl.substring(0,jumpAlipayUrl.indexOf("\""));
System.out.println("Alipay跳轉連接爲\n"+jumpAlipayUrl);
} else
System.out.println("頁面打開失敗");
get.abort();
//登錄Alipay提供給TB的接口
get=new HttpGet(jumpAlipayUrl);
response=http.execute(get);
if (response.getStatusLine().getStatusCode() == 200) {
entity = response.getEntity();
String htmlCode = EntityUtils.toString(entity);
jumpAlipayUrl = htmlCode.substring(htmlCode.indexOf("window.location.href = \"")+"window.location.href = \"".length());
jumpAlipayUrl = jumpAlipayUrl.substring(0,jumpAlipayUrl.indexOf("\""));
System.out.println("獲取跳轉到Alipay的URL+\n"+jumpAlipayUrl);
}
get.abort();
//跳轉到Alipay
get=new HttpGet(jumpAlipayUrl);
response=http.execute(get);
if (response.getStatusLine().getStatusCode() == 200) {
entity = response.getEntity();
String htmlCode = EntityUtils.toString(entity);
System.out.println("alipay content:\n"+htmlCode);
}
get.abort();
} else {
System.out.println("頁面打開失敗");
post.abort();
}
}
很好的程序,但是我测试时发现taobao给出的错误信息是验证码错误
我不太确定,手动输入验证码是不是在浏览器地址里填写程序中输出的URL,然后在程序中输入看到的验证码,期待您的Email.
很有帮助,谢谢分享!