[499] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
| 2 |
|
---|
[647] | 3 | if ( ! defined('_SBG_MO_REGISTER')) define('_SBG_MO_REGISTER', 'SUBSCR');
|
---|
| 4 | if ( ! defined('_SBG_MO_REGISTER_FOR')) define('_SBG_MO_REGISTER_FOR', 'SUBSCR_FOR');
|
---|
| 5 | if ( ! defined('_SBG_MO_PHONENUM_CHANGE')) define('_SBG_MO_PHONENUM_CHANGE', 'PHONE_CHANGE');
|
---|
| 6 | if ( ! defined('_SBG_MO_PASSWORD_RECOVERY')) define('_SBG_MO_PASSWORD_RECOVERY', 'PWD_RECOVER');
|
---|
| 7 | if ( ! defined('_SBG_MO_VIP_REGISTER')) define('_SBG_MO_VIP_REGISTER', 'REG_VIP');
|
---|
| 8 | if ( ! defined('_SBG_MO_PAY_TO_ACCOUNT')) define('_SBG_MO_PAY_TO_ACCOUNT', 'PAY');
|
---|
| 9 | if ( ! defined('_SBG_MO_PAY_TO_ACCOUNT_FOR')) define('_SBG_MO_PAY_TO_ACCOUNT_FOR', 'PAY_FOR');
|
---|
| 10 | if ( ! defined('_SBG_MO_UNSUBSCRIBE_SERVICE')) define('_SBG_MO_UNSUBSCRIBE_SERVICE', 'UNSUBSCR');
|
---|
| 11 | if ( ! defined('_SBG_MO_SUPPOR_SERVICE')) define('_SBG_MO_SUPPOR_SERVICE', 'SUPPORT');
|
---|
| 12 | if ( ! defined('_SBG_MO_SYNTAX_ERR')) define('_SBG_MO_SYNTAX_ERR', 'SYNTAX_ERR');
|
---|
[499] | 13 |
|
---|
[647] | 14 | if ( ! defined('_SBG_CARD_PAY_FAIL')) define('_SBG_CARD_PAY_FAIL', -1);
|
---|
| 15 | if ( ! defined('_SBG_CARD_PAY_SUCCESS')) define('_SBG_CARD_PAY_SUCCESS', 1);
|
---|
[499] | 16 |
|
---|
[647] | 17 | if ( ! defined('_SBG_CHARGING_FAIL')) define('_SBG_CHARGING_FAIL', -1);
|
---|
| 18 | if ( ! defined('_SBG_CHARGING_SUCCESS')) define('_SBG_CHARGING_SUCCESS', 1);
|
---|
| 19 | if ( ! defined('_SBG_CHARGING_FAIL_NOT_ENOUGH')) define('_SBG_CHARGING_FAIL_NOT_ENOUGH', 401);
|
---|
| 20 | if ( ! defined('_SBG_CHARGING_FAIL_NOT_VIETTEL')) define('_SBG_CHARGING_FAIL_NOT_VIETTEL', 402);
|
---|
| 21 | if ( ! defined('_SBG_CHARGING_NUMBER_NOT_EXISTED')) define('_SBG_CHARGING_NUMBER_NOT_EXISTED', 403);
|
---|
| 22 | if ( ! defined('_SBG_CHARGING_NUMBER_NOT_AVAILABLE')) define('_SBG_CHARGING_NUMBER_NOT_AVAILABLE', 404);
|
---|
| 23 | if ( ! defined('_SBG_CHARGING_NUMBER_CHANGED_OWNER')) define('_SBG_CHARGING_NUMBER_CHANGED_OWNER', 405);
|
---|
| 24 | if ( ! defined('_SBG_CHARGING_FAIL_MORETHAN_LIMIT')) define('_SBG_CHARGING_FAIL_MORETHAN_LIMIT', 406);
|
---|
| 25 | if ( ! defined('_SBG_CHARGING_GENERAL_ERROR')) define('_SBG_CHARGING_GENERAL_ERROR', 440);
|
---|
| 26 | if ( ! defined('_SBG_CHARGING_NUMBER_NOT_REGISTED')) define('_SBG_CHARGING_NUMBER_NOT_REGISTED', 501);
|
---|
[499] | 27 |
|
---|
[647] | 28 | if ( ! defined('_SBG_SEND_MT_FAIL')) define('_SBG_SEND_MT_FAIL', -1);
|
---|
| 29 | if ( ! defined('_SBG_SEND_MT_SUCCESS')) define('_SBG_SEND_MT_SUCCESS', 1);
|
---|
| 30 | if ( ! defined('_SBG_MT_SEND_NUMBER')) define('_SBG_MT_SEND_NUMBER', '841662860000');
|
---|
| 31 | if ( ! defined('_SBG_MT_CP_CODE')) define('_SBG_MT_CP_CODE', '601');
|
---|
[499] | 32 |
|
---|
[647] | 33 | if ( ! defined('_SBG_SERVICE_COMMAND_CODE')) define('_SBG_SERVICE_COMMAND_CODE', 'SBG');
|
---|
| 34 | if ( ! defined('_SBG_SERVICE_SERVICEID')) define('_SBG_SERVICE_SERVICEID', '8062');
|
---|
[598] | 35 |
|
---|
[647] | 36 | if ( ! defined('_SBG_MO_PROCCESS_ERR')) define('_SBG_MO_PROCCESS_ERR', 0);
|
---|
[598] | 37 |
|
---|
[499] | 38 | Class Services_model extends CI_Model
|
---|
| 39 | {
|
---|
| 40 | private $_arySmsMO = array(
|
---|
[647] | 41 | _SBG_MO_REGISTER => array('pattern' => '/^(SBG)([[:blank:]])(DK)$/'),
|
---|
| 42 | _SBG_MO_REGISTER_FOR => array('pattern' => '/^(SBG)([[:blank:]])(DK)([[:blank:]])([0-9]{10,11})$/'),
|
---|
| 43 | _SBG_MO_PHONENUM_CHANGE => array('pattern' => '/^(SBG)([[:blank:]])(DDT)([[:blank:]])([0-9]{10,11})([[:blank:]])([a-zA-Z0-9]{1,})$/'),
|
---|
| 44 | _SBG_MO_PASSWORD_RECOVERY => array('pattern' => '/^(SBG)([[:blank:]])(MK)$/'),
|
---|
| 45 | _SBG_MO_VIP_REGISTER => array('pattern' => '/^(SBG)([[:blank:]])(VIP)([[:blank:]])([a-zA-Z0-9]{1,})$/'),
|
---|
| 46 | _SBG_MO_PAY_TO_ACCOUNT => array('pattern' => '/^(SBG)([[:blank:]])(NAP)([[:blank:]])([0-9]{3,})$/'),
|
---|
| 47 | _SBG_MO_PAY_TO_ACCOUNT_FOR => array('pattern' => '/^(SBG)([[:blank:]])(NAP)([[:blank:]])([0-9]{3,})([[:blank:]])([0-9]{10,11})$/'),
|
---|
| 48 | _SBG_MO_SUPPOR_SERVICE => array('pattern' => '/^(SBG)([[:blank:]])(HD)$/'),
|
---|
| 49 | _SBG_MO_UNSUBSCRIBE_SERVICE => array('pattern' => '/^(SBG)([[:blank:]])(HUY)$/')
|
---|
| 50 | );
|
---|
[499] | 51 |
|
---|
| 52 | public function __construct(){
|
---|
| 53 | parent::__construct();
|
---|
[636] | 54 | $this->load->helper('language');
|
---|
| 55 | $this->lang->load('messages', 'message');
|
---|
[499] | 56 | }
|
---|
| 57 |
|
---|
[647] | 58 | /**
|
---|
| 59 | * messageAnalys
|
---|
| 60 | *
|
---|
| 61 | * @todo Analysis content of incoming message
|
---|
| 62 | *
|
---|
| 63 | * @param String $message - coming SMS
|
---|
| 64 | * @return multitype:Ambigous <string, multitype> multitype:multitype
|
---|
| 65 | */
|
---|
[579] | 66 | public function messageAnalys ($message)
|
---|
[499] | 67 | {
|
---|
[579] | 68 | $aryMatched = array();
|
---|
| 69 | $aryContent = array();
|
---|
[647] | 70 | $result = FALSE;
|
---|
[579] | 71 |
|
---|
[647] | 72 | foreach ($this->_arySmsMO as $case => $pattern)
|
---|
[499] | 73 | {
|
---|
[647] | 74 | $result = preg_match($pattern['pattern'], strtoupper(trim($message)));
|
---|
| 75 | if ((bool)$result) {
|
---|
| 76 | $aryMatched = explode(' ', trim($message));
|
---|
| 77 | break;
|
---|
| 78 | }
|
---|
[499] | 79 | }
|
---|
| 80 |
|
---|
[647] | 81 | $case = (bool)$result ? $case:_SBG_MO_SYNTAX_ERR;
|
---|
[583] | 82 |
|
---|
[647] | 83 | foreach($aryMatched as $k => $val) {
|
---|
| 84 | if ($k > 1) $aryContent[] = $val;
|
---|
[579] | 85 | }
|
---|
[583] | 86 |
|
---|
[647] | 87 | $aryResult = array('case' => $case, 'content' => $aryContent);
|
---|
[499] | 88 | return $aryResult;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[647] | 91 | /**
|
---|
| 92 | * processMORequest
|
---|
| 93 | *
|
---|
| 94 | * @todo process action analysed from messageAnalys
|
---|
| 95 | *
|
---|
| 96 | * @param unknown $sentNumber
|
---|
| 97 | * @param unknown $message
|
---|
| 98 | * @return string
|
---|
| 99 | */
|
---|
| 100 | public function processMORequest ($sentNumber, $message)
|
---|
[499] | 101 | {
|
---|
[513] | 102 | $debugMsg = $message."\n";
|
---|
| 103 |
|
---|
[575] | 104 | $sentNumber = $this->formatPhoneNumber($sentNumber);
|
---|
[499] | 105 |
|
---|
| 106 | $smsReturn = '';
|
---|
| 107 | $aryMOAnalys = $this->messageAnalys($message);
|
---|
| 108 | $case = $aryMOAnalys['case'];
|
---|
| 109 | $aryContents = isset($aryMOAnalys['content']) ? $aryMOAnalys['content']: null;
|
---|
| 110 | $this->load->model('frontend/user_model', 'objUserModel');
|
---|
[513] | 111 | $debugMsg .= $case;
|
---|
[615] | 112 |
|
---|
[499] | 113 | switch ($case) {
|
---|
| 114 | case _SBG_MO_REGISTER:
|
---|
| 115 | case _SBG_MO_REGISTER_FOR:
|
---|
[583] | 116 | if ($case == _SBG_MO_REGISTER_FOR) {
|
---|
[647] | 117 | if (!preg_match('/^([0-9]{10,11}$)$/', $aryContents[0])) {
|
---|
[636] | 118 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_PHONENUM_WRONG_FORMAT_MSG');
|
---|
[583] | 119 | break;
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[647] | 123 | $userName = isset($aryContents[0]) ? $this->formatPhoneNumber($aryContents[0]) : $sentNumber;
|
---|
| 124 | $collaborator = isset($aryContents[0]) ? $sentNumber:null;
|
---|
[579] | 125 | $collaboratorMsg = '';
|
---|
[615] | 126 |
|
---|
[579] | 127 | $sms = $this->objUserModel->register($userName, $collaborator, $collaboratorMsg);
|
---|
[528] | 128 | if ($case == _SBG_MO_REGISTER_FOR) {
|
---|
[579] | 129 | $smsReturn = $collaboratorMsg;
|
---|
[528] | 130 | $arySMS = explode ('|', $sms);
|
---|
[579] | 131 | if ((int)$arySMS[0] == 1 )
|
---|
| 132 | $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $arySMS[1]);
|
---|
[528] | 133 | }
|
---|
| 134 | else {
|
---|
| 135 | $smsReturn = $sms;
|
---|
| 136 | }
|
---|
[499] | 137 | break;
|
---|
| 138 | case _SBG_MO_PHONENUM_CHANGE:
|
---|
[647] | 139 | if (!preg_match('/^(09\d{8}|01\d{9})$/', $aryContents[0])) {
|
---|
[636] | 140 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_PHONENUM_WRONG_FORMAT_MSG');
|
---|
[583] | 141 | break;
|
---|
| 142 | }
|
---|
[615] | 143 |
|
---|
[647] | 144 | $oldPhoneNumber = $this->formatPhoneNumber($aryContents[0]);
|
---|
| 145 | $password = $aryContents[1];
|
---|
[499] | 146 | $smsReturn = $this->objUserModel->changeProfile($sentNumber, $oldPhoneNumber, $password);
|
---|
[615] | 147 |
|
---|
| 148 | $arySMS = explode('|', $smsReturn);
|
---|
| 149 | $changeResult = (int)$arySMS[0];
|
---|
| 150 |
|
---|
[636] | 151 | $aryPatterns = array('/:sentNumber:/');
|
---|
| 152 | $sms = preg_replace($aryPatterns, array($sentNumber), lang('_SBG_MO_USER_OLD_PHONENUM_CHANGE_SUCCESS_MSG'));
|
---|
[615] | 153 | $sendMT = $changeResult == 1 ? $this->sendMT($this->formatPhoneNumber($oldPhoneNumber, -1), $sms) : '';
|
---|
[499] | 154 | break;
|
---|
| 155 | case _SBG_MO_PASSWORD_RECOVERY:
|
---|
[647] | 156 | $smsReturn = $this->objUserModel->changePassword($sentNumber);
|
---|
| 157 | break;
|
---|
[499] | 158 | case _SBG_MO_VIP_REGISTER:
|
---|
[647] | 159 | $p_code = $aryContents[0];
|
---|
[499] | 160 | $smsReturn = $this->objUserModel->registerVip($sentNumber, $p_code);
|
---|
[646] | 161 | $this->objUserModel->insertRegisterVipLog($sentNumber, $p_code, true);
|
---|
[499] | 162 | break;
|
---|
| 163 | case _SBG_MO_PAY_TO_ACCOUNT:
|
---|
| 164 | case _SBG_MO_PAY_TO_ACCOUNT_FOR:
|
---|
[647] | 165 | $userName = isset($aryContents[1]) ? $this->formatPhoneNumber($aryContents[1]) : $sentNumber;
|
---|
[603] | 166 |
|
---|
[612] | 167 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR && !preg_match('/^(09\d{8}|01\d{9})$/', $userName)) {
|
---|
[636] | 168 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_PHONENUM_WRONG_FORMAT_MSG');
|
---|
[603] | 169 | break;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[647] | 172 | $amount = $aryContents[0];
|
---|
[615] | 173 | if (!preg_match('/^[0-9]{3,}$/', $amount)) {
|
---|
[636] | 174 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_AMOUNT_WRONG_FORMAT_MSG');
|
---|
[615] | 175 | break;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
[598] | 178 | $result =$this->chargeRootAccountProcess($sentNumber, $amount, $sentNumber.' paid for SBG');
|
---|
| 179 |
|
---|
| 180 | if ($result == _SBG_CHARGING_SUCCESS) {
|
---|
[499] | 181 | $smsReturn = $this->objUserModel->rechargeAccount($userName, $amount);
|
---|
[598] | 182 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR) {
|
---|
[579] | 183 | $arySmsReturn = explode ('|', $smsReturn);
|
---|
[636] | 184 | $aryPatterns = array('/:amount:/', '/:username:/', '/:sentNumber:/');
|
---|
| 185 | $smsMT = preg_replace($aryPatterns, array($amount, $username, $sentNumber), lang('_SBG_MO_PAY_TO_ACCOUNT_FOR_MSG'));
|
---|
[579] | 186 | $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $smsMT);
|
---|
[556] | 187 | }
|
---|
[647] | 188 |
|
---|
[598] | 189 | //write to paid log
|
---|
| 190 | $paidTime = date('Y-m-d H:i:s');
|
---|
| 191 | $this->objUserModel->insertPaidlog($sentNumber, $userName, _SBG_PAIDTYPE_SMS, $amount, $paidTime);
|
---|
[499] | 192 | }
|
---|
[598] | 193 | else if ($result == _SBG_CHARGING_FAIL_NOT_ENOUGH) {
|
---|
[599] | 194 | $aryPatterns = array ('/:amount:/', '/:username:/');
|
---|
[636] | 195 | $smsReturn = preg_replace($aryPatterns, array($amount, $userName), lang('_SBG_MO_CHARGING_FAIL_NOT_ENOUGH_MSG'));
|
---|
| 196 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.$smsReturn;
|
---|
[598] | 197 | }
|
---|
| 198 | else if ($result == _SBG_CHARGING_FAIL_MORETHAN_LIMIT) {
|
---|
| 199 | $aryPatterns = array ('/:sendid:/');
|
---|
[636] | 200 | $smsReturn = preg_replace($aryPatterns, array($sentNumber), lang('_SBG_MO_CHARGING_FAIL_MORETHAN_LIMIT_MSG'));
|
---|
| 201 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.$smsReturn;
|
---|
[612] | 202 | }else if ($result == _SBG_CHARGING_FAIL_NOT_VIETTEL || $result == _SBG_CHARGING_NUMBER_NOT_EXISTED || $result == _SBG_CHARGING_NUMBER_NOT_AVAILABLE) {
|
---|
[636] | 203 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_CHARGING_FAIL_NOT_VIETTEL_MSG');
|
---|
[598] | 204 | }
|
---|
| 205 | else {
|
---|
[636] | 206 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_CHARGING_FAIL_MSG');
|
---|
[598] | 207 | }
|
---|
[499] | 208 | break;
|
---|
[647] | 209 | case _SBG_MO_SUPPOR_SERVICE:
|
---|
| 210 | $smsReturn = '1|'.lang('_SBG_MO_SUPPORT_MSG');
|
---|
| 211 | break;
|
---|
[529] | 212 | case _SBG_MO_UNSUBSCRIBE_SERVICE:
|
---|
[499] | 213 | case _SBG_MO_SYNTAX_ERR:
|
---|
| 214 | default:
|
---|
[636] | 215 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_SYNTAX_ERR_MSG');
|
---|
[499] | 216 | break;
|
---|
| 217 | }
|
---|
| 218 |
|
---|
[579] | 219 | return $smsReturn.'|'.$case;
|
---|
[499] | 220 | }
|
---|
| 221 |
|
---|
[647] | 222 |
|
---|
| 223 | /**
|
---|
| 224 | * cardPaidProcess
|
---|
| 225 | *
|
---|
| 226 | * @todo Call Topup webservice to check and lock prepaid-card
|
---|
| 227 | * @param Array $aryCardInfo
|
---|
| 228 | * @param Array $aryTopupResult
|
---|
| 229 | * @return string
|
---|
| 230 | */
|
---|
[506] | 231 | public function cardPaidProcess ($aryCardInfo, &$aryTopupResult = array())
|
---|
[499] | 232 | {
|
---|
| 233 | $url = $this->config->item('topup_service_url');
|
---|
| 234 | $action = 'http://tempuri.org/ITopupService/TopUp';
|
---|
| 235 | $xml = $this->load->view('topup', $aryCardInfo, true);
|
---|
| 236 |
|
---|
| 237 | $client = new nusoap_client($url);
|
---|
| 238 | $client->useHTTPPersistentConnection();
|
---|
| 239 | $client->soap_defencoding = 'UTF-8';
|
---|
| 240 | $client->operation = $action;
|
---|
| 241 |
|
---|
[519] | 242 | $result = $client->send($xml, $action);
|
---|
[499] | 243 |
|
---|
| 244 | if ($client->fault) {
|
---|
| 245 | return _SBG_CARD_PAY_FAIL;
|
---|
| 246 | }
|
---|
| 247 |
|
---|
[528] | 248 | $keys = array_keys($result);
|
---|
[499] | 249 |
|
---|
[528] | 250 | $aryTopupResult = $result[$keys[0]];
|
---|
[632] | 251 |
|
---|
| 252 | $debugMsg = 'Logged time: '. date('Y-m-d H:i:s') ."\n";
|
---|
| 253 | $debugMsg .= 'Send:'."\n" .$xml ."\n\n";
|
---|
| 254 | $debugMsg .= 'Result:'."\n". var_export($result, TRUE);
|
---|
| 255 | write_file('./log/topup_log', $debugMsg);
|
---|
| 256 |
|
---|
[499] | 257 | if ($aryTopupResult['Success'] == 'false') {
|
---|
| 258 | return _SBG_CARD_PAY_FAIL;
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | return _SBG_CARD_PAY_SUCCESS;
|
---|
| 262 | }
|
---|
| 263 |
|
---|
[647] | 264 | /**
|
---|
| 265 | * chargeRootAccountProcess
|
---|
| 266 | *
|
---|
| 267 | * @todo Call charging webservice to charged fee from phone root account
|
---|
| 268 | * @param String $sentID
|
---|
| 269 | * @param Integer $amount
|
---|
| 270 | * @param String $contents
|
---|
| 271 | * @return string|number
|
---|
| 272 | */
|
---|
[499] | 273 | public function chargeRootAccountProcess ($sentID, $amount = 0, $contents = '')
|
---|
| 274 | {
|
---|
| 275 | $url = $this->config->item('charging_service_url');
|
---|
| 276 | $username = $this->config->item('charging_username');
|
---|
| 277 | $password = $this->config->item('charging_password');
|
---|
| 278 | $action = 'http://tempuri.org/processCharging';
|
---|
| 279 |
|
---|
| 280 | $aryParams = array(
|
---|
| 281 | 'user' => $username,
|
---|
| 282 | 'pass' => $password,
|
---|
| 283 | 'MSISDN' => $sentID,
|
---|
| 284 | 'Charging' => $amount,
|
---|
| 285 | 'Contents' => $contents
|
---|
| 286 | );
|
---|
| 287 |
|
---|
| 288 | $xml = $this->load->view('charging', $aryParams, true);
|
---|
| 289 | $client = new nusoap_client($url);
|
---|
| 290 | $client->useHTTPPersistentConnection();
|
---|
| 291 | $client->soap_defencoding = 'UTF-8';
|
---|
| 292 | $client->operation = $action;
|
---|
| 293 | $result = $client->send($xml, $action);
|
---|
[629] | 294 |
|
---|
[499] | 295 | if ($client->fault) {
|
---|
| 296 | return _SBG_CHARGING_FAIL;
|
---|
| 297 | }
|
---|
| 298 |
|
---|
[647] | 299 | $aryErrs = array ( _SBG_CHARGING_FAIL_NOT_ENOUGH,
|
---|
| 300 | _SBG_CHARGING_FAIL_NOT_VIETTEL,
|
---|
| 301 | _SBG_CHARGING_FAIL_MORETHAN_LIMIT,
|
---|
| 302 | _SBG_CHARGING_NUMBER_NOT_EXISTED,
|
---|
| 303 | _SBG_CHARGING_NUMBER_NOT_AVAILABLE,
|
---|
| 304 | _SBG_CHARGING_NUMBER_CHANGED_OWNER,
|
---|
| 305 | _SBG_CHARGING_GENERAL_ERROR,
|
---|
| 306 | _SBG_CHARGING_NUMBER_NOT_REGISTED);
|
---|
[499] | 307 |
|
---|
[598] | 308 | if (in_array((int)$result['processChargingResult'], $aryErrs))
|
---|
| 309 | return (int)$result['processChargingResult'];
|
---|
| 310 |
|
---|
[499] | 311 | return _SBG_CHARGING_SUCCESS;
|
---|
| 312 | }
|
---|
| 313 |
|
---|
[647] | 314 | /**
|
---|
| 315 | * sendMT
|
---|
| 316 | *
|
---|
| 317 | * @todo Calling MT webservice to send a SMS to a phone number
|
---|
| 318 | * @param String $receiverID
|
---|
| 319 | * @param String $message
|
---|
| 320 | * @return string
|
---|
| 321 | */
|
---|
[499] | 322 | public function sendMT ($receiverID, $message)
|
---|
| 323 | {
|
---|
| 324 | $aryMatch = array();
|
---|
[575] | 325 |
|
---|
[499] | 326 | if (preg_match('/^(0)([0-9]{9,10})$/', $receiverID, $aryMatch) == 1) {
|
---|
| 327 | $receiverID = '84'. $aryMatch[2];
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | $username = $this->config->item('mt_username');
|
---|
| 331 | $password = $this->config->item('mt_password');
|
---|
| 332 | $action = 'http://tempuri.org/InsertMT';
|
---|
| 333 |
|
---|
| 334 | $aryParams = array(
|
---|
| 335 | 'User' => $username,
|
---|
| 336 | 'Pass' => $password,
|
---|
| 337 | 'CPCode' => _SBG_MT_CP_CODE,
|
---|
| 338 | 'UserID' => _SBG_MT_SEND_NUMBER,
|
---|
| 339 | 'RequestID' => '4',
|
---|
| 340 | 'ReceiverID' => $receiverID,
|
---|
| 341 | 'ServiceID' => _SBG_SERVICE_SERVICEID,
|
---|
| 342 | 'CommandCode' => _SBG_SERVICE_COMMAND_CODE,
|
---|
| 343 | 'ContentType' => '0',
|
---|
| 344 | 'Info' => $message
|
---|
| 345 | );
|
---|
| 346 |
|
---|
| 347 | $xml = $this->load->view('mt', $aryParams, true);
|
---|
[513] | 348 | $url = $this->config->item('mt_service_url');
|
---|
[499] | 349 | $client = new nusoap_client($url);
|
---|
| 350 | $client->useHTTPPersistentConnection();
|
---|
| 351 | $client->soap_defencoding = 'UTF-8';
|
---|
| 352 | $client->operation = $action;
|
---|
| 353 | $result = $client->send($xml, $action);
|
---|
| 354 |
|
---|
| 355 | if ($client->fault || (int)$result['InsertMTResult'] != 1) {
|
---|
| 356 | return _SBG_SEND_MT_FAIL;
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | return _SBG_SEND_MT_SUCCESS;
|
---|
| 360 | }
|
---|
[575] | 361 |
|
---|
[647] | 362 | /**
|
---|
| 363 | * formatPhoneNumber
|
---|
| 364 | *
|
---|
| 365 | * @todo format phone number to prefix 0 or 84
|
---|
| 366 | * @param String $phoneNumber
|
---|
| 367 | * @param Integer $direction
|
---|
| 368 | * @return String
|
---|
| 369 | */
|
---|
[579] | 370 | public function formatPhoneNumber ($phoneNumber, $direction = 1) {
|
---|
[575] | 371 | $aryMatch = array();
|
---|
[579] | 372 | if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == 1) {
|
---|
[575] | 373 | $result = '0'. $aryMatch[2];
|
---|
| 374 | }
|
---|
[579] | 375 | else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == 1) {
|
---|
[575] | 376 | $result = $phoneNumber;
|
---|
| 377 | }
|
---|
[579] | 378 | else if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == -1) {
|
---|
| 379 | $result = $phoneNumber;
|
---|
| 380 | }
|
---|
| 381 | else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == -1) {
|
---|
| 382 | $result = '84'. $aryMatch[2];
|
---|
| 383 | }
|
---|
[575] | 384 |
|
---|
| 385 | return $result;
|
---|
| 386 | }
|
---|
[499] | 387 | } |
---|