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
772 B
31 lines
772 B
<?php
|
|
|
|
namespace WeWork\Crypt;
|
|
|
|
/**
|
|
* 计算公众平台的消息签名接口
|
|
*/
|
|
class SHA1
|
|
{
|
|
/**
|
|
* 用SHA1算法生成安全签名
|
|
*
|
|
* @param string $token 票据
|
|
* @param string $timestamp 时间戳
|
|
* @param string $nonce 随机字符串
|
|
* @param string $encrypt_msg 密文消息
|
|
* @return array
|
|
*/
|
|
public function getSHA1($token, $timestamp, $nonce, $encrypt_msg)
|
|
{
|
|
//排序
|
|
try {
|
|
$array = array($encrypt_msg, $token, $timestamp, $nonce);
|
|
sort($array, SORT_STRING);
|
|
$str = implode($array);
|
|
return array(ErrorCode::$OK, sha1($str));
|
|
} catch (\Exception $e) {
|
|
return array(ErrorCode::$ComputeSignatureError, null);
|
|
}
|
|
}
|
|
}
|
|
|