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