问个java网页操作的问题!

renjianxin0554 2015-08-19 11:22:04
获取方法

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class BaiduNetDisk {
public static List<Map<String, Object>> getUrl(String url) throws Exception {
List<String> fs_id = new ArrayList<String>();
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Document doc = Jsoup.connect(url).get();
String html = doc.toString();
int a = html.indexOf("{\"typicalPath");
int b = html.indexOf("yunData.getCon");
int sign_head = html.indexOf("yunData.SIGN = \"");
int sign_foot = html.indexOf("yunData.TIMESTAMP");
int time_head = html.indexOf("yunData.TIMESTAMP = \"");
int time_foot = html.indexOf("yunData.SHARE_UK");
int share_id_head = html.indexOf("yunData.SHARE_ID = \"");
int share_id_foot = html.indexOf("yunData.SIGN ");
String sign = html.substring(sign_head, sign_foot);
sign = sign.substring(sign.indexOf("\"") + 1, sign.indexOf("\";"));
String time = html.substring(time_head, time_foot);
time = time.substring(time.indexOf("\"") + 1, time.indexOf("\";"));
String share_id = html.substring(share_id_head, share_id_foot);
share_id = share_id.substring(share_id.indexOf("\"") + 1,
share_id.indexOf("\";"));
System.out.println(share_id);
html = html.substring(a, b);
a = html.indexOf("{\"typicalPath");
b = html.indexOf("};");
JSONObject jsonObject = new JSONObject(html.substring(a, b + 1));
String uk = jsonObject.getString("uk");
String shareid = jsonObject.getString("shareid");
String path = URLEncoder.encode(jsonObject.getString("typicalPath"),
"utf-8");
jsonObject = new JSONObject(jsonObject.getString("file_list"));
JSONArray jsonArray = new JSONArray(jsonObject.getString("list"));
jsonObject = jsonArray.getJSONObject(0);
String app_id = jsonObject.getString("app_id");
if (jsonObject.getString("isdir").equals("1")) {
String url1 = "http://pan.baidu.com/share/list?uk="
+ uk
+ "&shareid="
+ shareid
+ "&page=1&num=100&dir="
+ path
+ "&order=time&desc=1&_="
+ time
+ "&bdstoken=c51077ce0e0e313a16066612a13fbcd4&channel=chunlei&clienttype=0&web=1&app_id="
+ app_id;
String fileListJson = HttpRequest.getData(url1);
System.out.println(fileListJson);
jsonObject =new JSONObject(fileListJson);
jsonArray = new JSONArray(jsonObject.getString("list"));
}
final int size = jsonArray.length();
for (int i = 0; i < size; i++) {
Map<String, Object> map = new HashMap<String, Object>();
jsonObject = jsonArray.getJSONObject(i);
String fileName = jsonObject.getString("server_filename");
//储存文件名
map.put("fileName", fileName);
fs_id.add(jsonObject.getString("fs_id"));
String fileInfo = HttpRequest
.getData("http://pan.baidu.com/api/sharedownload?sign="
+ sign
+ "×tamp="
+ time
+ "&bdstoken=c51077ce0e0e313a16066612a13fbcd4&channel=chunlei&clienttype=0&web=1&app_id=250528&encrypt=0&product=share&uk="
+ uk + "&primaryid=" + share_id + "&fid_list=%5B"
+ fs_id.get(i) + "%5D");
JSONObject json_data = new JSONObject(fileInfo);
if (json_data.getString("errno").equals("0")) {
JSONArray jsonArray2 = new JSONArray(json_data.getString("list"));
json_data = jsonArray2.getJSONObject(0);
//储存文件下载实链
map.put("url", json_data.getString("dlink"));
} else if (json_data.getString("errno").equals("-20")) {
return null;
// String getVerCode();
} else {
return null;
}
list.add(map);
}
return list;
}
}



HttpRequest.java


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpRequest {
public static String getData(String u) throws Exception {
String re="";
URL url = new URL(u);
HttpURLConnection httpURLConnection = (HttpURLConnection) url
.openConnection();
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
InputStream is = httpURLConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader bufferedReader = new BufferedReader(isr);
String iL = "";
while ((iL = bufferedReader.readLine()) != null) {
re += iL + "\n";
}

return re;
}
}





问题,我是学易语言的。大神发给我了这个java代码。请问,他是怎么实现获取sign和timestamp的?
我好方便转换为易语言程序语言
...全文
136 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
renjianxin0554 2015-08-20
  • 打赏
  • 举报
回复
那个sign 怎么算的?有三个 呢 sign1 sign2 sign3
迷林 2015-08-20
  • 打赏
  • 举报
回复
引用 6 楼 rui888 的回复:
[quote=引用 5 楼 wi496481 的回复:] [quote=引用 4 楼 rui888 的回复:] sign: base64Encode(yunData.sign2(yunData.sign3, yunData.sign1)), 这个方法做的。具体里面逻辑不知道。
小萝莉,到那都能看见你的身影,你一天好像都没事可做啊 ,最近都快忙死了,抽点时间上来看看,发现你无处不在啊 [/quote]说说你们项目什么框架,什么高深技术来。[/quote] 没啥技术,就是对接德国和美国的物流接口,都 TMD 快吐了
renjianxin0554 2015-08-20
  • 打赏
  • 举报
