Authored by unknown

分享图片资源位 url截取

... ... @@ -4385,6 +4385,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
String templateName= json.getString("template_name");
Object object= json.get("data");
String url=getUrlFromJsonObjOrJsonArr(object);
// 分享banner
if("splitJointImgBanner".equals(templateName)){
bo.setImageUrl(url);
... ... @@ -4401,18 +4402,38 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* @return
*/
private String getUrlFromJsonObjOrJsonArr(Object object) {
String url="";
if(object instanceof JSONObject ){
JSONObject jsonObj=(JSONObject)JSONObject.toJSON(object);
return jsonObj.getString("src");
return subStringUrl(jsonObj.getString("src"));
}else if(object instanceof JSONArray){
JSONArray jSONArray=(JSONArray)JSONArray.toJSON(object);
if(jSONArray!=null){
JSONObject jSONObject=jSONArray.getJSONObject(0);
return jSONObject.getString("src");
return subStringUrl(jSONObject.getString("src"));
}
}
return null;
}
/**
* 截取src问号前面的部分
* @param src
* @return
*/
private String subStringUrl(String src) {
String url="";
if(StringUtils.isEmpty(src)){
return null;
}
int offset=src.indexOf("?");
// 不存在?,直接返回。截取会抛异常
if(offset==-1){
return src;
}
url=src.substring(0,offset);
return url;
}
});
}
}
... ...