码迷,mamicode.com
首页 > 微信 > 详细

ios 微信小程序分析

时间:2021-05-24 09:49:44      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:location   callback   方法   url   OLE   java   contain   adt   close   

小程序启动下载逻辑相关:

https://game.weixin.qq.com/cgi-bin/h5/static/commlib/index.html

技术图片

 

 这个是实时的。 但是貌似本地也会存储,存储路径: /var/mobile/Containers/Data/Application/B1E7B553-B1EC-4679-A4C1-ED81541F0D44/Library/WechatPrivate/WePkg/Data/commlib/9192/pkg.dat

这个dat格式和wxapkg格式有一点差别, 暂时还没有找到怎么解压它的方法。

 

下载小程序相关逻辑:

function (e, t, n) {
    var i = n(4),
      o = n(0);
    (i.downloadAppInternal =
      i.downloadAppInternal ||
      function (e, t) {
        e = e || {};
        var n = o.clientVersion(!0);
        o.versionCompare(n, "6.5.6") >= 0
          ? i.invoke("downloadAppInternal", e, t)
          : (t && t.call(i, {}), (window.location.href = e.appUrl));
      }),
      (e.exports = i);
  }
        downloadApp: {
          ios: function (e) {
            var t = e.appitem,
              n = e.callback,
              i = e.config || {};
            T.detail.launchApp({
              appitem: t,
              config: i,
              callback: function (e) {
                e.err_msg.indexOf(":ok") > -1 || e.err_msg.indexOf(":yes") > -1
                  ? n(e)
                  : (function (e, t) {
                      var n = e.DownloadInfo,
                        r = o.versionCompare(o.clientVersion(1), "6.5.5") > 0;
                      if (
                        !i.downloadInternal ||
                        !r ||
                        v.getQueryStr("isFromWeappEntry")
                      )
                        return (
                          (location.href = n.DownloadURL),
                          void t({ err_msg: "downloadAppInternal:ok" })
                        );
                      a.downloadAppInternal(
                        { appUrl: n.DownloadURL },
                        function (e) {
                          t(e);
                        }
                      );
                    })(t, n);
              },
            });
          },
          android: function (e) {
            var t = e.appitem,
              n = e.callback,
              i = e.config || {},
              s = t.AppID,
              l = t.DownloadInfo,
              u =
                o.versionCompare(o.clientVersion(1), "6.5.7") >= 0
                  ? "addDownloadTaskStraight"
                  : "addDownloadTask",
              d = "number" == typeof l.DownloaderType ? l.DownloaderType : 1,
              p =
                "boolean" == typeof l.use_downloader_widget &&
                l.use_downloader_widget,
              f = "boolean" == typeof l.download_in_wifi && l.download_in_wifi,
              g = i.isAutoDownload ? 3 : 1,
              m = l.android_section_md5_list || [];
            function h() {
              a.invoke(
                u,
                {
                  appid: s,
                  task_name: t.Name || t.PackageName,
                  package_name: t.PackageName,
                  task_url: l.DownloadURL,
                  file_md5: l.AndroidApkMd5,
                  task_size: l.AndroidApkSize,
                  alternative_url: l.AlternativeDownloadURL,
                  downloader_type: d,
                  download_type: g,
                  use_downloader_widget: p,
                  download_in_wifi: f,
                  scene: i.sceneid,
                  uiarea: i.uiarea,
                  fileSectionMd5: m,
                  extInfo: encodeURIComponent(
                    JSON.stringify({
                      gameid: s,
                      noticeid:
                        parseInt(t.Noticeid) ||
                        parseInt(v.getQueryStr("noticeid") || 0) ||
                        0,
                    })
                  ),
                },
                function (e) {
                  E(t, i, e, "add"),
                    n && n(e),
                    p &&
                      o.versionCompare(o.clientVersion(1), "7.0.3") >= 0 &&
                      r.trigger("addToDownloaderWidget", { appid: s });
                }
              );
            }
            i.showDownloadConfirmAlert && o.isAndroid
              ? c.alert("即将为你下载 ".concat(t.Name), {
                  confirmCb: function () {
                    h();
                  },
                  style: "twoBtn",
                  closeCb: function () {},
                })
              : h();
          },
        },
        launchApp: function (e) {
          var t = e.appitem,
            n = e.callback,
            i = e.config || {},
            r = t.AppID,
            s = t.DownloadInfo;
          if (t.has_sp_launch_privilege)
            new l({
              appid: r,
              ssid: i.sceneid,
              success: function (e) {
                d({ extern_info: e.extern_info });
              },
              fail: function () {
                d();
              },
              cancel: function () {},
            });
          else {
            var c = p.getKeyValue("first_launch_game_privilege");
            (!c || (c && -1 === c.indexOf(r || ""))) &&
            o.isAndroid &&
            t &&
            4 !== t.AppType
              ? ((c = c ? JSON.parse(c) : []).push(r),
                p.setKeyValue("first_launch_game_privilege", JSON.stringify(c)),
                new u({
                  appid: r,
                  appitem: t,
                  scene: "",
                  uiarea: "",
                  success: function (e) {
                    console.log("success"), d();
                  },
                  cancel: function () {
                    console.log("cancel");
                  },
                }))
              : d();
          }
          function d(e) {
            var c =
                o.versionCompare(o.clientVersion(1), "6.5.5") >= 0
                  ? "launchApplication"
                  : "launch3rdApp",
              l =
                (e = e || {}).extern_info ||
                t.launch_info ||
                (o.isAndroid ? i.launchAndroidAppText : i.launchIOSAppText);
            a.invoke(
              c,
              {
                appID: r,
                messageExt: l,
                extInfo: l,
                showLaunchFailToast: !1,
                installSchemeUrl: s.DownloadURL,
                installAction: 1,
              },
              function (e) {
                n && n(e);
              }
            );
          }
        },
        installApp: function (e) {
          var t = e.appitem,
            n = e.callback,
            i = e.config || {},
            o = t.AppID,
            r = i.isAutoDownload ? 3 : 1;
          a.queryDownloadTask({ appid: o }, function (e) {
            e.state.indexOf("_succ") > -1
              ? a.installDownloadTask(
                  { download_id: e.download_id, download_type: r },
                  function (e) {
                    n(e);
                  }
                )
              : n({
                  err_msg:
                    "(installApp -> queryDownloadTask):" + JSON.stringify(e),
                });
          });
        },
        launchAppOrH5: function (e) {
          var t = e.appitem,
            n = e.callback,
            i = e.config || {},
            o = T.detail;
          o.launchApp({
            appitem: t,
            callback: function (e) {
              e.err_msg.indexOf(":ok") > -1 ? n(e) : o.launchH5(t, n);
            },
            config: i,
          });
        },


这些都是比较核心的逻辑。

appitem是很关键的数据结构, 小程序的下载地址为: appitem.DownloadInfo.DownloadURL


微信小程序和微信APP的交互,全靠window.WeixinJSBridge 这个是很关键的东西。 

 

ios 微信小程序分析

标签:location   callback   方法   url   OLE   java   contain   adt   close   

原文地址:https://www.cnblogs.com/dzqdzq/p/14770068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!