sha1.php 867 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. include_once "errorCode.php";
  8. /**
  9. * SHA1 class
  10. *
  11. * 计算公众平台的消息签名接口.
  12. */
  13. class SHA1
  14. {
  15. /**
  16. * 用SHA1算法生成安全签名
  17. * @param string $token 票据
  18. * @param string $timestamp 时间戳
  19. * @param string $nonce 随机字符串
  20. * @param string $encrypt 密文消息
  21. */
  22. public function getSHA1($token, $timestamp, $nonce, $encrypt_msg)
  23. {
  24. //排序
  25. try {
  26. $array = array($encrypt_msg, $token, $timestamp, $nonce);
  27. sort($array, SORT_STRING);
  28. $str = implode($array);
  29. return array(ErrorCode::$OK, sha1($str));
  30. } catch (Exception $e) {
  31. //print $e . "\n";
  32. return array(ErrorCode::$ComputeSignatureError, null);
  33. }
  34. }
  35. }
  36. ?>