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