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