DecodeTrait.php 1006 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Common;
  3. trait DecodeTrait
  4. {
  5. public static function decodeBoxNo($arr = [])
  6. {
  7. $str = '';
  8. foreach ($arr as $item) {
  9. $str .= (int)$item;
  10. }
  11. return $str;
  12. }
  13. public static function decodeLocation($arr = [])
  14. {
  15. $str = '';
  16. foreach ($arr as $key => $item) {
  17. $str .= hexdec($item);
  18. if ($key === 0) {
  19. $str .= '.';
  20. }
  21. }
  22. return $str;
  23. }
  24. /**
  25. * 截取响应的数据串
  26. * @param $arr
  27. * @param $offset
  28. * @param bool $length
  29. * @return
  30. * Author: Mead
  31. */
  32. public static function stitching($arr, $offset, $length = false, $is_string = true)
  33. {
  34. $body = [];
  35. if ($length === false) {
  36. $body = array_slice($arr, $offset);
  37. } else {
  38. $body = array_slice($arr, $offset, $length);
  39. }
  40. if (!$is_string) return $body;
  41. return implode('', $body);
  42. }
  43. }