PARAM_ERROR QQ Кошелек / QQ 钱包 - PullRequest
       11

PARAM_ERROR QQ Кошелек / QQ 钱包

0 голосов
/ 30 августа 2018

Я пытаюсь отправить POST-запрос, чтобы проверить их ответ в моей песочнице QQ Wallet, но я продолжаю получать 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) }
})
...