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