瀏覽代碼

根据下载链接获取应用包名

yangzian 4 年之前
父節點
當前提交
c062ce0ee0

+ 1 - 1
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/vo/Result.java

@@ -125,7 +125,7 @@ public class Result<T> implements Serializable {
 	public static<T> Result<T> errorMsg(String msg) {
 		Result<T> r = new Result<T>();
 		r.setSuccess(true);
-		r.setCode(CommonConstant.STATUS_NORMAL);
+		r.setCode(CommonConstant.STATUS_DISABLE);
 		//r.setResult(t);
 		r.setMessage(msg);
 		return r;

+ 14 - 0
jeecg-boot-bytedance/pom.xml

@@ -25,6 +25,20 @@
             <artifactId>httpmime</artifactId>
             <version>4.5.10</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.github.tony19</groupId>
+            <artifactId>apktool-lib</artifactId>
+            <version>1.4.4-3</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.googlecode.plist</groupId>
+            <artifactId>dd-plist</artifactId>
+            <version>1.16</version>
+            <scope>compile</scope>
+        </dependency>
+
         <!--引入微服务启动依赖 starter
       <dependency>
           <groupId>org.jeecgframework.boot</groupId>

+ 249 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/utils/ApkUtils.java

@@ -0,0 +1,249 @@
+package org.jeecg.modules.bytedance.common.utils;
+
+import android.util.TypedValue;
+import brut.androlib.res.decoder.AXmlResourceParser;
+import com.dd.plist.NSArray;
+import com.dd.plist.NSString;
+import com.dd.plist.PropertyListParser;
+import org.xmlpull.v1.XmlPullParser;
+import com.dd.plist.NSDictionary;
+
+import java.io.*;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipInputStream;
+
+public class ApkUtils {
+    /**
+     * 读取apk
+     * @param apkUrl
+     * @return
+     */
+    public static Map<String,Object> readAPK(String apkUrl){
+        ZipFile zipFile;
+        Map<String,Object> map = new HashMap<String, Object>();
+        try {
+            zipFile = new ZipFile(apkUrl);
+            Enumeration<?> enumeration = zipFile.entries();
+            ZipEntry zipEntry = null;
+            while (enumeration.hasMoreElements()) {
+                zipEntry = (ZipEntry) enumeration.nextElement();
+                if (zipEntry.isDirectory()) {
+
+                } else {
+                    if ("androidmanifest.xml".equals(zipEntry.getName().toLowerCase())) {
+                        AXmlResourceParser parser = new AXmlResourceParser();
+                        parser.open(zipFile.getInputStream(zipEntry));
+                        while (true) {
+                            int type = parser.next();
+                            if (type == XmlPullParser.END_DOCUMENT) {
+                                break;
+                            }
+                            String name = parser.getName();
+                            if(null != name && "manifest".equals(name.toLowerCase())){
+                                for (int i = 0; i != parser.getAttributeCount(); i++) {
+                                    if ("versionName".equals(parser.getAttributeName(i))) {
+                                        String versionName = getAttributeValue(parser, i);
+                                        if(null == versionName){
+                                            versionName = "";
+                                        }
+                                        map.put("versionName", versionName);
+                                    } else if ("package".equals(parser.getAttributeName(i))) {
+                                        String packageName = getAttributeValue(parser, i);
+                                        if(null == packageName){
+                                            packageName = "";
+                                        }
+                                        map.put("package", packageName);
+                                    } else if("versionCode".equals(parser.getAttributeName(i))){
+                                        String versionCode = getAttributeValue(parser, i);
+                                        if(null == versionCode){
+                                            versionCode = "";
+                                        }
+                                        map.put("versionCode", versionCode);
+                                    }
+                                }
+                                break;
+                            }
+                        }
+                    }
+
+                }
+            }
+            zipFile.close();
+        } catch (Exception e) {
+            map.put("code", "fail");
+            map.put("error","读取apk失败");
+        }
+        return map;
+    }
+
+    private static String getAttributeValue(AXmlResourceParser parser, int index) {
+        int type = parser.getAttributeValueType(index);
+        int data = parser.getAttributeValueData(index);
+        if (type == TypedValue.TYPE_STRING) {
+            return parser.getAttributeValue(index);
+        }
+        if (type == TypedValue.TYPE_ATTRIBUTE) {
+            return String.format("?%s%08X", getPackage(data), data);
+        }
+        if (type == TypedValue.TYPE_REFERENCE) {
+            return String.format("@%s%08X", getPackage(data), data);
+        }
+        if (type == TypedValue.TYPE_FLOAT) {
+            return String.valueOf(Float.intBitsToFloat(data));
+        }
+        if (type == TypedValue.TYPE_INT_HEX) {
+            return String.format("0x%08X", data);
+        }
+        if (type == TypedValue.TYPE_INT_BOOLEAN) {
+            return data != 0 ? "true" : "false";
+        }
+        if (type == TypedValue.TYPE_DIMENSION) {
+            return Float.toString(complexToFloat(data)) + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
+        }
+        if (type == TypedValue.TYPE_FRACTION) {
+            return Float.toString(complexToFloat(data)) + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
+        }
+        if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
+            return String.format("#%08X", data);
+        }
+        if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
+            return String.valueOf(data);
+        }
+        return String.format("<0x%X, type 0x%02X>", data, type);
+    }
+
+    private static String getPackage(int id) {
+        if (id >>> 24 == 1) {
+            return "android:";
+        }
+        return "";
+    }
+
+    // ///////////////////////////////// ILLEGAL STUFF, DONT LOOK :)
+    public static float complexToFloat(int complex) {
+        return (float) (complex & 0xFFFFFF00) * RADIX_MULTS[(complex >> 4) & 3];
+    }
+
+    private static final float[] RADIX_MULTS =
+            {
+                    0.00390625F, 3.051758E-005F,
+                    1.192093E-007F, 4.656613E-010F
+            };
+    private static final String[] DIMENSION_UNITS = { "px", "dip", "sp", "pt", "in", "mm", "", "" };
+    private static final String[] FRACTION_UNITS = { "%", "%p", "", "", "", "", "", "" };
+
+    /**
+     * 读取ipa
+     */
+    public static Map<String,Object> readIPA(String ipaURL){
+        Map<String,Object> map = new HashMap<String,Object>();
+        try {
+            File file = new File(ipaURL);
+            InputStream is = new FileInputStream(file);
+            InputStream is2 = new FileInputStream(file);
+            ZipInputStream zipIns = new ZipInputStream(is);
+            ZipInputStream zipIns2 = new ZipInputStream(is2);
+            ZipEntry ze;
+            ZipEntry ze2;
+            InputStream infoIs = null;
+            NSDictionary rootDict = null;
+            String icon = null;
+            while ((ze = zipIns.getNextEntry()) != null) {
+                if (!ze.isDirectory()) {
+                    String name = ze.getName();
+                    if (null != name &&
+                            name.toLowerCase().contains(".app/info.plist")) {
+                        ByteArrayOutputStream copy = new
+                                ByteArrayOutputStream();
+                        int chunk = 0;
+                        byte[] data = new byte[1024];
+                        while(-1!=(chunk=zipIns.read(data))){
+                            copy.write(data, 0, chunk);
+                        }
+                        infoIs = new ByteArrayInputStream(copy.toByteArray());
+                        rootDict = (NSDictionary) PropertyListParser.parse(infoIs);
+
+                        //我们可以根据info.plist结构获取任意我们需要的东西
+                        //比如下面我获取图标名称,图标的目录结构请下面图片
+                        //获取图标名称
+                        NSDictionary iconDict = (NSDictionary) rootDict.get("CFBundleIcons");
+
+                        while (null != iconDict) {
+                            if(iconDict.containsKey("CFBundlePrimaryIcon")){
+                                NSDictionary CFBundlePrimaryIcon = (NSDictionary)iconDict.get("CFBundlePrimaryIcon");
+                                if(CFBundlePrimaryIcon.containsKey("CFBundleIconFiles")){
+                                    NSArray CFBundleIconFiles =(NSArray)CFBundlePrimaryIcon.get("CFBundleIconFiles");
+                                    icon = CFBundleIconFiles.getArray()[0].toString();
+                                    if(icon.contains(".png")){
+                                        icon = icon.replace(".png", "");
+                                    }
+                                    break;
+                                }
+                            }
+                        }
+                        break;
+                    }
+                }
+            }
+
+            //根据图标名称下载图标文件到指定位置
+            while ((ze2 = zipIns2.getNextEntry()) != null) {
+                if (!ze2.isDirectory()) {
+                    String name = ze2.getName();
+                    if(name.contains(icon.trim())){
+                        FileOutputStream fos = new FileOutputStream(new File("E:\\python\\img\\icon.png"));
+                        int chunk = 0;
+                        byte[] data = new byte[1024];
+                        while(-1!=(chunk=zipIns2.read(data))){
+                            fos.write(data, 0, chunk);
+                        }
+                        fos.close();
+                        break;
+                    }
+                }
+            }
+
+            // 应用包名
+            NSString parameters = (NSString) rootDict.get("CFBundleIdentifier");
+            map.put("package", parameters.toString());
+            // 应用版本名
+            parameters = (NSString) rootDict.objectForKey("CFBundleShortVersionString");
+            map.put("versionName", parameters.toString());
+            //应用版本号
+            parameters = (NSString) rootDict.get("CFBundleVersion");
+            map.put("versionCode", parameters.toString());
+
+            infoIs.close();
+            is.close();
+            zipIns.close();
+
+        } catch (Exception e) {
+            map.put("code", "-1");
+            map.put("error","读取ipa文件失败");
+        }
+        return map;
+    }
+
+
+    public static void main(String[] args) {
+       // Map map = ApkUtils.readAPK("https://apps.bytesfield.com/download/basic/cur/1c728178004c8d4d6c83444a05c414c1a1cfae48");
+
+        //String filePath = LoadFileUtil.downLoadFromUrl("https://apps.bytesfield.com/download/basic/cur/1c728178004c8d4d6c83444a05c414c1a1cfae48","apkFile");
+        String filePath = LoadFileUtil.downLoadFromUrl("https://apps.bytesfield.com/download/basic/cur/96e5f2491826db22962149059da9e4eee7589764","apkFile");
+
+        System.out.println(filePath);
+
+        Map map = ApkUtils.readAPK("C:\\Users\\Administrator\\Downloads\\489586631a2c162f812e03be33ca7e87.apk");
+        Map map2 = ApkUtils.readAPK(filePath);
+
+        System.out.println(map);
+        System.out.println(map2);
+
+
+    }
+
+}

