PARAM_ERROR QQ钱包/ QQ钱包

时间:2018-08-30 20:53:50

标签: wechat qq

我正在尝试发送POST请求,以测试我在“ QQ电子钱包”沙箱中的响应,但我一直从其服务器获取PARAM_ERROR。也许我缺少了我未看到的必需参数中的某些内容,或者还有其他内容?

这是我的快递服务器中的摘录:

async precreateOrder(options) {
// listing out needed params
    const { body, fee_type, total_fee, spbill_create_ip, trade_type, notify_url } = options
    const mch_id = this.mch_id
    const url = this.placeOrderUrl
    const nonce = stringHelper.generateNonce(32)
    const out_trade_no = this._generateOutTradeNoWithDate()
    // build a payment source string
    const source = `body=${body}&fee_type=${fee_type}&mch_id=${mch_id}&nonce_str=${nonce}&notify_url=${notify_url}&out_trade_no=${out_trade_no}&spbill_create_ip=${spbill_create_ip}&total_fee=${total_fee}&trade_type=${trade_type}&key=${this.api_key}`
    // sign the payment source string
    const sign = this._generateSignature(source)
    // build xml template
    var xml = jsonxml({
      xml: [
        { name: 'body', text: `${body}` }, // food-McNuggets
        { name: 'fee_type', text: `${fee_type}` }, // CNY
        { name: 'mch_id', text: `${mch_id}` }, // 123123
        { name: 'nonce_str', text: `${nonce}` }, // 123123
        { name: 'notify_url', text: `${notify_url}` }, // some_endpoint_on_aws
        { name: 'out_trade_no', text: `${out_trade_no}` }, // 商户支付的订单号由商户自定义生成 (user generated unuique product id)
        { name: 'sign', text: `${sign}` }, // 123123
        { name: 'spbill_create_ip', text: `${spbill_create_ip}` }, // 172.31.99.191 -- server ip
        { name: 'total_fee', text: `${total_fee}` }, // 300
        { name: 'trade_type', text: `${trade_type}` } // NATIVE
      ]
    })
    // send xml request to QQPay
    const requestOptions = {
      method: 'POST',
      uri: url,
      headers: { 'Content-Type': 'application/xml; charset=utf-8' },
      body: xml,
      xml: true
    }
    return request(url, requestOptions, (err, res, body) => {
      const resultJSON = xml2js.parseString(body)
      printer.prettyPrint(xml)
      printer.prettyPrint(body)
      return body
    })
  }

这是我的路由器:

router.post('/precreateorder', async (req, res, next) => {
    try {
        const results = await qqpayService.precreateOrder(req.body)
        const formattedResponce = response.formattedContent(true, 'success', results)
        res.status(200).json(formattedResponce)
    } catch (err) { next(err) }
})

0 个答案:

没有答案