2017-03-06 60 views
-2

我正在使用以下api:http://apidocs.mifinity.com/#/doc/2但它不工作?我想打電話給調用mifinity api使用php

我的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); 
+1

不以何種方式工作?你有錯誤嗎?你有沒有檢查你的錯誤日誌? –

+0

它沒有任何返回 –

+0

你檢查了你的錯誤日誌嗎? –

回答

0
$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; 
} 
+0

除非你正在考慮這個問題的答案,否則你不應該發佈代碼作爲答案。編輯原始帖子以添加任何新信息。 –