Skip to content

Instantly share code, notes, and snippets.

@nullcookies
Created September 14, 2018 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nullcookies/b63098df805ea830346e093f02717e6e to your computer and use it in GitHub Desktop.
Save nullcookies/b63098df805ea830346e093f02717e6e to your computer and use it in GitHub Desktop.
Confluence XML-RPC (atlassian.com)
<?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