こんにちは、ハブユーザーの皆様。
LanBillingとRTUのアカウントのステータスを同期するタスクがありました。
実装オプションを共有したいと思います。
中古
ランビリングv.1.8
RTUクラス4および5
PHP 5.3
mysql 5.0.51a-24 + lenny5
cron
実装
LanBillingアカウントステータスデータはvgroupsテーブルに保存されます。
テーブルフィールド:
ブロック -
ブロック状態(0-ロック解除、> 0-ブロック)
blk_req-ブロックのリクエストのステータス(!= 0 and!=ブロック-ブロック
、! = 0および=ブロック-ロック解除)
cronタスクでは、指定された間隔でphpスクリプトの実行を追加します。これにより、フィールドステータスが取得されます
LanBillingデータベースのblk_req、標準RTUスクリプト(set.aspxまたはget.aspx)の1つにsoapコマンドを送信し、trueの場合、
blockedおよび
blk_reqフィールドの値を変更します
SOAPリクエストを送信する機能
function xmlHttpsReq($xml,$type){ $ch = curl_init('https://IP_:/mobile_request/'.$type.'.aspx?admin'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $data=curl_exec($ch); $result=substr($data,0,strpos($data,'</Root>')+7); if( curl_errno($ch) != 0 ) { die('CURL_error: ' . curl_errno($ch) . ', ' . curl_error($ch)); }; curl_close($ch); return $result; }
すべてのユーザーに関するデータを受信する機能
function getUserList() { $data=xmlHttpsReq('<commands><command name="Get" table="User" /></commands>','get'); $xml = new SimpleXMLElement($data); foreach ($xml->command->user as $user) { $usr[]=$user; } return $usr; }
ログインによりユーザーデータを受信する機能
function getUser($ID) { $data=xmlHttpsReq('<commands><command name="Get" table="User"><item><id>'.$ID.'</id></item></command></commands>','get'); $xml = new SimpleXMLElement($data); return $xml->command->user; }
アカウントのパラメーターを設定する機能
function setUser($arr) { $converter = new Array2XML(); $obj = $converter->convert($arr); $data=xmlHttpsReq('<commands><command name="Edit" table="User">'.$obj.'</command></commands>','set'); $xml = new SimpleXMLElement($data); return $xml->command->item->result; }
配列をxmlに変換するクラス
class Array2XML { private $writer; private $rootName = 'item'; function __construct() { $this->writer = new XMLWriter(); } public function convert($data) { $this->writer->openMemory(); $this->writer->startElement($this->rootName); if (is_array($data)) { $this->getXML($data); } $this->writer->endElement(); return $this->writer->outputMemory(); } public function setVersion($version) { $this->version = $version; } public function setEncoding($encoding) { $this->encoding = $encoding; } public function setRootName($rootName) { $this->rootName = $rootName; } private function getXML($data) { foreach ($data as $key => $val) { if (is_numeric($key)) { $key = 'key'.$key; } if (is_array($val)) { $this->writer->startElement($key); $this->getXML($val); $this->writer->endElement(); } else { $this->writer->writeElement($key, $val); } } } }
アカウント設定を変更するには、ログインとGUIDを知る必要があります。
現在の実装では、RTU APIではログインによるアカウントのGUIDの取得が許可されていないため(
getUser関数)、
getUserList関数を使用してGUIDを取得します
実装
mysql_connect(HOST,USERNAME,PASSWORD); mysql_select_db(DBNAME);
コメントを歓迎します。