SHA1.php 772 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace WeWork\Crypt;
  3. /**
  4. * 计算公众平台的消息签名接口
  5. */
  6. class SHA1
  7. {
  8. /**
  9. * 用SHA1算法生成安全签名
  10. *
  11. * @param string $token 票据
  12. * @param string $timestamp 时间戳
  13. * @param string $nonce 随机字符串
  14. * @param string $encrypt_msg 密文消息
  15. * @return array
  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. return array(ErrorCode::$ComputeSignatureError, null);
  27. }
  28. }
  29. }