php - 在 PHP 中将字符串转换为 8 位二进制
问题描述
我需要能够使用 PHP 将字符串转换为 8 位二进制文件。那可能吗?该字符串将是一个图像 URL,例如https://www.someurl.com/someimage.jpg
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} ");
}
解决方案
推荐阅读
- javascript - 服务器运行时的Node.js javascript命令行?
- python - 如果数据类型是“时间戳”,我们可以过滤掉 z-score <-3 或 >3 的记录吗?
- node.js - 出现错误:表达式不可调用 Mongoose NextJS
- python - 如何将模糊匹配应用于数据框中的列
- javascript - 如何让这两个组件出现在同一行?(文本框标签和文本框)
- r - R:glm 中的起始值到底是什么以及如何指定?
- javascript - 在响应 onclick 中重定向到 index.html 文件
- typescript - TypeScript:如何使用变量推断类型在类之外定义另一个具有相同类型的变量
- c++ - 如何从 C++ 头文件中导出函数
- html - 如何将 html 表格行中的数据发送到后端