1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
2 |
|
---|
3 | if ( ! defined('_SBG_MO_REGISTER')) define('_SBG_MO_REGISTER', 0);
|
---|
4 | if ( ! defined('_SBG_MO_REGISTER_FOR')) define('_SBG_MO_REGISTER_FOR', 1);
|
---|
5 | if ( ! defined('_SBG_MO_PHONENUM_CHANGE')) define('_SBG_MO_PHONENUM_CHANGE', 2);
|
---|
6 | if ( ! defined('_SBG_MO_PASSWORD_RECOVERY')) define('_SBG_MO_PASSWORD_RECOVERY', 3);
|
---|
7 | if ( ! defined('_SBG_MO_PASSWORD_CHANGE')) define('_SBG_MO_PASSWORD_CHANGE', 4);
|
---|
8 | if ( ! defined('_SBG_MO_VIP_REGISTER')) define('_SBG_MO_VIP_REGISTER', 5);
|
---|
9 | if ( ! defined('_SBG_MO_PAY_TO_ACCOUNT')) define('_SBG_MO_PAY_TO_ACCOUNT', 6);
|
---|
10 | if ( ! defined('_SBG_MO_PAY_TO_ACCOUNT_FOR')) define('_SBG_MO_PAY_TO_ACCOUNT_FOR', 7);
|
---|
11 | if ( ! defined('_SBG_MO_UNSUBSCRIBE_SERVICE')) define('_SBG_MO_UNSUBSCRIBE_SERVICE', 8);
|
---|
12 |
|
---|
13 | if ( ! defined('_SBG_MO_SYNTAX_ERR')) define('_SBG_MO_SYNTAX_ERR', -1);
|
---|
14 | if ( ! defined('_SBG_MO_SYNTAX_ERR_MSG')) define('_SBG_MO_SYNTAX_ERR_MSG', 'SBG Online khong co dich vu nà y, ban vui long kiem tra lai. Tran trong.');
|
---|
15 |
|
---|
16 | if ( ! defined('_SBG_CARD_PAY_FAIL')) define('_SBG_CARD_PAY_FAIL', -1);
|
---|
17 | if ( ! defined('_SBG_CARD_PAY_SUCCESS')) define('_SBG_CARD_PAY_SUCCESS', 1);
|
---|
18 |
|
---|
19 | if ( ! defined('_SBG_CHARGING_FAIL')) define('_SBG_CHARGING_FAIL', -1);
|
---|
20 | if ( ! defined('_SBG_CHARGING_SUCCESS')) define('_SBG_CHARGING_SUCCESS', 1);
|
---|
21 |
|
---|
22 | if ( ! defined('_SBG_CHARGING_FAIL_NOT_ENOUGH')) define('_SBG_CHARGING_FAIL_NOT_ENOUGH', 401);
|
---|
23 | if ( ! defined('_SBG_CHARGING_FAIL_NOT_VIETTEL')) define('_SBG_CHARGING_FAIL_NOT_VIETTEL', 402);
|
---|
24 | if ( ! defined('_SBG_CHARGING_NUMBER_NOT_EXISTED')) define('_SBG_CHARGING_NUMBER_NOT_EXISTED', 403);
|
---|
25 |
|
---|
26 | if ( ! defined('_SBG_CHARGING_NUMBER_NOT_AVAILABLE')) define('_SBG_CHARGING_NUMBER_NOT_AVAILABLE', 404);
|
---|
27 | if ( ! defined('_SBG_CHARGING_NUMBER_CHANGED_OWNER')) define('_SBG_CHARGING_NUMBER_CHANGED_OWNER', 405);
|
---|
28 |
|
---|
29 | if ( ! defined('_SBG_CHARGING_FAIL_MORETHAN_LIMIT')) define('_SBG_CHARGING_FAIL_MORETHAN_LIMIT', 406);
|
---|
30 | if ( ! defined('_SBG_CHARGING_GENERAL_ERROR')) define('_SBG_CHARGING_GENERAL_ERROR', 440);
|
---|
31 | if ( ! defined('_SBG_CHARGING_NUMBER_NOT_REGISTED')) define('_SBG_CHARGING_NUMBER_NOT_REGISTED', 501);
|
---|
32 |
|
---|
33 | if ( ! defined('_SBG_CHARGING_FAIL_NOT_ENOUGH_MSG')) define('_SBG_CHARGING_FAIL_NOT_ENOUGH_MSG', 'Tai khoan chinh cua ban khong du de thuc hien nap :amount: vao tai khoan :username: tren SBG Online.');
|
---|
34 | if ( ! defined('_SBG_CHARGING_FAIL_MORETHAN_LIMIT_MSG')) define('_SBG_CHARGING_FAIL_MORETHAN_LIMIT_MSG', 'So tien nap lon nhat tren SBG Online la 50.000VND.');
|
---|
35 | if ( ! defined('_SBG_CHARGING_FAIL_NOT_VIETTEL_MSG')) define('_SBG_CHARGING_FAIL_NOT_VIETTEL_MSG', 'Chuc nang nap tien qua SMS cua SBG Online chi ap dung cho thue bao Viettel');
|
---|
36 |
|
---|
37 | if ( ! defined('_SBG_SEND_MT_FAIL')) define('_SBG_SEND_MT_FAIL', -1);
|
---|
38 | if ( ! defined('_SBG_SEND_MT_SUCCESS')) define('_SBG_SEND_MT_SUCCESS', 1);
|
---|
39 |
|
---|
40 | if ( ! defined('_SBG_MT_SEND_NUMBER')) define('_SBG_MT_SEND_NUMBER', '841662860000');
|
---|
41 | if ( ! defined('_SBG_MT_CP_CODE')) define('_SBG_MT_CP_CODE', '601');
|
---|
42 |
|
---|
43 | if ( ! defined('_SBG_SERVICE_COMMAND_CODE')) define('_SBG_SERVICE_COMMAND_CODE', 'SBG');
|
---|
44 | if ( ! defined('_SBG_SERVICE_SERVICEID')) define('_SBG_SERVICE_SERVICEID', '8062');
|
---|
45 |
|
---|
46 | Class Services_model extends CI_Model
|
---|
47 | {
|
---|
48 | private $_arySmsMO = array(
|
---|
49 | _SBG_MO_REGISTER => array('pattern' => '/^(SBG[[:blank:]])(DK)$/'),
|
---|
50 | _SBG_MO_REGISTER_FOR => array('pattern' => '/^(SBG[[:blank:]])(DK)([[:blank:]][0-9]{10,11})$/'),
|
---|
51 | _SBG_MO_PHONENUM_CHANGE => array('pattern' => '/^(SBG[[:blank:]])(DDT)([[:blank:]][0-9]{10,11})([[:blank:]][a-zA-Z0-9~!@#$%^&*]{4,16})$/'),
|
---|
52 | _SBG_MO_PASSWORD_RECOVERY => array('pattern' => '/^(SBG[[:blank:]])(MK)$/'),
|
---|
53 | /* _SBG_MO_PASSWORD_CHANGE => array('pattern' => '/^(SBG[[:blank:]])(MK)([[:blank:]][a-zA-Z0-9~!@#$%^&*]{4,16})$/'), */
|
---|
54 | _SBG_MO_VIP_REGISTER => array('pattern' => '/^(SBG[[:blank:]])(VIP)([[:blank:]][0-9]{1,2})$/'),
|
---|
55 | _SBG_MO_PAY_TO_ACCOUNT => array('pattern' => '/^(SBG[[:blank:]])(NAP)([[:blank:]][0-9]{3,})$/'),
|
---|
56 | _SBG_MO_PAY_TO_ACCOUNT_FOR => array('pattern' => '/^(SBG[[:blank:]])(NAP)([[:blank:]][0-9]{3,})([[:blank:]][0-9]{10,11})$/'),
|
---|
57 | _SBG_MO_UNSUBSCRIBE_SERVICE => array('pattern' => '/^(SBG[[:blank:]])(HUY)$/')
|
---|
58 | );
|
---|
59 |
|
---|
60 | private $_arySmsService = array(
|
---|
61 | 'DK' => _SBG_MO_REGISTER_FOR,
|
---|
62 | 'DDT' => _SBG_MO_PHONENUM_CHANGE,
|
---|
63 | 'NAP' => _SBG_MO_PAY_TO_ACCOUNT_FOR,
|
---|
64 | );
|
---|
65 |
|
---|
66 | public function __construct(){
|
---|
67 | parent::__construct();
|
---|
68 | }
|
---|
69 |
|
---|
70 | public function messageAnalys ($message)
|
---|
71 | {
|
---|
72 | $aryMatched = array();
|
---|
73 | $aryContent = array();
|
---|
74 | $result = false;
|
---|
75 |
|
---|
76 | foreach ($this->_arySmsMO as $key => $pattern)
|
---|
77 | {
|
---|
78 | $result = preg_match_all ($pattern['pattern'], strtoupper($message), $aryMatched);
|
---|
79 | if ((bool)$result) break;
|
---|
80 | }
|
---|
81 |
|
---|
82 | $key = (bool)$result ? $key:_SBG_MO_SYNTAX_ERR;
|
---|
83 |
|
---|
84 | if (count ($aryMatched) > 0) {
|
---|
85 | foreach ($aryMatched as $k => $val) {
|
---|
86 | if ($k == 0) continue;
|
---|
87 | $aryContent[] = trim($val[0]);
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | if ((bool)$result == FALSE) {
|
---|
92 | $aryContent = array();
|
---|
93 | foreach(explode(' ',strtoupper($message)) as $k => $val) {
|
---|
94 | $aryContent[] = $val;
|
---|
95 | }
|
---|
96 | $key = $this->_arySmsService[$aryContent[1]];
|
---|
97 | $result = 1;
|
---|
98 | }
|
---|
99 |
|
---|
100 | if ($key == _SBG_MO_PASSWORD_CHANGE || $key == _SBG_MO_PHONENUM_CHANGE) {
|
---|
101 | $index = $key == _SBG_MO_PASSWORD_CHANGE ? 2 : 3;
|
---|
102 | $upcasePass = $aryContent[$index];
|
---|
103 | $password = substr($message, -strlen($upcasePass));
|
---|
104 | $aryContent[$index] = $password;
|
---|
105 | }
|
---|
106 |
|
---|
107 | $aryResult = (bool)$result ? array('case' => $key, 'content' => $aryContent):array('case' => $key);
|
---|
108 | return $aryResult;
|
---|
109 | }
|
---|
110 |
|
---|
111 | public function processMORequest ($sentNumber,$message)
|
---|
112 | {
|
---|
113 | $debugMsg = $message."\n";
|
---|
114 |
|
---|
115 | $sentNumber = $this->formatPhoneNumber($sentNumber);
|
---|
116 |
|
---|
117 | $smsReturn = '';
|
---|
118 | $aryMOAnalys = $this->messageAnalys($message);
|
---|
119 | $case = $aryMOAnalys['case'];
|
---|
120 | $aryContents = isset($aryMOAnalys['content']) ? $aryMOAnalys['content']: null;
|
---|
121 | $debugMsg .= var_export($aryMOAnalys);
|
---|
122 | $this->load->model('frontend/user_model', 'objUserModel');
|
---|
123 | $debugMsg .= $case;
|
---|
124 | write_file('mt_log', $debugMsg);
|
---|
125 | switch ($case) {
|
---|
126 | case _SBG_MO_REGISTER:
|
---|
127 | case _SBG_MO_REGISTER_FOR:
|
---|
128 | if ($case == _SBG_MO_REGISTER_FOR) {
|
---|
129 | if (!preg_match('/^([0-9]{10,11}$)$/', $aryContents[2])) {
|
---|
130 | $smsReturn = '0|So dien thoai khach hang khong hop le. Vui long kiem tra lai.';
|
---|
131 | break;
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | $userName = isset($aryContents[2]) ? $this->formatPhoneNumber($aryContents[2]) : $sentNumber;
|
---|
136 | $collaborator = isset($aryContents[2]) ? $sentNumber:null;
|
---|
137 | $collaboratorMsg = '';
|
---|
138 | $sms = $this->objUserModel->register($userName, $collaborator, $collaboratorMsg);
|
---|
139 | if ($case == _SBG_MO_REGISTER_FOR) {
|
---|
140 | $smsReturn = $collaboratorMsg;
|
---|
141 | $arySMS = explode ('|', $sms);
|
---|
142 | if ((int)$arySMS[0] == 1 )
|
---|
143 | $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $arySMS[1]);
|
---|
144 | }
|
---|
145 | else {
|
---|
146 | $smsReturn = $sms;
|
---|
147 | }
|
---|
148 | break;
|
---|
149 | case _SBG_MO_PHONENUM_CHANGE:
|
---|
150 | if (!preg_match('/^(09\d{8}|01\d{9})$/', $aryContents[2])) {
|
---|
151 | $smsReturn = '0|So dien thoai khach hang khong hop le. Vui long kiem tra lai.';
|
---|
152 | break;
|
---|
153 | }
|
---|
154 | $oldPhoneNumber = $this->formatPhoneNumber($aryContents[2]);
|
---|
155 | $password = $aryContents[3];
|
---|
156 | $smsReturn = $this->objUserModel->changeProfile($sentNumber, $oldPhoneNumber, $password);
|
---|
157 | $sms = 'Ban da doi thanh cong so dien thoai tren SBG Online sang so dien thoai ' .$sentNumber. '. Tran trong.';
|
---|
158 | $sendMT = $this->sendMT($this->formatPhoneNumber($oldPhoneNumber, -1), $sms);
|
---|
159 | break;
|
---|
160 | case _SBG_MO_PASSWORD_RECOVERY:
|
---|
161 | case _SBG_MO_PASSWORD_CHANGE:
|
---|
162 | $password = isset($aryContents[2]) ? $aryContents[2] : null;
|
---|
163 | $smsReturn = $this->objUserModel->changePassword($sentNumber, $password);
|
---|
164 | break;
|
---|
165 | case _SBG_MO_VIP_REGISTER:
|
---|
166 | $p_code = $aryContents[2];
|
---|
167 | $smsReturn = $this->objUserModel->registerVip($sentNumber, $p_code);
|
---|
168 | break;
|
---|
169 | case _SBG_MO_PAY_TO_ACCOUNT:
|
---|
170 | case _SBG_MO_PAY_TO_ACCOUNT_FOR:
|
---|
171 | $userName = isset($aryContents[3]) ? $this->formatPhoneNumber($aryContents[3]) : $sentNumber;
|
---|
172 |
|
---|
173 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR && !preg_match('/^(09\d{8}|01\d{9})$/', $userName)) {
|
---|
174 | $smsReturn = '0|So dien thoai khach hang khong hop le. Vui long kiem tra lai.';
|
---|
175 | break;
|
---|
176 | }
|
---|
177 |
|
---|
178 | $amount = $aryContents[2];
|
---|
179 | $result =$this->chargeRootAccountProcess($sentNumber, $amount, $sentNumber.' paid for SBG');
|
---|
180 |
|
---|
181 | if ($result == _SBG_CHARGING_SUCCESS) {
|
---|
182 | $smsReturn = $this->objUserModel->rechargeAccount($userName, $amount);
|
---|
183 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR) {
|
---|
184 | $arySmsReturn = explode ('|', $smsReturn);
|
---|
185 | $smsMT = 'Ban da nap thanh cong ' .$amount . 'VND vao tai khoan ' .$username. ' tren SBG Online tu thue bao ' .$sentNumber. '. Tran trong.';
|
---|
186 | $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $smsMT);
|
---|
187 | }
|
---|
188 | //write to paid log
|
---|
189 | $paidTime = date('Y-m-d H:i:s');
|
---|
190 | $this->objUserModel->insertPaidlog($sentNumber, $userName, _SBG_PAIDTYPE_SMS, $amount, $paidTime);
|
---|
191 | }
|
---|
192 | else if ($result == _SBG_CHARGING_FAIL_NOT_ENOUGH) {
|
---|
193 | //$aryPatterns = array ('/:sendid:/', '/:amount:/', '/:username:/');
|
---|
194 | //$smsReturn = preg_replace($aryPatterns, array($sentNumber, $amount, $userName), _SBG_CHARGING_FAIL_NOT_ENOUGH_MSG);
|
---|
195 | $aryPatterns = array ('/:amount:/', '/:username:/');
|
---|
196 | $smsReturn = preg_replace($aryPatterns, array($amount, $userName), _SBG_CHARGING_FAIL_NOT_ENOUGH_MSG);
|
---|
197 | $smsReturn = '0|'.$smsReturn;
|
---|
198 | }
|
---|
199 | else if ($result == _SBG_CHARGING_FAIL_MORETHAN_LIMIT) {
|
---|
200 | $aryPatterns = array ('/:sendid:/');
|
---|
201 | $smsReturn = preg_replace($aryPatterns, array($sentNumber), _SBG_CHARGING_FAIL_MORETHAN_LIMIT_MSG);
|
---|
202 | $smsReturn = '0|'.$smsReturn;
|
---|
203 | }else if ($result == _SBG_CHARGING_FAIL_NOT_VIETTEL || $result == _SBG_CHARGING_NUMBER_NOT_EXISTED || $result == _SBG_CHARGING_NUMBER_NOT_AVAILABLE) {
|
---|
204 | $smsReturn = '0|'._SBG_CHARGING_FAIL_NOT_VIETTEL_MSG;
|
---|
205 | }
|
---|
206 | else {
|
---|
207 | $smsReturn = '0|Loi, khong thanh toan duoc tu tai khoan goc';
|
---|
208 | }
|
---|
209 | break;
|
---|
210 | case _SBG_MO_UNSUBSCRIBE_SERVICE:
|
---|
211 | case _SBG_MO_SYNTAX_ERR:
|
---|
212 | default:
|
---|
213 | $smsReturn = '0|'._SBG_MO_SYNTAX_ERR_MSG;
|
---|
214 | break;
|
---|
215 | }
|
---|
216 |
|
---|
217 | return $smsReturn.'|'.$case;
|
---|
218 | }
|
---|
219 |
|
---|
220 | public function cardPaidProcess ($aryCardInfo, &$aryTopupResult = array())
|
---|
221 | {
|
---|
222 | $url = $this->config->item('topup_service_url');
|
---|
223 | $action = 'http://tempuri.org/ITopupService/TopUp';
|
---|
224 | $xml = $this->load->view('topup', $aryCardInfo, true);
|
---|
225 |
|
---|
226 | $client = new nusoap_client($url);
|
---|
227 | $client->useHTTPPersistentConnection();
|
---|
228 | $client->soap_defencoding = 'UTF-8';
|
---|
229 | $client->operation = $action;
|
---|
230 |
|
---|
231 | $result = $client->send($xml, $action);
|
---|
232 |
|
---|
233 | $debugMsg = 'Logged time: '. date('Y-m-d H:i:s') ."\n";
|
---|
234 | $debugMsg .= 'Send:'."\n" .$xml ."\n\n";
|
---|
235 | $debugMsg .= 'Result:'."\n". var_export($result, TRUE);
|
---|
236 | write_file('topup_log', $debugMsg);
|
---|
237 |
|
---|
238 | if ($client->fault) {
|
---|
239 | return _SBG_CARD_PAY_FAIL;
|
---|
240 | }
|
---|
241 |
|
---|
242 | $keys = array_keys($result);
|
---|
243 |
|
---|
244 | $aryTopupResult = $result[$keys[0]];
|
---|
245 |
|
---|
246 | if ($aryTopupResult['Success'] == 'false') {
|
---|
247 | return _SBG_CARD_PAY_FAIL;
|
---|
248 | }
|
---|
249 |
|
---|
250 | return _SBG_CARD_PAY_SUCCESS;
|
---|
251 | }
|
---|
252 |
|
---|
253 | public function chargeRootAccountProcess ($sentID, $amount = 0, $contents = '')
|
---|
254 | {
|
---|
255 | $url = $this->config->item('charging_service_url');
|
---|
256 | $username = $this->config->item('charging_username');
|
---|
257 | $password = $this->config->item('charging_password');
|
---|
258 | $action = 'http://tempuri.org/processCharging';
|
---|
259 |
|
---|
260 | $aryParams = array(
|
---|
261 | 'user' => $username,
|
---|
262 | 'pass' => $password,
|
---|
263 | 'MSISDN' => $sentID,
|
---|
264 | 'Charging' => $amount,
|
---|
265 | 'Contents' => $contents
|
---|
266 | );
|
---|
267 |
|
---|
268 | $xml = $this->load->view('charging', $aryParams, true);
|
---|
269 | $client = new nusoap_client($url);
|
---|
270 | $client->useHTTPPersistentConnection();
|
---|
271 | $client->soap_defencoding = 'UTF-8';
|
---|
272 | $client->operation = $action;
|
---|
273 | $result = $client->send($xml, $action);
|
---|
274 | $debugMsg = var_export($xml, TRUE);
|
---|
275 | $debugMsg .= var_export($result, TRUE);
|
---|
276 | write_file('mt_log', $debugMsg);
|
---|
277 |
|
---|
278 | if ($client->fault) {
|
---|
279 | return _SBG_CHARGING_FAIL;
|
---|
280 | }
|
---|
281 |
|
---|
282 | $aryErrs = array (_SBG_CHARGING_FAIL_NOT_ENOUGH,
|
---|
283 | _SBG_CHARGING_FAIL_NOT_VIETTEL,
|
---|
284 | _SBG_CHARGING_FAIL_MORETHAN_LIMIT,
|
---|
285 | _SBG_CHARGING_NUMBER_NOT_EXISTED,
|
---|
286 | _SBG_CHARGING_NUMBER_NOT_AVAILABLE,
|
---|
287 | _SBG_CHARGING_NUMBER_CHANGED_OWNER,
|
---|
288 | _SBG_CHARGING_GENERAL_ERROR,
|
---|
289 | _SBG_CHARGING_NUMBER_NOT_REGISTED
|
---|
290 | );
|
---|
291 |
|
---|
292 | if (in_array((int)$result['processChargingResult'], $aryErrs))
|
---|
293 | return (int)$result['processChargingResult'];
|
---|
294 |
|
---|
295 | return _SBG_CHARGING_SUCCESS;
|
---|
296 | }
|
---|
297 |
|
---|
298 | public function sendMT ($receiverID, $message)
|
---|
299 | {
|
---|
300 | $aryMatch = array();
|
---|
301 |
|
---|
302 | if (preg_match('/^(0)([0-9]{9,10})$/', $receiverID, $aryMatch) == 1) {
|
---|
303 | $receiverID = '84'. $aryMatch[2];
|
---|
304 | }
|
---|
305 |
|
---|
306 | $username = $this->config->item('mt_username');
|
---|
307 | $password = $this->config->item('mt_password');
|
---|
308 | $action = 'http://tempuri.org/InsertMT';
|
---|
309 |
|
---|
310 | $aryParams = array(
|
---|
311 | 'User' => $username,
|
---|
312 | 'Pass' => $password,
|
---|
313 | 'CPCode' => _SBG_MT_CP_CODE,
|
---|
314 | 'UserID' => _SBG_MT_SEND_NUMBER,
|
---|
315 | 'RequestID' => '4',
|
---|
316 | 'ReceiverID' => $receiverID,
|
---|
317 | 'ServiceID' => _SBG_SERVICE_SERVICEID,
|
---|
318 | 'CommandCode' => _SBG_SERVICE_COMMAND_CODE,
|
---|
319 | 'ContentType' => '0',
|
---|
320 | 'Info' => $message
|
---|
321 | );
|
---|
322 |
|
---|
323 | $xml = $this->load->view('mt', $aryParams, true);
|
---|
324 | $url = $this->config->item('mt_service_url');
|
---|
325 | $client = new nusoap_client($url);
|
---|
326 | $client->useHTTPPersistentConnection();
|
---|
327 | $client->soap_defencoding = 'UTF-8';
|
---|
328 | $client->operation = $action;
|
---|
329 | $result = $client->send($xml, $action);
|
---|
330 |
|
---|
331 | //write_file('mt_log', var_export($client->fault, true)."\n".var_export($xml, true));
|
---|
332 |
|
---|
333 | if ($client->fault || (int)$result['InsertMTResult'] != 1) {
|
---|
334 | return _SBG_SEND_MT_FAIL;
|
---|
335 | }
|
---|
336 |
|
---|
337 | return _SBG_SEND_MT_SUCCESS;
|
---|
338 | }
|
---|
339 |
|
---|
340 | public function formatPhoneNumber ($phoneNumber, $direction = 1) {
|
---|
341 | $aryMatch = array();
|
---|
342 | if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == 1) {
|
---|
343 | $result = '0'. $aryMatch[2];
|
---|
344 | }
|
---|
345 | else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == 1) {
|
---|
346 | $result = $phoneNumber;
|
---|
347 | }
|
---|
348 | else if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == -1) {
|
---|
349 | $result = $phoneNumber;
|
---|
350 | }
|
---|
351 | else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == -1) {
|
---|
352 | $result = '84'. $aryMatch[2];
|
---|
353 | }
|
---|
354 |
|
---|
355 | return $result;
|
---|
356 | }
|
---|
357 | } |
---|