6 changed files with 103 additions and 5 deletions
@ -0,0 +1,47 @@ |
|||
<?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; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
<?php |
|||
|
|||
return [ |
|||
// wxOpenConfig |
|||
'APP_ID' => env('wx.app_id'), |
|||
'APP_SECRET' => env('wx.app_secret'), |
|||
|
|||
//回调url |
|||
'REDIRECT_URI' => env('wx.redirect_uri'), |
|||
]; |
|||
Loading…
Reference in new issue