1: <?php
2:
3: namespace tschiemer\Aspsms\Http;
4: use \tschiemer\Aspsms as Aspsms;
5:
6: /**
7: * Simple client interface for HTTP service only.
8: *
9: * @version 1.1.0
10: * @package aspsms
11: * @license LGPL v3 http://www.gnu.org/licenses/lgpl-3.0.txt
12: * @copyright 2013 Philip Tschiemer, <tschiemer@filou.se>
13: * @link https://github.com/tschiemer/aspsms-php
14: */
15: class HttpSimpleClient extends Aspsms\AbstractSimpleClient
16: {
17: /**
18: * @var SoapClient
19: */
20: var $driver;
21:
22: /**
23: * Constructor
24: *
25: * Sets up simple client and client/driver, thus taking any parameters for these to
26: * where any parameters for the driver must be fields of the base field 'httpclient'
27: * eg
28: *
29: * new HttpSimpleClient(array(
30: * 'userkey' => 'k',
31: * 'password' => 'p',
32: * 'originator' => 'o',
33: * 'httpclient' => array('method'=>'POST', .. )
34: * ));
35: *
36: *
37: * @param assoc $options
38: *
39: * @see AbstractSimpleClient::__construct()
40: * @see HttpClient::__construct()
41: */
42: public function __construct($options = array()) {
43: parent::__construct($options);
44:
45: if ( ! isset($options['httpclient']) or ! is_array($options['httpclient']))
46: {
47: $options['httpclient'] = array();
48: }
49:
50: $this->driver = new HttpClient($options['httpclient']);
51: }
52:
53: /**
54: * Get driver for simple client.
55: *
56: * @param \Aspsms\Request $request
57: * @return \Aspsms\AstractClient
58: */
59: public function driver(&$request) {
60: return $this->driver;
61: }
62:
63:
64: /**
65: * Request: Get Http Service version.
66: *
67: * @return array Associative array with fields 'all','version','build' and corresponding meaning.
68: */
69: public function getVersion()
70: {
71: return $this->send(array(
72: 'RequestName' => 'getVersion'
73: ));
74: }
75:
76:
77: /**
78: * Request: Get description to given status code.
79: *
80: * @param string|int $statusCode
81: * @return string
82: */
83: public function getStatusDescription($statusCode)
84: {
85: return $this->send(array(
86: 'RequestName' => 'getStatusCodeDescription',
87: 'StatusCode' => $statusCode
88: ));
89: }
90:
91:
92: /**
93: * Request: Send a token a predefined token to recipients.
94: *
95: * Official doc:
96: *
97: * If MessageData is set, the placeholder <VERIFICATIONCODE> will be
98: * substituted with the verification code. If MessageData is not defined,
99: * or if MessageData does not contain the placeholder <VERIFICATIONCODE>,
100: * only the verification code is sent.
101: *
102: * @param string $phoneNr Recipient phone number
103: * @param string $reference Your reference number
104: * @param string $verificationCode Required verification code to send
105: * @param string $message Message to send code with.
106: * @param int $minutes Validity of token in minutes (default 5)
107: * @param boolean $case_sensitive Is given code case sensitive?
108: * @return boolean Request success?
109: */
110: public function sendMyToken($phoneNr,$reference,$verificationCode,$message='',$minutes=5, $case_sensitive=0)
111: {
112: return $this->send(array(
113: 'RequestName' => 'sendToken',
114: 'Recipients' => $phoneNr,
115: 'TokenReference' => $reference,
116: 'VerificationCode' => $verificationCode,
117: 'MessageData' => $message,
118: 'TokenValidity' => $minutes,
119: 'TokenCaseSensitive'=> $case_sensitive
120: ));
121: }
122:
123: /**
124: * Request: Send a token as generated by ASPSMS.COM, optionally give token mask.
125: *
126: * Official doc:
127: *
128: * If MessageData is set, the placeholder <VERIFICATIONCODE> will be
129: * substituted with the verification code. If MessageData is not defined,
130: * or if MessageData does not contain the placeholder <VERIFICATIONCODE>,
131: * only the verification code is sent.
132: *
133: * Official doc:
134: *
135: * Used to have the ASPSMS generate a verification code by mask. The mask can contain the following special characters:
136: *
137: * # : a digit
138: * A : an alphabetic character
139: * N : an alphanumeric character
140: *
141: * All other characters are taken literally. If not specified, the Mask is "NNNN" by default.
142: *
143: *
144: * @param string $phoneNr Recipient phone number
145: * @param string $reference Your reference number
146: * @param string $message Message to send code with.
147: * @param string $mask Token code mask to use (# -> number, A -> Alphabetical)
148: * @param int $minutes Validity of token in minutes (default 5)
149: * @param boolean $case_sensitive Is given code case sensitive?
150: * @return boolean Request success?
151: */
152: public function sendGeneratedToken($phoneNr,$reference,$message='',$mask='######',$minutes=5, $case_sensitive=0)
153: {
154: return $this->send(array(
155: 'RequestName' => 'sendToken',
156: 'Recipients' => $phoneNr,
157: 'TokenReference' => $reference,
158: 'TokenMask' => $mask,
159: 'MessageData' => $message,
160: 'TokenValidity' => $minutes,
161: 'TokenCaseSensitive'=> $case_sensitive
162: ));
163: }
164:
165: /**
166: * Request: attempt to validate token.
167: *
168: * NOTE: If a token have been successfully validated, any future attempts (no matter the
169: * verification code use) succeed.
170: *
171: * @param string $phoneNr Recipient phone number
172: * @param string $reference Your reference number
173: * @param string $verificationCode Required verification code to validate
174: * @return boolean Is given verification code for use valid?
175: */
176: public function validateToken($phoneNr,$reference,$verificationCode)
177: {
178: return $this->send(array(
179: 'RequestName' => 'verifyToken',
180: 'PhoneNumber' => $phoneNr,
181: 'TokenReference' => $reference,
182: 'VerificationCode' => $verificationCode
183: ));
184: }
185: }