首页 > 解决方案 > 在 PHP 中将字符串转换为 8 位二进制

问题描述

我需要能够使用 PHP 将字符串转换为 8 位二进制文​​件。那可能吗?该字符串将是一个图像 URL,例如https://www.someurl.com/someimage.jpg

我正在做这个功能:https ://www.id3globalsupport.com/Website/content/Sample%20Code/Web%20Dev%20Guide%20HTML/html/6dfaafdb-ade8-1020-d02d-d43822eb4ae7.htm

GBG 刚刚告诉我,我发送的图像 URL 需要是 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} ");
}

标签: phpstringbinary8-bit

解决方案


推荐阅读