1
0

Sha1.php 720 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace weworkapi\receive;
  3. use weworkapi\receive\ErrorCode;
  4. /**
  5. * SHA1 class
  6. *
  7. * 计算公众平台的消息签名接口.
  8. */
  9. class Sha1
  10. {
  11. /**
  12. * 用SHA1算法生成安全签名
  13. * @param string $token 票据
  14. * @param string $timestamp 时间戳
  15. * @param string $nonce 随机字符串
  16. * @param string $encrypt 密文消息
  17. */
  18. public function getSHA1($token, $timestamp, $nonce, $encrypt_msg)
  19. {
  20. //排序
  21. try {
  22. $array = array($encrypt_msg, $token, $timestamp, $nonce);
  23. sort($array, SORT_STRING);
  24. $str = implode($array);
  25. return array(ErrorCode::$OK, sha1($str));
  26. } catch (Exception $e) {
  27. print $e . "\n";
  28. return array(ErrorCode::$ComputeSignatureError, null);
  29. }
  30. }
  31. }
  32. ?>