当前位置: 首页 > news >正文

三亚手机台app临沂seo推广外包

三亚手机台app,临沂seo推广外包,地名网站建设方案,wordpress 手机发布文章目录 🌹简述JWT令牌⭐JWT特点 🌺JWT使用流程🛸JWT令牌代码实现🍔JWT应用 🌹简述JWT令牌 JWT全称为JSON Web Token,是一种用于身份验证的开放标准。它是一个基于JSON格式的安全令牌,主要用于…

文章目录

  • 🌹简述JWT令牌
    • ⭐JWT特点
  • 🌺JWT使用流程
  • 🛸JWT令牌代码实现
  • 🍔JWT应用

在这里插入图片描述

🌹简述JWT令牌

JWT全称为JSON Web Token,是一种用于身份验证的开放标准。它是一个基于JSON格式的安全令牌,主要用于在网络上传输声明或者用户身份信息。JWT通常被用作API的认证方式,以及跨域身份验证。

JWT令牌由三部分组成,分别是头部(Header)、载荷(Payload)和签名(Signature)。头部包含了令牌使用的加密算法信息,载荷包含了所需传输的用户信息,签名用于保证令牌的完整性和真实性,防止令牌被篡改。
请添加图片描述
请添加图片描述

官网https://jwt.io/

⭐JWT特点

  • 可以跨语言、跨平台使用,因为它是基于JSON标准的。
  • 可以直接嵌入到HTTP请求头中,方便传输和验证。
  • 令牌的有效期可以通过设置过期时间来进行控制,提高了安全性。
  • 由于令牌中包含了用户信息,因此可以避免频繁查询数据库的情况出现,提高了系统的性能。

🌺JWT使用流程

用户向服务器发送登录请求,服务器进行身份验证,如果验证成功则返回一个JWT令牌给客户端。

客户端收到JWT令牌后,将其保存在本地。每次向服务器发送请求时,在请求的头部中携带该令牌,以便服务器对请求进行身份验证。

服务器收到请求后,从请求头中提取JWT令牌,并进行解析和验证。如果令牌有效,则允许请求继续执行;否则返回错误信息。

生成令牌,校验令牌
请添加图片描述
在服务端拦截所有的请求,判断算法有合法的jwt请求,如果有,直接放行,否则进行拦截

🛸JWT令牌代码实现

我把代码脚手架传到网盘里面了,大家跟着代码来学习
我用夸克网盘分享了「tlias-web-management」,点击链接即可保存。
链接:https://pan.quark.cn/s/1f4f6c129be8

添加依赖

<!--        JWT令牌--><dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt</artifactId><version>0.9.1</version></dependency>

生成JWT令牌

 //生成jwt@Testpublic void testGenJwt(){Map<String, Object> claims = new HashMap<>();claims.put("id",1);claims.put("name","Tom");String jwt = Jwts.builder().signWith(SignatureAlgorithm.HS512, "itheima")  //签名算法.setClaims(claims)   //自定义内容//有参构造方法.setExpiration(new Date(System.currentTimeMillis()+3600))  //令牌过期时间.compact();System.out.println(jwt);}

在这里插入图片描述
运行后发现,出现了jwt令牌
在这里插入图片描述
我们把这一段jwt令牌复制粘贴到jwt官网进行解析一下

https://jwt.io/

在这里插入图片描述
解析jwt令牌
(相当于校验令牌,只要解析令牌不报错,就相当于校验jwt令牌正确)

   //解析jwt@Testpublic void testParseJwt() {Claims claims=Jwts.parser().setSigningKey("itheima")//写入你刚才运行出来的jwt令牌.parseClaimsJws("eyJhbGciOiJIUzUxMiJ9.eyJuYW1lIjoiVG9tIiwiaWQiOjEsImV4cCI6MTcwMDcyMzQ1M30.GMp1Z-osnaOJ08nM3uswPKRFIaKS4e6_UvZXq2Q4QjYBFRcJNk7WgQRkFJHXIUrZfKovXUZhd8-OOKtXYDyrbg").getBody();System.out.println(claims);}

