Difference between revisions of "PHP5"

From CDYNE Wiki
Jump to navigation Jump to search
imported>Wwright
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
== Consuming Web Service ==
 
== Consuming Web Service ==
 
==== NotifyPhoneAdvanced ====
 
==== NotifyPhoneAdvanced ====
<php>
+
<syntaxhighlight lang="php" line="line">
 
define("ALERTD_CDYNE_LICENSE_KEY", 'secretKeyHere');
 
define("ALERTD_CDYNE_LICENSE_KEY", 'secretKeyHere');
 
define("ALERTD_POST_STATUS_URL", 'https://www.example.com/callback-URL/');
 
define("ALERTD_POST_STATUS_URL", 'https://www.example.com/callback-URL/');
Line 31: Line 31:
  
 
   try {
 
   try {
     $client = new SoapClient('http://ws.cdyne.com/NotifyWS/PhoneNotify.asmx?wsdl');  // can use iadws.cdyne.com to isolate to one of the server farms
+
     $client = new SoapClient('http://ws.cdyne.com/NotifyWS/PhoneNotify.asmx?wsdl');   
 
     $result = $client->NotifyPhoneAdvanced( new CallRequestData($phoneNumber, $message) );
 
     $result = $client->NotifyPhoneAdvanced( new CallRequestData($phoneNumber, $message) );
  
Line 92: Line 92:
 
}           
 
}           
  
</php>
+
</syntaxhighlight>
  
 
==== UploadSoundFile ====
 
==== UploadSoundFile ====
<php>
+
<syntaxhighlight lang="php" line="line">
  
 
define("ALERTD_CDYNE_LICENSE_KEY", 'secretKeyHere');
 
define("ALERTD_CDYNE_LICENSE_KEY", 'secretKeyHere');
Line 128: Line 128:
 
print_r($result);
 
print_r($result);
  
</php>
+
</syntaxhighlight>

Latest revision as of 18:07, 10 January 2019

Consuming Web Service

NotifyPhoneAdvanced

 1 define("ALERTD_CDYNE_LICENSE_KEY", 'secretKeyHere');
 2 define("ALERTD_POST_STATUS_URL", 'https://www.example.com/callback-URL/');
 3 define("ALERTD_CALLER_ID_NUMBER", '6175551212'); // caller id "from" number
 4 define("ALERTD_CALLER_ID_NAME", 'Example.com');
 5 
 6 
 7 
 8 try {
 9   $queueID = phone_notify_queueCall('6175551234', 'Test');
10   print "OK QueueID=$queueID";
11 } 
12 catch (Exception $e) {
13   print "ERROR " . $e->getMessage();
14 }
15 */
16 
17 
18 /** Queue a phone call to a given number. Returns the CDYNE queue ID, or throws an exception if the call is not queued successfully. */
19 function phone_notify_queueCall($phoneNumber, $message) {
20   $message = "~\SetVar(maxcallseconds|120)~
21             ~\StatusChangePostURL(" . ALERTD_POST_STATUS_URL . ")~ "
22             . $message .
23             " Press any key to confirm you have received this message.
24             ~\GetDigits(UserConfirmation|4)~
25             Thank you. Goodbye.
26             ~\EndCall()~
27             ";
28 
29   try {
30     $client = new SoapClient('http://ws.cdyne.com/NotifyWS/PhoneNotify.asmx?wsdl');  
31     $result = $client->NotifyPhoneAdvanced( new CallRequestData($phoneNumber, $message) );
32 
33     $ResponseCode = $result->NotifyPhoneAdvancedResult->ResponseCode;
34     $ResponseText = $result->NotifyPhoneAdvancedResult->ResponseText;
35     $queueID = $result->NotifyPhoneAdvancedResult->QueueID;
36 
37     if ($ResponseCode == '0' || $ResponseText == 'Queued') {
38             var_dump( $client->GetQueueIDStatusWithAdvancedInfo( new GetQueueIDStatusData($queueID) ) );
39             return $queueID;
40     }
41 
42     throw new Exception("Service returned queueing error: ResponseCode=$ResponseCode; ResponseText=$ResponseText");
43 
44   } catch (Exception $e) {
45     // This will catch SOAP exceptions as well.
46     throw new Exception("Unable to queue call: " . $e->getMessage());
47   }
48 }
49 
50 
51 /** Parameters for CDYNE CallRequestData call */
52 class CallRequestData {
53   public $anr;
54 
55   function CallRequestData($number,$text) { 
56             $this->anr = array();
57 
58             $this->anr['PhoneNumberToDial'] = $number;
59             $this->anr['TextToSay'] = $text;
60 
61             $this->anr['LicenseKey'] = ALERTD_CDYNE_LICENSE_KEY;
62             $this->anr['CallerIDNumber'] = ALERTD_CALLER_ID_NUMBER;
63             $this->anr['CallerIDName'] = ALERTD_CALLER_ID_NAME;
64             $this->anr['StatusChangePostUrl'] = ALERTD_POST_STATUS_URL;
65 
66             $this->anr['TransferNumber'] = '';
67             $this->anr['NextTryInSeconds'] = 180;
68             $this->anr['MaxCallLength'] = 120;
69             $this->anr['TryCount'] = 5;
70             $this->anr['TTSvolume'] = 100;
71             $this->anr['TTSrate'] = 25;
72             $this->anr['UTCScheduledDateTime'] = '1970-01-01T00:00:00Z';
73             $this->anr['VoiceID'] = 1;
74   }
75 
76 }
77 
78 
79 
80 /** Parameters for CDYNE GetQueueIDStatus call */
81 class GetQueueIDStatusData {
82   public $QueueID;
83   public $LicenseKey;
84 
85   function GetQueueIDStatusData($id) {
86             $this->QueueID = $id; 
87             $this->LicenseKey = ALERTD_CDYNE_LICENSE_KEY;
88   }
89 }

UploadSoundFile

 1 define("ALERTD_CDYNE_LICENSE_KEY", 'secretKeyHere');
 2 define("ALERTD_CALLER_ID_NUMBER", '6175551212'); // caller id "from" number
 3 define("ALERTD_CALLER_ID_NAME", 'Example.com');
 4 	
 5 $client = new SoapClient('http://ws.cdyne.com/NotifyWS/PhoneNotify.asmx?wsdl');
 6 print_r($client);
 7 	
 8 	
 9 	
10 	//Get contents of the file
11 	$handle = fopen("mywavfile.wav", "r");
12 	$contents = fread($handle, filesize("mywavfile.wav"));
13 	fclose($handle);
14 	
15 	//Set Parameters
16 
17             $params = array();
18  
19             $params['LicenseKey'] = ALERTD_CDYNE_LICENSE_KEY;
20  
21             $params['SoundFileID'] = 'test1';
22             $params['FileBinary'] = $contents;	
23 
24 	//Make Call
25 
26 	$result = $client->UploadSoundFile( $params );
27 
28 	//Print Result
29 
30 	print_r($result);