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; } /** * 获取vivo最新的版本号 * * @param appId * @return */ public static Integer getVIVOLatestVersionCode(String appId) { try { String url = String.format("https://hf.appstore.vivo.com.cn/detail/%s?frompage=messageh5&imei=1234567890&av=18&app_version=2100&pictype=webp&h5_websource=h5appstore", appId); System.out.println(url); String result = HttpUtil.get(url); JSONObject root = JSONObject.fromObject(result); return root.optInt("version_code"); } catch (Exception e) { e.printStackTrace(); } return null; } }