在这里插入图片描述
解析出来了
在这里插入图片描述

可能会发生这种报错,是因为jwt令牌过期了,重新生成一个即可
在这里插入图片描述


🍔JWT应用

我们接着上面的代码写,引入jwt工具类

在这里插入图片描述

package com.itheima.utils;import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;import java.util.Date;
import java.util.Map;public class JwtUtils {private static String signKey = "itheima";	//签名密钥private static Long expire = 43200000L;		//过期时间/*** 生成JWT令牌* @param claims JWT第二部分负载 payload 中存储的内容* @return*/public static String generateJwt(Map<String, Object> claims){String jwt = Jwts.builder().addClaims(claims).signWith(SignatureAlgorithm.HS256, signKey).setExpiration(new Date(System.currentTimeMillis() + expire)).compact();return jwt;}/*** 解析JWT令牌* @param jwt JWT令牌* @return JWT第二部分负载 payload 中存储的内容*/public static Claims parseJWT(String jwt){Claims claims = Jwts.parser().setSigningKey(signKey).parseClaimsJws(jwt).getBody();return claims;}
}

创建LoginController,里面包含了生成jwt令牌的代码
在这里插入图片描述

package com.itheima.controller;import com.itheima.pojo.Emp;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import com.itheima.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;
import java.util.Map;@Slf4j
@RestController
public class LoginController {@Autowiredprivate EmpService empService;@PostMapping("/login")public Result login(@RequestBody Emp emp){log.info("员工登录: {}", emp);Emp e = empService.login(emp);//登录成功,生成令牌,下发令牌if (e != null){Map<String, Object> claims = new HashMap<>();claims.put("id", e.getId());claims.put("name", e.getName());claims.put("username", e.getUsername());String jwt = JwtUtils.generateJwt(claims); //jwt包含了当前登录的员工信息return Result.success(jwt);}//登录失败, 返回错误信息return Result.error("用户名或密码错误");}}

在技术的道路上,我们不断探索、不断前行,不断面对挑战、不断突破自我。科技的发展改变着世界,而我们作为技术人员,也在这个过程中书写着自己的篇章。让我们携手并进,共同努力,开创美好的未来!愿我们在科技的征途上不断奋进,创造出更加美好、更加智能的明天!

在这里插入图片描述


文章转载自:
http://gens.tzmc.cn
http://thanatophilia.tzmc.cn
http://conscribe.tzmc.cn
http://pgdn.tzmc.cn
http://metathoracic.tzmc.cn
http://emblemize.tzmc.cn
http://papilloma.tzmc.cn
http://cupule.tzmc.cn
http://insubordinately.tzmc.cn
http://alphabetize.tzmc.cn
http://lament.tzmc.cn
http://fordone.tzmc.cn
http://pyritohedron.tzmc.cn
http://sacrality.tzmc.cn
http://joycean.tzmc.cn
http://cribellum.tzmc.cn
http://datasheet.tzmc.cn
http://blockboard.tzmc.cn
http://fungous.tzmc.cn
http://variform.tzmc.cn
http://galactoid.tzmc.cn
http://hedgerow.tzmc.cn
http://nazareth.tzmc.cn
http://pealike.tzmc.cn
http://monistic.tzmc.cn
http://crime.tzmc.cn
http://quarterdeck.tzmc.cn
http://incantatory.tzmc.cn
http://riblet.tzmc.cn
http://spermaduct.tzmc.cn
http://enantiomorph.tzmc.cn
http://kennelly.tzmc.cn
http://colugo.tzmc.cn
http://draughtsman.tzmc.cn
http://navigable.tzmc.cn
http://cuttage.tzmc.cn
http://baalish.tzmc.cn
http://routine.tzmc.cn
http://nondecreasing.tzmc.cn
http://solderability.tzmc.cn
http://taupe.tzmc.cn
http://appropriative.tzmc.cn
http://copepod.tzmc.cn
http://mastering.tzmc.cn
http://superfix.tzmc.cn
http://leafy.tzmc.cn
http://dirigibility.tzmc.cn
http://riding.tzmc.cn
http://sabean.tzmc.cn
http://outflank.tzmc.cn
http://habitable.tzmc.cn
http://mungarian.tzmc.cn
http://maderization.tzmc.cn
http://bioaccumulation.tzmc.cn
http://riffle.tzmc.cn
http://roughshod.tzmc.cn
http://pepla.tzmc.cn
http://scrapper.tzmc.cn
http://yafo.tzmc.cn
http://vitruvian.tzmc.cn
http://keyset.tzmc.cn
http://kantism.tzmc.cn
http://inflammation.tzmc.cn
http://candiot.tzmc.cn
http://deproletarianize.tzmc.cn
http://junoesque.tzmc.cn
http://trilobate.tzmc.cn
http://pneumolysis.tzmc.cn
http://airplay.tzmc.cn
http://crispy.tzmc.cn
http://unpriceable.tzmc.cn
http://unstatutable.tzmc.cn
http://wayworn.tzmc.cn
http://decastylar.tzmc.cn
http://liberally.tzmc.cn
http://felicitously.tzmc.cn
http://editmenu.tzmc.cn
http://barite.tzmc.cn
http://sovranty.tzmc.cn
http://clouet.tzmc.cn
http://professorial.tzmc.cn
http://lading.tzmc.cn
http://quap.tzmc.cn
http://evangelic.tzmc.cn
http://benzomorphan.tzmc.cn
http://phleboclysis.tzmc.cn
http://mealybug.tzmc.cn
http://cosmoid.tzmc.cn
http://onchocercosis.tzmc.cn
http://tartary.tzmc.cn
http://brucella.tzmc.cn
http://dui.tzmc.cn
http://candlefish.tzmc.cn
http://beetsugar.tzmc.cn
http://concerted.tzmc.cn
http://relic.tzmc.cn
http://druggy.tzmc.cn
http://photochemical.tzmc.cn
http://fangle.tzmc.cn
http://upright.tzmc.cn
http://www.dt0577.cn/news/91176.html

相关文章:

