Files
EasySoft-ZenTaoPMS/bin/getbugs.php
2010-11-10 08:09:52 +00:00

78 lines
2.3 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env php
<?php
/* 包含http客户端类snoopy。在禅道lib/snoopy里面可以找到。*/
include dirname(dirname(__FILE__)) . '/lib/snoopy/snoopy.class.php';
/* 用来登录的地址,用户名和密码。*/
$zentaoRoot = "http://demo.zentao.net/"; // 请根据实际的情况进行修改。
$account = "demo";
$password = "123456";
$requestType = 'PATH_INFO'; // 可选值: GET|PATH_INFO。
/* 设置API地址。*/
if($requestType == 'GET')
{
/* API地址以GET方式为例。*/
$loginAPI = $zentaoRoot . "?m=user&f=login";
$sessionAPI = $zentaoRoot . "?m=api&f=getSessionID&t=json";
$myBugAPI = $zentaoRoot . "?m=my&f=bug&t=json";
$superMyBugAPI = $zentaoRoot . "?m=api&f=getModel&module=bug&methodName=getUserBugPairs&params=account=$account";
}
elseif($requestType == 'PATH_INFO')
{
/* API地址以PATH_INFO方式为例。*/
$loginAPI = $zentaoRoot . "user-login.json?a=1";
$sessionAPI = $zentaoRoot . "api-getsessionid.json?a=1";
$myBugAPI = $zentaoRoot . "my-bug.json?a=1";
$superMyBugAPI = $zentaoRoot . "api-getmodel-bug-getUserBugPairs-account=$account.json?a=1";
}
/* 获取session. */
$snoopy = new Snoopy;
$snoopy->fetch($sessionAPI);
$session = json_decode($snoopy->results);
$session = json_decode($session->data);
/*用户登录*/
$authHash = md5(md5($password) . $session->rand);
$submitVars["account"] = $account;
$submitVars["password"] = $authHash;
$snoopy->cookies[$session->sessionName] = $session->sessionID;
$snoopy->submit($loginAPI, $submitVars);
/* 直接调用my模块的bugs页面。*/
$snoopy->fetch($myBugAPI . "&$session->sessionName=$session->sessionID");
$result = json_decode($snoopy->results);
if($result->status == 'success' && md5($result->data) == $result->md5)
{
$bugs = json_decode($result->data)->bugs;
}
else
{
echo "called failed or transfered not complete.";
exit;
}
if($bugs)
{
foreach($bugs as $bug) echo $bug->id . "\t" . $bug->title . "\n";
}
else
{
echo 'no bugs' . "\n";
}
/* 通过超级model调用。*/
$snoopy->fetch($superMyBugAPI . "&$session->sessionName=$session->sessionID");
$result = json_decode($snoopy->results);
if(is_object($result))
{
foreach($result as $id=>$bug) echo $id . "\t" . $bug . "\n";
}
else
{
echo 'no bugs' . "\n";
}
?>