Last active
November 30, 2023 15:21
-
-
Save spaantje/a9cbb59ea93a56e6694d43d465ff7849 to your computer and use it in GitHub Desktop.
De Rechtspraak CCBR data service
This file contains hidden or 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 | |
$api = resolve(CurateleEnBewindregisterApi::class); | |
$result = $api->search($client->lastname, $client->birthday); | |
// birthday format = Y-m-d |
This file contains hidden or 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 | |
namespace App\Apis\Rechtspraak; | |
use SoapVar; | |
use stdClass; | |
use SoapClient; | |
use SoapHeader; | |
class CurateleEnBewindregisterApi | |
{ | |
/**@var SoapClient */ | |
protected $soap; | |
/** @var string */ | |
protected $wsdl = 'https://curateleenbewindregisterservice.rechtspraak.nl/ccbrdataservice.svc?wsdl'; | |
/** @var RechtspraakApi */ | |
protected $tokenApi; | |
public function __construct() | |
{ | |
$this->tokenApi = resolve(RechtspraakApi::class); | |
$this->soap = new SoapClient($this->wsdl, [ | |
'uri' => 'ccbr.rechtspraak.nl/v1', | |
'location' => 'https://curateleenbewindregisterservice.rechtspraak.nl/ccbrdataservice.svc', | |
'soap_version' => SOAP_1_2, | |
'exceptions' => false, | |
'trace' => true, | |
'cache_wsdl' => WSDL_CACHE_MEMORY, | |
]); | |
} | |
/** | |
* Try to find a client based on the name / birthday | |
* | |
* @param $name | |
* @param $birthday | |
* @return mixed | |
* @throws \SoapFault | |
*/ | |
public function search($name, $birthday) | |
{ | |
$auth = new stdClass(); | |
$auth->Security = new SoapVar($this->tokenApi->token(), XSD_ANYXML, null, null, null, null); | |
$security = new SoapVar($auth, SOAP_ENC_OBJECT, null, null, null, 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'); | |
$this->soap->__setSoapHeaders([ | |
new SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', 'ccbr.rechtspraak.nl/v1/CcbrDataservice/ZoekRegisterkaarten'), | |
new SoapHeader('http://www.w3.org/2005/08/addressing', 'To', 'https://curateleenbewindregisterservice.rechtspraak.nl/ccbrdataservice.svc'), | |
new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $security), | |
]); | |
$response = $this->soap->ZoekRegisterkaarten( | |
new SoapVar(new ZoekRegisterkaartenSoapObject($name, $birthday), XSD_ANYXML, null, null, null, null) | |
); | |
return $response; | |
} | |
/** | |
* Try to find the datials based on the Registerkaart Aanduiding | |
* | |
* @param $RegisterkaartAanduiding | |
* @return mixed | |
* @throws \SoapFault | |
*/ | |
public function registerkaart($RegisterkaartAanduiding) | |
{ | |
$auth = new stdClass(); | |
$auth->Security = new SoapVar($this->tokenApi->token(), XSD_ANYXML, null, null, null, null); | |
$security = new SoapVar($auth, SOAP_ENC_OBJECT, null, null, null, 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'); | |
$this->soap->__setSoapHeaders([ | |
new SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', 'ccbr.rechtspraak.nl/v1/CcbrDataservice/RaadpleegRegisterkaart'), | |
new SoapHeader('http://www.w3.org/2005/08/addressing', 'To', 'https://curateleenbewindregisterservice.rechtspraak.nl/ccbrdataservice.svc'), | |
new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $security), | |
]); | |
$xml = '<RaadpleegRegisterkaart xmlns="ccbr.rechtspraak.nl/v1"><registerkaartAanduiding>' . $RegisterkaartAanduiding . '</registerkaartAanduiding></RaadpleegRegisterkaart>'; | |
$ZoekRegisterkaarten = new SoapVar($xml, XSD_ANYXML, null, null, null, null); | |
$response = $this->soap->RaadpleegRegisterkaart($ZoekRegisterkaarten); | |
return $response; | |
} | |
} |
This file contains hidden or 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 | |
namespace App\Apis\Rechtspraak; | |
use SoapVar; | |
use stdClass; | |
use SoapFault; | |
use SoapClient; | |
use SoapHeader; | |
use Carbon\Carbon; | |
use Illuminate\Support\Facades\Cache; | |
class RechtspraakApi | |
{ | |
/** | |
* Retrieve the token from Rechtspraak | |
* | |
* @return mixed | |
* @throws SoapFault | |
*/ | |
public function token() | |
{ | |
$wsdl = 'https://sts.rechtspraak.nl/adfs/services/trust/mex'; | |
$cache_token = config('rechtspraak.cache-token'); | |
$username = config('rechtspraak.username'); | |
$password = config('rechtspraak.password'); | |
// Try to get it from the cache so we don't have to request it multiple times.. | |
if (Cache::has($cache_token)) { | |
return Cache::get($cache_token); | |
} | |
$client = new SoapClient($wsdl, [ | |
'soap_version' => SOAP_1_2, | |
'exceptions' => true, | |
'trace' => true, | |
'cache_wsdl' => WSDL_CACHE_NONE, | |
]); | |
$wrapper = new stdClass(); | |
$wrapper->Username = new SoapVar($username, XSD_STRING, null, null, null, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); | |
$wrapper->Password = new SoapVar($password, XSD_STRING, null, null, null, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); | |
$auth = new stdClass(); | |
$auth->UsernameToken = new SoapVar($wrapper, SOAP_ENC_OBJECT, null, null, null, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); | |
$client->__setSoapHeaders([ | |
new SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', 'http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue'), | |
new SoapHeader('http://www.w3.org/2005/08/addressing', 'To', 'https://sts.rechtspraak.nl/adfs/services/trust/13/usernamemixed'), | |
new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $auth), | |
]); | |
$EndpointReference = new stdClass(); | |
$EndpointReference->Address = new SoapVar('https://curateleenbewindregisterservice.rechtspraak.nl/', XSD_STRING, null, null, null, "http://www.w3.org/2005/08/addressing"); | |
$AppliesTo = new stdClass(); | |
$AppliesTo->EndpointReference = new SoapVar($EndpointReference, SOAP_ENC_OBJECT, null, null, null, "http://www.w3.org/2005/08/addressing"); | |
$RSTRequest = new stdClass(); | |
$RSTRequest->AppliesTo = new SoapVar($AppliesTo, SOAP_ENC_OBJECT, null, null, null, "http://schemas.xmlsoap.org/ws/2004/09/policy"); | |
$RSTRequest->KeyType = new SoapVar('http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer', XSD_STRING, null, null, null, "http://docs.oasis-open.org/ws-sx/ws-trust/200512"); | |
$RSTRequest->RequestType = new SoapVar('http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue', XSD_STRING, null, null, null, "http://docs.oasis-open.org/ws-sx/ws-trust/200512"); | |
$RequestSecurityToken = new SoapVar($RSTRequest, SOAP_ENC_OBJECT, null, null, null, "http://docs.oasis-open.org/ws-sx/ws-trust/200512"); | |
$response = $client->__soapCall('Trust13IssueAsync', ['RequestSecurityToken' => $RequestSecurityToken], [ | |
'location' => 'https://sts.rechtspraak.nl/adfs/services/trust/13/usernamemixed' | |
]); | |
$token = $response->RequestSecurityTokenResponse->any; | |
// ToDo: Clean this up! | |
$expresion = '/<wsu:Expires [\S]*>(.*)<\/wsu:Expires>/m'; | |
preg_match($expresion, $token, $matches); | |
$expires = Carbon::parse($matches[1], 'Zulu')->setTimezone('Europe/Amsterdam'); | |
$re = '/<trust:RequestedSecurityToken>(.*)<\/trust:RequestedSecurityToken>/m'; | |
preg_match($re, $token, $matches); | |
return Cache::remember($cache_token, $expires, function () use ($matches) { | |
return $matches[1]; | |
}); | |
} | |
} |
This file contains hidden or 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 | |
namespace App\Apis\Rechtspraak; | |
class ZoekRegisterkaartenSoapObject | |
{ | |
public $voorvoegsel; | |
public $achternaam; | |
public $geboorte; | |
private $birthday; | |
public function __construct($name, $birthday) | |
{ | |
$this->achternaam = $name; // ToDo; normalize name, so we don't send any non utf-8 chars... | |
$this->birthday = $birthday; // ToDo; normalize birthday to be sure we have the correct format (Y-m-d)... | |
} | |
/** | |
* Use this object to create the XML needed for the request. | |
* | |
* @return string | |
*/ | |
public function __toString() | |
{ | |
return '<ZoekRegisterkaarten xmlns="ccbr.rechtspraak.nl/v1">' . | |
'<voorvoegsel/>' . | |
'<achternaam>' . $this->achternaam . '</achternaam>' . | |
'<geboorte xmlns:b="ccbr.rechtspraak.nl/v1/CcbrDataservice/berichten" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">' . | |
'<b:Datum>' . $this->birthday . '</b:Datum>' . | |
'<b:Jaar i:nil="true"/>' . | |
'</geboorte>' . | |
'</ZoekRegisterkaarten>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@spaantje,
Ik had het in de tussentijd gevonden en aan de praat gekregen met behulp ook van de code in deze repo.
Nogmaals bedankt, ik zal bewind-register-api-v2 er ook bij pakken.
Groetjes Sierky