租房掌柜微信小程序Api以及小程序前端模板
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.
 
 
 
 
 
 

56 lines
1.6 KiB

<?php
namespace crypt;
/**
* SHA1 class
*
* 计算公众平台的消息签名接口.
*/
class Sha1
{
/**
* 用SHA1算法生成安全签名
* @param string $token 票据
* @param string $timestamp 时间戳
* @param string $nonce 随机字符串
* @param string $encrypt 密文消息
*/
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) {
//print $e . "\n";
return array(ErrorCode::$ComputeSignatureError, null);
}
}
/**
* 签名生成
* @param unknown $appid
* @param unknown $encodingAesKey
* @param unknown $appToken
* @param unknown $token
* @param unknown $timestamp
* @param unknown $data
* @return multitype:string number |multitype:NULL number
*/
public function signature($appid,$encodingAesKey,$appToken,$token,$timestamp,$data) {
try {
$data['appid'] = $appid;
$data['encodingAesKey'] = $encodingAesKey;
$data['appToken'] = $appToken;
$data['token'] = $token;
$data['timestamp'] = $timestamp;
krsort($data);
$str = implode($data);
return array(ErrorCode::$OK, sha1($str));
} catch (\Exception $e) {
//print $e . "\n";
return array(ErrorCode::$ComputeSignatureError, null);
}
}
}