-
-
Save spaantje/a9cbb59ea93a56e6694d43d465ff7849 to your computer and use it in GitHub Desktop.
<?php | |
$api = resolve(CurateleEnBewindregisterApi::class); | |
$result = $api->search($client->lastname, $client->birthday); | |
// birthday format = Y-m-d |
<?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; | |
} | |
} |
<?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]; | |
}); | |
} | |
} |
<?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>'; | |
} | |
} |
@MickeyMuis Kijk even naar deze repo: https://github.com/spaantje/bewind-register-api-v2
Deze gaat wel uit van een config() helper om de api token en username op te halen.
En van een Cache class voor caching van de token (scheelt weer bij toekomstige requests).
En je hebt Carbon nodig.
Maar hiermee moet je in ieder geval vooruit kunnen.
@spaantje
Ik ga het uitproberen.
Alvast bedankt voor deze info.
groet
Mick
Hoi @spaantje, bedankt voor deze github, door te googlen op de wsdl kwam ik hier uit.
deze:
https://curateleenbewindregisterservice.rechtspraak.nl/ccbrdataservice.svc?wsdl
Want die wsdl lijkt niet meer te werken. Enig idee waarom die er uit ligt of is de url misschien veranderd?
Groet Sierky
edit: want ik sprak de verkeerde aan, excuses @spaantje
Goedemiddag Sierky,
Hij is tegenwoordig te bereiken op: https://ccbrservice.rechtspraak.nl/ccbrdataservice.svc?wsdl
Zie ook deze repo: https://github.com/spaantje/bewind-register-api-v2
Groeten,
Sonny
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
Dank voor deze gist. Ik gebruik geen laravel en probeer dus een en ander te 'vertalen' naar 'gewoon' php.
Het aanvragen van een token gaat goed maar ik loop vast op het vervolg.
$wsdl = 'https://ccbrservice.rechtspraak.nl/ccbrdataservice.svc?wsdl';
$achternaam = "Vermeijdt";
$birthday = "1980-10-08";
$soap = new SoapClient($wsdl, [
'uri' => 'ccbr.rechtspraak.nl/v1/CcbrDataservice/berichten',
'location' => 'ccbrservice.rechtspraak.nl/ccbrdataservice.svc',
'soap_version' => SOAP_1_2,
'exceptions' => true,
'trace' => true,
'cache_wsdl' => WSDL_CACHE_MEMORY,
]);
$auth = new stdClass();
$auth->Security = new SoapVar($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');
$soap->__setSoapHeaders([
new SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', 'https://ccbr.rechtspraak.nl/v1/CcbrDataservice/ZoekRegisterkaarten'),
new SoapHeader('http://www.w3.org/2005/08/addressing', 'To', 'https://ccbrservice.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 = $soap->ZoekRegisterkaarten(
new SoapVar('' .
'' .
'' . $achternaam . '' .
'' .
'<b:Datum>' . $birthday . '</b:Datum>' .
'<b:Jaar i:nil="true"/>' .
'' .
'', XSD_ANYXML, null, null, null, null)
);
Ik probeer het te snappen maar eerlijk gezegd ...