inital commit
This commit is contained in:
69
webroot/Staff/rc-fax.php
Normal file
69
webroot/Staff/rc-fax.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This is a script which sends Fax to provided numbers from RingCentral Account
|
||||
* using RingCentral SDK PHP Client
|
||||
*
|
||||
* @author Azhar Uddin <getazharuddin@gmail.com>
|
||||
*/
|
||||
|
||||
require('vendor/autoload.php');
|
||||
use RingCentral\SDK\SDK;
|
||||
|
||||
// $receiverFaxNo = '+18775770854';
|
||||
$fileToFax = realpath('dummy1.pdf');
|
||||
//header( 'Content-type: application/pdf' );
|
||||
//header( 'Content-Dispostion: inline; filename="'.basename($fileToFax).'"' );
|
||||
//header( 'Content-Transfer-Encoding: binary' );
|
||||
//header( 'Accept-Ranges: bytes' );
|
||||
|
||||
include "rc_config.php";
|
||||
|
||||
$response = sendFaxByringcentral($credentials, $fileToFax); // function call
|
||||
|
||||
function sendFaxByringcentral($credentials, $fileToFax){
|
||||
// for production use RingCentral\SDK\SDK::SERVER_PRODUCTION
|
||||
$result = false;
|
||||
$rcsdk = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Fax|SMS|MMS', '1.0.0');
|
||||
|
||||
$platform = $rcsdk->platform();
|
||||
|
||||
// Authorize
|
||||
|
||||
try{
|
||||
$platform->login($credentials['account_phone'], $credentials['extension'], $credentials['password']);
|
||||
|
||||
if($rcsdk->platform()->loggedIn()){
|
||||
// echo "Yes authenticated";exit;
|
||||
}
|
||||
// Send Fax
|
||||
|
||||
$request = $rcsdk->createMultipartBuilder()
|
||||
->setBody(array(
|
||||
'to' => array(
|
||||
array('phoneNumber' => $credentials['receiverFaxNo']),
|
||||
),
|
||||
'faxResolution' => 'High',
|
||||
))
|
||||
//->add('Plain Text', 'file.txt')
|
||||
->add(fopen($fileToFax, 'r'),basename($fileToFax))
|
||||
// ->add('FAX from RTG', 'test.pdf')
|
||||
// ->add($fileToFax, basename($fileToFax))
|
||||
|
||||
->request('/account/~/extension/~/fax');
|
||||
|
||||
$response = $platform->sendRequest($request);
|
||||
$status = $response->response()->getStatusCode();
|
||||
|
||||
if($status == 200){
|
||||
$result = true;
|
||||
echo 'SUCCESS in Sending';
|
||||
}
|
||||
}catch(\Exception $e){
|
||||
echo($e->getMessage());
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user