将http authentification和标头传递给modrestcurlclient请求

时间:2017-07-10 12:20:51

标签: curl modx modx-revolution

我尝试使用付款系统(bePaid)在我的网站上创建付款页面。要付款,我需要创建令牌。 要创建令牌,我需要将带有身份验证数据的POST请求,带有参数的JSON和JSON发送到支付系统网址。

以纯粹的bash形式,它看起来像

curl https://checkout.bepaid.by/ctp/api/checkouts -u shopId:shopKey -H 'Content-type: application/json' -d '
{
  "checkout": {
    "order": {
      "amount": 1,
      "currency": "USD",
      "description": "Test"
    },
    "settings": {
      "decline_url": "http://www.example.com/decline",
      "fail_url": "http://www.example.com/fail",
      "notification_url": "http://www.example.com/notify",
      "success_url": "http://www.example.com/success"
    },
    "transaction_type": "payment",
    "version": 2
  }
}'

我的网站是关于MODX革命的。我知道它有自己的CURL客户端。从文档中我看到了如何发送请求

request( string $host, string $path, string $method = GET, array $params = array, array $options = array )

因此$hosthttps://checkout.bepaid.by/ctp/api/checkouts$path为' /',method为POST,$params为JSON。我不知道$options是什么。如果这是验证数据和标题 - 语法是什么?如果没有,我应该在哪里传递这些信息?

1 个答案:

答案 0 :(得分:0)

答案在$ options中。如果该数组包含值为modRestClient::OPT_USERPWD(或userpwd)且值为shopId:shopKey且值为const launchChrome = require('@serverless-chrome/lambda') const Chromeless = require('chromeless').Chromeless module.exports.handler = function handler (event, context, callback) { const body = JSON.parse(event.body) // event.body coming from API Gateway const url = body.url const evaluateJs = body.evaluateJs launchChrome({ flags: ['--window-size=1280x1696', '--hide-scrollbars'], }) .then((chrome) => { // Chrome is now running on localhost:9222 const chromeless = new Chromeless({ launchChrome: false, }) chromeless .goto(url) .wait('body') .evaluate(() => ` // this will be executed in headless chrome ${evaluateJs} `) .then((result) => { chromeless .end() .then(chrome.kill) // https://github.com/adieuadieu/serverless-chrome/issues/41#issuecomment-317989508 .then(() => { callback(null, { statusCode: 200, body: JSON.stringify({ result }) }) }) }) .catch(callback) }) .catch((error) => { // Chrome didn't launch correctly callback(error) }) } 的键,则将其设置为BASIC AUTH标头。