1.java方面:要从后台获取终端需要的数据,通过接口提供。例:
这是终端需要用到的值
category --------------文章所属的栏目
mediaPath -------------文章的音频文件
staticurl --------------文章的静态访问路径
mediaType -------------音频类型
type --------------发布文章的类型
vurl --------------视频文件
id ---------------文章id
java返回值
public static void responseObj(HttpServletResponse response, Object data){
//response.setm
try {
PrintWriter out = null;
response.setContentType("text/plain");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("text/json;charset=UTF-8");
out = response.getWriter();
JsonFromServer<Object> json= new JsonFromServer<Object>();
json.code = 200;
json.msg = "SUCCESS";
json.data = data;
// out.println(getRightJson(array.toString(), list.size()));// 返回jsonp格式数据
out.println(com.alibaba.fastjson.JSONObject.toJSONString(json));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
java的基础底层类
/*
java的基础底层
*/
public class JsonFromServer<T>{
public int code;
public String msg;
public T data;
}
java的接口
/**
* @param contentId
* @param userId
* @param request
* @param response
* 获取从手机跳转到app的稿件详情页参数
*/
@RequestMapping("/forApp/****.jspx")
public void ***(Integer contentId,Integer userId,
HttpServletRequest request, HttpServletResponse response) {
Content content = null;
WapContentBean wcb = null;
Integer siteId = null;
try {
content = wapMmanager.getContenById(contentId);
if (content != null) {
if(content.getStatus()==2){
wcb = new WapContentBean();
}
//id
wcb.setId(content.getId());
//移动标题图
if(StringUtils.isEmpty(content.getWapTitleImg())){
if(!StringUtils.isEmpty(content.getTypeImg())){
wcb.setWapImg(content.getTypeImg().replace("/", httpURL));
}else{
wcb.setWapImg("");
}
}else{
wcb.setWapImg(content.getWapTitleImg().replace("/", httpURL));
}
//图片、图片描述
if (content.getPictures() != null) {
String[] pic = new String[content.getPictures().size()];
String[] picDesc = new String[content.getPictures()
.size()];
for (int i = 0; i < content.getPictures().size(); i++) {
pic[i] = content.getPictures().get(i)
.getImgAndroidPath();// 待修改
picDesc[i] = content.getPictures().get(i)
.getDescription();
}
wcb.setPicPaths(pic);
wcb.setPicDesc(picDesc);
}
if (content.getMediaPath() != null) {//多媒体语音文件路径
wcb.setMediaPath(content.getMediaPath());
}
if (content.getVurl() != null) {//视频路径
wcb.setVurl(content.getVurl());
}
wcb.setType(content.getType().getId());
//静态页APP的web路径
String appUrl = httpURL+"/app"+content.getUrl().replace("/lrqw", "");
wcb.setContent(appUrl);
//静态页web路径
wcb.setStaticurl(appUrl);
Integer newsType = content.getChannel().getChannelExt().getNewsType();
String category = "图文";
if(newsType == 2){
category = "图片";
}else if(newsType == 3){
category = "视频";
}
wcb.setCategory(category);
//借用此字段提供稿件位置说明
if(category.equals("图片") || wcb.getPicPaths().length >= 3){
wcb.setMediaType("4");
}else{
if(category.equals("视频")){
wcb.setMediaType("5");
}else{
//其他稿件
if(StringUtils.isEmpty(wcb.getWapImg())){
wcb.setMediaType("1");
}else{
if(wcb.getType()==5){
wcb.setMediaType("3");
}else{
wcb.setMediaType("2");
}
}
}
}
//栏目名称
wcb.setCategory(content.getChannel().getName());
//视频地址
if(content.getVurl() != null && !content.getVurl().isEmpty() ){
wcb.setVurl(content.getVurl());
}else{
wcb.setVurl("");
}
//语音文件地址
wcb.setMediaPath(content.getMediaPath());
BaseAppUtils.responseObj(response, wcb);
}else if(content.getStatus()==3){
BaseAppUtils.responseStrError(response, "此稿件已被删除");
}
} catch (Exception e) {
e.printStackTrace();
BaseAppUtils.responseStrError(response, "获取数据异常");
}
}
前台页面的html代码1
写出一个是否的弹框按钮
var answer = confirm("前往日本头条体验更佳");
if(answer){
window.location.href = 'http://localhost:8080/lrqw/guide.html?uid=${content.user.id}&cid=${content.id}'
}
前台页面的html代码2
guide.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<!--<script type="text/javascript" src="jquery-3.2.1.min.js"></script>-->
</head>
<body style="background: #f1f1f1;">
<img src="http://localhost:8080/mobile/images/pict.png" style="padding: 0; margin: 0; width: 100%;" />
<script type="text/javascript" src="http://localhost:8080/r/cms/www/tpl_lrqwnet/lrqw_js_wap/jquery-1.7.2.min.js"></script>
<script>
function getQueryVariable(variable) {
var reg = new RegExp("(^|&)" + variable + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]);
return null;
}
$(function() {
var IosLinks = "";//旅日
var AndroidLinks = "";
var uid = getQueryVariable('uid')
var cid = getQueryVariable('cid')
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
var isWeixin = !!/MicroMessenger/i.test(u);
if (isWeixin) {
console.log('Weixin')
} else {
var str = "http://localhost:8080/forApp/****.jspx?userId=" + uid + "&contentId=" + cid;
$.ajax({
type: "POST",
url: str,
dataType: "json",
success(data) {
console.log(111, data);
var category = data.data.category;
var mediaPath = data.data.mediaPath;
var staticurl = data.data.staticurl;
var mediaType = data.data.mediaType;
var type = data.data.type;
var vurl = data.data.vurl;
var id = data.data.id;
console.log(111, data.data.mediaPath);
console.log(111, data.data.category);
console.log(111, data.data.mediaType);
console.log(111, data.data.staticurl);
console.log(111, data.data.vurl);
console.log(111, data.data.id);
if (isAndroid) {
var an ="znn://riben:80/test?category=" + category + '&mediaPath=' + mediaPath + '&mediaType=' + mediaType + '&staticurl=' + staticurl + '&type=' + type + '&vurl=' + vurl + '&contentId=' + id
$('img').click(function() {
/* 安卓下载地址 */
window.location.href = AndroidLinks
});
window.open(an)
// window.location.href = "znn://riben:80/test?category=" + category + '&mediaPath=' + mediaPath + '&mediaType=' + mediaType + '&staticurl=' + staticurl + '&type=' + type + '&vurl=' + vurl + '&contentId=' + id;
} else if (isiOS) {
window.location.href = "JPTop://parameters?category=" + category + '&contentId=' + id + '&staticurl=' + staticurl + '&mediaType=' + mediaType;
$('img').click(function() {
/* IOS下载地址 */
window.location.href = IosLinks
});
}
}
})
}
})
</script>
</body>
</html>