(四)支付流程(前端):提交订单,对接沙箱支付宝 nodejs版

292 阅读1分钟

四:提交订单,对接沙箱支付宝 nodejs版.png

前端:

// 提交订单:
async submitOrder() {
  let res = await http.$axios({
    url: "/api/updateOrderStatus",
    method: "POST",
    headers: {
      token: true,
    },
    data: {
      oriderList: this.select,
      orderId: this.order_code[0].order_id,
    },
  });

  // 订单参数
  // 商品名称拼接在一起
  let shop_titles = [];
  this.cartlists.forEach((v) => {
    return shop_titles.push(v.shop_title);
  });

  let orderData = {
    totalPrice: this.total.price, // 总价、
    orderId: this.order_code[0].order_id, // 订单号
    shop_title: shop_titles.join(" "),
  };

  // 发送请求 对接支付宝沙箱
  if (res.success) {
    let ress = await http.$axios({
      url: "/api/aliPay",
      method: "POST",
      headers: {
        token: true,
        "Content-Type": "application/x-www-form-urlencoded",
      },
      // qs 是增加安全性的序列化
      data: qs.stringify(orderData),
    });
    if (ress.success) {
      // 打开支付页面 :测试 用无痕模式访问自己的项目才可以 进行模拟支付,否者会说 为钓鱼支付,无法测试
      // 支付账号密码:在沙箱这里获取买家信息:https://openhome.alipay.com/platform/appDaily.htm?tab=account
      location.href = ress.paymentUrl;
    }
    console.log(ress);
  }
},