微信 ios二次分享,页面打开空白,已做授权重定向处理

发布于 2022-09-12 02:34:41 字数 1563 浏览 21 评论 0

背景:分享出去的外链,会自动给加上微信标识,导致二次分享失败,
如打开页面:

`https://xxx/#/deepCoupling/v-main?aaa=5555`

分享出去链接:

https://xxx/from=groupmessage&isappinstalled=0#/deepCoupling/v-main?aaa=5555

解决办法:

R1、替换路径,简单粗暴(query字段只对微信有用,对我们没用)

  const origin = isIOS() ? window.location.origin + '/#/' : window.location.origin;
  window.location.href = environment.wxAuthUrl + '/third/authForLogin?authorizerAppid=' + wxAppId + '&businessURI=' + encodeURIComponent(origin);
  alert(window.location.href + '授权后地址333');
  if (isIOS()) {
    alert(getCookie('deepCouplingVmain') + '获取getCookie3333');
    if (window.location.href.indexOf('from') !== -1 || window.location.href.indexOf('isappinstalled') !== -1) {
      if (window.location.href.indexOf('deepCoupling/v-main') !== -1) {
        // window.location.href = getCookie('deepCouplingVmain') + '?random=' + Math.floor(Math.random() * 1048576);
        window.history.replaceState(null, '', getCookie('deepCouplingVmain'));
      }
    
    } else {
      if (window.location.href.indexOf('deepCoupling/v-main') !== -1) {
        if (!(getCookie('deepCouplingVmain'))) {
          setCookie('deepCouplingVmain', window.location.href);
        }
      }
    }
  }

但是页面重定向后没有刷新,需要手动刷新

ios第二次分享打不开

如果url不带?aaa=5555即正常
但是后面带了参数第二次分享就打不开了

 https://xxx/#/deepCoupling/v-main?aaa=5555

解决方案参考 https://segmentfault.com/a/11...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

日裸衫吸 2022-09-19 02:34:41
    window.location.replace(href);

试用了也是没效果 也是需要刷新

解决方案:

由于url带?a=555 参数都会导致 ios在第二次分享的时候打开页面空白状态
最后将a=555,进来的时候就setcookie,然后在ulr 带 from等因分享附带的参数 情况下,重定向,重定向url不带?a=555,而将?a=555放到分享的链接上。

代码如下:

export const getSearchUrl = (url) => {
    if (url.indexOf('?') !== -1) {
      const afterUrl = url.substring(url.indexOf('?') + 1);
      const cookieKey = afterUrl.substring(0 , afterUrl.indexOf('='));
      const cookieVal = afterUrl.substring(afterUrl.indexOf('=') + 1);
      setCookie(cookieKey, cookieVal);
    }
};
export const redirect = (url) => {
  if (url.indexOf('?') !== -1) {
    const beforeUrl = url.substring(0, url.indexOf('?'));
    if (window.location.href.indexOf('from') !== -1 || window.location.href.indexOf('isappinstalled') !== -1) {
      if (window.location.href.indexOf(beforeUrl) !== -1) {
        window.location.href =  environment.domainUrl + beforeUrl;
      }
    }
  }
}
export const wxOAuth = (wxAppId: string, url: string) => {
  sessionStorage.setItem(LAST_URL, url);
  getSearchUrl(url);
  const origin = isIOS() ? window.location.origin + '/#/' : window.location.origin;
  window.location.href = environment.wxAuthUrl + '/third/authForLogin?authorizerAppid=' + wxAppId + '&businessURI=' + encodeURIComponent(origin);
  redirect(url);
};

页面进来,获取id:

activateInfo.queryParams.subscribe(queryParams => {
      if (queryParams.mediaActivityParticipantId === '' || queryParams.mediaActivityParticipantId === null  || queryParams.mediaActivityParticipantId === undefined) {
        this.tutorId = getCookie('mediaActivityParticipantId');
      } else {
        this.tutorId = queryParams.mediaActivityParticipantId;
      }
    });

分享代码:

 wxShare({
        title: '',
        desc: '',
        link: window.location.origin + '/#/deepCoupling/v-main?mediaActivityParticipantId=' + this.tutorId,
        imgUrl: window.location.origin + '/assets/img/deep/share.jpg'
      });

页面关闭,清楚改页面cookie

ngOnDestroy() {
    delCookie('mediaActivityParticipantId');
  }
三人与歌 2022-09-19 02:34:41

我....顶你个。在公司打开了你的连接...

情绪操控生活 2022-09-19 02:34:41

重定向使用window.location.replace

let href = window.location.href;
if(href.indexOf('groupmessage') > -1 || href.indexOf('singlemessage') > -1 || href.indexOf('timeline') > -1){
    href = href.replace(/\?from=(groupmessage|singlemessage|timeline)(\S*)#/, '#');
    window.location.replace(href);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文