+ 51 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/bytedance/advertise/controller/AiBytedanceAdvertiserStrategyController.java

@@ -22,14 +22,18 @@ import org.jeecg.modules.bytedance.common.constant.BytedanceConstant;
 import org.jeecg.modules.bytedance.common.entity.MaterialImageInfo;
 import org.jeecg.modules.bytedance.common.service.IMaterialImageInfoService;
 import org.jeecg.modules.bytedance.common.service.impl.MaterialImageInfoServiceImpl;
+import org.jeecg.modules.bytedance.common.utils.ApkUtils;
 import org.jeecg.modules.bytedance.common.utils.Check;
+import org.jeecg.modules.bytedance.common.utils.LoadFileUtil;
 import org.jeecg.modules.system.service.ISysRoleService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 头条智能投放账户配置信息表
@@ -126,13 +130,20 @@ public class AiBytedanceAdvertiserStrategyController {
 	@PutMapping(value = "/edit")
 	public Result<AiBytedanceAdvertiserStrategy> edit(@RequestBody AiBytedanceAdvertiserStrategy aiBytedanceAdvertiserStrategy) {
 		Result<AiBytedanceAdvertiserStrategy> result = new Result<AiBytedanceAdvertiserStrategy>();
+		//商品卖点
+		aiBytedanceAdvertiserStrategy.setCreativeProductSellingPoints(StringUtils.join(aiBytedanceAdvertiserStrategy.getProductSellingPoints(), ","));
+		//广告位置
+		aiBytedanceAdvertiserStrategy.setCreativeInventoryType(StringUtils.join(aiBytedanceAdvertiserStrategy.getCreativeInventoryTypes(), ","));
+		//创意标签
+		aiBytedanceAdvertiserStrategy.setCreativeAdKeywords(StringUtils.join(aiBytedanceAdvertiserStrategy.getAdKeywords(), ","));
+
 		AiBytedanceAdvertiserStrategy aiBytedanceAdvertiserStrategyEntity = aiBytedanceAdvertiserStrategyService.getById(aiBytedanceAdvertiserStrategy.getId());
 		if(aiBytedanceAdvertiserStrategyEntity==null) {
 			result.error500("未找到对应实体");
 		}else {
 			boolean ok = aiBytedanceAdvertiserStrategyService.updateById(aiBytedanceAdvertiserStrategy);
 			if(ok) {
-				result.success("修改成功!");
+				return  Result.successMsg("修改成功!", null);
 			}
 		}
 
@@ -153,7 +164,7 @@ public class AiBytedanceAdvertiserStrategyController {
 			log.error("删除失败",e.getMessage());
 			return Result.error("删除失败!");
 		}
-		return Result.ok("删除成功!");
+		return Result.successMsg("删除成功!",null);
 	}
 
 	/**
@@ -300,4 +311,42 @@ public class AiBytedanceAdvertiserStrategyController {
 
 
 
+	/**
+	 *
+	 * @description:根据下载链接获取应用包名
+	 *
+	 * @param downloadType 类型
+	 * @param urlPath 下载链接
+	 * @return: org.jeecg.common.api.vo.Result
+	 * @author: zianY
+	 */
+	@ApiOperation(value="根据下载链接获取应用包名", notes="根据下载链接获取应用包名")
+	@GetMapping(value = "/getPackageNameByUrl")
+	public Result getPackageNameByUrl(@RequestParam("downloadType") String downloadType,@RequestParam("urlPath") String urlPath) {
+
+		try {
+			Map map = new HashMap();
+			//根据下载链接上传附件
+			urlPath = LoadFileUtil.downLoadFromUrl(urlPath, "appFiles");
+			if ("android".equalsIgnoreCase(downloadType)){
+				// 根据附件地址 读取 apk 信息
+				 map = ApkUtils.readAPK(urlPath);
+			}
+			if ("ios".equalsIgnoreCase(downloadType)){
+				 map = ApkUtils.readIPA(urlPath);
+			}
+			return Result.successMsg("根据下载链接获取应用包名成功", map);
+		}catch (Exception e){
+			log.error("根据下载链接获取应用包名异常",e.getMessage());
+			return Result.error("请求失败,请联系开发人员!");
+		}
+	}
+
+
+
+
+
+
+
+
 }