package org.yeshi.utils;
|
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
|
import java.net.URLEncoder;
|
|
/**
|
* 应用市场帮助类
|
*/
|
public class AppMarketUtil {
|
|
/**
|
* 获取应用的最新版本
|
*
|
* @param appId
|
* @return
|
*/
|
public static String getHWLatestVersion(String appId) {
|
try {
|
String url = String.format("https://appgallery.cloud.huawei.com/uowap/index?method=internal.getTabDetail&serviceType=13&reqPageNum=1&uri=%s&appid=C%s&shareTo=undefined&locale=en_US&maxResults=10¤tUrl=%s&version=10.0.0", URLEncoder.encode("app|C" + appId, "UTF-8"), appId, URLEncoder.encode(String.format("https://appgallery.cloud.huawei.com/uowap/index.html#/detailApp/C%s", appId), "UTF-8"));
|
System.out.println(url);
|
String result = HttpUtil.get(url);
|
JSONObject root = JSONObject.fromObject(result);
|
JSONArray array = root.optJSONArray("layoutData");
|
for (int i = 0; i < array.size(); i++) {
|
JSONObject item = array.optJSONObject(i);
|
if (item != null && item.optJSONArray("dataList") != null) {
|
JSONArray array1 = item.optJSONArray("dataList");
|
if (array1 != null)
|
for (int j = 0; j < array1.size(); j++) {
|
item = array1.optJSONObject(j);
|
if (item != null && !StringUtil.isNullOrEmpty(item.optString("version") )) {
|
return item.optString("version").trim();
|
}
|
}
|
}
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
|
}
|