• ios 微信小程序分析


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

    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 这个是很关键的东西。 
  • 相关阅读:
    BZOJ 5059: 前鬼后鬼的守护 可并堆 左偏树 数学
    BZOJ 1975: [Sdoi2010]魔法猪学院 大水题 第k短路 spfa
    BZOJ 4003: [JLOI2015]城池攻占 左偏树 可并堆
    BZOJ 3091: 城市旅行 lct 期望 splay
    2018/3/27 省选模拟赛 140分
    BZOJ 2959: 长跑 lct 双联通分量 并查集 splay
    2018/3/26 省选模拟赛 60分
    快速排序
    插入排序法
    快速排序的两种方法
  • 原文地址:https://www.cnblogs.com/dzqdzq/p/14770068.html
Copyright © 2020-2023  润新知