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