You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
687 B

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