123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- var $zip;
- var domain = "https://aspx.bssji.com/";
- zip.useWebWorkers = false;
- zip.workerScriptsPath = "/Content/js/jszip/";
- $(function () {
- var myDropzone = new Dropzone("#dropz", {
- url: '/u.aspx',
- maxFiles: 1,
- maxFilesize: 51200,
- autoProcessQueue: false,
- acceptedFiles: ".apk,.ipa",
- //上传成功回调
- success: function (file, data) {
- console.log(data);
- },
- error: function (a, b, c) {
- console.log(a);
- console.log(b);
- console.log(c);
- },
- init: function () {
- this.on("addedfile", function (file) {
- processZipFile(file);
- });
- }
- });
- //提交上传
- $("#submit").on("click", function () {
- $("input[name='hlogo']").val($("#image").val());
- $("input[name='happName']").val($("#appName").val());
- $("input[name='hversion']").val($("#version").val());
- $("input[name='hpackageName']").val($("#packageName").val());
- $("input[name='hversionCode']").val($("#versionCode").val());
- myDropzone.processQueue();
- });
- //重新选择
- $("#reset").on("click", function () {
- location = location;
- });
- function parse(infoplist, resoucesArsc, androidManifest) {
- var data = {};
- if (androidManifest.length > 0) {
- data.system = "android";
- resoucesArsc[0].async("uint8array").then(function (arsc) {
- androidManifest[0].async("uint8array").then(function (mainifest) {
- data.arsc = Base64.encode(arsc);
- data.mainifest = Base64.encode(mainifest);
- callback(data);
- });
- });
- } else if (infoplist.length > 0) {
- data.system = "ios";
- infoplist[0].async("uint8array").then(function (d) {
- data.plist = Base64.encode(d);
- callback(data);
- });
- }
- }
- });
- function showLoading() {
- $("#full,#loading").fadeIn();
- }
- function hideLoading() {
- $("#full,#loading").fadeOut();
- }
- function ajaxCallBack(d, sys) {
- $("input[name='hsysname']").val(sys);
- //切换
- $(".zone,.tip").hide();
- $(".info").show();
- //给字段赋值
- $("#appName").val(d.Name);
- $("#version").val(d.Version);
- $("#packageName").val(d.PackageName);
- $("#versionCode").val(d.VersionCode);
- //$("#logo").val(d.LogoName);
- var logoType = logotype(d.LogoName);
- //如果是ios并且没有扩展名称
- if (sys == "ios" && d.LogoName.indexOf(".") == -1) {
- d.LogoName = "/" + d.LogoName + "([\\d]+x[\\d]+)?(@[\\d]x)?.png";
- } else if (sys == "ios") {
- d.LogoName = "/" + d.LogoName;
- }
- //图片
- if (d.LogoName) {
- var logo = getIconFile(d.LogoName);
- if (logo) {
- logo.getData(new zip.BlobWriter(), function (blob) {
- var reader = new FileReader();
- reader.addEventListener("loadend", function () {
- var dd = Base64.encode(new Uint8Array(reader.result));
- $.ajax({
- url: domain + "GetString.ashx",
- type: "POST",
- cache: false,
- data: { image: dd, system: sys },
- complete: function () {
- hideLoading();
- },
- error: function () {
- alert("获取Logo失败")
- },
- success: function (abc) {
- $("input[name='logo']").val(abc);
- $("#image").attr("src", "data:" + logoType + ";base64," + abc);
- }
- });
- });
- reader.readAsArrayBuffer(blob);
- });
- }
- else {
- hideLoading();
- $("input[name='logo']").val("");
- $("#image").attr("src", "./Content/default.png");
- }
- }
- else {
- hideLoading();
- $("input[name='logo']").val("");
- $("#image").attr("src", "./Content/default.png");
- }
-
- }
- function logotype(filename) {
- if (/(\.|\/)(png)$/i.test(filename)) {
- return 'image/png';
- }
- if (/(\.|\/)(ico)$/i.test(filename)) {
- return 'image/x-icon';
- }
- if (/(\.|\/)(gif)$/i.test(filename)) {
- return 'image/gif';
- }
- if (/(\.|\/)(bmp)$/i.test(filename)) {
- return 'image/bmp';
- }
- if (/(\.|\/)(jpeg|jpg|jpe)$/i.test(filename)) {
- return 'image/jpeg';
- }
- return 'image/png';
- }
- function processZipFile(file) {
- zip.createReader(new zip.BlobReader(file), function (reader) {
- reader.getEntries(function (entries) {
- $zip = entries;
- var infoplist = null, resoucesArsc = null, androidManifest = null;
- for (var i = 0; i < entries.length; i++) {
- if (entries[i].filename.match(/^(([^\\\?\/\*\|<>:"]+\/){2})Info\.plist/) || entries[i].filename.indexOf('.app/Info.plist') != -1) {
- infoplist = entries[i];
- continue;
- }
- if (entries[i].filename.match(/AndroidManifest.xml/)) {
- androidManifest = entries[i];
- continue;
- }
- if (entries[i].filename.match(/resources.arsc/)) {
- resoucesArsc = entries[i];
- continue;
- }
- }
- processZipFileSubmit(infoplist, resoucesArsc, androidManifest);
- });
- }, function (error) {
- console.log(error);
- alert("读取安装包信息失败!");
- });
- }
- function processZipFileSubmit(infoplist, resoucesArsc, androidManifest) {
- var data = {};
- if (infoplist != null) {
- data.system = "ios";
- infoplist.getData(new zip.BlobWriter(), function (blob) {
- var reader = new FileReader();
- reader.addEventListener("loadend", function () {
- var bytes = new Uint8Array(reader.result);
- data.plist = Base64.encode(bytes);
- callback(data);
- });
- reader.readAsArrayBuffer(blob);
- });
- }
- else if (resoucesArsc != null && androidManifest != null) {
- data.system = "android";
- function readArsc() {
- resoucesArsc.getData(new zip.BlobWriter(), function (blob) {
- var reader = new FileReader();
- reader.addEventListener("loadend", function () {
- data.arsc = Base64.encode(new Uint8Array(reader.result));
- readManifest();
- });
- reader.readAsArrayBuffer(blob);
- });
- }
- function readManifest() {
- androidManifest.getData(new zip.BlobWriter(), function (blob) {
- var reader = new FileReader();
- reader.addEventListener("loadend", function () {
- data.mainifest = Base64.encode(new Uint8Array(reader.result));
- callback(data);
- });
- reader.readAsArrayBuffer(blob);
- });
- }
- readArsc();
- } else {
- alert("上传的文件不正确,无法读取!");
- return;
- }
- }
- function callback(data) {
- showLoading();
- $.ajax({
- url: domain + "GetAppInfo.ashx",
- type: "POST",
- data: data,
- cache: false,
- success: function (d) {
- if (d.Success) {
- ajaxCallBack(d, data.system);
- } else {
- hideLoading();
- alert("获取不到安装包信息!");
- }
- },
- error: function () {
- hideLoading();
- alert("error");
- }
- });
- }
- function getIconFile(fileName) {
- var iconFile = null;
- for (var i = 0; i < $zip.length; i++) {
- if ($zip[i].filename.match(new RegExp(fileName, "i"))) {
- iconFile = $zip[i];
- break;
- }
- }
- return iconFile;
- }
- Uint8Array.prototype.toString = function () {
- if (this.join) {
- return this.join(',');
- } else {
- var a = Array.prototype.slice.call(this);
- return a.join(',');
- }
- }
|