回复
引用 4 楼 rui888 的回复:
sign: base64Encode(yunData.sign2(yunData.sign3, yunData.sign1)), 这个方法做的。具体里面逻辑不知道。
function s(j, r) {
    var a = [];
    var p = [];
    var o = \x22\x22;
    var v = j.length;
    for (var q = 0; q < 256; q++) {
        a[q] = j.substr((q % v), 1).charCodeAt(0);
        p[q] = q
    }
    for (var u = q = 0; q < 256; q++) {
        u = (u + p[q] + a[q]) % 256;
        var t = p[q];
        p[q] = p[u];
        p[u] = t
    };
    for (var i = u = q = 0; q < r.length; q++) {
        i = (i + 1) % 256;
        u = (u + p[i]) % 256;
        var t = p[i];
        p[i] = p[u];
        p[u] = t;
        k = p[((p[i] + p[u]) % 256)];
        o += String.fromCharCode(r.charCodeAt(q) ^ k)
    }
    return o;
}
调试提示出错。他应该是用sign2 把sign1和sign3 作用 输出的吧。可是为什么出错
tony4geek 2015-08-20
  • 打赏
  • 举报
回复
引用 5 楼 wi496481 的回复:
[quote=引用 4 楼 rui888 的回复:] sign: base64Encode(yunData.sign2(yunData.sign3, yunData.sign1)), 这个方法做的。具体里面逻辑不知道。
小萝莉,到那都能看见你的身影,你一天好像都没事可做啊 ,最近都快忙死了,抽点时间上来看看,发现你无处不在啊 [/quote]说说你们项目什么框架,什么高深技术来。
迷林 2015-08-20
  • 打赏
  • 举报
回复
引用 4 楼 rui888 的回复:
sign: base64Encode(yunData.sign2(yunData.sign3, yunData.sign1)), 这个方法做的。具体里面逻辑不知道。
小萝莉,到那都能看见你的身影,你一天好像都没事可做啊 ,最近都快忙死了,抽点时间上来看看,发现你无处不在啊
tony4geek 2015-08-20
  • 打赏
  • 举报
回复
sign: base64Encode(yunData.sign2(yunData.sign3, yunData.sign1)), 这个方法做的。具体里面逻辑不知道。
renjianxin0554 2015-08-20
  • 打赏
  • 举报
回复
引用 2 楼 rui888 的回复:
String html = doc.toString(); int a = html.indexOf("{\"typicalPath"); int b = html.indexOf("yunData.getCon"); int sign_head = html.indexOf("yunData.SIGN = \""); int sign_foot = html.indexOf("yunData.TIMESTAMP"); int time_head = html.indexOf("yunData.TIMESTAMP = \""); int time_foot = html.indexOf("yunData.SHARE_UK"); 是在html 中 index 找到后截取的。
这个我解决了 新问题又来了 网页里截取的代码:
yunData.sign1 = '6d3c9955129c765f5b00df0b18470304de876a5f';
        
                    yunData.sign2 = 'function s(j,r){var a=[];var p=[];var o=\x22\x22;var v=j.length;for(var q=0;q<256;q++){a[q]=j.substr((q%v),1).charCodeAt(0);p[q]=q}for(var u=q=0;q<256;q++){u=(u+p[q]+a[q])%256;var t=p[q];p[q]=p[u];p[u]=t}for(var i=u=q=0;q<r.length;q++){i=(i+1)%256;u=(u+p[i])%256;var t=p[i];p[i]=p[u];p[u]=t;k=p[((p[i]+p[u])%256)];o+=String.fromCharCode(r.charCodeAt(q)^k)}return o};';
        
                    yunData.sign3 = 'e8c7d729eea7b54551aa594f942decbe';
        
                    yunData.timestamp = '1440034296';
        
这个是获取sign的脚本代码:
 url = RestAPI.DOWN_GET_DLINK;
            if ("function" != typeof yunData.sign2) try {
                yunData.sign2 = new Function("return " + yunData.sign2)();
            } catch(o) {}
            data = {
                sign: base64Encode(yunData.sign2(yunData.sign3, yunData.sign1)),
                timestamp: yunData.timestamp,
                bdstoken: yunData.MYBDSTOKEN,
                fidlist: fidlist,
                type: (items.length > 1 || items[0]['isdir']) ? "batch": "dlink"
请问 这个sign2是干嘛的?怎么算出最终的sign
tony4geek 2015-08-20
  • 打赏
  • 举报
回复
String html = doc.toString(); int a = html.indexOf("{\"typicalPath"); int b = html.indexOf("yunData.getCon"); int sign_head = html.indexOf("yunData.SIGN = \""); int sign_foot = html.indexOf("yunData.TIMESTAMP"); int time_head = html.indexOf("yunData.TIMESTAMP = \""); int time_foot = html.indexOf("yunData.SHARE_UK"); 是在html 中 index 找到后截取的。

50,343

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