← 回到文章列表

使用HttpClient4登录支付宝-淘宝接口

其实登录支付宝的方式有很多种 最简单的就是搞清楚支付宝的 3DES加密方式 直接在主页登录 这边当然讲的就是如何绕过支付宝加密 然后登入到支付宝内拉 方式有很多种 这里先讲下淘宝接口好了 众所周知 登入淘宝帐号之后 在我的淘宝中是有支付宝的跳转接口的 还有就…

其实登录支付宝的方式有很多种
最简单的就是搞清楚支付宝的
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();
		}
	}

在这里找找

输入关键词,找一篇过去的记录。