做个笔记,A站登录Cookie应该如何获取(๑•̀ㅂ•́)و✧
要做的事情
- 发起API请求1,获得
qrLoginToken
和qrLoginSignature1
- 由
qrLoginToken
构造二维码,供手机端扫描 - 发起API请求2,确认手机端是否扫描,得到
qrLoginToken
和新的qrLoginSignature2
- 发起API请求3,确认手机端扫描后是否授权登录,得到
Cookie
发起API请求1
HttpHeaders headers = new HttpHeaders();
String url = "https://scan.acfun.cn/rest/pc-direct/qr/start?type=WEB_LOGIN";
String json = util.getContent(url, headers.getAcFunLoginAuthVaHeaders());
JSONObject jObj = new JSONObject(json);
String qrLoginSignature = jObj.getString("qrLoginSignature");
String qrLoginToken = jObj.getString("qrLoginToken");
构造二维码
qrCodeStr = String.format("http://scan.acfun.cn/l/%s", qrLoginToken);
发起API请求2
String param = String.format("qrLoginToken=%s&qrLoginSignature=%s", qrLoginToken, qrLoginSignature);
String url = "https://scan.acfun.cn/rest/pc-direct/qr/scanResult?" + param;
String json = util.getContent(url, headers.getAcFunLoginAuthVaHeaders());
System.out.println(json);
JSONObject jObj = new JSONObject(json);
// 手机端是否扫描
jObj.getInt("result") == 0 ?
// 更新qrLoginSignature
qrLoginSignature = jObj.getString("qrLoginSignature")
发起API请求3
String param = String.format("qrLoginToken=%s&qrLoginSignature=%s", qrLoginToken, qrLoginSignature);
String url = "https://scan.acfun.cn/rest/pc-direct/qr/acceptResult?" + param;
String json = util.getContent(url, headers.getAcFunLoginAuthVaHeaders());
System.out.println(json);
jObj = new JSONObject(json);
// 手机端扫描后,是否点击确认
jObj.getInt("result") == 0 ?
// 得到Cookie
iCookies = util.DefaultCookieManager().getCookieStore().getCookies();