MessageDigestUtil.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\utils\Ocr\Util;
  8. /*
  9. * Licensed to the Apache Software Foundation (ASF) under one
  10. * or more contributor license agreements. See the NOTICE file
  11. * distributed with this work for additional information
  12. * regarding copyright ownership. The ASF licenses this file
  13. * to you under the Apache License, Version 2.0 (the
  14. * "License"); you may not use this file except in compliance
  15. * with the License. You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing,
  20. * software distributed under the License is distributed on an
  21. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22. * KIND, either express or implied. See the License for the
  23. * specific language governing permissions and limitations
  24. * under the License.
  25. */
  26. use yii\base\Exception;
  27. class MessageDigestUtil
  28. {
  29. /**
  30. * md5和base64处理
  31. *
  32. * @param $input
  33. * @return
  34. */
  35. public static function Base64AndMD5($input)
  36. {
  37. if ($input == null || strlen($input) == 0) {
  38. throw new Exception("input can not be null");
  39. }
  40. return base64_encode(md5(unpack('C*', $input)));
  41. }
  42. /**
  43. * UTF-8编码转换为ISO-9959-1
  44. *
  45. * @param str
  46. * @return
  47. */
  48. public static function Utf8ToIso88591($input)
  49. {
  50. if ($input == null || strlen($input) == 0) {
  51. return $input;
  52. }
  53. return mb_convert_encoding($input, "ISO-8859-1", "UTF-8");
  54. }
  55. }