透過 php 轉碼。
//建立檔案清單 <td></td>
// 01 23 456789112345 67 89 21 2345678931 23 45 678941234567 89 51234567896123456789712345678981234567
// | | | | | | | | |
//EX: 07 91 889628911234 04 0A A1 9028214365 00 08 211150419593 23 1200540065007300746E2C8A66003900370039
// | | | | | | | | | | | |
// | | | | | | | | | | | 用戶資訊(TP-UD)
// | | | | | | | | | | 用戶資訊長度(TP-UDL)訊息長度 23
// | | | | | | | | | 服務時間戳(TP-SCTS)時間點: 211150419593 => 121105145939 => 2012/11/05 14:59:39
// | | | | | | | | 用戶資訊編碼方式(TP-DCS)UCS2-CODE
// | | | | | | | 協定標識(TP-PID) 是普通GSM 類型,點到點方式
// | | | | | | 回復地址(TP-RA) 來自: 9028214365 (0982123456)
// | | | | | 回復地址格式(TON/NPI)
// | | | | 回復位址數位個數 0A A=10(16進制)
// | | | 基本參數(TP-MTI/MMS/RP)
// | | SMSC號碼:886982194008
// | SMSC 地址格式(TON/NPI): +886前的字碼 "+"
// SMSC 位址資訊的長度 7位元組
//CH: 07 91 889628911234 04 0A A1 9028214365 00 08 121105145939 23 UCS2-CODE
//

// 所需要轉的 PDU 碼 "123 How are you? I am fine,thank you."
$PDU = '31D90C847CDF41617919947FD77FA02428DC0699D3EE320B444787DD6B50FE5D7701';

echo "PDU = $PDU\n<br>";

// 16 進位轉二進位
$HextoBin = hexbin($PDU);
echo "Hex to binary = $HextoBin\n<br>";

// 二進位轉 Septets
$BinSep = binsep($HextoBin);
echo "Binary to Septets = $BinSep\n<br>";

// Septets 7 Bit 切割
$SevenBit = seven($BinSep);
echo "Septets Seven Bit = $SevenBit\n<br>";

// 二進位轉 16 進位
$HexBit = binhex($SevenBit);
echo "Bin to Hex = $HexBit\n<br>";

// 16 進位轉 ASCII String
$HextoStr = hex2str($HexBit);
echo "Hex to String = $HextoStr\n<br>";

function binsep($bin){
$t = '';

// 每 56 bit 為一個單位
for($m=0;$m<strlen($bin)/56;$m+=1)
{
echo "This loop is ".$m."\n<br>";
// 每 56 bit 為一個單位
$tmp1 = substr($bin,$m*56,56);
echo "tmp1 is ".$tmp1."\n<br>";
// 每 8 bit 為一組
for($i=0;$i<8;$i+=1)
{
// 每 8 bit 為一組
$tmp2 = substr($tmp1,$i*8,8);
$b[$i] = substr($tmp2,$i+1);
$a[$i+1] = substr($tmp2,0,$i+1);
$tmp3 = $b[$i].$a[$i];
$t .= $tmp3;
}
}
echo "t is ".$t."\n<br>";
return($t);
}

function seven($sev) {
$s='';
for($i=0;$i<strlen($sev)/7;$i++)
{
$s .= "0".substr($sev,$i*7,7);
//echo "s is ".$s."\n<br>";
}
return($s);
}

function hextostr($x) {
$s='';
foreach(explode("\n",trim(chunk_split($x,2))) as $h) $s.=chr(hexdec($h));
return($s);
}

function hex2str($hex) {
for($i=0;$i<strlen($hex);$i+=2)
{
$str .= chr(hexdec(substr($hex,$i,2)));
}
return $str;
}

// 53 → 101 0011
function hexbin($hex){
$bin='';
for($i=0;$i<strlen($hex);$i++)
$bin.=str_pad(decbin(hexdec($hex{$i})),4,'0',STR_PAD_LEFT);
return $bin;
}

function binhex($str)
{
// 取消字串中的空白部分
$str = str_replace(" ","",$str);
// ======= explode — Split a string by string =======
// ======= chunk_split — Split a string into smaller chunks =======
$text_array = explode("\r\n",chunk_split($str,8));
for ($i = 0; $i < count($text_array)-1; $i++)
{
// ======== base_convert — Convert a number between arbitrary bases =======
$string .= base_convert($text_array[$i],2,16);
}
return $string;
}

?>

flyfox 發表在 痞客邦 PIXNET 留言(0) 人氣()