我需要能够使用PHP将字符串转换为8位二进制文件。那可能吗?该字符串将是图片网址,例如https://www.someurl.com/someimage.jpg
GBG刚刚告诉我,我发送的图片网址必须是8位二进制数组。
这是代码,可以正常工作,只需要$ bit8变量为二进制数组即可即可。
date_default_timezone_set('Europe/London');
class WsseAuthHeader extends SoapHeader
{
private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
function __construct($user, $pass, $ns = null)
{ if ($ns)
{
$this->wss_ns = $ns;
}
$auth = new stdClass();
$auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$username_token = new stdClass();
$username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
$security_sv = new SoapVar(
new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
parent::__construct($this->wss_ns, 'Security', $security_sv, true);
}
}
$username = "XXXXXX";
$password = "XXXXXX";
$wsse_header = new WsseAuthHeader($username, $password);
$options = array(
'soap_version' => SOAP_1_1,
'exceptions' => true,
'trace' => 1,
'wdsl_local_copy' => true
);
// This is currently linked to the pilot or test site.
$wsdl = 'https://pilot.id3global.com/ID3gWS/ID3global.svc?wsdl';
$soapClient = new SoapClient($wsdl, $options);
$soapClient->__setSoapHeaders(array($wsse_header));
$objParam = new stdClass();
$objParam ->ProfileIDVersion = new stdClass();
$objParam ->ProfileIDVersion ->ID ='XXXXXXXXXXXXXX'; // This can be found via the admin portal of id3 global.
$objParam ->ProfileIDVersion ->Version =0; // Setting this to zero will by default call the latest active version of the profile$objParam ->CustomerReference particular customer
$objParam ->InputData = new stdClass();
$objParam ->InputData->UploadAndProcess = new stdClass();
$objParam ->InputData->UploadAndProcess->DocImage = new stdClass();
$objParam ->InputData->UploadAndProcess->DocImage->$bit8;
if (is_soap_fault($soapClient)) {
throw new Exception(" {$soapClient->faultcode}: {$soapClient->faultstring} ");
}
$objRet = null;
try
{
$objRet = $soapClient->AuthenticateSP($objParam);
echo '<pre>';
print"Decision Band :".($objRet->AuthenticateSPResult->BandText)."<br>";
echo '</pre>';}
catch (Exception $e) {
echo "<pre>";
print_r($e);
echo "</pre>";
}
if (is_soap_fault($objRet))
{
throw new Expception(" {$objRet->faultcode}: {$objRet->faultstring} ");
}