Php 向RingCentral API发出的请求
我正在尝试向Php 向RingCentral API发出的请求,php,api,curl,ringcentral,Php,Api,Curl,Ringcentral,我正在尝试向RingCentral API发送请求。指向文档的链接是https://developers.ringcentral.com/api-reference/Fax/createFaxMessage如果我没有指定faxResolution或coverIndex一切正常,传真可以发送。但如果我像下面的代码中那样添加faxResolution参数,我会收到error“参数[faxResolution]值无效”,“errorCode”:“CMN-101”。与coverIndex参数相同。我的客
RingCentral API
发送请求。指向文档的链接是https://developers.ringcentral.com/api-reference/Fax/createFaxMessage
如果我没有指定faxResolution
或coverIndex
一切正常,传真可以发送。但如果我像下面的代码中那样添加faxResolution参数,我会收到error“参数[faxResolution]值无效”,“errorCode”:“CMN-101”。
与coverIndex参数相同。我的客户是http 6.3
$token = $this->ringcentral->platform()->auth()->data()['access_token'];
$a = array();
foreach ($destination_numbers as $number) {
$a[] = [
'name' => 'to',
'contents' => $number,
'headers' => ['Content-Type' => 'multipart/form-data']
];
}
$a[] = [
'name' => 'faxResolution',
'contents' => 'High',
'headers' => ['Content-Type' => 'multipart/form-data']
];
foreach ($attachments as $attachment) {
$file_pointer = fopen($attachment, 'r');
$mime = mime_content_type($attachment);
$a[] = [
'name' => 'attachment',
'contents' => $file_pointer,
'headers' => ['Content-Type' => $mime]
];
}
$client = new Client();
try {
$response = $client->request('POST', url(config('services.ringcentral.app_url')) . '/restapi/v1.0/account/~/extension/~/fax', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $token
],
'multipart' => $a
]);
$response = json_decode($response->getBody(), true);
} catch (\GuzzleHttp\Exception\ClientException $e) {
echo($e->getResponse()->getBody()->getContents());
}
以下是RingCentral在使用PHP时的建议。我包括了他们建议的所有内容,但只要看看关于传真分辨率的部分(下降了2/3)
链接到您在此提出的特定请求的API文档?
<?php
// https://developers.ringcentral.com/my-account.html#/applications
// Find your credentials at the above url, set them as environment variables, or enter them below
// PATH PARAMETERS
$accountId = '<ENTER VALUE>';
$extensionId = '<ENTER VALUE>';
$recipient = '<ENTER VALUE>';
require('vendor/autoload.php');
$rcsdk = new RingCentral\SDK\SDK(getenv('clientId'), getenv('clientSecret'), getenv('serverURL'));
$platform = $rcsdk->platform();
$platform->login(getenv('username'), getenv('extension'), getenv('password'));
$request = $rcsdk->createMultipartBuilder()
->setBody(array(
'to' => array(array('phoneNumber' => $recipient)),
'faxResolution' => 'High',
))
->add(fopen('fax.jpg', 'r'))
->request("/restapi/v1.0/account/{$accountId}/extension/{$extensionId}/fax");
$r = $platform->sendRequest($request);
?>