1 | <?php |
---|
2 | |
---|
3 | class userActions extends sfActions |
---|
4 | { |
---|
5 | const TOKENPW = 'violet'; |
---|
6 | |
---|
7 | public function executeTest() { |
---|
8 | var_dump(1); |
---|
9 | return sfView::NONE; |
---|
10 | } |
---|
11 | |
---|
12 | private function getUserField($fieldName, $value, $currentId = null) { |
---|
13 | $c = new Criteria(); |
---|
14 | $c->add($fieldName, $value); |
---|
15 | if ($currentId) $c->add(TbluserPeer::US_ID, $currentId, Criteria::NOT_EQUAL); |
---|
16 | return TbluserPeer::doSelectOne($c); |
---|
17 | } |
---|
18 | |
---|
19 | private function validateData($name, $email, $phone, &$error, $checkfullname = true) { |
---|
20 | $nameValid = $checkfullname ? ($name != null && !myUtility::validate('sfFilterValidator', $name, $error)) || |
---|
21 | ($name != null && !myUtility::validate('sfFullnameValidator', $name, $error)) : TRUE; |
---|
22 | return |
---|
23 | $nameValid || ($email != null && !myUtility::validate('sfEmailValidator', $email, $error)) || |
---|
24 | ($phone != null && !myUtility::validate('sfPhoneValidator', $phone, $error)); |
---|
25 | } |
---|
26 | |
---|
27 | private function getUserInfo($tbluser) { |
---|
28 | $fullname = ''; |
---|
29 | if ($tbluser->getUsStatus()<10) { |
---|
30 | if (null==$tbluser->getUsLastname() && null==$tbluser->getUsFirstname()) |
---|
31 | $fullname = ''; |
---|
32 | else |
---|
33 | $fullname = $tbluser->getUsLastname().' '.$tbluser->getUsFirstname(); |
---|
34 | } else { |
---|
35 | $fullname = 'Äang bá» khóa'; |
---|
36 | } |
---|
37 | |
---|
38 | $result = 'id='.$tbluser->getUsId(); |
---|
39 | $result .= '&username='.$tbluser->getUsUsername(); |
---|
40 | $result .= '&fullname='.$fullname; |
---|
41 | $result .= '&gender='.($tbluser->getUsSex()==1? 'male': 'female'); |
---|
42 | $result .= '&email='.$tbluser->getUsEmail(); |
---|
43 | $result .= '&phone='.$tbluser->getUSPhone(); |
---|
44 | $result .= '&school='.$tbluser->getUsSchool(); |
---|
45 | $result .= '&province='.$tbluser->getUsProvince(); |
---|
46 | $result .= '&money='.$tbluser->getUsMoney(); |
---|
47 | return $result; |
---|
48 | } |
---|
49 | |
---|
50 | private function getPEncrypted($tbluser) { |
---|
51 | $result = 'pencrypted='.$tbluser->getUsPassword(); |
---|
52 | return $result; |
---|
53 | } |
---|
54 | |
---|
55 | private function getLicense($tbluser) { |
---|
56 | $productId = $this->getRequestParameter('product'); |
---|
57 | $version = $this->getRequestParameter('version'); |
---|
58 | if ($productId == null) return; |
---|
59 | |
---|
60 | $c = new Criteria(); |
---|
61 | $c->add(TblprolicensePeer::LI_TYPE, 1); |
---|
62 | $c->add(TblprolicensePeer::LI_CUSTOMER, $tbluser->getUsId()); |
---|
63 | $c->add(TblprolicensePeer::LI_PRODUCT, $productId); |
---|
64 | $c->add(TblprolicensePeer::LI_VERSION, $version, Criteria::GREATER_EQUAL); |
---|
65 | $c->add(TblprolicensePeer::LI_EXPIREDATE, date('Y-m-d H:i:s'), Criteria::GREATER_EQUAL); |
---|
66 | $license = TblprolicensePeer::doSelectOne($c); |
---|
67 | $userdetail = TblblogcheckinfoPeer::retrieveByPk($tbluser->getUsId()); |
---|
68 | if ($license == null && $userdetail != null) { |
---|
69 | $c = new Criteria(); |
---|
70 | $c->add(TblprolicensePeer::LI_TYPE, 2); |
---|
71 | $c->add(TblprolicensePeer::LI_CUSTOMER, $userdetail->getCiSchool()); |
---|
72 | $c->add(TblprolicensePeer::LI_PRODUCT, $productId); |
---|
73 | $c->add(TblprolicensePeer::LI_VERSION, $version, Criteria::GREATER_EQUAL); |
---|
74 | $c->add(TblprolicensePeer::LI_EXPIREDATE, date('Y-m-d H:i:s'), Criteria::GREATER_EQUAL); |
---|
75 | $license = TblprolicensePeer::doSelectOne($c); |
---|
76 | } |
---|
77 | return $license; |
---|
78 | } |
---|
79 | |
---|
80 | public function executeLogin() { |
---|
81 | $src = $this->getRequestParameter('src'); |
---|
82 | $token = $this->getRequestParameter('token'); |
---|
83 | $account = $this->getRequestParameter('username'); |
---|
84 | $password = $this->getRequestParameter('password'); |
---|
85 | |
---|
86 | if ($account == null || $password == null) return $this->renderText('status=1&errMsg=Not enough data'); |
---|
87 | if ($src == null || $token != md5($account.self::TOKENPW)) return $this->renderText('status=10'); |
---|
88 | |
---|
89 | $tbluser = $this->getUserField(TbluserPeer::US_USERNAME, $account); |
---|
90 | |
---|
91 | if (!$tbluser) $tbluser = $this->getUserField(TbluserPeer::US_EMAIL, $account); |
---|
92 | if (!$tbluser) $tbluser = $this->getUserField(TbluserPeer::US_PHONE, $account); |
---|
93 | if (!$tbluser) return $this->renderText('status=2&errMsg=User not found'); |
---|
94 | if ($tbluser->getUsPassword() != md5($password)) return $this->renderText('status=3&errMsg=Incorrect password'); |
---|
95 | |
---|
96 | $loginResult = $this->getUserInfo($tbluser); |
---|
97 | if ($tbluser->getUsStatus() == 0) return $this->renderText($loginResult.'&status=4&errMsg=Account is not activated'); |
---|
98 | |
---|
99 | if ($license = $this->getLicense($tbluser)) { |
---|
100 | $loginResult .= '&level='.$license->getLiLevel(); |
---|
101 | $ltype = $license->getLiType(); |
---|
102 | $cid = $license->getLiCustomer(); |
---|
103 | $customer = $ltype == 1? $tbluser->getUsFullname(): TblblogschoolsPeer::retrieveByPk($cid)->getScName(); |
---|
104 | $loginResult .= '&licType='.$ltype; |
---|
105 | $loginResult .= '&licCustomer='.$customer; |
---|
106 | $loginResult .= '&licCreate='.$license->getLiCreatedate('d/m/Y'); |
---|
107 | $loginResult .= '&licExpire='.$license->getLiExpiredate('d/m/Y'); |
---|
108 | } |
---|
109 | else |
---|
110 | $loginResult .= '&level=0'; |
---|
111 | |
---|
112 | $loginResult .= '&status=0'; |
---|
113 | |
---|
114 | /*try { |
---|
115 | $this->getUser()->signIn($tbluser); |
---|
116 | } catch (Exception $e) { |
---|
117 | return $this->renderText('&status=5&errMsg='.$e->getMessage()); |
---|
118 | }*/ |
---|
119 | $ip = myUtility::getRealIpAddr(); |
---|
120 | myUtility::log("$ip login from $src ($account)", 'apiuser.log'); |
---|
121 | return $this->renderText($loginResult); |
---|
122 | } |
---|
123 | |
---|
124 | public function executeLogout() { |
---|
125 | $this->getUser()->signOut(); |
---|
126 | return sfView::NONE; |
---|
127 | } |
---|
128 | |
---|
129 | /*public function executeGetinfo() { |
---|
130 | $src = $this->getRequestParameter('src'); |
---|
131 | $us_id = $this->getRequestParameter('us_id'); |
---|
132 | $uname = $this->getRequestParameter('username'); |
---|
133 | $email = $this->getRequestParameter('email'); |
---|
134 | $phone = $this->getRequestParameter('phone'); |
---|
135 | $token = $this->getRequestParameter('token'); |
---|
136 | if ($src == null) return sfView::NONE; |
---|
137 | |
---|
138 | if ($us_id && $token==md5($us_id.self::TOKENPW)) $tbluser = $this->getUserField(TbluserPeer::US_ID, $us_id); |
---|
139 | if ($uname && $token==md5($uname.self::TOKENPW)) $tbluser = $this->getUserField(TbluserPeer::US_USERNAME, $uname); |
---|
140 | if ($email && $token==md5($email.self::TOKENPW)) $tbluser = $this->getUserField(TbluserPeer::US_EMAIL, $email); |
---|
141 | if ($phone && $token==md5($phone.self::TOKENPW)) $tbluser = $this->getUserField(TbluserPeer::US_PHONE, $phone); |
---|
142 | |
---|
143 | if ($tbluser) $result = $this->getUserInfo($tbluser); |
---|
144 | else return sfView::NONE; |
---|
145 | |
---|
146 | $ip = myUtility::getRealIpAddr(); |
---|
147 | myUtility::log("$ip get info from $src".($tbluser? ' ('.$tbluser->getUsUsername().')': ' failed'), 'apiuser.log'); |
---|
148 | return $this->renderText($result); |
---|
149 | }*/ |
---|
150 | |
---|
151 | public function executeGetinfo() { |
---|
152 | $src = $this->getRequestParameter('src'); |
---|
153 | $us_id = $this->getRequestParameter('us_id'); |
---|
154 | $uname = $this->getRequestParameter('username'); |
---|
155 | $email = $this->getRequestParameter('email'); |
---|
156 | $phone = $this->getRequestParameter('phone'); |
---|
157 | $token = $this->getRequestParameter('token'); |
---|
158 | |
---|
159 | $passwd_only = $this->getRequestParameter('ponly'); |
---|
160 | |
---|
161 | if ($src == null) return sfView::NONE; |
---|
162 | |
---|
163 | if ($us_id && $token==md5($us_id.self::TOKENPW)) $tbluser = $this->getUserField(TbluserPeer::US_ID, $us_id); |
---|
164 | if ($uname && $token==md5($uname.self::TOKENPW)) $tbluser = $this->getUserField(TbluserPeer::US_USERNAME, $uname); |
---|
165 | if ($email && $token==md5($email.self::TOKENPW)) $tbluser = $this->getUserField(TbluserPeer::US_EMAIL, $email); |
---|
166 | if ($phone && $token==md5($phone.self::TOKENPW)) $tbluser = $this->getUserField(TbluserPeer::US_PHONE, $phone); |
---|
167 | |
---|
168 | if ($tbluser) |
---|
169 | $result = !$passwd_only ? $this->getUserInfo($tbluser) : $this->getPEncrypted($tbluser); |
---|
170 | else return sfView::NONE; |
---|
171 | |
---|
172 | $ip = myUtility::getRealIpAddr(); |
---|
173 | myUtility::log("$ip get info from $src".($tbluser? ' ('.$tbluser->getUsUsername().')': ' failed'), 'apiuser.log'); |
---|
174 | return $this->renderText($result); |
---|
175 | } |
---|
176 | |
---|
177 | public function executeUpdate() { |
---|
178 | $src = $this->getRequestParameter('src'); |
---|
179 | $us_id = $this->getRequestParameter('us_id'); |
---|
180 | $username = $this->getRequestParameter('username'); |
---|
181 | $password = $this->getRequestParameter('password'); |
---|
182 | $fullname = $this->getRequestParameter('fullname'); |
---|
183 | $gender = $this->getRequestParameter('gender'); |
---|
184 | $email = $this->getRequestParameter('email'); |
---|
185 | $phone = $this->getRequestParameter('phone'); |
---|
186 | $school = $this->getRequestParameter('school'); |
---|
187 | $province = $this->getRequestParameter('province'); |
---|
188 | $token = $this->getRequestParameter('token'); |
---|
189 | $sendmail = $this->getRequestParameter('sendmail'); |
---|
190 | $oldpass = $this->getRequestParameter('oldpass'); |
---|
191 | |
---|
192 | if ($src == null) return $this->renderText('status=10'); |
---|
193 | //if ($this->validateData($fullname, $email, $phone, $error, false)) return $this->renderText('status=7&errMsg='.$error); |
---|
194 | |
---|
195 | if ($us_id == null) { |
---|
196 | if ($token != md5($username.self::TOKENPW)) return $this->renderText('status=10'); |
---|
197 | if (!$username || !$password /*|| !$fullname*/) return $this->renderText('status=1&errMsg=Not enough data'); |
---|
198 | if ($this->getUserField(TbluserPeer::US_USERNAME, $username)) return $this->renderText('status=2&errMsg=Username has existed'); |
---|
199 | if ($this->getUserField(TbluserPeer::US_EMAIL, $email)) return $this->renderText('status=3&errMsg=Email has existed'); |
---|
200 | if ($this->getUserField(TbluserPeer::US_PHONE, $phone)) return $this->renderText('status=4&errMsg=Phone number has existed'); |
---|
201 | |
---|
202 | $tbluser = new Tbluser(); |
---|
203 | $tbluser->setUsRegisterdate(date('Y-m-d H:i:s')); |
---|
204 | $tbluser->setUsScore(sfConfig::get('app_user_start_point')); |
---|
205 | |
---|
206 | } else { |
---|
207 | if ($token != md5($us_id.self::TOKENPW)) return $this->renderText('status=10'); |
---|
208 | if ($username != null && $this->getUserField(TbluserPeer::US_USERNAME, $username, $us_id)) return $this->renderText('status=2&errMsg=Username has existed'); |
---|
209 | if ($email != null && $this->getUserField(TbluserPeer::US_EMAIL, $email, $us_id)) return $this->renderText('status=3&errMsg=Email has existed'); |
---|
210 | if ($phone != null && $this->getUserField(TbluserPeer::US_PHONE, $phone, $us_id)) return $this->renderText('status=4&errMsg=Phone number has existed'); |
---|
211 | |
---|
212 | $tbluser = TbluserPeer::retrieveByPK($us_id); |
---|
213 | if ($tbluser == null) return $this->renderText('status=5&errMsg=User not found'); |
---|
214 | if (($username != null || $password != null) && md5($oldpass) != $tbluser->getUsPassword() && $src != 'SBG') return $this->renderText('status=6&errMsg=Incorrect old password'); |
---|
215 | if ($oldpass != null && (md5($oldpass) != $tbluser->getUsPassword()) || $src != 'SBG') return $this->renderText('status=6&errMsg=Incorrect old password'); |
---|
216 | if ($email != null && $email != $tbluser->getUsEmail()) $tbluser->setEmailConfirm(0); |
---|
217 | if ($phone != null && $phone != $tbluser->getUsPhone()) $tbluser->setMobileConfirm(0); |
---|
218 | } |
---|
219 | |
---|
220 | if ($username != null) $tbluser->setUsUsername($username); |
---|
221 | if ($password != null) $tbluser->setUsPassword(md5($password)); |
---|
222 | if ($fullname != null) $tbluser->setUsFullname($fullname); |
---|
223 | if ($gender != null) $tbluser->setUsSex($gender=='male'? 1: 2); |
---|
224 | if ($email != null) $tbluser->setUsEmail($email); |
---|
225 | if ($phone != null) $tbluser->setUsPhone($phone); |
---|
226 | if ($school != null) $tbluser->setUsSchool($school); |
---|
227 | if ($province != null) $tbluser->setUsProvince($province); |
---|
228 | |
---|
229 | $tbluser->save(); |
---|
230 | |
---|
231 | if ($sendmail == 'true') userMessage::sendConfirmEmail($tbluser, $password); |
---|
232 | $ip = myUtility::getRealIpAddr(); |
---|
233 | $act = ($us_id == null? 'create': 'update'); |
---|
234 | myUtility::log("$ip $act from $src".($tbluser? ' ('.$tbluser->getUsUsername().')': ' failed'), 'apiuser.log'); |
---|
235 | return $this->renderText('status=0&id='.$tbluser->getUsId()); |
---|
236 | } |
---|
237 | |
---|
238 | public function executeForgotpassword() { |
---|
239 | $src = $this->getRequestParameter('src'); |
---|
240 | $email = $this->getRequestParameter('email'); |
---|
241 | $token = $this->getRequestParameter('token'); |
---|
242 | if ($src != null && $email != null && $token == md5($email.self::TOKENPW)) { |
---|
243 | $c = new Criteria(); |
---|
244 | $c->add(TbluserPeer::US_EMAIL, trim($email)); |
---|
245 | $tbluser = TbluserPeer::doSelectOne($c); |
---|
246 | if ($tbluser != null) { |
---|
247 | $res = userMessage::sendForgotPassEmail($tbluser); |
---|
248 | $ip = myUtility::getRealIpAddr(); |
---|
249 | $acc = $tbluser->getUsUsername(); |
---|
250 | myUtility::log("$ip from $src get password ($acc)".($res?'':' failed'), 'apiuser.log'); |
---|
251 | return $this->renderText('status=0'); |
---|
252 | } |
---|
253 | return $this->renderText('status=1&errMsg=Email not found'); |
---|
254 | } |
---|
255 | return $this->renderText('status=10'); |
---|
256 | } |
---|
257 | |
---|
258 | public function executeGetonlineuser() { |
---|
259 | return sfView::NONE; |
---|
260 | } |
---|
261 | |
---|
262 | public function executeGetprice() { |
---|
263 | $products = $this->getRequestParameter('product'); |
---|
264 | $products = explode(',', $products); |
---|
265 | $result = ''; |
---|
266 | foreach ($products as $product) { |
---|
267 | $c = new Criteria(); |
---|
268 | $c->add(TblproductPeer::PRO_NAME, $product); |
---|
269 | $tblprod = TblproductPeer::doSelectOne($c); |
---|
270 | if ($tblprod) $result .= '&'.$product.'='.$tblprod->getProPrice(); |
---|
271 | } |
---|
272 | return $this->renderText($result); |
---|
273 | } |
---|
274 | |
---|
275 | public function executePayment() { |
---|
276 | $src = $this->getRequestParameter('src'); |
---|
277 | $us_id = $this->getRequestParameter('us_id'); |
---|
278 | $product = $this->getRequestParameter('product'); |
---|
279 | $token = $this->getRequestParameter('token'); |
---|
280 | if ($src == null || $token != md5($us_id.self::TOKENPW)) return $this->renderText('status=10'); |
---|
281 | |
---|
282 | $c = new Criteria(); |
---|
283 | $c->add(TblproductPeer::PRO_NAME, $product); |
---|
284 | $tblprod = TblproductPeer::doSelectOne($c); |
---|
285 | $price = $tblprod->getProPrice(); |
---|
286 | |
---|
287 | $tbluser = TbluserPeer::retrieveByPk($us_id); |
---|
288 | if ($tbluser == null) return $this->renderText('status=1&errMsg=User not found'); |
---|
289 | if ($tbluser->getUsMoney() < $price) return $this->renderText('status=2&errMsg=Not enough money'); |
---|
290 | $tbluser->doTransaction(-$price, 'pay', $product); |
---|
291 | |
---|
292 | if ($tblprod->getProType() > 0) { |
---|
293 | if ($tbllic = $tblprod->getUserLicense($us_id)) { |
---|
294 | $exp = $tbllic->getLiExpiredate(); |
---|
295 | $start = strtotime($exp) > time()? $exp: date('Y-m-d H:i:s'); |
---|
296 | $tbllic->setLiExpiredate(date('Y-m-d H:i:s', strtotime($start.' + 1 year'))); |
---|
297 | $tbllic->save(); |
---|
298 | } else { |
---|
299 | $tblprod->createUserLicense($us_id, 1); |
---|
300 | } |
---|
301 | } |
---|
302 | $ip = myUtility::getRealIpAddr(); |
---|
303 | $acc = $tbluser->getUsUsername(); |
---|
304 | myUtility::log("$ip pay $price from $src ($acc)", 'apiuser.log'); |
---|
305 | return $this->renderText('status=0&price='.$price.'&money='.$tbluser->getUsMoney()); |
---|
306 | } |
---|
307 | |
---|
308 | public function executeActivate() { |
---|
309 | $arParams['access_key'] = $this->getRequestParameter('access_key', 'no_access_key'); |
---|
310 | $arParams['command'] = $this->getRequestParameter('command', 'no_command'); |
---|
311 | $arParams['mo_message'] = $this->getRequestParameter('mo_message', 'no_mo_message'); |
---|
312 | $arParams['msisdn'] = $this->getRequestParameter('msisdn', 'no_msisdn'); |
---|
313 | $arParams['request_id'] = $this->getRequestParameter('request_id', 'no_request_id'); |
---|
314 | $arParams['request_time'] = $this->getRequestParameter('request_time', 'no_request_time'); |
---|
315 | $arParams['short_code'] = $this->getRequestParameter('short_code', 'no_short_code'); |
---|
316 | $arParams['signature'] = $this->getRequestParameter('signature', 'no_signature'); |
---|
317 | |
---|
318 | $data = "access_key=" . $arParams['access_key'] . "&command=" . $arParams['command'] . "&mo_message=" . $arParams['mo_message'] . "&msisdn=" . $arParams['msisdn']; |
---|
319 | $data .= "&request_id=" . $arParams['request_id'] . "&request_time=" . $arParams['request_time'] . "&short_code=" . $arParams['short_code']; |
---|
320 | $secret = 'evvx931itxysfnp9m94rf2vxd101zegr'; |
---|
321 | $signature = hash_hmac("sha256", $data, $secret); |
---|
322 | |
---|
323 | $smsPrice = array('80'=>500, '81'=>1000, '82'=>2000, '83'=>3000, '84'=>4000, '85'=>5000, '86'=>10000, '87'=>15000); |
---|
324 | $money = @$smsPrice[substr($arParams['short_code'], 0, 2)]; |
---|
325 | |
---|
326 | if ($arParams['signature'] == $signature) { |
---|
327 | $phone = preg_replace('/^84/', '0', $arParams['msisdn']); |
---|
328 | preg_match('/^nc +(\w+) *(\d*)/i', $arParams['mo_message'], $match); |
---|
329 | $key = strtolower(@$match[1]); |
---|
330 | $uid = @$match[2]; |
---|
331 | $findid = ($key == 'nt' && is_numeric($uid)); |
---|
332 | if ($findid) $tbluser = TbluserPeer::retrieveByPk($uid); |
---|
333 | else $tbluser = $this->getUserField(TbluserPeer::US_PHONE, $phone); |
---|
334 | |
---|
335 | if ($tbluser != null) { |
---|
336 | switch ($key) { |
---|
337 | case 'kh': |
---|
338 | if ($tbluser->getMobileConfirm() == 0) { |
---|
339 | $tbluser->setUsScore($tbluser->getUsScore() + sfConfig::get('app_user_activate_point')); |
---|
340 | $tbluser->setMobileConfirm(1); |
---|
341 | $tbluser->save(); |
---|
342 | $arResponse['sms'] = 'Kich hoat thanh cong tai khoan '.$tbluser->getUsUsername(); |
---|
343 | } else { |
---|
344 | $arResponse['sms'] = 'Tai khoan '.$tbluser->getUsUsername().' da duoc kich hoat'; |
---|
345 | } |
---|
346 | break; |
---|
347 | case 'mk': |
---|
348 | $passwd = myUtility::create_password(); |
---|
349 | $tbluser->setUsPassword(md5($passwd)); |
---|
350 | $tbluser->setMobileConfirm(1); |
---|
351 | $tbluser->save(); |
---|
352 | $arResponse['sms'] = 'Tai khoan Violet.vn, ten truy nhap: '.$tbluser->getUsUsername().', mat khau: '.$passwd; |
---|
353 | break; |
---|
354 | case 'nt': |
---|
355 | $tbluser->doTransaction($money, 'sms', $phone); |
---|
356 | $arResponse['sms'] = 'Tai khoan '.$tbluser->getUsUsername().' da duoc nap them '.$money.' dong, hien dang co '.$tbluser->getUsMoney().' dong'; |
---|
357 | break; |
---|
358 | default: |
---|
359 | $arResponse['sms'] = 'Tin nhan cua quy vi khong dung cu phap cua Violet.vn'; |
---|
360 | } |
---|
361 | } else { |
---|
362 | $arResponse['sms'] = 'Khong tim thay tai khoan nao co '.($findid? ('id '.$uid): ('so dien thoai '.$phone)).' tren Violet.vn'; |
---|
363 | } |
---|
364 | } else { |
---|
365 | $arResponse['sms'] = 'Sai chu ky'; |
---|
366 | } |
---|
367 | |
---|
368 | $arResponse['status'] = 1; |
---|
369 | $arResponse['type'] = 'text'; |
---|
370 | myUtility::log($arParams['msisdn'].': '.$arParams['mo_message'].' -> '.$arParams['short_code'].' | '.$arResponse['sms'], 'sms.log'); |
---|
371 | return $this->renderText(json_encode($arResponse)); |
---|
372 | } |
---|
373 | |
---|
374 | private function execPostRequest($url, $data){ |
---|
375 | $ch = curl_init(); |
---|
376 | curl_setopt($ch, CURLOPT_URL, $url); |
---|
377 | curl_setopt($ch, CURLOPT_POST, 1); |
---|
378 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
---|
379 | curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); |
---|
380 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
---|
381 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
---|
382 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
---|
383 | $result = curl_exec($ch); |
---|
384 | curl_close($ch); |
---|
385 | return $result; |
---|
386 | } |
---|
387 | |
---|
388 | public function executeCardcharge() { |
---|
389 | $src = $this->getRequestParameter('src'); |
---|
390 | $us_id = $this->getRequestParameter('us_id'); |
---|
391 | $token = $this->getRequestParameter('token'); |
---|
392 | if ($src == null || $token != md5($us_id.self::TOKENPW)) return $this->renderText('status=10'); |
---|
393 | |
---|
394 | $tbluser = TbluserPeer::retrieveByPk($us_id); |
---|
395 | if ($tbluser == null) return $this->renderText('status=5&errMsg=User not found'); |
---|
396 | |
---|
397 | $access_key = 'in3je3d6lxh8zx8m68ox'; |
---|
398 | $secret = 'evvx931itxysfnp9m94rf2vxd101zegr'; |
---|
399 | $type = $this->getRequestParameter('type'); |
---|
400 | $pin = $this->getRequestParameter('pin'); |
---|
401 | $serial = $this->getRequestParameter('serial'); |
---|
402 | |
---|
403 | $data = "access_key=".$access_key."&pin=".$pin."&serial=".$serial."&type=".$type; |
---|
404 | $signature = hash_hmac("sha256", $data, $secret); |
---|
405 | $data .= "&signature=".$signature; |
---|
406 | $res = json_decode($this->execPostRequest('https://api.1pay.vn/card-charging/v2/topup', $data)); |
---|
407 | $status = (int)$res->status; |
---|
408 | $amount = (int)$res->amount; |
---|
409 | $desc = $res->description; |
---|
410 | |
---|
411 | if ($status == 0) $tbluser->doTransaction($amount*2, 'card', $serial); |
---|
412 | $ip = myUtility::getRealIpAddr(); |
---|
413 | myUtility::log("$ip load $type $serial (pin $pin) from $src: ".($status==0? $amount.'VND': $desc), 'card.log'); |
---|
414 | return $this->renderText('status='.$status.'&amount='.$amount.'&money='.$tbluser->getUsMoney().'&errMsg='.$desc); |
---|
415 | } |
---|
416 | } |
---|
417 | |
---|
418 | ?> |
---|