概述
package cn.rs.blog.service.jiexi;
import com.jfinal.kit.HttpKit;
import org.apache.http.client.CookieStore;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.json.JSONObject;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* 微信公众号 java微技术 2020/6/10
*/
public class UcUtil {
public String getUcUrl(String s) {
// String s = ("https://mparticle.uc.cn/video.html?uc_param_str=frdnsnpfvecpntnwprdssskt&btifl=10016&app=smds-iflow&title_type=1&wm_id=1c4c29e197e54fa6bccf325098bd20bb&wm_cid=305663355587135488&pagetype=share&client=&uc_share_depth=1");
// 全局请求设置
RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
// 创建cookie store的本地实例
CookieStore cookieStore = new BasicCookieStore();
// 创建HttpClient上下文
HttpClientContext context = HttpClientContext.create();
context.setCookieStore(cookieStore);
// 创建一个HttpClient
CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(globalConfig)
.setDefaultCookieStore(cookieStore).build();
CloseableHttpResponse res = null;
// 创建本地的HTTP内容
try {
try {
// 创建一个get请求用来获取必要的Cookie,如_xsrf信息
HttpGet get = new HttpGet(s);
res = httpClient.execute(get, context);
// 获取常用Cookie,包括_xsrf信息
System.out.println("访问uc的获取的常规Cookie:===============");
String nametempvpstoken = null;
for (Cookie c : cookieStore.getCookies()) {
String nametemp = c.getName();
if ("vpstoken".equalsIgnoreCase(nametemp)) {
nametempvpstoken = c.getValue();
}
System.out.println(c.getName() + ": " + c.getValue());
}
res.close();
if(nametempvpstoken ==null){
return null;
}
Map<String, String> mapFromStr = getMapFromStr(s);
String wm_id = mapFromStr.get("wm_id");
String wm_cid = mapFromStr.get("wm_cid");
String s1 = HttpKit.get("https://ff.dayu.com/contents/" + wm_cid + "?biz_id=1002");
JSONObject jsonObject = new JSONObject(s1);
String ums_id = jsonObject.getJSONObject("data").getJSONObject("body").getJSONArray("videos").getJSONObject(0).getString("ums_id");
String requestUrl = "https://mparticle.uc.cn/api/vps?token=" + nametempvpstoken + "&ums_id=" + ums_id + "&wm_cid=" + wm_cid + "&wm_id=" + wm_id + "&resolution=high";
s1 = HttpKit.get(requestUrl);
jsonObject = new JSONObject(s1);
s1 = jsonObject.getJSONObject("data").getString("url");
return s1;
} finally {
httpClient.close();
}
} catch (IOException e) {
}
return null;
}
public Map<String, String> getMapFromStr(String str) {
if (str == null || "".equalsIgnoreCase(str)) {
return null;
}
String[] arr = str.split("\&");
Map<String, String> map = new HashMap<>();
for (String item : arr) {
String[] itemArr = item.split("=", 2);
map.put(itemArr[0], itemArr[1]);
}
return map;
}
}
最后
以上就是痴情缘分为你收集整理的uc浏览器解析视频源码,不废话,直接源码的全部内容,希望文章能够帮你解决uc浏览器解析视频源码,不废话,直接源码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复