weixin_58412143 2025-10-23 10:31 采纳率: 83.7%
浏览 7

微信小程序调起微信支付失败

但是我在微信浏览器里没有调起微信支付,然后没有用开发者工具,所以没法看报错,这个要怎么处理?

const handleRecharge = () => {
  if (!amount.value) {
    showToast(t("PleaseEnterRechargeAmount"));
    return;
  }
  orderNo.value = generateOrderNo();
  // 处理充值逻辑
  showLoadingToast({
    message: t("Recharging"),
    forbidClick: true,
  });

  try {
    console.log("amount", amount.value);
    passageApi
      .getWeChatRecharge(amount.value * 100, orderNo.value)
      .then((res) => {
        console.log("res", res);
        // 请求成功后关闭loading
        document.querySelector(".van-loading-toast")?.remove();

        // 可以根据响应结果显示成功消息
        if (res && res.success) {
          const payParams = res.data.pay_params;
          console.log("payParams", payParams);
          wx.requestPayment({
            timeStamp: payParams.timeStamp,
            nonceStr: payParams.nonceStr,
            package: payParams.package,
            signType: payParams.signType,
            paySign: payParams.paySign,
            success: function (res) {
              console.log("支付成功", res);
              // 支付成功
              // showSuccessToast(t('RechargeSuccess'));
              // amount.value = '';
              // 支付成功后更新卡片信息
              // fetchCardInfo().then(() => {
              //   setTimeout(() => {
              //     router.push({ name: "home" });
              //   }, 1500);
              // });
            },
            fail: function (err) {
              // 支付失败
              console.error("支付失败:", err);
              // if (err.errMsg !== 'requestPayment:fail cancel') {
              //   // showToast(t('PaymentFailed'));
              // }
            },
          });
          amount.value = "";
          // setTimeout(() => {
          //   router.push({ name: "home" });
          // }, 1500);
        } else {
          // showToast(res?.message || t('RechargeFailed'));
          console.log("充值接口失败");
        }
      }).catch(error => {
      // 请求失败时也关闭loading
      document.querySelector(".van-loading-toast")?.remove();
      console.error("充值请求失败:", error);
      // showToast(t("NetworkError"));
    });;
  } catch (error) {
    // 请求失败时也关闭loading
    document.querySelector(".van-loading-toast")?.remove();
    console.error("充值请求失败:", error);
    showToast(t("NetworkError"));
  }
}; <van-button type="primary" block @click="handleRecharge">{{
          t("ConfirmRecharge")
        }}</van-button>在微信浏览器里点击确认充值后没有调起微信支付
  • 写回答

3条回答 默认 最新

  • 阿里嘎多学长 2025-10-23 10:47
    关注

    阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程

    解决微信小程序调起微信支付失败问题

    根据你的描述,问题可能出在微信小程序的支付配置或代码上。由于你没有使用开发者工具,所以无法直接查看报错信息。以下是几种可能的解决方案:

    1. 检查支付配置:确保你的微信小程序支付配置正确,包括appid、secret、商户号等信息。
    2. 检查支付接口:检查你的支付接口是否正确,包括支付金额、订单号等信息。
    3. 检查微信支付 SDK:检查微信支付 SDK 是否正确引入和使用。
    4. 检查微信浏览器版本:微信浏览器版本可能会影响支付功能的正常工作。

    核心代码检查

    // 检查支付配置
    wx.cloud.callFunction({
      name: 'pay',
      data: {
        amount: amount.value,
        orderNo: orderNo.value,
      },
      success: (res) => {
        // 支付成功
      },
      fail: (err) => {
        // 支付失败
        console.error(err);
      },
    });
    

    建议

    • 使用微信开发者工具来调试支付功能,方便查看报错信息。
    • 检查支付配置和接口是否正确。
    • 检查微信支付 SDK 是否正确引入和使用。
    • 检查微信浏览器版本是否影响支付功能的正常工作。
    评论

报告相同问题?

问题事件

  • 创建了问题 10月23日