人间熙攘,好久不见

vuePress-theme-reco Magic    2017 - 2023
人间熙攘,好久不见 人间熙攘,好久不见

Choose mode

  • dark
  • auto
  • light
Home
Category
  • tools
  • Zsh
  • iTerm2
  • Front-end
  • 版本控制-Git
  • Rust
  • skia-safe
  • 第三方对接
  • MQTT
  • Powershell
  • python
  • MD5
  • SHA1
  • wsl2
Tags
TimeLine
GitHub
  • Github (opens new window)
  • Before (opens new window)
author-avatar

Magic

23

文章

15

标签

Home
Category
  • tools
  • Zsh
  • iTerm2
  • Front-end
  • 版本控制-Git
  • Rust
  • skia-safe
  • 第三方对接
  • MQTT
  • Powershell
  • python
  • MD5
  • SHA1
  • wsl2
Tags
TimeLine
GitHub
  • Github (opens new window)
  • Before (opens new window)

微博钱包对接

vuePress-theme-reco Magic    2017 - 2023

微博钱包对接

Magic 2021-07-26 微博

微博钱包对接 💢

# 微博钱包对接

需要接入它的轻应用文档 (opens new window)

H5轻应用js目前不可用(截止:2021-08-13)后续可根对接方确认

页面不支持 post 请求,可让后端提供接口来进行中转或者通过 ng 来做

# 支付对接

  • 可以创建一个 from 表单来拉起支付
if (channel === PayChannel.WEIBO_MOBILE) {
  // 微博客户端 this.$router.replace 之后不会进入 created,所以提前弹窗
  if (res.params && res.params.url) { // 微博支付参数
    const formDOM = document.createElement('form');
    formDOM.action = res.params.url;
    formDOM.target = '_self';
    formDOM.method = 'post';
    formDOM.style.display = 'none';
    document.body.appendChild(formDOM);
    formDOM.submit();
    // ...dosomething
  } else {
    Toast('支付链接无效!');
  }
}

# 落地页返回需要跳转到 微博钱包页面

示例方法:

export function historyBackAddUrl(addUrl: string, curUrl = window.location.href) {
  const { history } = window;
  if (history.pushState && history.length <= 2) {
    history.replaceState('curstate', '', curUrl);
    history.pushState({}, '', curUrl);
  }
  window.onpopstate = (e: PopStateEvent) => {
    if (e.state === 'curstate') {
      window.location.replace(addUrl);
    }
  };
}

historyBackAddUrl('https://pay.sc.weibo.com/pay/index?source=xxxxxxxxx');

目前我们项目落地页是在首页通过参数来跳转到一个新的页面,微博钱包安卓端 容器有问题,需要用户手动点击容器后才能正确返回,所以可以在落地页增加一个弹窗来让用户点击。但是微博端要求落地页直接点击返回就要返回微博钱包,所以就以下面的方式改了下

beforeRouteLeave(toRoute, fromRoute, next) {
if (globalData.weiboWallet && this.$route.query.tag === 'auto' && toRoute.name === 'home') {
  location.href = 'https://pay.sc.weibo.com/pay/index?source=xxxxxxxx';
  return;
}
next();
},

所以说微博 难搞呀。。。

欢迎来到 人间熙攘,好久不见
看板娘