[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);
|
---|
| 11 |
|
---|
| 12 | if ( ! defined('_SBG_MO_SYNTAX_ERR')) define('_SBG_MO_SYNTAX_ERR', -1);
|
---|
| 13 | if ( ! defined('_SBG_MO_SYNTAX_ERR_MSG')) define('_SBG_MO_SYNTAX_ERR_MSG', 'soanbaigiang.smas.vn khong co dich vu nay!');
|
---|
| 14 |
|
---|
| 15 | if ( ! defined('_SBG_CARD_PAY_FAIL')) define('_SBG_CARD_PAY_FAIL', -1);
|
---|
| 16 | if ( ! defined('_SBG_CARD_PAY_SUCCESS')) define('_SBG_CARD_PAY_SUCCESS', 1);
|
---|
| 17 |
|
---|
| 18 | if ( ! defined('_SBG_CHARGING_FAIL')) define('_SBG_CHARGING_FAIL', -1);
|
---|
| 19 | if ( ! defined('_SBG_CHARGING_SUCCESS')) define('_SBG_CHARGING_SUCCESS', 1);
|
---|
| 20 |
|
---|
| 21 | if ( ! defined('_SBG_CHARGING_FAIL_NOT_ENOUGH')) define('_SBG_CHARGING_FAIL_NOT_ENOUGH', 401);
|
---|
| 22 | 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');
|
---|
| 23 |
|
---|
| 24 | if ( ! defined('_SBG_SEND_MT_FAIL')) define('_SBG_SEND_MT_FAIL', -1);
|
---|
| 25 | if ( ! defined('_SBG_SEND_MT_SUCCESS')) define('_SBG_SEND_MT_SUCCESS', 1);
|
---|
| 26 |
|
---|
| 27 | if ( ! defined('_SBG_MT_SEND_NUMBER')) define('_SBG_MT_SEND_NUMBER', '841662860000');
|
---|
| 28 | if ( ! defined('_SBG_MT_CP_CODE')) define('_SBG_MT_CP_CODE', '601');
|
---|
| 29 |
|
---|
| 30 | if ( ! defined('_SBG_SERVICE_COMMAND_CODE')) define('_SBG_SERVICE_COMMAND_CODE', 'SBG');
|
---|
| 31 | if ( ! defined('_SBG_SERVICE_SERVICEID')) define('_SBG_SERVICE_SERVICEID', '8062');
|
---|
| 32 |
|
---|
| 33 | Class Services_model extends CI_Model
|
---|
| 34 | {
|
---|
| 35 | private $_arySmsMO = array(
|
---|
| 36 | _SBG_MO_REGISTER => array('pattern' => '/^(SBG[[:blank:]])(DK)$/'),
|
---|
| 37 | _SBG_MO_REGISTER_FOR => array('pattern' => '/^(SBG[[:blank:]])(DK)([[:blank:]][0-9]{10,11})$/'),
|
---|
| 38 | _SBG_MO_PHONENUM_CHANGE => array('pattern' => '/^(SBG[[:blank:]])(DDT)([[:blank:]][0-9]{10,11})([[:blank:]][a-zA-Z0-9]{4,16})$/'),
|
---|
| 39 | _SBG_MO_PASSWORD_RECOVERY => array('pattern' => '/^(SBG[[:blank:]])(MK)$/'),
|
---|
| 40 | _SBG_MO_PASSWORD_CHANGE => array('pattern' => '/^(SBG[[:blank:]])(MK)([[:blank:]][a-zA-Z0-9]{4,16})$/'),
|
---|
| 41 | _SBG_MO_VIP_REGISTER => array('pattern' => '/^(SBG[[:blank:]])(VIP)([[:blank:]][0-9]{1,2})$/'),
|
---|
| 42 | _SBG_MO_PAY_TO_ACCOUNT => array('pattern' => '/^(SBG[[:blank:]])(NAP)([[:blank:]][0-9]{3,})$/'),
|
---|
| 43 | _SBG_MO_PAY_TO_ACCOUNT_FOR => array('pattern' => '/^(SBG[[:blank:]])(NAP)([[:blank:]][0-9]{3,})([[:blank:]][0-9]{10,11})$/'),
|
---|
| 44 | );
|
---|
| 45 |
|
---|
| 46 | public function __construct(){
|
---|
| 47 | parent::__construct();
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | private function messageAnalys ($message)
|
---|
| 51 | {
|
---|
| 52 | $aryMatched = array();
|
---|
| 53 | $result = false;
|
---|
| 54 | foreach ($this->_arySmsMO as $key => $pattern)
|
---|
| 55 | {
|
---|
| 56 | $result = preg_match($pattern['pattern'], $message, $aryMatched);
|
---|
| 57 | if ((bool)$result) break;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | $key = (bool)$result ? $key:_SBG_MO_SYNTAX_ERR;
|
---|
| 61 | $aryResult = (bool)$result ? array('case' => $key, 'content' => $aryMatched):array('case' => $key);
|
---|
| 62 | return $aryResult;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | public function processMORequest ($sentNumber,$message)
|
---|
| 66 | {
|
---|
| 67 | $aryMatch = array();
|
---|
| 68 | if (preg_match('/^(84)([0-9]{9,10})$/', $sentNumber, $aryMatch) == 1) {
|
---|
| 69 | $sentNumber = '0'. $aryMatch[2];
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | $smsReturn = '';
|
---|
| 73 | $aryMOAnalys = $this->messageAnalys($message);
|
---|
| 74 | $case = $aryMOAnalys['case'];
|
---|
| 75 | $aryContents = isset($aryMOAnalys['content']) ? $aryMOAnalys['content']: null;
|
---|
| 76 | if ($aryContents != null){
|
---|
| 77 | unset($aryContents[0]);
|
---|
| 78 | $aryTmp = array();
|
---|
| 79 | foreach ($aryContents as $key => $val)
|
---|
| 80 | {
|
---|
| 81 | $aryTmp[] = trim($val);
|
---|
| 82 | }
|
---|
| 83 | $aryContents = $aryTmp;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | $this->load->model('frontend/user_model', 'objUserModel');
|
---|
| 87 |
|
---|
| 88 | switch ($case) {
|
---|
| 89 | case _SBG_MO_REGISTER:
|
---|
| 90 | case _SBG_MO_REGISTER_FOR:
|
---|
| 91 | $userName = isset($aryContents[2]) ? $aryContents[2]:$sentNumber;
|
---|
| 92 | $collaborator = isset($aryContents[2]) ? $aryContents[0]:null;
|
---|
| 93 | $smsReturn = $this->objUserModel->register($userName, $collaborator);
|
---|
| 94 | break;
|
---|
| 95 | case _SBG_MO_PHONENUM_CHANGE:
|
---|
| 96 | $oldPhoneNumber = $aryContents[2];
|
---|
| 97 | $password = $aryContents[3];
|
---|
| 98 | $smsReturn = $this->objUserModel->changeProfile($sentNumber, $oldPhoneNumber, $password);
|
---|
| 99 | $this->sendMT($oldPhoneNumber, $smsReturn);
|
---|
| 100 | break;
|
---|
| 101 | case _SBG_MO_PASSWORD_RECOVERY:
|
---|
| 102 | case _SBG_MO_PASSWORD_CHANGE:
|
---|
| 103 | $password = isset($aryContents[2]) ? $aryContents[2] : null;
|
---|
| 104 | $smsReturn = $this->objUserModel->changePassword($sentNumber, $password);
|
---|
| 105 | break;
|
---|
| 106 | case _SBG_MO_VIP_REGISTER:
|
---|
| 107 | $p_code = $aryContents[2];
|
---|
| 108 | $smsReturn = $this->objUserModel->registerVip($sentNumber, $p_code);
|
---|
| 109 | //$smsReturn = $this->objUserModel->getVIP($sentNumber, $p_code);
|
---|
| 110 | break;
|
---|
| 111 | case _SBG_MO_PAY_TO_ACCOUNT:
|
---|
| 112 | case _SBG_MO_PAY_TO_ACCOUNT_FOR:
|
---|
| 113 | $userName = isset($aryContents[3]) ? $aryContents[3] : $sentNumber;
|
---|
| 114 | $amount = $aryContents[2];
|
---|
| 115 | $result =$this->chargeRootAccountProcess($sentNumber, $amount);
|
---|
| 116 | if ($result == _SBG_CHARGING_FAIL_NOT_ENOUGH) {
|
---|
| 117 | $aryPatterns = array ('/:sendid:/', '/:amount:/', '/:username:/');
|
---|
| 118 | $smsReturn = preg_replace($aryPatterns, array($sentNumber, $amount, $userName), _SBG_CHARGING_FAIL_NOT_ENOUGH_MSG);
|
---|
| 119 | $smsReturn = '0|'.$smsReturn;
|
---|
| 120 | }
|
---|
| 121 | else {
|
---|
| 122 | $smsReturn = $this->objUserModel->rechargeAccount($userName, $amount);
|
---|
| 123 | }
|
---|
| 124 | //write to paid log
|
---|
| 125 | break;
|
---|
| 126 | case _SBG_MO_SYNTAX_ERR:
|
---|
| 127 | default:
|
---|
| 128 | $smsReturn = '0|'._SBG_MO_SYNTAX_ERR_MSG;
|
---|
| 129 | break;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | return $smsReturn;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | public function cardPaidProcess ($aryCardInfo)
|
---|
| 136 | {
|
---|
| 137 | $url = $this->config->item('topup_service_url');
|
---|
| 138 | $action = 'http://tempuri.org/ITopupService/TopUp';
|
---|
| 139 | $xml = $this->load->view('topup', $aryCardInfo, true);
|
---|
| 140 |
|
---|
| 141 | $client = new nusoap_client($url);
|
---|
| 142 | $client->useHTTPPersistentConnection();
|
---|
| 143 | $client->soap_defencoding = 'UTF-8';
|
---|
| 144 | $client->operation = $action;
|
---|
| 145 |
|
---|
| 146 | $result = $client->send($this->_xmlHeader.$xml, $operation);
|
---|
| 147 |
|
---|
| 148 | if ($client->fault) {
|
---|
| 149 | return _SBG_CARD_PAY_FAIL;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | $aryTopupResult = $result['TopUpResult'];
|
---|
| 153 |
|
---|
| 154 | if ($aryTopupResult['Success'] == 'false') {
|
---|
| 155 | return _SBG_CARD_PAY_FAIL;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | return _SBG_CARD_PAY_SUCCESS;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | public function chargeRootAccountProcess ($sentID, $amount = 0, $contents = '')
|
---|
| 162 | {
|
---|
| 163 | $url = $this->config->item('charging_service_url');
|
---|
| 164 | $username = $this->config->item('charging_username');
|
---|
| 165 | $password = $this->config->item('charging_password');
|
---|
| 166 | $action = 'http://tempuri.org/processCharging';
|
---|
| 167 |
|
---|
| 168 | $aryParams = array(
|
---|
| 169 | 'user' => $username,
|
---|
| 170 | 'pass' => $password,
|
---|
| 171 | 'MSISDN' => $sentID,
|
---|
| 172 | 'Charging' => $amount,
|
---|
| 173 | 'Contents' => $contents
|
---|
| 174 | );
|
---|
| 175 |
|
---|
| 176 | $xml = $this->load->view('charging', $aryParams, true);
|
---|
| 177 | $client = new nusoap_client($url);
|
---|
| 178 | $client->useHTTPPersistentConnection();
|
---|
| 179 | $client->soap_defencoding = 'UTF-8';
|
---|
| 180 | $client->operation = $action;
|
---|
| 181 | $result = $client->send($xml, $action);
|
---|
| 182 |
|
---|
| 183 | if ($client->fault) {
|
---|
| 184 | return _SBG_CHARGING_FAIL;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | if ((int)$result['processChargingResult'] == _SBG_CHARGING_FAIL_NOT_ENOUGH)
|
---|
| 188 | return _SBG_CHARGING_FAIL_NOT_ENOUGH;
|
---|
| 189 |
|
---|
| 190 | return _SBG_CHARGING_SUCCESS;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | public function sendMT ($receiverID, $message)
|
---|
| 194 | {
|
---|
| 195 | $aryMatch = array();
|
---|
| 196 | if (preg_match('/^(0)([0-9]{9,10})$/', $receiverID, $aryMatch) == 1) {
|
---|
| 197 | $receiverID = '84'. $aryMatch[2];
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | $username = $this->config->item('mt_username');
|
---|
| 201 | $password = $this->config->item('mt_password');
|
---|
| 202 | $action = 'http://tempuri.org/InsertMT';
|
---|
| 203 |
|
---|
| 204 | $aryParams = array(
|
---|
| 205 | 'User' => $username,
|
---|
| 206 | 'Pass' => $password,
|
---|
| 207 | 'CPCode' => _SBG_MT_CP_CODE,
|
---|
| 208 | 'UserID' => _SBG_MT_SEND_NUMBER,
|
---|
| 209 | 'RequestID' => '4',
|
---|
| 210 | 'ReceiverID' => $receiverID,
|
---|
| 211 | 'ServiceID' => _SBG_SERVICE_SERVICEID,
|
---|
| 212 | 'CommandCode' => _SBG_SERVICE_COMMAND_CODE,
|
---|
| 213 | 'ContentType' => '0',
|
---|
| 214 | 'Info' => $message
|
---|
| 215 | );
|
---|
| 216 |
|
---|
| 217 | $xml = $this->load->view('mt', $aryParams, true);
|
---|
| 218 | $client = new nusoap_client($url);
|
---|
| 219 | $client->useHTTPPersistentConnection();
|
---|
| 220 | $client->soap_defencoding = 'UTF-8';
|
---|
| 221 | $client->operation = $action;
|
---|
| 222 | $result = $client->send($xml, $action);
|
---|
| 223 |
|
---|
| 224 | if ($client->fault || (int)$result['InsertMTResult'] != 1) {
|
---|
| 225 | return _SBG_SEND_MT_FAIL;
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | return _SBG_SEND_MT_SUCCESS;
|
---|
| 229 | }
|
---|
| 230 | } |
---|