[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 |
|
---|
[685] | 38 | if ( ! defined('_SBG_GET_COLLABORATOR_FAIL')) define('_SBG_GET_COLLABORATOR_FAIL', -1);
|
---|
| 39 |
|
---|
[499] | 40 | Class Services_model extends CI_Model
|
---|
| 41 | {
|
---|
| 42 | private $_arySmsMO = array(
|
---|
[647] | 43 | _SBG_MO_REGISTER => array('pattern' => '/^(SBG)([[:blank:]])(DK)$/'),
|
---|
| 44 | _SBG_MO_REGISTER_FOR => array('pattern' => '/^(SBG)([[:blank:]])(DK)([[:blank:]])([0-9]{10,11})$/'),
|
---|
[707] | 45 | //_SBG_MO_PHONENUM_CHANGE => array('pattern' => '/^(SBG)([[:blank:]])(DDT)([[:blank:]])([0-9]{10,11})([[:blank:]])([a-zA-Z0-9]{1,})$/'),
|
---|
[647] | 46 | _SBG_MO_PASSWORD_RECOVERY => array('pattern' => '/^(SBG)([[:blank:]])(MK)$/'),
|
---|
| 47 | _SBG_MO_VIP_REGISTER => array('pattern' => '/^(SBG)([[:blank:]])(VIP)([[:blank:]])([a-zA-Z0-9]{1,})$/'),
|
---|
| 48 | _SBG_MO_PAY_TO_ACCOUNT => array('pattern' => '/^(SBG)([[:blank:]])(NAP)([[:blank:]])([0-9]{3,})$/'),
|
---|
| 49 | _SBG_MO_PAY_TO_ACCOUNT_FOR => array('pattern' => '/^(SBG)([[:blank:]])(NAP)([[:blank:]])([0-9]{3,})([[:blank:]])([0-9]{10,11})$/'),
|
---|
| 50 | _SBG_MO_SUPPOR_SERVICE => array('pattern' => '/^(SBG)([[:blank:]])(HD)$/'),
|
---|
| 51 | _SBG_MO_UNSUBSCRIBE_SERVICE => array('pattern' => '/^(SBG)([[:blank:]])(HUY)$/')
|
---|
| 52 | );
|
---|
[499] | 53 |
|
---|
| 54 | public function __construct(){
|
---|
| 55 | parent::__construct();
|
---|
[636] | 56 | $this->load->helper('language');
|
---|
| 57 | $this->lang->load('messages', 'message');
|
---|
[499] | 58 | }
|
---|
| 59 |
|
---|
[647] | 60 | /**
|
---|
| 61 | * messageAnalys
|
---|
| 62 | *
|
---|
| 63 | * @todo Analysis content of incoming message
|
---|
| 64 | *
|
---|
| 65 | * @param String $message - coming SMS
|
---|
| 66 | * @return multitype:Ambigous <string, multitype> multitype:multitype
|
---|
| 67 | */
|
---|
[579] | 68 | public function messageAnalys ($message)
|
---|
[499] | 69 | {
|
---|
[579] | 70 | $aryMatched = array();
|
---|
| 71 | $aryContent = array();
|
---|
[647] | 72 | $result = FALSE;
|
---|
[579] | 73 |
|
---|
[647] | 74 | foreach ($this->_arySmsMO as $case => $pattern)
|
---|
[499] | 75 | {
|
---|
[647] | 76 | $result = preg_match($pattern['pattern'], strtoupper(trim($message)));
|
---|
| 77 | if ((bool)$result) {
|
---|
| 78 | $aryMatched = explode(' ', trim($message));
|
---|
| 79 | break;
|
---|
| 80 | }
|
---|
[499] | 81 | }
|
---|
| 82 |
|
---|
[647] | 83 | $case = (bool)$result ? $case:_SBG_MO_SYNTAX_ERR;
|
---|
[583] | 84 |
|
---|
[647] | 85 | foreach($aryMatched as $k => $val) {
|
---|
| 86 | if ($k > 1) $aryContent[] = $val;
|
---|
[579] | 87 | }
|
---|
[583] | 88 |
|
---|
[707] | 89 | return array('case' => $case, 'content' => $aryContent);
|
---|
[499] | 90 | }
|
---|
| 91 |
|
---|
[647] | 92 | /**
|
---|
| 93 | * processMORequest
|
---|
| 94 | *
|
---|
| 95 | * @todo process action analysed from messageAnalys
|
---|
| 96 | *
|
---|
| 97 | * @param unknown $sentNumber
|
---|
| 98 | * @param unknown $message
|
---|
| 99 | * @return string
|
---|
| 100 | */
|
---|
| 101 | public function processMORequest ($sentNumber, $message)
|
---|
[499] | 102 | {
|
---|
[513] | 103 | $debugMsg = $message."\n";
|
---|
| 104 |
|
---|
[575] | 105 | $sentNumber = $this->formatPhoneNumber($sentNumber);
|
---|
[499] | 106 |
|
---|
| 107 | $smsReturn = '';
|
---|
| 108 | $aryMOAnalys = $this->messageAnalys($message);
|
---|
| 109 | $case = $aryMOAnalys['case'];
|
---|
| 110 | $aryContents = isset($aryMOAnalys['content']) ? $aryMOAnalys['content']: null;
|
---|
| 111 | $this->load->model('frontend/user_model', 'objUserModel');
|
---|
[513] | 112 | $debugMsg .= $case;
|
---|
[615] | 113 |
|
---|
[499] | 114 | switch ($case) {
|
---|
| 115 | case _SBG_MO_REGISTER:
|
---|
| 116 | case _SBG_MO_REGISTER_FOR:
|
---|
[583] | 117 | if ($case == _SBG_MO_REGISTER_FOR) {
|
---|
[647] | 118 | if (!preg_match('/^([0-9]{10,11}$)$/', $aryContents[0])) {
|
---|
[636] | 119 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_PHONENUM_WRONG_FORMAT_MSG');
|
---|
[583] | 120 | break;
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[647] | 124 | $userName = isset($aryContents[0]) ? $this->formatPhoneNumber($aryContents[0]) : $sentNumber;
|
---|
| 125 | $collaborator = isset($aryContents[0]) ? $sentNumber:null;
|
---|
[579] | 126 | $collaboratorMsg = '';
|
---|
[615] | 127 |
|
---|
[579] | 128 | $sms = $this->objUserModel->register($userName, $collaborator, $collaboratorMsg);
|
---|
[707] | 129 |
|
---|
[528] | 130 | if ($case == _SBG_MO_REGISTER_FOR) {
|
---|
[579] | 131 | $smsReturn = $collaboratorMsg;
|
---|
[528] | 132 | $arySMS = explode ('|', $sms);
|
---|
[579] | 133 | if ((int)$arySMS[0] == 1 )
|
---|
| 134 | $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $arySMS[1]);
|
---|
[528] | 135 | }
|
---|
| 136 | else {
|
---|
| 137 | $smsReturn = $sms;
|
---|
| 138 | }
|
---|
[707] | 139 |
|
---|
[499] | 140 | break;
|
---|
| 141 | case _SBG_MO_PHONENUM_CHANGE:
|
---|
[647] | 142 | if (!preg_match('/^(09\d{8}|01\d{9})$/', $aryContents[0])) {
|
---|
[636] | 143 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_PHONENUM_WRONG_FORMAT_MSG');
|
---|
[583] | 144 | break;
|
---|
| 145 | }
|
---|
[615] | 146 |
|
---|
[647] | 147 | $oldPhoneNumber = $this->formatPhoneNumber($aryContents[0]);
|
---|
| 148 | $password = $aryContents[1];
|
---|
[499] | 149 | $smsReturn = $this->objUserModel->changeProfile($sentNumber, $oldPhoneNumber, $password);
|
---|
[615] | 150 |
|
---|
| 151 | $arySMS = explode('|', $smsReturn);
|
---|
| 152 | $changeResult = (int)$arySMS[0];
|
---|
| 153 |
|
---|
[636] | 154 | $aryPatterns = array('/:sentNumber:/');
|
---|
| 155 | $sms = preg_replace($aryPatterns, array($sentNumber), lang('_SBG_MO_USER_OLD_PHONENUM_CHANGE_SUCCESS_MSG'));
|
---|
[615] | 156 | $sendMT = $changeResult == 1 ? $this->sendMT($this->formatPhoneNumber($oldPhoneNumber, -1), $sms) : '';
|
---|
[499] | 157 | break;
|
---|
| 158 | case _SBG_MO_PASSWORD_RECOVERY:
|
---|
[647] | 159 | $smsReturn = $this->objUserModel->changePassword($sentNumber);
|
---|
| 160 | break;
|
---|
[499] | 161 | case _SBG_MO_VIP_REGISTER:
|
---|
[707] | 162 | $packageData = array();
|
---|
[647] | 163 | $p_code = $aryContents[0];
|
---|
[707] | 164 | $smsReturn = $this->objUserModel->registerVip($sentNumber, $p_code, $packageData);
|
---|
| 165 |
|
---|
| 166 | $arySmsReturn = explode('|', $smsReturn);
|
---|
| 167 | $result = $arySmsReturn[0];
|
---|
| 168 |
|
---|
| 169 | if (trim($arySmsReturn[1]) == trim(lang('_SBG_MO_USER_REGISTER_VIP_FAIL_NOT_ENOUGH_MSG'))) {
|
---|
| 170 |
|
---|
| 171 | $amount = $packageData ['p_price'];
|
---|
| 172 | $result = $this->chargeRootAccountProcess($sentNumber, $amount, $sentNumber.' paid for SBG');
|
---|
| 173 |
|
---|
| 174 | if ($result == _SBG_CHARGING_SUCCESS) {
|
---|
| 175 | $this->objUserModel->rechargeAccount($sentNumber, $amount);
|
---|
| 176 | $smsReturn = $this->objUserModel->registerVip($sentNumber, $p_code, $packageData);
|
---|
| 177 |
|
---|
| 178 | $paidTime = date('Y-m-d H:i:s');
|
---|
| 179 | $this->objUserModel->insertPaidlog($sentNumber, $sentNumber, _SBG_PAIDTYPE_SMS, $amount, $paidTime);
|
---|
| 180 | $result = 1;
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | if ((int)$result == 1) $this->objUserModel->insertRegisterVipLog($sentNumber, $p_code, true);
|
---|
[499] | 185 | break;
|
---|
[707] | 186 |
|
---|
[499] | 187 | case _SBG_MO_PAY_TO_ACCOUNT:
|
---|
| 188 | case _SBG_MO_PAY_TO_ACCOUNT_FOR:
|
---|
[707] | 189 |
|
---|
[647] | 190 | $userName = isset($aryContents[1]) ? $this->formatPhoneNumber($aryContents[1]) : $sentNumber;
|
---|
[603] | 191 |
|
---|
[612] | 192 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR && !preg_match('/^(09\d{8}|01\d{9})$/', $userName)) {
|
---|
[636] | 193 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_PHONENUM_WRONG_FORMAT_MSG');
|
---|
[603] | 194 | break;
|
---|
| 195 | }
|
---|
| 196 |
|
---|
[647] | 197 | $amount = $aryContents[0];
|
---|
[615] | 198 | if (!preg_match('/^[0-9]{3,}$/', $amount)) {
|
---|
[636] | 199 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_AMOUNT_WRONG_FORMAT_MSG');
|
---|
[615] | 200 | break;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[598] | 203 | $result =$this->chargeRootAccountProcess($sentNumber, $amount, $sentNumber.' paid for SBG');
|
---|
| 204 |
|
---|
| 205 | if ($result == _SBG_CHARGING_SUCCESS) {
|
---|
[499] | 206 | $smsReturn = $this->objUserModel->rechargeAccount($userName, $amount);
|
---|
[598] | 207 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR) {
|
---|
[579] | 208 | $arySmsReturn = explode ('|', $smsReturn);
|
---|
[653] | 209 | $aryPatterns = array('/:amount:/', '/:sentNumber:/');
|
---|
| 210 | $smsMT = preg_replace($aryPatterns, array($amount, $sentNumber), lang('_SBG_MO_PAY_TO_ACCOUNT_FOR_MSG'));
|
---|
[579] | 211 | $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $smsMT);
|
---|
[707] | 212 | $smsReturn = $arySmsReturn[0].'|'.preg_replace(array('/:amount:/','/:username:/'), array($amount, $userName), lang('_SBG_MO_PAY_TO_ACCOUNT_FOR_OTHER_SUCCESS_MSG'));
|
---|
[556] | 213 | }
|
---|
[598] | 214 | //write to paid log
|
---|
| 215 | $paidTime = date('Y-m-d H:i:s');
|
---|
| 216 | $this->objUserModel->insertPaidlog($sentNumber, $userName, _SBG_PAIDTYPE_SMS, $amount, $paidTime);
|
---|
[499] | 217 | }
|
---|
[598] | 218 | else if ($result == _SBG_CHARGING_FAIL_NOT_ENOUGH) {
|
---|
[653] | 219 | $aryPatterns = array ('/:amount:/');
|
---|
| 220 | $smsReturn = preg_replace($aryPatterns, array($amount), lang('_SBG_MO_CHARGING_FAIL_NOT_ENOUGH_MSG'));
|
---|
| 221 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR) {
|
---|
| 222 | $aryPatterns = array ('/:amount:/', '/:username:/');
|
---|
| 223 | $smsReturn = preg_replace($aryPatterns, array($amount, $userName), lang('_SBG_MO_CHARGING_FAIL_NOT_ENOUGH_FOR_MSG'));
|
---|
| 224 | }
|
---|
[636] | 225 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.$smsReturn;
|
---|
[598] | 226 | }
|
---|
| 227 | else if ($result == _SBG_CHARGING_FAIL_MORETHAN_LIMIT) {
|
---|
| 228 | $aryPatterns = array ('/:sendid:/');
|
---|
[636] | 229 | $smsReturn = preg_replace($aryPatterns, array($sentNumber), lang('_SBG_MO_CHARGING_FAIL_MORETHAN_LIMIT_MSG'));
|
---|
| 230 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.$smsReturn;
|
---|
[612] | 231 | }else if ($result == _SBG_CHARGING_FAIL_NOT_VIETTEL || $result == _SBG_CHARGING_NUMBER_NOT_EXISTED || $result == _SBG_CHARGING_NUMBER_NOT_AVAILABLE) {
|
---|
[636] | 232 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_CHARGING_FAIL_NOT_VIETTEL_MSG');
|
---|
[598] | 233 | }
|
---|
| 234 | else {
|
---|
[636] | 235 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_CHARGING_FAIL_MSG');
|
---|
[598] | 236 | }
|
---|
[499] | 237 | break;
|
---|
[647] | 238 | case _SBG_MO_SUPPOR_SERVICE:
|
---|
| 239 | $smsReturn = '1|'.lang('_SBG_MO_SUPPORT_MSG');
|
---|
| 240 | break;
|
---|
[529] | 241 | case _SBG_MO_UNSUBSCRIBE_SERVICE:
|
---|
[499] | 242 | case _SBG_MO_SYNTAX_ERR:
|
---|
| 243 | default:
|
---|
[636] | 244 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_SYNTAX_ERR_MSG');
|
---|
[499] | 245 | break;
|
---|
| 246 | }
|
---|
| 247 |
|
---|
[579] | 248 | return $smsReturn.'|'.$case;
|
---|
[499] | 249 | }
|
---|
| 250 |
|
---|
[647] | 251 |
|
---|
| 252 | /**
|
---|
| 253 | * cardPaidProcess
|
---|
| 254 | *
|
---|
| 255 | * @todo Call Topup webservice to check and lock prepaid-card
|
---|
| 256 | * @param Array $aryCardInfo
|
---|
| 257 | * @param Array $aryTopupResult
|
---|
| 258 | * @return string
|
---|
| 259 | */
|
---|
[506] | 260 | public function cardPaidProcess ($aryCardInfo, &$aryTopupResult = array())
|
---|
[499] | 261 | {
|
---|
| 262 | $url = $this->config->item('topup_service_url');
|
---|
| 263 | $action = 'http://tempuri.org/ITopupService/TopUp';
|
---|
| 264 | $xml = $this->load->view('topup', $aryCardInfo, true);
|
---|
| 265 |
|
---|
| 266 | $client = new nusoap_client($url);
|
---|
| 267 | $client->useHTTPPersistentConnection();
|
---|
| 268 | $client->soap_defencoding = 'UTF-8';
|
---|
| 269 | $client->operation = $action;
|
---|
| 270 |
|
---|
[519] | 271 | $result = $client->send($xml, $action);
|
---|
[499] | 272 |
|
---|
| 273 | if ($client->fault) {
|
---|
| 274 | return _SBG_CARD_PAY_FAIL;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[528] | 277 | $keys = array_keys($result);
|
---|
[499] | 278 |
|
---|
[528] | 279 | $aryTopupResult = $result[$keys[0]];
|
---|
[632] | 280 |
|
---|
| 281 | $debugMsg = 'Logged time: '. date('Y-m-d H:i:s') ."\n";
|
---|
| 282 | $debugMsg .= 'Send:'."\n" .$xml ."\n\n";
|
---|
| 283 | $debugMsg .= 'Result:'."\n". var_export($result, TRUE);
|
---|
| 284 | write_file('./log/topup_log', $debugMsg);
|
---|
| 285 |
|
---|
[499] | 286 | if ($aryTopupResult['Success'] == 'false') {
|
---|
| 287 | return _SBG_CARD_PAY_FAIL;
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | return _SBG_CARD_PAY_SUCCESS;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
[647] | 293 | /**
|
---|
| 294 | * chargeRootAccountProcess
|
---|
| 295 | *
|
---|
| 296 | * @todo Call charging webservice to charged fee from phone root account
|
---|
| 297 | * @param String $sentID
|
---|
| 298 | * @param Integer $amount
|
---|
| 299 | * @param String $contents
|
---|
| 300 | * @return string|number
|
---|
| 301 | */
|
---|
[499] | 302 | public function chargeRootAccountProcess ($sentID, $amount = 0, $contents = '')
|
---|
| 303 | {
|
---|
| 304 | $url = $this->config->item('charging_service_url');
|
---|
| 305 | $username = $this->config->item('charging_username');
|
---|
| 306 | $password = $this->config->item('charging_password');
|
---|
| 307 | $action = 'http://tempuri.org/processCharging';
|
---|
| 308 |
|
---|
| 309 | $aryParams = array(
|
---|
| 310 | 'user' => $username,
|
---|
| 311 | 'pass' => $password,
|
---|
| 312 | 'MSISDN' => $sentID,
|
---|
| 313 | 'Charging' => $amount,
|
---|
| 314 | 'Contents' => $contents
|
---|
| 315 | );
|
---|
[707] | 316 |
|
---|
[499] | 317 | $xml = $this->load->view('charging', $aryParams, true);
|
---|
| 318 | $client = new nusoap_client($url);
|
---|
| 319 | $client->useHTTPPersistentConnection();
|
---|
| 320 | $client->soap_defencoding = 'UTF-8';
|
---|
| 321 | $client->operation = $action;
|
---|
| 322 | $result = $client->send($xml, $action);
|
---|
[629] | 323 |
|
---|
[499] | 324 | if ($client->fault) {
|
---|
| 325 | return _SBG_CHARGING_FAIL;
|
---|
| 326 | }
|
---|
| 327 |
|
---|
[647] | 328 | $aryErrs = array ( _SBG_CHARGING_FAIL_NOT_ENOUGH,
|
---|
| 329 | _SBG_CHARGING_FAIL_NOT_VIETTEL,
|
---|
| 330 | _SBG_CHARGING_FAIL_MORETHAN_LIMIT,
|
---|
| 331 | _SBG_CHARGING_NUMBER_NOT_EXISTED,
|
---|
| 332 | _SBG_CHARGING_NUMBER_NOT_AVAILABLE,
|
---|
| 333 | _SBG_CHARGING_NUMBER_CHANGED_OWNER,
|
---|
| 334 | _SBG_CHARGING_GENERAL_ERROR,
|
---|
| 335 | _SBG_CHARGING_NUMBER_NOT_REGISTED);
|
---|
[499] | 336 |
|
---|
[598] | 337 | if (in_array((int)$result['processChargingResult'], $aryErrs))
|
---|
| 338 | return (int)$result['processChargingResult'];
|
---|
| 339 |
|
---|
[499] | 340 | return _SBG_CHARGING_SUCCESS;
|
---|
| 341 | }
|
---|
| 342 |
|
---|
[647] | 343 | /**
|
---|
| 344 | * sendMT
|
---|
| 345 | *
|
---|
| 346 | * @todo Calling MT webservice to send a SMS to a phone number
|
---|
| 347 | * @param String $receiverID
|
---|
| 348 | * @param String $message
|
---|
| 349 | * @return string
|
---|
| 350 | */
|
---|
[499] | 351 | public function sendMT ($receiverID, $message)
|
---|
| 352 | {
|
---|
| 353 | $aryMatch = array();
|
---|
[575] | 354 |
|
---|
[499] | 355 | if (preg_match('/^(0)([0-9]{9,10})$/', $receiverID, $aryMatch) == 1) {
|
---|
| 356 | $receiverID = '84'. $aryMatch[2];
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | $username = $this->config->item('mt_username');
|
---|
| 360 | $password = $this->config->item('mt_password');
|
---|
| 361 | $action = 'http://tempuri.org/InsertMT';
|
---|
| 362 |
|
---|
| 363 | $aryParams = array(
|
---|
| 364 | 'User' => $username,
|
---|
| 365 | 'Pass' => $password,
|
---|
| 366 | 'CPCode' => _SBG_MT_CP_CODE,
|
---|
| 367 | 'UserID' => _SBG_MT_SEND_NUMBER,
|
---|
| 368 | 'RequestID' => '4',
|
---|
| 369 | 'ReceiverID' => $receiverID,
|
---|
| 370 | 'ServiceID' => _SBG_SERVICE_SERVICEID,
|
---|
| 371 | 'CommandCode' => _SBG_SERVICE_COMMAND_CODE,
|
---|
| 372 | 'ContentType' => '0',
|
---|
| 373 | 'Info' => $message
|
---|
| 374 | );
|
---|
| 375 |
|
---|
| 376 | $xml = $this->load->view('mt', $aryParams, true);
|
---|
[513] | 377 | $url = $this->config->item('mt_service_url');
|
---|
[499] | 378 | $client = new nusoap_client($url);
|
---|
| 379 | $client->useHTTPPersistentConnection();
|
---|
| 380 | $client->soap_defencoding = 'UTF-8';
|
---|
| 381 | $client->operation = $action;
|
---|
| 382 | $result = $client->send($xml, $action);
|
---|
| 383 |
|
---|
| 384 | if ($client->fault || (int)$result['InsertMTResult'] != 1) {
|
---|
| 385 | return _SBG_SEND_MT_FAIL;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | return _SBG_SEND_MT_SUCCESS;
|
---|
| 389 | }
|
---|
[575] | 390 |
|
---|
[677] | 391 | public function getCollaborator ($type = 2, $page = 10, $displaypage = 1) {
|
---|
| 392 | $action = 'http://tempuri.org/InsertMT';
|
---|
| 393 | $url = $this->config->item('bccs_service_url');
|
---|
| 394 | $username = $this->config->item('bccs_username');
|
---|
| 395 | $password = $this->config->item('bccs_password');
|
---|
| 396 | $wscode = 'getListShopAndStaftInfo';
|
---|
| 397 | $aryParams = array(
|
---|
| 398 | 'user' => $username,
|
---|
| 399 | 'pass' => $password,
|
---|
| 400 | 'wscode' => $wscode,
|
---|
| 401 | 'type' => $type,
|
---|
| 402 | 'page' => $page,
|
---|
| 403 | 'displaypage' => $displaypage
|
---|
| 404 | );
|
---|
| 405 | $xml = $this->load->view('bscc', $aryParams, true);
|
---|
| 406 |
|
---|
| 407 | $client = new nusoap_client($url);
|
---|
| 408 | $client->useHTTPPersistentConnection();
|
---|
| 409 | $client->soap_defencoding = 'UTF-8';
|
---|
[685] | 410 | //$client->soap_defencoding = 'ISO-8859-1';
|
---|
| 411 |
|
---|
[677] | 412 | $client->operation = $action;
|
---|
| 413 | $result = $client->send($xml, $action);
|
---|
[685] | 414 | if ($client->fault || (int)$result['Result']['error'] != 0) {
|
---|
| 415 | return _SBG_GET_COLLABORATOR_FAIL;
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | return $result['Result']['original'];
|
---|
[677] | 419 | }
|
---|
| 420 |
|
---|
[647] | 421 | /**
|
---|
| 422 | * formatPhoneNumber
|
---|
| 423 | *
|
---|
| 424 | * @todo format phone number to prefix 0 or 84
|
---|
| 425 | * @param String $phoneNumber
|
---|
| 426 | * @param Integer $direction
|
---|
| 427 | * @return String
|
---|
| 428 | */
|
---|
[579] | 429 | public function formatPhoneNumber ($phoneNumber, $direction = 1) {
|
---|
[575] | 430 | $aryMatch = array();
|
---|
[579] | 431 | if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == 1) {
|
---|
[575] | 432 | $result = '0'. $aryMatch[2];
|
---|
| 433 | }
|
---|
[579] | 434 | else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == 1) {
|
---|
[575] | 435 | $result = $phoneNumber;
|
---|
| 436 | }
|
---|
[579] | 437 | else if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == -1) {
|
---|
| 438 | $result = $phoneNumber;
|
---|
| 439 | }
|
---|
| 440 | else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == -1) {
|
---|
| 441 | $result = '84'. $aryMatch[2];
|
---|
| 442 | }
|
---|
[575] | 443 |
|
---|
| 444 | return $result;
|
---|
| 445 | }
|
---|
[688] | 446 |
|
---|
| 447 |
|
---|
| 448 | public function syncCollaborator($data){
|
---|
| 449 | if ($data){
|
---|
| 450 | $sql = $this->db->insert_string('tblcollaborator', $data) . ' ON DUPLICATE KEY UPDATE address = "'.$data['address'].'",
|
---|
| 451 | code = "'.$data['code'].'",
|
---|
| 452 | district = "'.$data['district'].'",
|
---|
| 453 | email = "'.$data['email'].'",
|
---|
| 454 | full_name = "'.$data['full_name'].'",
|
---|
| 455 | cellphone = "'.$data['cellphone'].'",
|
---|
| 456 | precinct = "'.$data['precinct'].'",
|
---|
| 457 | province = "'.$data['province'].'",
|
---|
| 458 | updated_time = "'.$data['updated_time'].'"';
|
---|
| 459 | $this->db->query($sql);
|
---|
| 460 | $id = $this->db->insert_id();
|
---|
| 461 | if ($this->db->affected_rows()){
|
---|
[689] | 462 | //echo "Collaborator ID: ".$id.". Sync Success !<br/>";
|
---|
| 463 | $logMsg = date('Y-m-d H:i:s') . " Collaborator ID: ".$id.". Sync Success !\n";
|
---|
| 464 | write_file('./log/sync_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
|
---|
[688] | 465 | }else{
|
---|
[689] | 466 | //echo "Collaborator ID: ".$id.". Sync fail!. Sql = ".$sql."<br/>";
|
---|
| 467 | $logMsg = date('Y-m-d H:i:s') . " Collaborator ID: ".$id.". Sync fail!. Sql = ".$sql."\n";
|
---|
| 468 | write_file('./log/sync_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
|
---|
[688] | 469 | }
|
---|
| 470 | }else {
|
---|
[689] | 471 | $logMsg = date('Y-m-d H:i:s') . " Data is null \n";
|
---|
| 472 | write_file('./log/sync_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
|
---|
[688] | 473 | }
|
---|
| 474 | }
|
---|
[499] | 475 | } |
---|