本文整理汇总了PHP中Pack函数的典型用法代码示例。如果您正苦于以下问题:PHP Pack函数的具体用法?PHP Pack怎么用?PHP Pack使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Pack函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Query
public function Query()
{
$Length = StrLen($this->ServerIP);
$Data = Pack('cccca*', HexDec($Length), 0, 0x4, $Length, $this->ServerIP) . Pack('nc', $this->ServerPort, 0x1);
Socket_Send($this->Socket, $Data, StrLen($Data), 0);
// handshake
Socket_Send($this->Socket, "", 2, 0);
// status ping
$Length = $this->ReadVarInt();
// full packet length
if ($Length < 10) {
return FALSE;
}
Socket_Read($this->Socket, 1);
// packet type, in server ping it's 0
$Length = $this->ReadVarInt();
// string length
$Data = Socket_Read($this->Socket, $Length, PHP_NORMAL_READ);
// and finally the json string
if ($Data === FALSE) {
throw new MinecraftPingException('Server didn\'t return any data');
}
$Data = JSON_Decode($Data, true);
if (JSON_Last_Error() !== JSON_ERROR_NONE) {
if (Function_Exists('json_last_error_msg')) {
throw new MinecraftPingException(JSON_Last_Error_Msg());
} else {
throw new MinecraftPingException('JSON parsing failed');
}
return FALSE;
}
return $Data;
}
示例2: WriteData
private function WriteData($Command, $String = "")
{
$Data = Pack('VV', $this->RequestId++, $Command) . $String . "";
$Data = Pack('V', StrLen($Data)) . $Data;
$Length = StrLen($Data);
return $Length === FWrite($this->Socket, $Data, $Length);
}
示例3: Write
public function Write($Header, $String = '')
{
// Pack the packet together
$Command = Pack('VV', ++$this->RconRequestId, $Header) . $String . "";
// Prepend packet length
$Command = Pack('V', StrLen($Command)) . $Command;
$Length = StrLen($Command);
return $Length === FWrite($this->RconSocket, $Command, $Length);
}
示例4: Write
public function Write($Header, $String = '')
{
switch ($this->Socket->Engine) {
case CI_SourceQuery::GOLDSOURCE:
$Command = Pack('cccca*', 0xff, 0xff, 0xff, 0xff, $String);
$Length = StrLen($Command);
return $Length === FWrite($this->Socket->Socket, $Command, $Length);
case CI_SourceQuery::SOURCE:
// Pack the packet together
$Command = Pack('VV', ++$this->RequestId, $Header) . $String . "";
// Prepend packet length
$Command = Pack('V', StrLen($Command)) . $Command;
$Length = StrLen($Command);
return $Length === FWrite($this->RconSocket, $Command, $Length);
}
}
示例5: WriteData
private function WriteData($Command, $Append = "")
{
$Command = Pack('c*', 0xfe, 0xfd, $Command, 0x1, 0x2, 0x3, 0x4) . $Append;
$Length = StrLen($Command);
if ($Length !== FWrite($this->Socket, $Command, $Length)) {
throw new MinecraftQueryException("Failed to write on socket.");
}
$Data = FRead($this->Socket, 2048);
if ($Data === false) {
throw new MinecraftQueryException("Failed to read from socket.");
}
if (StrLen($Data) < 5 || $Data[0] != $Command[2]) {
return false;
}
return SubStr($Data, 5);
}
示例6: Write
public function Write($Header, $String = '')
{
$Command = Pack('ccccca*', 0xff, 0xff, 0xff, 0xff, $Header, $String);
$Length = StrLen($Command);
return $Length === FWrite($this->Socket, $Command, $Length);
}
示例7: Iconv
$Hash .= $v;
#-------------------------------------------------------------------------------
}
#-------------------------------------------------------------------------------
} else {
#-------------------------------------------------------------------------------
//Конвертация из текущей кодировки (UTF-8)
//необходима только если кодировка магазина отлична от Windows-1251
$value = Iconv("utf-8", "windows-1251", $value);
#-------------------------------------------------------------------------------
$Hash .= $value;
#-------------------------------------------------------------------------------
}
#-------------------------------------------------------------------------------
}
#-------------------------------------------------------------------------------
// Формирование значения параметра WMI_SIGNATURE, путем
// вычисления отпечатка, сформированного выше сообщения,
// по алгоритму MD5 и представление его в Base64
Debug(SPrintF('[comp/Invoices/PaymentSystems/W1]: Hash = %s', $Hash));
#-------------------------------------------------------------------------------
$Send['WMI_SIGNATURE'] = Base64_Encode(Pack("H*", sha1($Hash . $Settings['Hash'])));
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# так как CSRF уже есть, удаляем её из списка полей, иначе задублируется
unset($Send['CSRF']);
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
return $Send;
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
示例8: WriteData
private function WriteData($Command, $Append = "")
{
$Command = Pack('c*', 0xfe, 0xfd, $Command, 0x1, 0x2, 0x3, 0x4) . $Append;
$Length = StrLen($Command);
if ($Length !== FWrite($this->Socket, $Command, $Length)) {
return false;
}
$Data = FRead($this->Socket, 1440);
if (StrLen($Data) < 5 || $Data[0] != $Command[2]) {
return false;
}
return SubStr($Data, 5);
}
示例9: Config
#-------------------------------------------------------------------------------
$Config = Config();
#-------------------------------------------------------------------------------
$Settings = $Config['Invoices']['PaymentSystems']['W1'];
#-------------------------------------------------------------------------------
UkSort($Args, "strcasecmp");
#-------------------------------------------------------------------------------
$Values = "";
#-------------------------------------------------------------------------------
foreach ($Args as $Key => $Value) {
if ($Key != "WMI_SIGNATURE") {
$Values .= $Value;
}
}
#-------------------------------------------------------------------------------
if (Base64_Encode(Pack("H*", sha1($Values . $Settings['Hash']))) != $Args['WMI_SIGNATURE']) {
return ERROR | @Trigger_Error('[comp/www/Merchant/W1]: проверка подлинности завершилась не удачей');
}
#-------------------------------------------------------------------------------
$Invoice = DB_Select('Invoices', array('ID', 'Summ'), array('UNIQ', 'ID' => $OrderID));
#-------------------------------------------------------------------------------
switch (ValueOf($Invoice)) {
case 'error':
return ERROR | @Trigger_Error(500);
case 'exception':
return ERROR | @Trigger_Error(400);
case 'array':
break;
default:
return ERROR | @Trigger_Error(101);
}