Created
September 14, 2018 16:23
-
-
Save nullcookies/b63098df805ea830346e093f02717e6e to your computer and use it in GitHub Desktop.
Confluence XML-RPC (atlassian.com)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fullname = 'test1'; | |
$username = 'test1'; | |
$email = 'test1@gmail.com'; | |
$password = '123456'; | |
$xmlRpc = new XmlRPC('http://localhost:8090','/rpc/xmlrpc'); | |
$xmlRpc->setCredentials('admin','123456'); | |
$token = $xmlRpc->call(xmlrpc_encode_request("confluence1.login", ['admin','123456'])); | |
$request = $xmlRpc->call(xmlrpc_encode_request("confluence1.addUser", [$token, ['email'=>$email,'fullname'=>$fullname, 'name' => $fullname], $password])); | |
class XmlRPC { | |
private $host; | |
private $path; | |
private $user; | |
private $pass; | |
public $token; | |
public function __construct($host,$path) { | |
$this->host = $host; | |
$this->path = $path; | |
} | |
public function setCredentials($user,$pass) { | |
$this->user = $user; | |
$this->pass = $pass; | |
} | |
public function setToken($token){ | |
$this->token = $token; | |
} | |
public function call($request) { | |
$auth = base64_encode($this->user.":".$this->pass); | |
$header = (version_compare(phpversion(), '5.2.8')) | |
? array("Content-Type: text/xml","Authorization: Basic $auth") | |
: "Content-Type: text/xml\r\nAuthorization: Basic $auth" ; //[1] | |
$context = stream_context_create(array('http' => array( | |
'method' => "POST", | |
'header' => $header, | |
'content' => $request | |
))); | |
$webservice= $this->host.$this->path; | |
$file = file_get_contents($webservice, false, $context); | |
return $token = xmlrpc_decode($file); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment