[499] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
| 2 |
|
---|
| 3 | if ( ! defined('_SBG_MO_REGISTER')) define('_SBG_MO_REGISTER', 0);
|
---|
| 4 | if ( ! defined('_SBG_MO_REGISTER_FOR')) define('_SBG_MO_REGISTER_FOR', 1);
|
---|
| 5 | if ( ! defined('_SBG_MO_PHONENUM_CHANGE')) define('_SBG_MO_PHONENUM_CHANGE', 2);
|
---|
| 6 | if ( ! defined('_SBG_MO_PASSWORD_RECOVERY')) define('_SBG_MO_PASSWORD_RECOVERY', 3);
|
---|
| 7 | if ( ! defined('_SBG_MO_PASSWORD_CHANGE')) define('_SBG_MO_PASSWORD_CHANGE', 4);
|
---|
| 8 | if ( ! defined('_SBG_MO_VIP_REGISTER')) define('_SBG_MO_VIP_REGISTER', 5);
|
---|
| 9 | if ( ! defined('_SBG_MO_PAY_TO_ACCOUNT')) define('_SBG_MO_PAY_TO_ACCOUNT', 6);
|
---|
| 10 | if ( ! defined('_SBG_MO_PAY_TO_ACCOUNT_FOR')) define('_SBG_MO_PAY_TO_ACCOUNT_FOR', 7);
|
---|
[529] | 11 | if ( ! defined('_SBG_MO_UNSUBSCRIBE_SERVICE')) define('_SBG_MO_UNSUBSCRIBE_SERVICE', 8);
|
---|
[499] | 12 |
|
---|
| 13 | if ( ! defined('_SBG_MO_SYNTAX_ERR')) define('_SBG_MO_SYNTAX_ERR', -1);
|
---|
| 14 | if ( ! defined('_SBG_MO_SYNTAX_ERR_MSG')) define('_SBG_MO_SYNTAX_ERR_MSG', 'soanbaigiang.smas.vn khong co dich vu nay!');
|
---|
| 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);
|
---|
| 23 | if ( ! defined('_SBG_CHARGING_FAIL_NOT_ENOUGH_MSG')) define('_SBG_CHARGING_FAIL_NOT_ENOUGH_MSG', 'Tai khoan chinh cua so dien thoai :sendid: khong du de thuc hien lenh nap :amount: vao tai khoan :username: tren soanbaigiang.smas.vn');
|
---|
| 24 |
|
---|
| 25 | if ( ! defined('_SBG_SEND_MT_FAIL')) define('_SBG_SEND_MT_FAIL', -1);
|
---|
| 26 | if ( ! defined('_SBG_SEND_MT_SUCCESS')) define('_SBG_SEND_MT_SUCCESS', 1);
|
---|
| 27 |
|
---|
| 28 | if ( ! defined('_SBG_MT_SEND_NUMBER')) define('_SBG_MT_SEND_NUMBER', '841662860000');
|
---|
| 29 | if ( ! defined('_SBG_MT_CP_CODE')) define('_SBG_MT_CP_CODE', '601');
|
---|
| 30 |
|
---|
| 31 | if ( ! defined('_SBG_SERVICE_COMMAND_CODE')) define('_SBG_SERVICE_COMMAND_CODE', 'SBG');
|
---|
| 32 | if ( ! defined('_SBG_SERVICE_SERVICEID')) define('_SBG_SERVICE_SERVICEID', '8062');
|
---|
| 33 |
|
---|
| 34 | Class Services_model extends CI_Model
|
---|
| 35 | {
|
---|
| 36 | private $_arySmsMO = array(
|
---|
| 37 | _SBG_MO_REGISTER => array('pattern' => '/^(SBG[[:blank:]])(DK)$/'),
|
---|
| 38 | _SBG_MO_REGISTER_FOR => array('pattern' => '/^(SBG[[:blank:]])(DK)([[:blank:]][0-9]{10,11})$/'),
|
---|
| 39 | _SBG_MO_PHONENUM_CHANGE => array('pattern' => '/^(SBG[[:blank:]])(DDT)([[:blank:]][0-9]{10,11})([[:blank:]][a-zA-Z0-9]{4,16})$/'),
|
---|
| 40 | _SBG_MO_PASSWORD_RECOVERY => array('pattern' => '/^(SBG[[:blank:]])(MK)$/'),
|
---|
| 41 | _SBG_MO_PASSWORD_CHANGE => array('pattern' => '/^(SBG[[:blank:]])(MK)([[:blank:]][a-zA-Z0-9]{4,16})$/'),
|
---|
| 42 | _SBG_MO_VIP_REGISTER => array('pattern' => '/^(SBG[[:blank:]])(VIP)([[:blank:]][0-9]{1,2})$/'),
|
---|
| 43 | _SBG_MO_PAY_TO_ACCOUNT => array('pattern' => '/^(SBG[[:blank:]])(NAP)([[:blank:]][0-9]{3,})$/'),
|
---|
| 44 | _SBG_MO_PAY_TO_ACCOUNT_FOR => array('pattern' => '/^(SBG[[:blank:]])(NAP)([[:blank:]][0-9]{3,})([[:blank:]][0-9]{10,11})$/'),
|
---|
[529] | 45 | _SBG_MO_UNSUBSCRIBE_SERVICE => array('pattern' => '/^(SBG[[:blank:]])(HUY)$/')
|
---|
[499] | 46 | );
|
---|
| 47 |
|
---|
| 48 | public function __construct(){
|
---|
| 49 | parent::__construct();
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | private function messageAnalys ($message)
|
---|
| 53 | {
|
---|
| 54 | $aryMatched = array();
|
---|
| 55 | $result = false;
|
---|
| 56 | foreach ($this->_arySmsMO as $key => $pattern)
|
---|
| 57 | {
|
---|
| 58 | $result = preg_match($pattern['pattern'], $message, $aryMatched);
|
---|
| 59 | if ((bool)$result) break;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | $key = (bool)$result ? $key:_SBG_MO_SYNTAX_ERR;
|
---|
| 63 | $aryResult = (bool)$result ? array('case' => $key, 'content' => $aryMatched):array('case' => $key);
|
---|
| 64 | return $aryResult;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | public function processMORequest ($sentNumber,$message)
|
---|
| 68 | {
|
---|
[513] | 69 | $debugMsg = $message."\n";
|
---|
| 70 |
|
---|
[499] | 71 | $aryMatch = array();
|
---|
| 72 | if (preg_match('/^(84)([0-9]{9,10})$/', $sentNumber, $aryMatch) == 1) {
|
---|
| 73 | $sentNumber = '0'. $aryMatch[2];
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | $smsReturn = '';
|
---|
| 77 | $aryMOAnalys = $this->messageAnalys($message);
|
---|
| 78 | $case = $aryMOAnalys['case'];
|
---|
| 79 | $aryContents = isset($aryMOAnalys['content']) ? $aryMOAnalys['content']: null;
|
---|
| 80 | if ($aryContents != null){
|
---|
| 81 | unset($aryContents[0]);
|
---|
| 82 | $aryTmp = array();
|
---|
| 83 | foreach ($aryContents as $key => $val)
|
---|
| 84 | {
|
---|
| 85 | $aryTmp[] = trim($val);
|
---|
| 86 | }
|
---|
| 87 | $aryContents = $aryTmp;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | $this->load->model('frontend/user_model', 'objUserModel');
|
---|
[513] | 91 | $debugMsg .= $case;
|
---|
| 92 | write_file('mt_log', $debugMsg);
|
---|
[499] | 93 | switch ($case) {
|
---|
| 94 | case _SBG_MO_REGISTER:
|
---|
| 95 | case _SBG_MO_REGISTER_FOR:
|
---|
[528] | 96 | $userName = isset($aryContents[2]) ? $aryContents[2] : $sentNumber;
|
---|
| 97 | $collaborator = isset($aryContents[2]) ? $sentNumber:null;
|
---|
| 98 | $sms = $this->objUserModel->register($userName, $collaborator);
|
---|
| 99 | if ($case == _SBG_MO_REGISTER_FOR) {
|
---|
| 100 | $smsReturn = '1|Ban da dang ky thanh cong dich vu Soan bai giang Online cho '. $userName;
|
---|
| 101 | $arySMS = explode ('|', $sms);
|
---|
| 102 | $sendMT = $this->sendMT($userName, $arySMS[1]);
|
---|
| 103 | }
|
---|
| 104 | else {
|
---|
| 105 | $smsReturn = $sms;
|
---|
| 106 | }
|
---|
[499] | 107 | break;
|
---|
| 108 | case _SBG_MO_PHONENUM_CHANGE:
|
---|
| 109 | $oldPhoneNumber = $aryContents[2];
|
---|
| 110 | $password = $aryContents[3];
|
---|
| 111 | $smsReturn = $this->objUserModel->changeProfile($sentNumber, $oldPhoneNumber, $password);
|
---|
[513] | 112 | $sendMT = $this->sendMT($oldPhoneNumber, $smsReturn);
|
---|
[499] | 113 | break;
|
---|
| 114 | case _SBG_MO_PASSWORD_RECOVERY:
|
---|
| 115 | case _SBG_MO_PASSWORD_CHANGE:
|
---|
| 116 | $password = isset($aryContents[2]) ? $aryContents[2] : null;
|
---|
| 117 | $smsReturn = $this->objUserModel->changePassword($sentNumber, $password);
|
---|
| 118 | break;
|
---|
| 119 | case _SBG_MO_VIP_REGISTER:
|
---|
| 120 | $p_code = $aryContents[2];
|
---|
| 121 | $smsReturn = $this->objUserModel->registerVip($sentNumber, $p_code);
|
---|
| 122 | break;
|
---|
| 123 | case _SBG_MO_PAY_TO_ACCOUNT:
|
---|
| 124 | case _SBG_MO_PAY_TO_ACCOUNT_FOR:
|
---|
| 125 | $userName = isset($aryContents[3]) ? $aryContents[3] : $sentNumber;
|
---|
| 126 | $amount = $aryContents[2];
|
---|
| 127 | $result =$this->chargeRootAccountProcess($sentNumber, $amount);
|
---|
| 128 | if ($result == _SBG_CHARGING_FAIL_NOT_ENOUGH) {
|
---|
| 129 | $aryPatterns = array ('/:sendid:/', '/:amount:/', '/:username:/');
|
---|
| 130 | $smsReturn = preg_replace($aryPatterns, array($sentNumber, $amount, $userName), _SBG_CHARGING_FAIL_NOT_ENOUGH_MSG);
|
---|
| 131 | $smsReturn = '0|'.$smsReturn;
|
---|
| 132 | }
|
---|
| 133 | else {
|
---|
| 134 | $smsReturn = $this->objUserModel->rechargeAccount($userName, $amount);
|
---|
[556] | 135 | if (_SBG_MO_PAY_TO_ACCOUNT_FOR) {
|
---|
| 136 | $smsMT = $smsReturn .' tu thue bao '. $sentNumber;
|
---|
| 137 | $sendMT = $this->sendMT($userName, $smsMT);
|
---|
| 138 | }
|
---|
[499] | 139 | }
|
---|
[556] | 140 |
|
---|
[499] | 141 | //write to paid log
|
---|
[561] | 142 | $paidTime = date('Y-m-d H:i:s');
|
---|
| 143 | $this->objUserModel->insertPaidlog($sentNumber, $userName, _SBG_PAIDTYPE_SMS, $amount, $paidTime);
|
---|
[499] | 144 | break;
|
---|
[529] | 145 | case _SBG_MO_UNSUBSCRIBE_SERVICE:
|
---|
[499] | 146 | case _SBG_MO_SYNTAX_ERR:
|
---|
| 147 | default:
|
---|
| 148 | $smsReturn = '0|'._SBG_MO_SYNTAX_ERR_MSG;
|
---|
| 149 | break;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | return $smsReturn;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[506] | 155 | public function cardPaidProcess ($aryCardInfo, &$aryTopupResult = array())
|
---|
[499] | 156 | {
|
---|
[507] | 157 | /*
|
---|
| 158 | ["BalanceAfterTransaction"]=>
|
---|
| 159 | string(1) "0"
|
---|
| 160 | ["ErrorCode"]=>
|
---|
| 161 | string(3) "199"
|
---|
| 162 | ["ErrorMessage"]=>
|
---|
| 163 | string(29) "L?i exception Payment service"
|
---|
| 164 | ["LastLockedOutDate"]=>
|
---|
| 165 | string(19) "0001-01-01T00:00:00"
|
---|
| 166 | ["RemainTimeToUnLock"]=>
|
---|
| 167 | string(1) "0"
|
---|
| 168 | ["Success"]=>
|
---|
| 169 | string(5) "false"
|
---|
| 170 | ["TransactionAmount"]=>
|
---|
| 171 | string(1) "0"
|
---|
| 172 | ["TransactionID"]=>
|
---|
| 173 | string(1) "0"
|
---|
| 174 | ["TransactionTime"]=>
|
---|
| 175 | string(19) "0001-01-01T00:00:00"
|
---|
| 176 | */
|
---|
[499] | 177 | $url = $this->config->item('topup_service_url');
|
---|
| 178 | $action = 'http://tempuri.org/ITopupService/TopUp';
|
---|
| 179 | $xml = $this->load->view('topup', $aryCardInfo, true);
|
---|
| 180 |
|
---|
| 181 | $client = new nusoap_client($url);
|
---|
| 182 | $client->useHTTPPersistentConnection();
|
---|
| 183 | $client->soap_defencoding = 'UTF-8';
|
---|
| 184 | $client->operation = $action;
|
---|
| 185 |
|
---|
[519] | 186 | $result = $client->send($xml, $action);
|
---|
[499] | 187 |
|
---|
| 188 | if ($client->fault) {
|
---|
| 189 | return _SBG_CARD_PAY_FAIL;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
[528] | 192 | $keys = array_keys($result);
|
---|
[499] | 193 |
|
---|
[528] | 194 | $aryTopupResult = $result[$keys[0]];
|
---|
| 195 |
|
---|
[499] | 196 | if ($aryTopupResult['Success'] == 'false') {
|
---|
| 197 | return _SBG_CARD_PAY_FAIL;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | return _SBG_CARD_PAY_SUCCESS;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | public function chargeRootAccountProcess ($sentID, $amount = 0, $contents = '')
|
---|
| 204 | {
|
---|
| 205 | $url = $this->config->item('charging_service_url');
|
---|
| 206 | $username = $this->config->item('charging_username');
|
---|
| 207 | $password = $this->config->item('charging_password');
|
---|
| 208 | $action = 'http://tempuri.org/processCharging';
|
---|
| 209 |
|
---|
| 210 | $aryParams = array(
|
---|
| 211 | 'user' => $username,
|
---|
| 212 | 'pass' => $password,
|
---|
| 213 | 'MSISDN' => $sentID,
|
---|
| 214 | 'Charging' => $amount,
|
---|
| 215 | 'Contents' => $contents
|
---|
| 216 | );
|
---|
| 217 |
|
---|
| 218 | $xml = $this->load->view('charging', $aryParams, true);
|
---|
| 219 | $client = new nusoap_client($url);
|
---|
| 220 | $client->useHTTPPersistentConnection();
|
---|
| 221 | $client->soap_defencoding = 'UTF-8';
|
---|
| 222 | $client->operation = $action;
|
---|
| 223 | $result = $client->send($xml, $action);
|
---|
| 224 |
|
---|
| 225 | if ($client->fault) {
|
---|
| 226 | return _SBG_CHARGING_FAIL;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | if ((int)$result['processChargingResult'] == _SBG_CHARGING_FAIL_NOT_ENOUGH)
|
---|
| 230 | return _SBG_CHARGING_FAIL_NOT_ENOUGH;
|
---|
| 231 |
|
---|
| 232 | return _SBG_CHARGING_SUCCESS;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | public function sendMT ($receiverID, $message)
|
---|
| 236 | {
|
---|
| 237 | $aryMatch = array();
|
---|
| 238 | if (preg_match('/^(0)([0-9]{9,10})$/', $receiverID, $aryMatch) == 1) {
|
---|
| 239 | $receiverID = '84'. $aryMatch[2];
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | $username = $this->config->item('mt_username');
|
---|
| 243 | $password = $this->config->item('mt_password');
|
---|
| 244 | $action = 'http://tempuri.org/InsertMT';
|
---|
| 245 |
|
---|
| 246 | $aryParams = array(
|
---|
| 247 | 'User' => $username,
|
---|
| 248 | 'Pass' => $password,
|
---|
| 249 | 'CPCode' => _SBG_MT_CP_CODE,
|
---|
| 250 | 'UserID' => _SBG_MT_SEND_NUMBER,
|
---|
| 251 | 'RequestID' => '4',
|
---|
| 252 | 'ReceiverID' => $receiverID,
|
---|
| 253 | 'ServiceID' => _SBG_SERVICE_SERVICEID,
|
---|
| 254 | 'CommandCode' => _SBG_SERVICE_COMMAND_CODE,
|
---|
| 255 | 'ContentType' => '0',
|
---|
| 256 | 'Info' => $message
|
---|
| 257 | );
|
---|
| 258 |
|
---|
| 259 | $xml = $this->load->view('mt', $aryParams, true);
|
---|
[513] | 260 | $url = $this->config->item('mt_service_url');
|
---|
[499] | 261 | $client = new nusoap_client($url);
|
---|
| 262 | $client->useHTTPPersistentConnection();
|
---|
| 263 | $client->soap_defencoding = 'UTF-8';
|
---|
| 264 | $client->operation = $action;
|
---|
| 265 | $result = $client->send($xml, $action);
|
---|
| 266 |
|
---|
[513] | 267 | //write_file('mt_log', var_export($client->fault, true)."\n".var_export($xml, true));
|
---|
| 268 |
|
---|
[499] | 269 | if ($client->fault || (int)$result['InsertMTResult'] != 1) {
|
---|
| 270 | return _SBG_SEND_MT_FAIL;
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | return _SBG_SEND_MT_SUCCESS;
|
---|
| 274 | }
|
---|
| 275 | } |
---|