发票管理apiadmin
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.
 
 
 

47 lines
1.0 KiB

<?php
namespace app\controller\api;
use app\BaseController;
use think\facade\Log;
use think\Request;
class Wx extends BaseController
{
protected $token = 'invoiceApi';
public function verify(Request $request)
{
$param = $request->param();
$signature = $param['signature'] ?? '';// 签名
$timestamp = $param['timestamp'] ?? '';// 时间戳
$nonce = $param['nonce'] ?? '';// 随机数
$echostr = $param['echostr'] ?? '0'; // 随机字符串
$checkRes = $this->checkSignature($signature,$timestamp,$nonce);
$param['res_error'] = $checkRes;
Log::write($param);
echo $echostr;die;
}
private function checkSignature($signature,$timestamp,$nonce):bool
{
$token = $this->token;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
}