需要利用小程序 websocket 发送 byte.
php 代码
<?php
$str0 = '01 00 00 16 00 00 00 9c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 /r /n';
$byte_str0 = tobyte($str0);
function tobyte($str)
{
$arr = str_split(str_ireplace(' ', '', $str), 2);//去掉空格后,2 字符一段切分成数组
$byte_arr = array();
foreach ($arr as $h) {
$byte_arr[] = chr(hexdec($h));
}
$byte_str = implode('', $byte_arr);
return $byte_str;
}
- 上面这段如何用 JS 实现?
- ArrayBuffe 与上面的有关系?