标题给了我一些SO链接但不幸的是我无法让它们工作。我对SOAP完全不熟悉。我有一个wsdl链接,我需要通过soap调用一些方法。
我被困在一个特定的地方,它说
未捕获的SoapFault异常:[客户端]发现错误" uri"物业 在此代码中生成错误。
class SoapClientCompatibility extends SoapClient{
public function __construct($wsdl, $options){
// do things here, like:
// download the wsdl using curl
}}function soapClientWSSecurityHeader($user, $password){
// Creating date using yyyy-mm-ddThh:mm:ssZ format
$tm_created = gmdate('Y-m-d\TH:i:s\Z');
$tm_expires = gmdate('Y-m-d\TH:i:s\Z', gmdate('U') + 180); //only necessary if using the timestamp element
// Generating and encoding a random number
$simple_nonce = mt_rand();
$encoded_nonce = base64_encode($simple_nonce);
// Compiling WSS string
$passdigest = base64_encode(sha1($simple_nonce . $tm_created . $password, true));
// Initializing namespaces
$ns_wsse = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
$ns_wsu = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
$password_type = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest';
$encoding_type = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary';
// Creating WSS identification header using SimpleXML
$root = new SimpleXMLElement('<root/>');
$security = $root->addChild('wsse:Security', null, $ns_wsse);
//the timestamp element is not required by all servers
$timestamp = $security->addChild('wsu:Timestamp', null, $ns_wsu);
$timestamp->addAttribute('wsu:Id', 'Timestamp-28');
$timestamp->addChild('wsu:Created', $tm_created, $ns_wsu);
$timestamp->addChild('wsu:Expires', $tm_expires, $ns_wsu);
$usernameToken = $security->addChild('wsse:UsernameToken', null, $ns_wsse);
$usernameToken->addChild('wsse:Username', $user, $ns_wsse);
$usernameToken->addChild('wsse:Password', $passdigest, $ns_wsse)->addAttribute('Type', $password_type);
$usernameToken->addChild('wsse:Nonce', $encoded_nonce, $ns_wsse)->addAttribute('EncodingType', $encoding_type);
$usernameToken->addChild('wsu:Created', $tm_created, $ns_wsu);
// Recovering XML value from that object
$root->registerXPathNamespace('wsse', $ns_wsse);
$full = $root->xpath('/root/wsse:Security');
$auth = $full[0]->asXML();
print_r($auth);
return new SoapHeader($ns_wsse, 'Security', new SoapVar($auth, XSD_ANYXML), true,'https://mywebsite.com');
}
class Valid {
function Valid($hn, $vc)
{
$this->healthNumber = $healthNumber;
$this->versionCode = $versionCode;
}
}
$hcvRequest = array(
"healthNumber" => "1286844022",
"versionCode" => "YX"
);
$valid = array(
"hcvRequest" => $hcvRequest
);
$params = array(
"requests" => $valid
);
$client = new SoapClientCompatibility('https://example.com/?wsdl');$client->__setSoapHeaders(soapClientWSSecurityHeader('someemail@email.com', 'somepassword'));
echo "<pre>";
$response = $client->__soapCall("validate", array($params));
print_r($client);
print_r($response);