H5 when WeChat Pay's iPhone opens the page for the second time, the payment cashier will not be able to adjust.

question:
in the case of the second page within WeChat Pay ios in h5, after canceling the payment for the first time, there is a probability that the same page will trigger WeixinJSBridge = "undefined",WeixinJSBridgeReady will not continue, resulting in the failure of the payment cashier.

WeChat Pay source code:

const onBridgeReady = (config, success, fail) => {
  WeixinJSBridge.invoke(   // eslint-disable-line
    "getBrandWCPayRequest", config,
    (res) => {
      if (res.err_msg === "get_brand_wcpay_request:ok") {
        success(res)
      } else {
        fail()
      }
    }
  )
}

export const wxRealPay = (config, success, fail) => {
  if (typeof WeixinJSBridge === "undefined") {
    if (document.addEventListener) {
      document.addEventListener("WeixinJSBridgeReady", () => onBridgeReady(config, success, fail), false)
    } else if (document.attachEvent) {
      document.attachEvent("WeixinJSBridgeReady", () => onBridgeReady(config, success, fail))
      document.attachEvent("onWeixinJSBridgeReady", () => onBridgeReady(config, success, fail))
    }
  } else {
    onBridgeReady(config, success, fail)
  }
}

payment has been online for some time, so there is no problem under normal circumstances. It feels like both WeixinJSBridge and WeixinJSBridgeReady are invalid.

at first I thought it was the ios cache problem. Through this link , I used both timestamps and < html manifest=" IGNORE.manifest "> methods, but to no avail.

now we can only let him refresh in place, hoping to find a better way


after searching for a long time, I didn't find the reason, but finally let him refresh it every time he came in, and he could indeed adjust the payment cashier

.
window.onload = function() {
    if(!window.location.hash) {
        window.location = window.location + '-sharploaded';
        window.location.reload();
    }
}

there is a better way. You are welcome to leave the answer

.
Menu