Changeset 620 for pro-violet-viettel/sourcecode/service.php
- Timestamp:
- Nov 24, 2014 4:27:40 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pro-violet-viettel/sourcecode/service.php
r473 r620 1 1 <?php 2 require_once('/srv/www/sbg/application/libraries/nusoap/nusoap.php');3 2 4 $nusoap_server = new soap_server(); 5 $nusoap_server->configureWSDL('messageReceiverWSDL','urn:messageReceiverWSDL'); 6 7 $nusoap_server->soap_defencoding = 'UTF-8'; 8 $nusoap_server->methodreturnisliteral=TRUE; 9 10 $nusoap_server->wsdl->schemaTargetNamespace = 'http://soapinterop.org/xsd/'; 11 $nusoap_server->wsdl->addComplexType( 12 'messageReceiver', 13 'simpleType', 14 'struct', 15 '', 16 'SOAP-ENC:Array', 17 array( 18 'username'=>array('name'=>'username', 'type'=>'xsd:string'), 19 'password'=>array('name'=>'password', 'type'=>'xsd:string'), 20 'requestID'=>array('name'=>'requestID', 'type'=>'xsd:string'), 21 'userID'=>array('name'=>'userID', 'type'=>'xsd:string'), 22 'receiverID'=>array('name'=>'receiverID', 'type'=>'xsd:string'), 23 'serviceID'=>array('name'=>'serviceID', 'type'=>'xsd:string'), 24 'commandCode'=>array('name'=>'commandCode', 'type'=>'xsd:string'), 25 'contentType'=>array('name'=>'contentType', 'type'=>'xsd:string'), 26 'info'=>array('name'=>'info', 'type'=>'xsd:string'), 27 'receiveTime'=>array('name'=>'receiveTime', 'type'=>'xsd:string') 28 ) 29 ); 30 31 $nusoap_server->register ( 'MOReceiver', 32 array( 'username' => 'xsd:string', 33 'password' => 'xsd:string', 34 'requestID' => 'xsd:string', 35 'userID' => 'xsd:string', 36 'receiverID' => 'xsd:string', 37 'serviceID' => 'xsd:string', 38 'commandCode' => 'xsd:string', 39 'contentType' => 'xsd:string', 40 'info' => 'xsd:string', 41 'receiveTime' => 'xsd:string') 42 , array ('return' => 'xsd:string'), 43 'urn:messageReceiverWSDL',"urn:messageReceiverWSDL#MOReceiver","rpc","encoded"); 44 45 function MOReceiver($username, $password, $requestID, $userID, $receiverID, $serviceID, $commandCode, $contentType ,$info, $receiveTime) 3 function createLockFile ($lockFilePrefix, $maxReach, $timeToUnlock, $colSep = '|') 46 4 { 5 $currentTimeStamp = time(); 6 $filePath = $lockFilePrefix.'_lock'; 7 $fileExisted = file_exists($filePath); 8 $content = ''; 9 $lastTimeLock = ''; 10 $lockCount = 0; 11 $isLocked = 0; 47 12 13 if ($fileExisted) { 14 $content = file_get_contents($filePath); 15 } 16 17 if ($content != '') { 18 list($lockCount, $lastTimeLock, $isLocked) = explode ($colSep, $content); 19 } 20 21 $timeDiffMin = $lastTimeLock != '' ? dateDifference(date('Y-m-d H:i:s',$currentTimeStamp), date('Y-m-d H:i:s',$lastTimeLock), '%i') : 0; 22 23 24 if ($lockCount < $maxReach && $timeDiffMin < $timeToUnlock) { 25 $lockCount ++; 26 $isLocked = $lockCount < $maxReach ? 0:1; 27 } 28 else if ($timeDiffMin > $timeToUnlock) { 29 $lockCount = 0; 30 $isLocked = 0; 31 } 32 33 $lockTime = ($isLocked == 1) ? $lastTimeLock : $currentTimeStamp; 34 $content = $lockCount . $colSep . $lockTime . $colSep . $isLocked; 35 $fh = fopen ($filePath,'w'); 36 fwrite ($fh, $content); 37 fclose ($fh); 38 39 return $timeDiffMin; 48 40 } 49 41 50 $nusoap_server->service(file_get_contents("php://input")); 42 function releaseLockFile ($lockFilePrefix) 43 { 44 $filePath = $lockFilePrefix.'_lock'; 45 $fileExisted = file_exists($filePath); 46 if ($fileExisted) { 47 unlink($filePath); 48 } 49 } 50 51 function dateDifference($date_1 , $date_2 , $differenceFormat = '%a' ) 52 { 53 $datetime1 = date_create($date_1); 54 $datetime2 = date_create($date_2); 55 $interval = date_diff($datetime1, $datetime2); 56 return $interval->format($differenceFormat); 57 } 58 59 $username = '0988568786'; 60 $maxReach = 3; 61 $timeToUnlock = 1; 62 echo createLockFile($username, $maxReach, $timeToUnlock); 63 releaseLockFile ($username); 64 65
Note: See TracChangeset
for help on using the changeset viewer.