|
|
@@ -7,7 +7,7 @@
|
|
|
|
|
|
namespace common\components;
|
|
|
|
|
|
-use biz\platform\services\WxOpenService;
|
|
|
+use biz\weixin\services\WxOpenService;
|
|
|
use Lcobucci\JWT\Builder;
|
|
|
use Lcobucci\JWT\Parser;
|
|
|
use Lcobucci\JWT\ValidationData;
|
|
|
@@ -26,7 +26,7 @@ class jwt
|
|
|
$salt = Yii::$app->params['secretKey'];
|
|
|
$key = new Key($salt);
|
|
|
$host = httpUtil::getHost();
|
|
|
- $sourceId = WxOpenService::getSourceId();
|
|
|
+ $sourceId = httpUtil::getSourceId();
|
|
|
$jwtId = $sourceId . '_' . $uniqueId;
|
|
|
$token = (new Builder())->issuedBy($host)//发布者的url地址
|
|
|
->canOnlyBeUsedBy($host)//接受者的url地址
|
|
|
@@ -68,7 +68,7 @@ class jwt
|
|
|
$token->getClaims(); // 获取JWT的PayLoad(负载)信息
|
|
|
$uniqueId = $token->getClaim('uniqueId');
|
|
|
$sourceId = $token->getClaim('sourceId');
|
|
|
- $currentSourceId = WxOpenService::getSourceId();
|
|
|
+ $currentSourceId = httpUtil::getSourceId();
|
|
|
if ($sourceId != $currentSourceId) {
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -86,52 +86,4 @@ class jwt
|
|
|
return self::validate($token);
|
|
|
}
|
|
|
|
|
|
- public static function delToken($uniqueId)
|
|
|
- {
|
|
|
- $token = httpUtil::getToken();
|
|
|
- $host = httpUtil::getHost();
|
|
|
- $signer = new Sha256();//生成JWT时使用的加密方式
|
|
|
- $salt = Yii::$app->params['secretKey'];
|
|
|
- $signKey = new Key($salt);
|
|
|
-
|
|
|
- $token = (new Parser())->parse($token);
|
|
|
- //数据校验
|
|
|
- $data = new ValidationData();//使用当前时间来校验数据
|
|
|
- $data->setIssuer($host);
|
|
|
- $data->setAudience($host);
|
|
|
-
|
|
|
- if (!$token->verify($signer, $signKey)) {
|
|
|
- Yii::info('token解密没有通过。token:' . $token);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- if (!$token->validate($data)) {
|
|
|
- Yii::info('token验证没有通过。token:' . $token);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- $token->getHeaders(); // 获取JWT的Header(头部)信息
|
|
|
- $token->getClaims(); // 获取JWT的PayLoad(负载)信息
|
|
|
- $returnId = $token->getClaim('uniqueId');
|
|
|
- $sourceId = $token->getClaim('sourceId');
|
|
|
- $currentSourceId = WxOpenService::getSourceId();
|
|
|
-
|
|
|
- echo $currentSourceId.' '.$sourceId.' '.$returnId.' '.$uniqueId;
|
|
|
- die;
|
|
|
-
|
|
|
- if($currentSourceId != $sourceId){
|
|
|
- Yii::info('不是你此端的token。token:' . $token);
|
|
|
- return false;
|
|
|
- }
|
|
|
- if ($returnId != $uniqueId) {
|
|
|
- Yii::info('token验证出的id不是登陆用户id。token:' . $token);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- //设置为过期
|
|
|
- $data->setCurrentTime(time() + 600);
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
}
|