[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);
|
---|
[620] | 14 | if ( ! defined('_SBG_MO_SYNTAX_ERR_MSG')) define('_SBG_MO_SYNTAX_ERR_MSG', 'SBG Online khong co dich vu nay, ban vui long kiem tra lai. Tran trong.');
|
---|
[499] | 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 |
|
---|
[599] | 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.');
|
---|
[613] | 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');
|
---|
[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})$/'),
|
---|
[615] | 51 | _SBG_MO_PHONENUM_CHANGE => array('pattern' => '/^(SBG[[:blank:]])(DDT)([[:blank:]][0-9]{10,11})([[:blank:]][a-zA-Z0-9]{1,})$/'),
|
---|
[499] | 52 | _SBG_MO_PASSWORD_RECOVERY => array('pattern' => '/^(SBG[[:blank:]])(MK)$/'),
|
---|
[609] | 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 |
|
---|
[615] | 60 | private $_aryServiceName = array('DK','DDT','VIP','NAP');
|
---|
[583] | 61 |
|
---|
[499] | 62 | public function __construct(){
|
---|
| 63 | parent::__construct();
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[579] | 66 | public function messageAnalys ($message)
|
---|
[499] | 67 | {
|
---|
[579] | 68 | $aryMatched = array();
|
---|
| 69 | $aryContent = array();
|
---|
[499] | 70 | $result = false;
|
---|
[579] | 71 |
|
---|
| 72 | foreach ($this->_arySmsMO as $key => $pattern)
|
---|
[499] | 73 | {
|
---|
[615] | 74 | $result = preg_match_all ($pattern['pattern'], strtoupper(trim($message)), $aryMatched);
|
---|
[499] | 75 | if ((bool)$result) break;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[583] | 78 | $key = (bool)$result ? $key:_SBG_MO_SYNTAX_ERR;
|
---|
| 79 |
|
---|
[579] | 80 | if (count ($aryMatched) > 0) {
|
---|
| 81 | foreach ($aryMatched as $k => $val) {
|
---|
| 82 | if ($k == 0) continue;
|
---|
[615] | 83 | if (count($val) == 0) {
|
---|
| 84 | $key = _SBG_MO_SYNTAX_ERR;
|
---|
| 85 | break;
|
---|
| 86 | }
|
---|
[579] | 87 | $aryContent[] = trim($val[0]);
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[583] | 91 | if ((bool)$result == FALSE) {
|
---|
| 92 | $aryContent = array();
|
---|
[615] | 93 | foreach(explode(' ',strtoupper(trim($message))) as $k => $val) {
|
---|
[583] | 94 | $aryContent[] = $val;
|
---|
| 95 | }
|
---|
[615] | 96 |
|
---|
| 97 | $serviceName = $aryContent[1];
|
---|
| 98 | if (in_array($serviceName, $this->_aryServiceName)) {
|
---|
| 99 | if ($serviceName == 'DK' && count($aryContent) == 3) {
|
---|
| 100 | $key = _SBG_MO_REGISTER_FOR;
|
---|
| 101 | }
|
---|
| 102 | else if ($serviceName == 'DDT' && count($aryContent) == 4){
|
---|
| 103 | $key = _SBG_MO_PHONENUM_CHANGE;
|
---|
| 104 | }
|
---|
| 105 | else if ($serviceName == 'VIP' && count($aryContent) == 3){
|
---|
| 106 | $key = _SBG_MO_VIP_REGISTER;
|
---|
| 107 | }else if ($serviceName == 'NAP' && count($aryContent) == 3){
|
---|
| 108 | $key = _SBG_MO_PAY_TO_ACCOUNT;
|
---|
| 109 | }else if ($serviceName == 'NAP' && count($aryContent) == 4){
|
---|
| 110 | $key = _SBG_MO_PAY_TO_ACCOUNT_FOR;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | foreach ($aryContent as $k => $val) {
|
---|
| 114 | $aryContent[$k] = trim($val);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | $result = TRUE;
|
---|
| 118 | }
|
---|
[583] | 119 | }
|
---|
| 120 |
|
---|
[615] | 121 | if ($key == _SBG_MO_PHONENUM_CHANGE) {
|
---|
| 122 | $upcasePass = $aryContent[3];
|
---|
[579] | 123 | $password = substr($message, -strlen($upcasePass));
|
---|
| 124 | $aryContent[$index] = $password;
|
---|
| 125 | }
|
---|
[615] | 126 |
|
---|
[579] | 127 | $aryResult = (bool)$result ? array('case' => $key, 'content' => $aryContent):array('case' => $key);
|
---|
[499] | 128 | return $aryResult;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | public function processMORequest ($sentNumber,$message)
|
---|
| 132 | {
|
---|
[513] | 133 | $debugMsg = $message."\n";
|
---|
| 134 |
|
---|
[575] | 135 | $sentNumber = $this->formatPhoneNumber($sentNumber);
|
---|
[499] | 136 |
|
---|
| 137 | $smsReturn = '';
|
---|
| 138 | $aryMOAnalys = $this->messageAnalys($message);
|
---|
| 139 | $case = $aryMOAnalys['case'];
|
---|
| 140 | $aryContents = isset($aryMOAnalys['content']) ? $aryMOAnalys['content']: null;
|
---|
| 141 | $this->load->model('frontend/user_model', 'objUserModel');
|
---|
[513] | 142 | $debugMsg .= $case;
|
---|
[615] | 143 |
|
---|
[499] | 144 | switch ($case) {
|
---|
| 145 | case _SBG_MO_REGISTER:
|
---|
| 146 | case _SBG_MO_REGISTER_FOR:
|
---|
[583] | 147 | if ($case == _SBG_MO_REGISTER_FOR) {
|
---|
| 148 | if (!preg_match('/^([0-9]{10,11}$)$/', $aryContents[2])) {
|
---|
[599] | 149 | $smsReturn = '0|So dien thoai khach hang khong hop le. Vui long kiem tra lai.';
|
---|
[583] | 150 | break;
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[575] | 154 | $userName = isset($aryContents[2]) ? $this->formatPhoneNumber($aryContents[2]) : $sentNumber;
|
---|
[528] | 155 | $collaborator = isset($aryContents[2]) ? $sentNumber:null;
|
---|
[579] | 156 | $collaboratorMsg = '';
|
---|
[615] | 157 |
|
---|
[579] | 158 | $sms = $this->objUserModel->register($userName, $collaborator, $collaboratorMsg);
|
---|
[528] | 159 | if ($case == _SBG_MO_REGISTER_FOR) {
|
---|
[579] | 160 | $smsReturn = $collaboratorMsg;
|
---|
[528] | 161 | $arySMS = explode ('|', $sms);
|
---|
[579] | 162 | if ((int)$arySMS[0] == 1 )
|
---|
| 163 | $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $arySMS[1]);
|
---|
[528] | 164 | }
|
---|
| 165 | else {
|
---|
| 166 | $smsReturn = $sms;
|
---|
| 167 | }
|
---|
[499] | 168 | break;
|
---|
| 169 | case _SBG_MO_PHONENUM_CHANGE:
|
---|
[603] | 170 | if (!preg_match('/^(09\d{8}|01\d{9})$/', $aryContents[2])) {
|
---|
[599] | 171 | $smsReturn = '0|So dien thoai khach hang khong hop le. Vui long kiem tra lai.';
|
---|
[583] | 172 | break;
|
---|
| 173 | }
|
---|
[615] | 174 |
|
---|
[575] | 175 | $oldPhoneNumber = $this->formatPhoneNumber($aryContents[2]);
|
---|
[499] | 176 | $password = $aryContents[3];
|
---|
| 177 | $smsReturn = $this->objUserModel->changeProfile($sentNumber, $oldPhoneNumber, $password);
|
---|
[615] | 178 |
|
---|
| 179 | $arySMS = explode('|', $smsReturn);
|
---|
| 180 | $changeResult = (int)$arySMS[0];
|
---|
| 181 |
|
---|
[599] | 182 | $sms = 'Ban da doi thanh cong so dien thoai tren SBG Online sang so dien thoai ' .$sentNumber. '. Tran trong.';
|
---|
[615] | 183 | $sendMT = $changeResult == 1 ? $this->sendMT($this->formatPhoneNumber($oldPhoneNumber, -1), $sms) : '';
|
---|
[499] | 184 | break;
|
---|
| 185 | case _SBG_MO_PASSWORD_RECOVERY:
|
---|
[615] | 186 | /* case _SBG_MO_PASSWORD_CHANGE: */
|
---|
| 187 | /* $password = isset($aryContents[2]) ? $aryContents[2] : null; */
|
---|
| 188 | $smsReturn = $this->objUserModel->changePassword($sentNumber/* , $password */);
|
---|
[499] | 189 | break;
|
---|
| 190 | case _SBG_MO_VIP_REGISTER:
|
---|
| 191 | $p_code = $aryContents[2];
|
---|
| 192 | $smsReturn = $this->objUserModel->registerVip($sentNumber, $p_code);
|
---|
[633] | 193 | $source = 'sms';
|
---|
| 194 | $this->objUserModel->insertRegisterVipLog($source, $p_code);
|
---|
[499] | 195 | break;
|
---|
| 196 | case _SBG_MO_PAY_TO_ACCOUNT:
|
---|
| 197 | case _SBG_MO_PAY_TO_ACCOUNT_FOR:
|
---|
[575] | 198 | $userName = isset($aryContents[3]) ? $this->formatPhoneNumber($aryContents[3]) : $sentNumber;
|
---|
[603] | 199 |
|
---|
[612] | 200 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR && !preg_match('/^(09\d{8}|01\d{9})$/', $userName)) {
|
---|
[603] | 201 | $smsReturn = '0|So dien thoai khach hang khong hop le. Vui long kiem tra lai.';
|
---|
| 202 | break;
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[499] | 205 | $amount = $aryContents[2];
|
---|
[615] | 206 | if (!preg_match('/^[0-9]{3,}$/', $amount)) {
|
---|
[616] | 207 | $smsReturn = '0|So tien nap khong hop le. Vui long kiem tra lai.';
|
---|
[615] | 208 | break;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
[598] | 211 | $result =$this->chargeRootAccountProcess($sentNumber, $amount, $sentNumber.' paid for SBG');
|
---|
| 212 |
|
---|
| 213 | if ($result == _SBG_CHARGING_SUCCESS) {
|
---|
[499] | 214 | $smsReturn = $this->objUserModel->rechargeAccount($userName, $amount);
|
---|
[598] | 215 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR) {
|
---|
[579] | 216 | $arySmsReturn = explode ('|', $smsReturn);
|
---|
[599] | 217 | $smsMT = 'Ban da nap thanh cong ' .$amount . 'VND vao tai khoan ' .$username. ' tren SBG Online tu thue bao ' .$sentNumber. '. Tran trong.';
|
---|
[579] | 218 | $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $smsMT);
|
---|
[556] | 219 | }
|
---|
[598] | 220 | //write to paid log
|
---|
| 221 | $paidTime = date('Y-m-d H:i:s');
|
---|
| 222 | $this->objUserModel->insertPaidlog($sentNumber, $userName, _SBG_PAIDTYPE_SMS, $amount, $paidTime);
|
---|
[499] | 223 | }
|
---|
[598] | 224 | else if ($result == _SBG_CHARGING_FAIL_NOT_ENOUGH) {
|
---|
[599] | 225 | //$aryPatterns = array ('/:sendid:/', '/:amount:/', '/:username:/');
|
---|
| 226 | //$smsReturn = preg_replace($aryPatterns, array($sentNumber, $amount, $userName), _SBG_CHARGING_FAIL_NOT_ENOUGH_MSG);
|
---|
| 227 | $aryPatterns = array ('/:amount:/', '/:username:/');
|
---|
| 228 | $smsReturn = preg_replace($aryPatterns, array($amount, $userName), _SBG_CHARGING_FAIL_NOT_ENOUGH_MSG);
|
---|
[598] | 229 | $smsReturn = '0|'.$smsReturn;
|
---|
| 230 | }
|
---|
| 231 | else if ($result == _SBG_CHARGING_FAIL_MORETHAN_LIMIT) {
|
---|
| 232 | $aryPatterns = array ('/:sendid:/');
|
---|
| 233 | $smsReturn = preg_replace($aryPatterns, array($sentNumber), _SBG_CHARGING_FAIL_MORETHAN_LIMIT_MSG);
|
---|
| 234 | $smsReturn = '0|'.$smsReturn;
|
---|
[612] | 235 | }else if ($result == _SBG_CHARGING_FAIL_NOT_VIETTEL || $result == _SBG_CHARGING_NUMBER_NOT_EXISTED || $result == _SBG_CHARGING_NUMBER_NOT_AVAILABLE) {
|
---|
[598] | 236 | $smsReturn = '0|'._SBG_CHARGING_FAIL_NOT_VIETTEL_MSG;
|
---|
| 237 | }
|
---|
| 238 | else {
|
---|
| 239 | $smsReturn = '0|Loi, khong thanh toan duoc tu tai khoan goc';
|
---|
| 240 | }
|
---|
[499] | 241 | break;
|
---|
[529] | 242 | case _SBG_MO_UNSUBSCRIBE_SERVICE:
|
---|
[499] | 243 | case _SBG_MO_SYNTAX_ERR:
|
---|
| 244 | default:
|
---|
| 245 | $smsReturn = '0|'._SBG_MO_SYNTAX_ERR_MSG;
|
---|
| 246 | break;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
[579] | 249 | return $smsReturn.'|'.$case;
|
---|
[499] | 250 | }
|
---|
| 251 |
|
---|
[506] | 252 | public function cardPaidProcess ($aryCardInfo, &$aryTopupResult = array())
|
---|
[499] | 253 | {
|
---|
| 254 | $url = $this->config->item('topup_service_url');
|
---|
| 255 | $action = 'http://tempuri.org/ITopupService/TopUp';
|
---|
| 256 | $xml = $this->load->view('topup', $aryCardInfo, true);
|
---|
| 257 |
|
---|
| 258 | $client = new nusoap_client($url);
|
---|
| 259 | $client->useHTTPPersistentConnection();
|
---|
| 260 | $client->soap_defencoding = 'UTF-8';
|
---|
| 261 | $client->operation = $action;
|
---|
| 262 |
|
---|
[519] | 263 | $result = $client->send($xml, $action);
|
---|
[499] | 264 |
|
---|
| 265 | if ($client->fault) {
|
---|
| 266 | return _SBG_CARD_PAY_FAIL;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
[528] | 269 | $keys = array_keys($result);
|
---|
[499] | 270 |
|
---|
[528] | 271 | $aryTopupResult = $result[$keys[0]];
|
---|
[632] | 272 |
|
---|
| 273 | $debugMsg = 'Logged time: '. date('Y-m-d H:i:s') ."\n";
|
---|
| 274 | $debugMsg .= 'Send:'."\n" .$xml ."\n\n";
|
---|
| 275 | $debugMsg .= 'Result:'."\n". var_export($result, TRUE);
|
---|
| 276 | write_file('./log/topup_log', $debugMsg);
|
---|
| 277 |
|
---|
[499] | 278 | if ($aryTopupResult['Success'] == 'false') {
|
---|
| 279 | return _SBG_CARD_PAY_FAIL;
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | return _SBG_CARD_PAY_SUCCESS;
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | public function chargeRootAccountProcess ($sentID, $amount = 0, $contents = '')
|
---|
| 286 | {
|
---|
| 287 | $url = $this->config->item('charging_service_url');
|
---|
| 288 | $username = $this->config->item('charging_username');
|
---|
| 289 | $password = $this->config->item('charging_password');
|
---|
| 290 | $action = 'http://tempuri.org/processCharging';
|
---|
| 291 |
|
---|
| 292 | $aryParams = array(
|
---|
| 293 | 'user' => $username,
|
---|
| 294 | 'pass' => $password,
|
---|
| 295 | 'MSISDN' => $sentID,
|
---|
| 296 | 'Charging' => $amount,
|
---|
| 297 | 'Contents' => $contents
|
---|
| 298 | );
|
---|
| 299 |
|
---|
| 300 | $xml = $this->load->view('charging', $aryParams, true);
|
---|
| 301 | $client = new nusoap_client($url);
|
---|
| 302 | $client->useHTTPPersistentConnection();
|
---|
| 303 | $client->soap_defencoding = 'UTF-8';
|
---|
| 304 | $client->operation = $action;
|
---|
| 305 | $result = $client->send($xml, $action);
|
---|
[629] | 306 |
|
---|
[499] | 307 | if ($client->fault) {
|
---|
| 308 | return _SBG_CHARGING_FAIL;
|
---|
| 309 | }
|
---|
| 310 |
|
---|
[598] | 311 | $aryErrs = array (_SBG_CHARGING_FAIL_NOT_ENOUGH,
|
---|
| 312 | _SBG_CHARGING_FAIL_NOT_VIETTEL,
|
---|
| 313 | _SBG_CHARGING_FAIL_MORETHAN_LIMIT,
|
---|
| 314 | _SBG_CHARGING_NUMBER_NOT_EXISTED,
|
---|
| 315 | _SBG_CHARGING_NUMBER_NOT_AVAILABLE,
|
---|
| 316 | _SBG_CHARGING_NUMBER_CHANGED_OWNER,
|
---|
| 317 | _SBG_CHARGING_GENERAL_ERROR,
|
---|
| 318 | _SBG_CHARGING_NUMBER_NOT_REGISTED
|
---|
| 319 | );
|
---|
[499] | 320 |
|
---|
[598] | 321 | if (in_array((int)$result['processChargingResult'], $aryErrs))
|
---|
| 322 | return (int)$result['processChargingResult'];
|
---|
| 323 |
|
---|
[499] | 324 | return _SBG_CHARGING_SUCCESS;
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | public function sendMT ($receiverID, $message)
|
---|
| 328 | {
|
---|
| 329 | $aryMatch = array();
|
---|
[575] | 330 |
|
---|
[499] | 331 | if (preg_match('/^(0)([0-9]{9,10})$/', $receiverID, $aryMatch) == 1) {
|
---|
| 332 | $receiverID = '84'. $aryMatch[2];
|
---|
| 333 | }
|
---|
| 334 |
|
---|
| 335 | $username = $this->config->item('mt_username');
|
---|
| 336 | $password = $this->config->item('mt_password');
|
---|
| 337 | $action = 'http://tempuri.org/InsertMT';
|
---|
| 338 |
|
---|
| 339 | $aryParams = array(
|
---|
| 340 | 'User' => $username,
|
---|
| 341 | 'Pass' => $password,
|
---|
| 342 | 'CPCode' => _SBG_MT_CP_CODE,
|
---|
| 343 | 'UserID' => _SBG_MT_SEND_NUMBER,
|
---|
| 344 | 'RequestID' => '4',
|
---|
| 345 | 'ReceiverID' => $receiverID,
|
---|
| 346 | 'ServiceID' => _SBG_SERVICE_SERVICEID,
|
---|
| 347 | 'CommandCode' => _SBG_SERVICE_COMMAND_CODE,
|
---|
| 348 | 'ContentType' => '0',
|
---|
| 349 | 'Info' => $message
|
---|
| 350 | );
|
---|
| 351 |
|
---|
| 352 | $xml = $this->load->view('mt', $aryParams, true);
|
---|
[513] | 353 | $url = $this->config->item('mt_service_url');
|
---|
[499] | 354 | $client = new nusoap_client($url);
|
---|
| 355 | $client->useHTTPPersistentConnection();
|
---|
| 356 | $client->soap_defencoding = 'UTF-8';
|
---|
| 357 | $client->operation = $action;
|
---|
| 358 | $result = $client->send($xml, $action);
|
---|
| 359 |
|
---|
| 360 | if ($client->fault || (int)$result['InsertMTResult'] != 1) {
|
---|
| 361 | return _SBG_SEND_MT_FAIL;
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 | return _SBG_SEND_MT_SUCCESS;
|
---|
| 365 | }
|
---|
[575] | 366 |
|
---|
[579] | 367 | public function formatPhoneNumber ($phoneNumber, $direction = 1) {
|
---|
[575] | 368 | $aryMatch = array();
|
---|
[579] | 369 | if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == 1) {
|
---|
[575] | 370 | $result = '0'. $aryMatch[2];
|
---|
| 371 | }
|
---|
[579] | 372 | else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == 1) {
|
---|
[575] | 373 | $result = $phoneNumber;
|
---|
| 374 | }
|
---|
[579] | 375 | else if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == -1) {
|
---|
| 376 | $result = $phoneNumber;
|
---|
| 377 | }
|
---|
| 378 | else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == -1) {
|
---|
| 379 | $result = '84'. $aryMatch[2];
|
---|
| 380 | }
|
---|
[575] | 381 |
|
---|
| 382 | return $result;
|
---|
| 383 | }
|
---|
[499] | 384 | } |
---|