/** * Sends an SMS to a recipient * * @method sendSms * * @param {string} address Wireless number of the recipient(s). Can contain comma separated list for multiple recipients. * @param {string} message The text of the message to send * * @return {Response} Returns Response object * @throws ServiceException if API request was not successful. */ public function sendSms($address, $message) { $token = $this->getCurrentClientToken(); $smsSrvc = new SMSService($this->base_url, $token); if (strstr($address, ",")) { // If it's csv, split and iterate over each value prepending each value with "tel:" $address = explode(",", $address); foreach ($address as $key => $value) { $address[$key] = $this->parseAddress($value); } } else { $address = $this->parseAddress($address); } return $smsSrvc->sendSMS($address, $message, false, true); }
public function testRequest() { require __DIR__ . '/cfgs/sms_config.php'; if (isset($proxyHost) && isset($proxyPort)) { RestfulEnvironment::setProxy($proxyHost, $proxyPort); } if (isset($allowAllCerts)) { RestfulEnvironment::setAcceptAllCerts($allowAllCerts); } $osrvc = new OAuthTokenService($FQDN, $api_key, $secret_key); $token = $osrvc->getToken('SMS'); $srvc = new SMSService($FQDN, $token); $response = $srvc->getMessages($getMsgsShortCode); $this->assertTrue($response->getResourceUrl() != null); $response = $srvc->sendSMS($phoneNumber, 'test msg ok', false); $this->assertTrue($response->getMessageId() != null); $msgId = $response->getMessageId(); $response = $srvc->getSMSDeliveryStatus($msgId); $this->assertTrue($response->getResourceUrl() != null); }
private function _handleSendSMS() { if (!isset($_REQUEST['sendSMS'])) { return; } try { $rawaddrs = $_REQUEST['address']; $_SESSION['rawaddrs'] = $rawaddrs; $addrArray = Util::convertAddresses($rawaddrs); $addr = count($addrArray) == 1 ? $addrArray[0] : $addrArray; $msg = $_REQUEST['message']; $getNotification = isset($_REQUEST['chkGetOnlineStatus']); $srvc = new SMSService($this->apiFQDN, $this->getFileToken()); $result = $srvc->sendSMS($addr, $msg, $getNotification); if (!$getNotification) { $_SESSION['SmsId'] = $result->getMessageId(); } $this->results[SMSController::RESULT_SEND_SMS] = $result; } catch (Exception $e) { $this->errors[SMSController::ERROR_SEND_SMS] = $e->getMessage(); } }
* http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ session_start(); require_once __DIR__ . '/common.php'; require_once __DIR__ . '/../lib/Util/Util.php'; require_once __DIR__ . '/../lib/SMS/SMSService.php'; use Att\Api\Util\Util; use Att\Api\SMS\SMSService; $arr = null; try { envinit(); $smsService = new SMSService(getFqdn(), getFileToken()); $addr = Util::convertAddresses($_POST['address']); $addr = count($addr) == 1 ? $addr[0] : $addr; $msg = $_POST['message']; $notifyDeliveryStatus = isset($_POST['deliveryNotificationStatus']); $response = $smsService->sendSMS($addr, $msg, $notifyDeliveryStatus); $resourceUrl = $response->getResourceUrl(); $resourceUrl = $resourceUrl == null ? '-' : $resourceUrl; $arr = array('success' => true, 'tables' => array(array('caption' => 'Message sent successfully', 'headers' => array('Message ID', 'Resource URL'), 'values' => array(array($response->getMessageId(), $resourceUrl))))); } catch (Exception $e) { $arr = array('success' => false, 'text' => $e->getMessage()); } echo json_encode($arr); /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// in your app account. $clientSecret = 'ENTER VALUE!'; // Create the service for requesting an OAuth access token. $osrvc = new OAuthTokenService('https://api.att.com', $clientId, $clientSecret); // Get the OAuth access token using the SMS scope. $token = $osrvc->getToken('SMS'); // Create the service for interacting with the SMS API. $smsSrvc = new SMSService('https://api.att.com', $token); /* This try/catch block tests the sendSMS method. */ try { // Specify the phone number where the SMS message is sent. // For example: $number = '5555555555'; $number = 'ENTER VALUE!'; // Send the SMS message to the specified phone number and // do not receive status notification. $response = $smsSrvc->sendSMS($number, 'Test Message', false); echo 'msgId: ' . $response->getMessageId() . "\n"; } catch (ServiceException $se) { echo $se->getErrorResponse(); } /* This try/catch block tests the getSMSDeliveryStatus method. */ try { // Enter the id of the SMS message. $smsId = 'ENTER VALUE!'; // Send the request for getting the SMS delivery status. $status = $smsSrvc->getSMSDeliveryStatus($smsId); echo 'resourceUrl: ' . $status->getResourceUrl() . "\n"; } catch (ServiceException $se) { echo $se->getErrorResponse(); } /* This try/catch block tests the getMessages method. */