Welcome to Yumao′s Blog.
使用HttpClient4登錄支付寶-二維碼接口
, 2014年07月15日 , Java Language , 评论 在〈使用HttpClient4登錄支付寶-二維碼接口〉中留言功能已關閉 ,

因爲淘寶登錄的時候會記錄登錄ip
導致異地登錄次數過多的時候
會強制進行二次驗證攔截
導致登錄失效問題發生
所以就想了下從其他接口快速登入淘寶試試
瞄上了手機快捷掃碼登入方式


直接上代碼

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
public static void main(String[] args) throws Exception{
    ThreadHttpClient.getInstance();
    ThreadHttpClient.getInstance().initHttp();
     
    String preAlipayHtml = ClientHttp.doGet("https://auth.alipay.com/login/index.htm");
    //獲取安全參數
    String brCode = preAlipayHtml.substring(preAlipayHtml.indexOf("barcode: \"")+"barcode: \"".length());
    brCode = brCode.substring(0,brCode.indexOf("\""));
    String secId = preAlipayHtml.substring(preAlipayHtml.indexOf("securityId: \"")+"securityId: \"".length());
    secId = secId.substring(0,secId.indexOf("\""));
    System.out.println("二維碼地址:\n"+brCode);
    //獲取hidden的input value
    Map<String,String> inputParams = new HashMap<String,String>();
    while(preAlipayHtml.contains("<input type=\"hidden\"")){
        preAlipayHtml = preAlipayHtml.substring(preAlipayHtml.indexOf("<input type=\"hidden\""));
        String tmp = preAlipayHtml.substring(0,preAlipayHtml.indexOf("/>")+"/>".length());
        tmp = tmp.replace("value = ", "value=");
        preAlipayHtml = preAlipayHtml.substring(1,preAlipayHtml.length());
        String name = tmp.substring(tmp.indexOf("name=\"")+"name=\"".length());
        name = name.substring(0,name.indexOf("\""));
        String value = "";
        if(tmp.contains("value=")){
            value = tmp.substring(tmp.indexOf("value=\"")+"value=\"".length());
            value = value.substring(0,value.indexOf("\""));
        }
        inputParams.put(name, value);
    }
    //打印二維碼 詳見之前的文章
    QRcodeEncoder.qRCodeCommon(brCode,3);
    //等待20秒 用來手機操作
    try {
        Thread.sleep(20000);
    } catch (InterruptedException e) {
        logger.info("進程等待出現異常");
    }
    //獲取二維碼認證結果
    String checkBarcode = ClientHttp.doGet("https://securitycore.alipay.com/barcode/barcodeProcessStatus.json",
            "securityId="+URLEncoder.encode(secId,"utf-8")
            +"&_callback="+URLEncoder.encode("_callbacks.callback1","utf-8"));
    System.out.println(checkBarcode);
     
    //進行參數整合 發送
    Map<String,String> postParams = new LinkedHashMap<String,String>();
    postParams.put("ua", "");
    postParams.put("support", "000001");
    postParams.put("needTransfer", "");
    postParams.put("CtrlVersion", "1,1,0,1");
    postParams.put("loginScene", "index");
    postParams.put("redirectType", "");
    postParams.put("personalLoginError", "");
    postParams.put("goto", "");
    postParams.put("errorVM", "");
    postParams.put("sso_hid", "");
    postParams.put("site", "");
    postParams.put("errorGoto", "");
    postParams.put("rds_form_token", inputParams.get("rds_form_token"));
    postParams.put("json_tk", "");
    postParams.put("method", "qrCodeLogin");
    postParams.put("logonId", "");
    postParams.put("superSwitch", "true");
    postParams.put("noActiveX", "false");
    postParams.put("passwordSecurityId", inputParams.get("passwordSecurityId"));
    postParams.put("qrCodeSecurityId", inputParams.get("qrCodeSecurityId"));
    postParams.put("scid", "");
    postParams.put("password_input", "");
    postParams.put("J_aliedit_using", "true");
    postParams.put("password", "");
    postParams.put("J_aliedit_key_hidn", "password");
    postParams.put("J_aliedit_uid_hidn", "alieditUid");
    postParams.put("alieditUid", inputParams.get("alieditUid"));
    postParams.put("REMOTE_PCID_NAME", "_seaside_gogo_pcid");
    postParams.put("_seaside_gogo_pcid", "");
    postParams.put("_seaside_gogo_", "");;
    postParams.put("_seaside_gogo_p", "");
    postParams.put("J_aliedit_prod_type", "");
    postParams.put("checkCode", "");
    postParams.put("idPrefix", "");
     
    ClientHttp.doPost("https://auth.alipay.com/login/index.htm", postParams, "UTF-8");
     
    String loginAlipay = ClientHttp.doGet("http://my.alipay.com");
    //登入完畢
    System.out.println(loginAlipay);
}

评论已关闭