alipay / alipay-sdk-nodejs-all

支付宝开放平台 Alipay SDK for Node.js
https://docs.open.alipay.com/54/103419/
Other
407 stars 64 forks source link

下单出现 ret.status === 200,ret.data 是个 html 的情况,然后 JSON.parse(ret.data)出问题 #50

Closed heibai01 closed 3 months ago

heibai01 commented 4 years ago

// egg app/extend/application.js

  async getAlipayClient() {
    if (!this[ALIPAY]) {
      // this.config.alipay.notifyUrl = await this.createAnonymousContext().serverRequest.getServiceUrl('ms-order') + '/order/payNotify/alipay';
      this[ALIPAY] = new AlipaySdk(this.config.alipay);
    }
    return this[ALIPAY];
  },

// 下单代码

      const ali = await ctx.app.getAlipayClient();
      const notifyUrl = await ctx.serverRequest.getServiceUrl('ms-order') + '/order/payNotify/alipay';
      const bizContent = {
        subject: order.title,
        timeoutExpress: '10m',
        totalAmount: String(order.amount),
        outTradeNo: orderSn,
      };
      let result = {};
      if (query.alipayMode === 'APP') {
        result = {
          payData: await ali.exec('alipay.trade.app.pay', {
            notifyUrl,
            charset: 'GBK',
            bizContent,
          }),
        };

Debug 如下图所示:

5EC9EAF3-EE07-4A9C-BB77-6C3CF827CDB9
tudou527 commented 4 years ago

参数出错了,这是个错误页面。

heibai01 commented 4 years ago

一个最简单的 app 支付,总得告诉我是哪个参数出错了吧? https://docs.open.alipay.com/api_1/alipay.trade.app.pay

tudou527 commented 4 years ago

https://www.yuque.com/chenqiu/alipay-node-sdk/page_api#SyhyY

heibai01 commented 4 years ago

image

我初衷是要用这个 alipay.trade.page.pay 这个方式,用了表单传参的方式,一样的问题。 所以我就看看 alipay.trade.app.pay 这种 APP 支付的,这种传参比较简单,想跑通下流程,可是得的却是一个 HTML。

heibai01 commented 4 years ago

alipay.trade.page.pay 这个调通了,我把 formData 放在外层了,没有这样 { formData }。

那这种非页面类的,我是要在 APP 内部发起原生支付宝APP支付的,使用alipay.trade.app.pay这个应该没问题吧,我上面的贴的代码示例有问题吗?应该接收一个 JSON 数据的呀。