TheNorthMemory / wechatpay-axios-plugin

微信支付 WeChatPay OpenAPI v2&v3' SDK,以命令行方式与接口交互,play the openapi requests over command line

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

“特约商户进件” 以slash(/)结尾的接口调用接口返回404.

lovebaonvwu opened this issue · comments

感谢你提供的开发库。
我在使用的过程中碰到了一个问题。

  try {
    const res = await wxpay.v3.pay.partner.transactions.native({
      sp_appid,
      sp_mchid,
      sub_mchid,
      description,
      out_trade_no,
      time_expire: new Date( (+new Date) + 33*60*1000 ), //after 33 minutes
      attach,
      notify_url,
      amount: {
        total: 1,
      }
    })
    console.info(res.data.code_url)
  } catch (error) {
    console.error(error)
  }
})()

按照示例可以正常调用微信支付的API。

现在我想调用另外一个接口,“特约商户进件”,https://api.mch.weixin.qq.com/v3/applyment4sub/applyment/

 try {
            const result = await this.wxapi.v3.applyment4sub.applyment({});
            return console.log(result);
        } catch (err) {
            return console.error(err)
        }

这次接口调用返回404 Not Found.
通过catch 到的内容,我检查了请求的信息,如下:

config: {
    url: '/v3/applyment4sub/applyment',
    method: 'post',
    data: '{}',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
      'User-Agent': 'wechatpay-axios-plugin/0.4.5 axios/0.21.1 node/14.15.4 darwin/x64',
      Authorization: 'WECHATPAY2-SHA256-RSA2048 mchid="1270921201",nonce_str="KKuwhzeDvaIU6eykvDn4oYM7QZkjBVRu",signature="RXOv9YfWJBw/DjHpqQgsjzHJjkRXxIOthtXAL+J/mx0CfUnGlSwMciZagHgCAG8S5x8XR3q1B/khavW8YNPHM2n4Q/ooHc8EKFCRH+uPSN6iqIqluG5iTNd53a7h92/vk6zMKcMCH58ocJRvm/vMH/3CUUzRfpSJkCVccAVIgL3WpVGvzhBrUbTfP0PepwNselJqAXjCzC6MQgo83QrUHaHbdx8llz2Cs6v0tw8yD5faT+eaybHhPCOuc/qk9Y1ITRSSgRv6mfWUIE19LHPDDbI2hKjkzQUPbPwPNj9XK/OY0BV1NIgfxdYlK8RPX1HBquwwDiC4EKmUFr6v0/6NNA==",timestamp="1616655313",serial_no="623FFEC95EF4B583D2157DFE81E66FFA15DE67C3"',
      'Content-Length': 2
    },
    baseURL: 'https://api.mch.weixin.qq.com',
    ...

看起来请求的数据没有什么异常。
我把headers里面的内容,通过postman 发起一个请求,是可以得到微信平台的应答的。
image

所以不知道是不是其他的问题导致的,希望能帮我看一下,谢谢。

这个问题曾给官方同学反馈过很多次,是接口语义化定义的一个缺陷,可以用如下方法“绕”过:

方式1,动态参数方式:

try {
  const result = await this.wxapi.v3.applyment4sub.applyment.$noop$({}, {noop: ''});
  return console.log(result);
} catch (err) {
  return console.error(err)
}

方式2,属性方式:

try {
  const result = await this.wxapi['v3/applyment4sub/applyment/']({});
  return console.log(result);
} catch (err) {
  return console.error(err)
}

非常感谢你的回复,问题解决了。