【问题标题】:I want to call call the mifinity api using php我想使用 php 调用 mifinity api
【发布时间】:2017-03-06 18:28:53
【问题描述】:

我正在使用以下 api:http://apidocs.mifinity.com/#/doc/2 但它不起作用??

我的 API 密钥

$data = array(
    'key' => "1234567777"
);
$url = 'https://demo.mifinitypay.com/';
$ch = curl_init($url);
$postString = http_build_query($data, '', '&');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);

【问题讨论】:

  • 不以什么方式工作?你有错误吗?你检查过你的错误日志吗?
  • 它什么也没返回
  • 你检查过你的错误日志吗?
  • 是的,我做到了,不会出现任何错误。
  • 我可以通过使用 PHP 的 HttpRequest() 类而不是 CURl 来解决这个问题。

标签: php json api


【解决方案1】:
$request = new HttpRequest();
$request->setUrl('https://demo.mifinitypay.com/api/oauth/token');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'postman-token' => '6396dfb7-540b-0e7d-7333-5d0eeff4d606',
  'cache-control' => 'no-cache',
  'authorization' => 'Basic username:password encoded using Base64',
  'x-api-version' => '1',
  'accept' => 'application/json',
  'content-type' => 'application/x-www-form-urlencoded'
));

$request->setContentType('application/x-www-form-urlencoded');
$request->setPostFields(array(
  'grant_type' => 'client_credentials'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

【讨论】:

  • 除非您认为这是原始问题的答案,否则您不应发布代码作为答案。编辑您的原始帖子以添加任何新信息。
猜你喜欢
  • 2023-04-10
  • 1970-01-01
  • 2021-10-26
  • 1970-01-01
  • 2018-04-01
  • 2019-11-22
  • 1970-01-01
  • 2017-02-03
  • 2012-10-28
相关资源
最近更新 更多