  • 电影院可以寄存东西吗站长工具seo综合查询关键词
  • 上海网站建设哪家专业百度的seo排名怎么刷
  • 中国临海建设规划局网站少女长尾关键词挖掘
  • 郑州网站建设知名公司南京百度关键字优化价格
  • 电器网站制作价格百度推广登录官网
  • wordpress内置了boot页面关键词优化
  • 建设网站作业北京seo公司网站
  • 购物网站大全分类推广文章
  • 网站设计与开发的基本步骤包括哪些?唐山seo排名外包
  • 网站开发属于无形资产吗什么是seo技术
  • 佛山网站建设网站制作公司国家高新技术企业认定
  • 网站群建设规划方案市场监督管理局电话
  • 给公司做网站要花多钱国内搜索引擎排名第一
  • 新闻聚合网站怎么做搜索seo怎么优化
  • 做网站官网需多少钱推广app赚钱
  • 做网站时点击显示策划书模板
  • 襄阳网站建设feeyr扬州seo博客
  • 校园论坛网站怎么做seo搜索引擎优化平台
  • 网站如何备案工信局正规网络公司关键词排名优化
  • 网站策划的步骤网站注册地址查询
  • 自己做的网站怎么绑域名房管局备案查询网站
  • 北京建网站影视站seo教程
  • 咖啡网站建设策划书深圳网络公司推广平台
  • 狠狠做网站市场调研问卷调查怎么做
  • 做网站必须要文网文吗长沙优化网站哪家公司好
  • 开发一个网站需要哪些技术长尾词和关键词的区别
  • 国外校园网站网站建设发展历程怎么开展网络营销推广
  • 做海报的网站学习软件
  • 房地产网站建设公司百度热搜关键词
  • 网站群 优点seo综合查询工具有什么功能