[499] | 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);
|
---|
[529] | 11 | if ( ! defined('_SBG_MO_UNSUBSCRIBE_SERVICE')) define('_SBG_MO_UNSUBSCRIBE_SERVICE', 8);
|
---|
[499] | 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', 'soanbaigiang.smas.vn khong co dich vu nay!');
|
---|
| 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);
|
---|
[598] | 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 |
|
---|
[499] | 33 | if ( ! defined('_SBG_CHARGING_FAIL_NOT_ENOUGH_MSG')) define('_SBG_CHARGING_FAIL_NOT_ENOUGH_MSG', 'Tai khoan chinh cua so dien thoai :sendid: khong du de thuc hien lenh nap :amount: vao tai khoan :username: tren soanbaigiang.smas.vn');
|
---|
[598] | 34 | if ( ! defined('_SBG_CHARGING_FAIL_MORETHAN_LIMIT_MSG')) define('_SBG_CHARGING_FAIL_MORETHAN_LIMIT_MSG', 'So tien nap gioi han lon nhat la 50,000 vnd');
|
---|
| 35 | if ( ! defined('_SBG_CHARGING_FAIL_NOT_VIETTEL_MSG')) define('_SBG_CHARGING_FAIL_NOT_VIETTEL_MSG', 'Chi danh cho thue bao Viettel');
|
---|
[499] | 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})$/'),
|
---|
[583] | 51 | _SBG_MO_PHONENUM_CHANGE => array('pattern' => '/^(SBG[[:blank:]])(DDT)([[:blank:]][0-9]{10,11})([[:blank:]][a-zA-Z0-9~!@#$%^&*]{4,16})$/'),
|
---|
[499] | 52 | _SBG_MO_PASSWORD_RECOVERY => array('pattern' => '/^(SBG[[:blank:]])(MK)$/'),
|
---|
[579] | 53 | _SBG_MO_PASSWORD_CHANGE => array('pattern' => '/^(SBG[[:blank:]])(MK)([[:blank:]][a-zA-Z0-9~!@#$%^&*]{4,16})$/'),
|
---|
[499] | 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})$/'),
|
---|
[529] | 57 | _SBG_MO_UNSUBSCRIBE_SERVICE => array('pattern' => '/^(SBG[[:blank:]])(HUY)$/')
|
---|
[499] | 58 | );
|
---|
| 59 |
|
---|
[583] | 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 |
|
---|
[499] | 66 | public function __construct(){
|
---|
| 67 | parent::__construct();
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[579] | 70 | public function messageAnalys ($message)
|
---|
[499] | 71 | {
|
---|
[579] | 72 | $aryMatched = array();
|
---|
| 73 | $aryContent = array();
|
---|
[499] | 74 | $result = false;
|
---|
[579] | 75 |
|
---|
| 76 | foreach ($this->_arySmsMO as $key => $pattern)
|
---|
[499] | 77 | {
|
---|
[579] | 78 | $result = preg_match_all ($pattern['pattern'], strtoupper($message), $aryMatched);
|
---|
[499] | 79 | if ((bool)$result) break;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[583] | 82 | $key = (bool)$result ? $key:_SBG_MO_SYNTAX_ERR;
|
---|
| 83 |
|
---|
[579] | 84 | if (count ($aryMatched) > 0) {
|
---|
| 85 | foreach ($aryMatched as $k => $val) {
|
---|
| 86 | if ($k == 0) continue;
|
---|
| 87 | $aryContent[] = trim($val[0]);
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[583] | 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 |
|
---|
[579] | 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);
|
---|
[499] | 108 | return $aryResult;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | public function processMORequest ($sentNumber,$message)
|
---|
| 112 | {
|
---|
[513] | 113 | $debugMsg = $message."\n";
|
---|
| 114 |
|
---|
[575] | 115 | $sentNumber = $this->formatPhoneNumber($sentNumber);
|
---|
[499] | 116 |
|
---|
| 117 | $smsReturn = '';
|
---|
| 118 | $aryMOAnalys = $this->messageAnalys($message);
|
---|
| 119 | $case = $aryMOAnalys['case'];
|
---|
| 120 | $aryContents = isset($aryMOAnalys['content']) ? $aryMOAnalys['content']: null;
|
---|
[579] | 121 | $debugMsg .= var_export($aryMOAnalys);
|
---|
[499] | 122 | $this->load->model('frontend/user_model', 'objUserModel');
|
---|
[513] | 123 | $debugMsg .= $case;
|
---|
| 124 | write_file('mt_log', $debugMsg);
|
---|
[499] | 125 | switch ($case) {
|
---|
| 126 | case _SBG_MO_REGISTER:
|
---|
| 127 | case _SBG_MO_REGISTER_FOR:
|
---|
[583] | 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';
|
---|
| 131 | break;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[575] | 135 | $userName = isset($aryContents[2]) ? $this->formatPhoneNumber($aryContents[2]) : $sentNumber;
|
---|
[528] | 136 | $collaborator = isset($aryContents[2]) ? $sentNumber:null;
|
---|
[579] | 137 | $collaboratorMsg = '';
|
---|
| 138 | $sms = $this->objUserModel->register($userName, $collaborator, $collaboratorMsg);
|
---|
[528] | 139 | if ($case == _SBG_MO_REGISTER_FOR) {
|
---|
[579] | 140 | $smsReturn = $collaboratorMsg;
|
---|
[528] | 141 | $arySMS = explode ('|', $sms);
|
---|
[579] | 142 | if ((int)$arySMS[0] == 1 )
|
---|
| 143 | $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $arySMS[1]);
|
---|
[528] | 144 | }
|
---|
| 145 | else {
|
---|
| 146 | $smsReturn = $sms;
|
---|
| 147 | }
|
---|
[499] | 148 | break;
|
---|
| 149 | case _SBG_MO_PHONENUM_CHANGE:
|
---|
[583] | 150 |
|
---|
| 151 | if (!preg_match('/^([0-9]{10,11}$)$/', $aryContents[2])) {
|
---|
| 152 | $smsReturn = '0|So dien thoai khach hang khong hop le';
|
---|
| 153 | break;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[575] | 156 | $oldPhoneNumber = $this->formatPhoneNumber($aryContents[2]);
|
---|
[499] | 157 | $password = $aryContents[3];
|
---|
| 158 | $smsReturn = $this->objUserModel->changeProfile($sentNumber, $oldPhoneNumber, $password);
|
---|
[583] | 159 | $arySMS = explode ('|', $smsReturn);
|
---|
| 160 | $sendMT = $this->sendMT($this->formatPhoneNumber($oldPhoneNumber, -1), $arySMS[1]);
|
---|
| 161 |
|
---|
[499] | 162 | break;
|
---|
| 163 | case _SBG_MO_PASSWORD_RECOVERY:
|
---|
| 164 | case _SBG_MO_PASSWORD_CHANGE:
|
---|
| 165 | $password = isset($aryContents[2]) ? $aryContents[2] : null;
|
---|
| 166 | $smsReturn = $this->objUserModel->changePassword($sentNumber, $password);
|
---|
| 167 | break;
|
---|
| 168 | case _SBG_MO_VIP_REGISTER:
|
---|
| 169 | $p_code = $aryContents[2];
|
---|
| 170 | $smsReturn = $this->objUserModel->registerVip($sentNumber, $p_code);
|
---|
| 171 | break;
|
---|
| 172 | case _SBG_MO_PAY_TO_ACCOUNT:
|
---|
| 173 | case _SBG_MO_PAY_TO_ACCOUNT_FOR:
|
---|
[575] | 174 | $userName = isset($aryContents[3]) ? $this->formatPhoneNumber($aryContents[3]) : $sentNumber;
|
---|
[499] | 175 | $amount = $aryContents[2];
|
---|
[598] | 176 | $result =$this->chargeRootAccountProcess($sentNumber, $amount, $sentNumber.' paid for SBG');
|
---|
| 177 |
|
---|
| 178 | if ($result == _SBG_CHARGING_SUCCESS) {
|
---|
[499] | 179 | $smsReturn = $this->objUserModel->rechargeAccount($userName, $amount);
|
---|
[598] | 180 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR) {
|
---|
[579] | 181 | $arySmsReturn = explode ('|', $smsReturn);
|
---|
| 182 | $smsMT = $arySmsReturn[1] .' tu thue bao '. $sentNumber;
|
---|
| 183 | $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $smsMT);
|
---|
[556] | 184 | }
|
---|
[598] | 185 | //write to paid log
|
---|
| 186 | $paidTime = date('Y-m-d H:i:s');
|
---|
| 187 | $this->objUserModel->insertPaidlog($sentNumber, $userName, _SBG_PAIDTYPE_SMS, $amount, $paidTime);
|
---|
[499] | 188 | }
|
---|
[598] | 189 | else if ($result == _SBG_CHARGING_FAIL_NOT_ENOUGH) {
|
---|
| 190 | $aryPatterns = array ('/:sendid:/', '/:amount:/', '/:username:/');
|
---|
| 191 | $smsReturn = preg_replace($aryPatterns, array($sentNumber, $amount, $userName), _SBG_CHARGING_FAIL_NOT_ENOUGH_MSG);
|
---|
| 192 | $smsReturn = '0|'.$smsReturn;
|
---|
| 193 | }
|
---|
| 194 | else if ($result == _SBG_CHARGING_FAIL_MORETHAN_LIMIT) {
|
---|
| 195 | $aryPatterns = array ('/:sendid:/');
|
---|
| 196 | $smsReturn = preg_replace($aryPatterns, array($sentNumber), _SBG_CHARGING_FAIL_MORETHAN_LIMIT_MSG);
|
---|
| 197 | $smsReturn = '0|'.$smsReturn;
|
---|
| 198 | }else if ($result == _SBG_CHARGING_FAIL_NOT_VIETTEL || $result == _SBG_CHARGING_NUMBER_NOT_EXISTED) {
|
---|
| 199 | $smsReturn = '0|'._SBG_CHARGING_FAIL_NOT_VIETTEL_MSG;
|
---|
| 200 | }
|
---|
| 201 | else {
|
---|
| 202 | $smsReturn = '0|Loi, khong thanh toan duoc tu tai khoan goc';
|
---|
| 203 | }
|
---|
[499] | 204 | break;
|
---|
[529] | 205 | case _SBG_MO_UNSUBSCRIBE_SERVICE:
|
---|
[499] | 206 | case _SBG_MO_SYNTAX_ERR:
|
---|
| 207 | default:
|
---|
| 208 | $smsReturn = '0|'._SBG_MO_SYNTAX_ERR_MSG;
|
---|
| 209 | break;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
[579] | 212 | return $smsReturn.'|'.$case;
|
---|
[499] | 213 | }
|
---|
| 214 |
|
---|
[506] | 215 | public function cardPaidProcess ($aryCardInfo, &$aryTopupResult = array())
|
---|
[499] | 216 | {
|
---|
| 217 | $url = $this->config->item('topup_service_url');
|
---|
| 218 | $action = 'http://tempuri.org/ITopupService/TopUp';
|
---|
| 219 | $xml = $this->load->view('topup', $aryCardInfo, true);
|
---|
| 220 |
|
---|
| 221 | $client = new nusoap_client($url);
|
---|
| 222 | $client->useHTTPPersistentConnection();
|
---|
| 223 | $client->soap_defencoding = 'UTF-8';
|
---|
| 224 | $client->operation = $action;
|
---|
| 225 |
|
---|
[519] | 226 | $result = $client->send($xml, $action);
|
---|
[499] | 227 |
|
---|
[598] | 228 | $debugMsg = 'Logged time: '. date('Y-m-d H:i:s') ."\n";
|
---|
| 229 | $debugMsg .= 'Send:'."\n" .$xml ."\n\n";
|
---|
| 230 | $debugMsg .= 'Result:'."\n". var_export($result, TRUE);
|
---|
| 231 | write_file('topup_log', $debugMsg);
|
---|
| 232 |
|
---|
[499] | 233 | if ($client->fault) {
|
---|
| 234 | return _SBG_CARD_PAY_FAIL;
|
---|
| 235 | }
|
---|
| 236 |
|
---|
[528] | 237 | $keys = array_keys($result);
|
---|
[499] | 238 |
|
---|
[528] | 239 | $aryTopupResult = $result[$keys[0]];
|
---|
| 240 |
|
---|
[499] | 241 | if ($aryTopupResult['Success'] == 'false') {
|
---|
| 242 | return _SBG_CARD_PAY_FAIL;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | return _SBG_CARD_PAY_SUCCESS;
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | public function chargeRootAccountProcess ($sentID, $amount = 0, $contents = '')
|
---|
| 249 | {
|
---|
| 250 | $url = $this->config->item('charging_service_url');
|
---|
| 251 | $username = $this->config->item('charging_username');
|
---|
| 252 | $password = $this->config->item('charging_password');
|
---|
| 253 | $action = 'http://tempuri.org/processCharging';
|
---|
| 254 |
|
---|
| 255 | $aryParams = array(
|
---|
| 256 | 'user' => $username,
|
---|
| 257 | 'pass' => $password,
|
---|
| 258 | 'MSISDN' => $sentID,
|
---|
| 259 | 'Charging' => $amount,
|
---|
| 260 | 'Contents' => $contents
|
---|
| 261 | );
|
---|
| 262 |
|
---|
| 263 | $xml = $this->load->view('charging', $aryParams, true);
|
---|
| 264 | $client = new nusoap_client($url);
|
---|
| 265 | $client->useHTTPPersistentConnection();
|
---|
| 266 | $client->soap_defencoding = 'UTF-8';
|
---|
| 267 | $client->operation = $action;
|
---|
| 268 | $result = $client->send($xml, $action);
|
---|
[598] | 269 | $debugMsg = var_export($xml, TRUE);
|
---|
| 270 | $debugMsg .= var_export($result, TRUE);
|
---|
| 271 | write_file('mt_log', $debugMsg);
|
---|
[499] | 272 |
|
---|
| 273 | if ($client->fault) {
|
---|
| 274 | return _SBG_CHARGING_FAIL;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[598] | 277 | $aryErrs = array (_SBG_CHARGING_FAIL_NOT_ENOUGH,
|
---|
| 278 | _SBG_CHARGING_FAIL_NOT_VIETTEL,
|
---|
| 279 | _SBG_CHARGING_FAIL_MORETHAN_LIMIT,
|
---|
| 280 | _SBG_CHARGING_NUMBER_NOT_EXISTED,
|
---|
| 281 | _SBG_CHARGING_NUMBER_NOT_AVAILABLE,
|
---|
| 282 | _SBG_CHARGING_NUMBER_CHANGED_OWNER,
|
---|
| 283 | _SBG_CHARGING_GENERAL_ERROR,
|
---|
| 284 | _SBG_CHARGING_NUMBER_NOT_REGISTED
|
---|
| 285 | );
|
---|
[499] | 286 |
|
---|
[598] | 287 | if (in_array((int)$result['processChargingResult'], $aryErrs))
|
---|
| 288 | return (int)$result['processChargingResult'];
|
---|
| 289 |
|
---|
[499] | 290 | return _SBG_CHARGING_SUCCESS;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | public function sendMT ($receiverID, $message)
|
---|
| 294 | {
|
---|
| 295 | $aryMatch = array();
|
---|
[575] | 296 |
|
---|
[499] | 297 | if (preg_match('/^(0)([0-9]{9,10})$/', $receiverID, $aryMatch) == 1) {
|
---|
| 298 | $receiverID = '84'. $aryMatch[2];
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | $username = $this->config->item('mt_username');
|
---|
| 302 | $password = $this->config->item('mt_password');
|
---|
| 303 | $action = 'http://tempuri.org/InsertMT';
|
---|
| 304 |
|
---|
| 305 | $aryParams = array(
|
---|
| 306 | 'User' => $username,
|
---|
| 307 | 'Pass' => $password,
|
---|
| 308 | 'CPCode' => _SBG_MT_CP_CODE,
|
---|
| 309 | 'UserID' => _SBG_MT_SEND_NUMBER,
|
---|
| 310 | 'RequestID' => '4',
|
---|
| 311 | 'ReceiverID' => $receiverID,
|
---|
| 312 | 'ServiceID' => _SBG_SERVICE_SERVICEID,
|
---|
| 313 | 'CommandCode' => _SBG_SERVICE_COMMAND_CODE,
|
---|
| 314 | 'ContentType' => '0',
|
---|
| 315 | 'Info' => $message
|
---|
| 316 | );
|
---|
| 317 |
|
---|
| 318 | $xml = $this->load->view('mt', $aryParams, true);
|
---|
[513] | 319 | $url = $this->config->item('mt_service_url');
|
---|
[499] | 320 | $client = new nusoap_client($url);
|
---|
| 321 | $client->useHTTPPersistentConnection();
|
---|
| 322 | $client->soap_defencoding = 'UTF-8';
|
---|
| 323 | $client->operation = $action;
|
---|
| 324 | $result = $client->send($xml, $action);
|
---|
| 325 |
|
---|
[513] | 326 | //write_file('mt_log', var_export($client->fault, true)."\n".var_export($xml, true));
|
---|
| 327 |
|
---|
[499] | 328 | if ($client->fault || (int)$result['InsertMTResult'] != 1) {
|
---|
| 329 | return _SBG_SEND_MT_FAIL;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | return _SBG_SEND_MT_SUCCESS;
|
---|
| 333 | }
|
---|
[575] | 334 |
|
---|
[579] | 335 | public function formatPhoneNumber ($phoneNumber, $direction = 1) {
|
---|
[575] | 336 | $aryMatch = array();
|
---|
[579] | 337 | if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == 1) {
|
---|
[575] | 338 | $result = '0'. $aryMatch[2];
|
---|
| 339 | }
|
---|
[579] | 340 | else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == 1) {
|
---|
[575] | 341 | $result = $phoneNumber;
|
---|
| 342 | }
|
---|
[579] | 343 | else if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == -1) {
|
---|
| 344 | $result = $phoneNumber;
|
---|
| 345 | }
|
---|
| 346 | else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == -1) {
|
---|
| 347 | $result = '84'. $aryMatch[2];
|
---|
| 348 | }
|
---|
[575] | 349 |
|
---|
| 350 | return $result;
|
---|
| 351 | }
|
---|
[499] | 352 | } |
---|