Jwt登录退出

article/2025/9/20 12:21:52

1.登录获取用户信息并写入token

@Overridepublic CommonResult loginV2(RcSysUserEntity byAccount) {log.info("********************");log.info("******************** account-V2:{}",byAccount.getAccount());log.info("********************");CommonResult userInfoV2 = getUserInfoV2(byAccount);return userInfoV2;}//todopublic CommonResult getUserInfoV2(RcSysUserEntity byAccount){List<TMenu> menus= new ArrayList<>();String tokenResult="";Map<String, Object> result = new HashMap<>();try {//获取权限信息Optional<TRole> tRoleopt=tRoleRepository.findById(Integer.valueOf(byAccount.getRoleId()));if(tRoleopt.isPresent()){TRole role = tRoleopt.get();List<TMenu> tMenus = tRoleService.querySysMenus(role.getMenuIds());menus = tRoleService.buildMenuTreeSelect(tMenus);}if(null!=byAccount){JwtPayLoad jwtPayLoad = new JwtPayLoad();jwtPayLoad.setId(byAccount.getId());
//                jwtPayLoad.setToken(byAccount.getToken());jwtPayLoad.setAccount(byAccount.getAccount());jwtPayLoad.setRealname(byAccount.getRealname());jwtPayLoad.setRoleId(byAccount.getRoleId());jwtPayLoad.setCtime(byAccount.getCtime());jwtPayLoad.setCuser(byAccount.getCuser());jwtPayLoad.setTel(byAccount.getTel());jwtPayLoad.setEmail(byAccount.getEmail());tokenResult = JwtTokenUtil.createToken(jwtPayLoad);result.put("token", tokenResult);result.put("permission", menus);result.put("userInfo", byAccount);//更新登录tokenbyAccount.setToken(tokenResult);rcSysUserRepository.save(byAccount);//写入登录日志AsyncManager.me().execute(AsyncFactory.recordLogininfor(byAccount.getAccount(), byAccount.getAccount(), String.valueOf(byAccount.getId()), String.valueOf(byAccount.getId()), "", Constants.LOGIN_SUCCESS, "登录成功"));return CommonResult.success(result);}} catch (Exception e) {logger.info(e.getMessage());}return CommonResult.failed("认证失败,用户名或密码错误");}

2.token验证获取用户信息

/*** token验证获取用户信息* @param token* @return*/@ApiOperation(value = "token验证获取用户信息",httpMethod = "POST")@RequestMapping(value = "tokenAuth")@ResponseBodypublic CommonResult tokenAuth(String token) {RcSysUserEntity userInfo = null;try {logger.debug("token验证获取用户信息...");RcSysUserEntity byToken = rcSysUserRepository.findByToken(token);if (null==byToken) return CommonResult.failed("token验证获取用户信息失效!");JwtPayLoad jwtPayLoad = JwtTokenUtil.getJwtPayLoad(token);CommonResult tokenUser = loginService.getTokenUserV2(jwtPayLoad);logger.debug("userInfo:{}",JSONObject.toJSONString(tokenUser.getData()));logger.debug("token验证获取用户信息 success !");return tokenUser;} catch (Exception e) {logger.debug("token验证获取用户信息 error !");e.printStackTrace();}Map<String, Object> resultMap=new HashMap<>();resultMap.put("userInfo",userInfo);logger.debug("resultMap:{}",JSONObject.toJSONString(resultMap));return CommonResult.success(resultMap);}
public CommonResult getTokenUserV2(JwtPayLoad jwtPayLoad) {Long id=jwtPayLoad.getId();Optional<RcSysUserEntity> byAccountOpt = rcSysUserRepository.findById(id);if (byAccountOpt.isPresent()) {RcSysUserEntity byAccount = byAccountOpt.get();//移除加密信息byAccount.setSalt("");byAccount.setPassword("");Optional<TRole> tRoleopt=tRoleRepository.findById(Integer.valueOf(byAccount.getRoleId()));if(tRoleopt.isPresent()){TRole role = tRoleopt.get();List<TMenu> tMenus = tRoleService.querySysMenus(role.getMenuIds());List<TMenu> menus = tRoleService.buildMenuTreeSelect(tMenus);byAccount.setMenus(menus);return CommonResult.success(byAccount);}}return CommonResult.failed("token验证获取用户信息失败!");}@Overridepublic List<TMenu> querySysMenus(String menu) {RowMapper<TMenu> rowMapper=new BeanPropertyRowMapper<>(TMenu.class);String query=" select * from t_sys_menu where 1=1 ";if (!menu.equals("-1")) {//-1为查全部query+=" and  find_in_set(id,'"+menu+"')  ";}List<TMenu> list = jdbcTemplate.query(query,rowMapper);return list;}/*** 构建前端所需要下拉树结构** @param menus 菜单列表* @return 下拉树结构列表*/@Overridepublic List<TMenu> buildMenuTreeSelect(List<TMenu> menus){//转换为前端data格式List<TMenu> topNodes=menus.stream().filter(item->item.getParentId()==0).collect(Collectors.toList());List<TMenu> nodes=new ArrayList<>();for(TMenu item : topNodes){TMenu combotreeVo = new TMenu();combotreeVo.setId(item.getId());combotreeVo.setMenuName(item.getMenuName());combotreeVo.setParentId(item.getParentId());combotreeVo.setMenuUrl(item.getMenuUrl());fillSubNode(combotreeVo,menus);if(combotreeVo.getChildren()!=null&&combotreeVo.getChildren().size()>0){combotreeVo.setStatus(0);}else{combotreeVo.setStatus(1);}nodes.add(combotreeVo);}return nodes;}/*** 转换* @param pnode* @param all*/public void fillSubNode(TMenu pnode, List<TMenu> all) {List<TMenu> subNodes = all.stream().filter(item -> item.getParentId()==pnode.getId()).collect(Collectors.toList());if (subNodes == null || subNodes.size() == 0) {return;}pnode.setChildren(new ArrayList<TMenu>());for (TMenu item : subNodes) {TMenu combotreeVo = new TMenu();combotreeVo.setId(item.getId());combotreeVo.setMenuName(item.getMenuName());combotreeVo.setParentId(item.getParentId());combotreeVo.setMenuUrl(item.getMenuUrl());fillSubNode(combotreeVo, all);if (combotreeVo.getChildren() != null && combotreeVo.getChildren().size() > 0) {combotreeVo.setStatus(0);} else {combotreeVo.setStatus(1);}pnode.getChildren().add(combotreeVo);}}

3.退出

	@ApiOperation(value = "退出", httpMethod = "POST")@RequestMapping(value = "/logout")@ResponseBodypublic CommonResult logout(@RequestParam(value = "token", required = true) String token) {RcSysUserEntity byToken = rcSysUserRepository.findByToken(token);if (byToken == null) return CommonResult.failed("token参数异常!");byToken.setToken("");rcSysUserRepository.save(byToken);return CommonResult.success("退出成功!");}

4.角色和权限实体类

package com.zkdj.data.entity.pojo;import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;/*** @description 系统角色权限表* @author gxf* @date 2023-06-02*/
@Entity
@Data
@Table(name="t_sys_menu")
@ApiModel("系统角色权限表")
public class TMenu implements Serializable {private static final long serialVersionUID = 1L;/*** 主键*/@Id@ApiModelProperty("主键")@GeneratedValue(strategy = GenerationType.IDENTITY)@Column(name = "id", nullable = false)private Integer id;/*** 菜单名称*/@ApiModelProperty("菜单名称")@Column(name="menu_name")private String menuName;/*** 父级id*/@ApiModelProperty("父级id")@Column(name="parent_id")private Integer parentId;/*** 菜单路径*/@ApiModelProperty("菜单路径")@Column(name="menu_url")private String menuUrl;/*** 创建时间*/@ApiModelProperty("创建时间")@Column(name="ctime")private String ctime;/*** 修改时间*/@ApiModelProperty("修改时间")@Column(name="utime")private String utime;/*** 状态 : 0 未启用 1 已启用*/@ApiModelProperty("状态 : 0 未启用 1 已启用")@Column(name="status")private Integer status;/*** 排序*/@ApiModelProperty("排序")@Column(name="sort")private Integer sort;/*** 是否是父级 0 不是 1是*/@ApiModelProperty("是否是父级 0 不是 1是")@Column(name="is_parent")private Integer isParent;/** 子节点 */@JsonInclude(JsonInclude.Include.NON_EMPTY)@Transientprivate List<TMenu> children=new ArrayList<>();public TMenu() {}public TMenu(TMenu tMenu) {}
}
package com.zkdj.data.entity.pojo;import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;import javax.persistence.*;
import java.io.Serializable;
/*** @description 系统角色表* @author gxf* @date 2023-05-29*/
@Entity
@Data
@Table(name="t_sys_role")
@ApiModel("系统角色表")
public class TRole implements Serializable {private static final long serialVersionUID = 1L;/*** 主键*/@Id@ApiModelProperty("主键")@GeneratedValue(strategy = GenerationType.IDENTITY)@Column(name = "id", nullable = false)private Integer id;/*** 角色名称*/@ApiModelProperty("角色名称")@Column(name="role_name")private String roleName;/*** 角色标识*/@ApiModelProperty("角色标识")@Column(name="role_type")private String roleType;/*** 角色描述*/@ApiModelProperty("角色描述")@Column(name="role_descrip")private String roleDescrip;/*** 创建时间*/@ApiModelProperty("创建时间")@Column(name="ctime")private String ctime;/*** 修改时间*/@ApiModelProperty("修改时间")@Column(name="utime")private String utime;/*** 角色权限ids*/@ApiModelProperty("角色权限ids")@Column(name="menu_ids")private String menuIds;public TRole() {}}

5.Jwt工具类

package com.zkdj.data.common.config.jwt.payload;import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.zkdj.data.entity.model.RcSysUserEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Map;/*** @author Administrator*/
@Data
@ApiModel("jwt")
public class JwtPayLoad  {private static final long serialVersionUID = 1L;@ApiModelProperty("过期时间")private String expTime;/*** 主键*/@Id@ApiModelProperty("主键")@GeneratedValue(strategy = GenerationType.IDENTITY)private Long id;/*** 账号*/@ApiModelProperty("账号")private String account;/*** 密码*/@ApiModelProperty("密码")private String password;/*** 真实姓名*/@ApiModelProperty("真实姓名")private String realname;/*** 角色id*/@ApiModelProperty("角色id")private String roleId;/*** 盐值*/@ApiModelProperty("盐值")private String salt;/*** 类型*/@ApiModelProperty("类型")private Integer type;/*** 创建时间*/@ApiModelProperty("创建时间")private String ctime;/*** 创建用户*/@ApiModelProperty("创建用户")private String cuser;/*** 更新时间*/@ApiModelProperty("更新时间")private String utime;/*** 令牌*/@ApiModelProperty("令牌")private String token;/*** 电话*/@ApiModelProperty("电话")private String tel;/*** 邮箱*/@ApiModelProperty("邮箱")private String email;/*** 启用禁用 0禁用1启用*/@ApiModelProperty("启用禁用 0禁用1启用")private Integer status;/*** 用户的键*/private String userKey;public JwtPayLoad() {}public JwtPayLoad(Long id, String roleId, String account, String realname) {this.id = id;this.roleId = roleId;this.account = account;this.realname = realname;}public JwtPayLoad(Long id, String roleId, String account, String realname,String expTime,String password,String salt,Integer type,String ctime,String cuser,String utime,String token,String tel,String email,Integer status,String userKey) {this.id = id;this.roleId = roleId;this.account = account;this.realname = realname;this.expTime = expTime;this.password = password;this.salt = salt;this.type = type;this.ctime = ctime;this.ctime = ctime;this.cuser = cuser;this.utime = utime;this.token = token;this.tel = tel;this.email = email;this.status = status;this.userKey = userKey;}/*** payload转化为map形式** @Date 2023/7/20 20:50*/public Map<String, Object> toMap() {Map<String, Object> map = BeanUtil.beanToMap(new JwtPayLoad(id, roleId, account, realname, expTime, password, salt,type, ctime, cuser, utime, token, tel, email, status, userKey), false, true);return map;}/*** payload转化为map形式** @Date 2023/7/20 20:50*/public static JwtPayLoad toBean(Map<String, Object> map) {if (map == null || map.size() == 0) {return new JwtPayLoad();} else {JwtPayLoad jwtPayLoad = BeanUtil.mapToBean(map, JwtPayLoad.class, true, new CopyOptions());return jwtPayLoad;}}
}
/*** Copyright 2018-2020 stylefeng & fengshuonan (sn93@qq.com)* <p>* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at* <p>* http://www.apache.org/licenses/LICENSE-2.0* <p>* Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/
package com.zkdj.data.common.config.jwt;import com.zkdj.data.common.config.jwt.payload.JwtPayLoad;
import com.zkdj.data.utils.UUIDUtil;
import com.zkdj.data.utils.date.DateUtil;
import io.jsonwebtoken.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;/*** <p>jwt token工具类</p>* <pre>*     jwt的claim里一般包含以下几种数据:*         1. iss -- token的发行者*         2. sub -- 该JWT所面向的用户*         3. aud -- 接收该JWT的一方*         4. exp -- token的失效时间*         5. nbf -- 在此时间段之前,不会被处理*         6. iat -- jwt发布时间*         7. jti -- jwt唯一标识,防止重复使用* </pre>*/
public class JwtTokenUtil {static Integer DEFAULTSECS = 60*60*12;  //默认过期时间10分钟private final static String DEFAULT_SECRET="eyJhbGciOiJIUzUxMiJ9";public final static String FORMAT="yyyy-MM-dd HH:mm:ss";/*** 生成token*/public static String createToken(JwtPayLoad jwtPayLoad) {Integer expiredSeconds = DEFAULTSECS;Date expirationDate = new Date(System.currentTimeMillis() + expiredSeconds * 1000);if(StringUtils.isNotBlank(jwtPayLoad.getExpTime())){expirationDate = DateUtil.getDateFormateStr(jwtPayLoad.getExpTime(),FORMAT);}jwtPayLoad.setExpTime(DateUtil.getDateTimeConvertStr(expirationDate,FORMAT));return generateToken(String.valueOf(jwtPayLoad.getId()),expirationDate,jwtPayLoad.toMap());}/*** 获取解析当前登录的用户token信息* @return*/public static JwtPayLoad getTokenJwtPayLoadInfo() {HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();return JwtTokenUtil.getJwtPayLoad( request.getHeader("token"));}/*** 获取jwt的payload部分*/public static JwtPayLoad getJwtPayLoad(String token) {Claims claimFromToken = getClaimFromToken(token);return JwtPayLoad.toBean(claimFromToken);}/*** 解析token是否正确(true-正确, false-错误)*/public static Boolean checkToken(String token) {try {Jwts.parser().setSigningKey(DEFAULT_SECRET).parseClaimsJws(token).getBody();return true;} catch (JwtException e) {return false;}}/*** 验证token是否失效*/public static Boolean isTokenExpired(String token) {try {final Date expiration = getExpirationDateFromToken(token);if(null==expiration){return true;}return expiration.before(new Date());} catch (ExpiredJwtException expiredJwtException) {return true;}}/*** 获取jwt失效时间*/public static Date getExpirationDateFromToken(String token) {try {return getClaimFromToken(token).getExpiration();}catch (Exception ex){return null;}}/*** 生成token 核心方法*/public static String generateToken(String userId, Date expiredDate, Map<String, Object> claims) {final Date createdDate = new Date();if (claims == null) {return Jwts.builder().setSubject(userId).setIssuedAt(createdDate).setExpiration(expiredDate).signWith(SignatureAlgorithm.HS256, DEFAULT_SECRET).compact();} else {return Jwts.builder().setClaims(claims).setSubject(userId).setIssuedAt(createdDate).setExpiration(expiredDate).signWith(SignatureAlgorithm.HS256, DEFAULT_SECRET).compact();}}/*** 获取jwt的payload部分*/public static Claims getClaimFromToken(String token) {if (StringUtils.isEmpty(token)) {throw new IllegalArgumentException("token参数为空!");}return Jwts.parser().setSigningKey(DEFAULT_SECRET).parseClaimsJws(token).getBody();}public static void main(String[] args) {System.out.println(UUIDUtil.get32UUID());JwtPayLoad payLoad=new JwtPayLoad();
//        payLoad.setUserId("103");
//        payLoad.setExpTime("2021-12-26 23:50:50");payLoad.setToken("eyJhbGciOiJIUzI1NiJ9.eyJleHBUaW1lIjoiMjAyMy0wNi0wMiAwMzowNjowMiIsImlkIjo0LCJhY2NvdW50IjoiemtkaiIsInJlYWxuYW1lIjoiemtkaiIsInJvbGVJZCI6IjEiLCJjdGltZSI6IjIwMjMtMDUtMzEgMTg6MDA6NDMiLCJjdXNlciI6InprZGoiLCJ0ZWwiOiIxODYxMDA4NjEwMCIsImVtYWlsIjoiMTAwMDBAcXEuY29tIiwic3ViIjoiNCIsImlhdCI6MTY4NTYwMzE2MiwiZXhwIjoxNjg1NjQ2MzYyfQ.2pI28yqsG43gRkbsUv5UyH4OqSff3w3IASmNmF7lJRo");payLoad.setId(1L);String jwtsecret = "";String s = JwtTokenUtil.createToken(payLoad);
//        String s = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMDMiLCJleHBUaW1lIjoiMjAyMS0xMi0xMSAwMDo1MDo1MCIsImN1c3RvbWVySWQiOm51bGwsInVzZXJOYW1lIjpudWxsLCJleHAiOjE2MzkxNTUwNTAsInVzZXJJZCI6IjEwMyIsImlhdCI6MTYzOTE1NDE0NiwiY3VzdG9tZXJOYW1lIjpudWxsfQ.WUlQlhG7DQUkMFNzm-uwD4lVCyeeNmRXY05tSeKYuEc";
//        JwtPayLoad jwtPayLoad = getJwtPayLoad("eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMDUiLCJleHBUaW1lIjoiMjAyMS0xMi0yNyAyMTozNzowOCIsImN1c3RvbWVySWQiOm51bGwsInVzZXJOYW1lIjoieHlneHEiLCJleHAiOjE2NDA2MTIyMjgsInVzZXJJZCI6IjEwNSIsImlhdCI6MTY0MDYxMTYyOCwiY3VzdG9tZXJOYW1lIjpudWxsfQ.8lazFHdMdQP5K-iJCGdflCBZnlNOilXVSuGcA0mU1A0");JwtPayLoad jwtPayLoad = getJwtPayLoad(s);System.out.println("Secret:"+ jwtPayLoad.getToken());System.out.println("token是否正确:"+ JwtTokenUtil.checkToken(s)+jwtPayLoad.getExpTime());System.out.println("token是否失效:"+ JwtTokenUtil.isTokenExpired(s));System.out.println("token过期日期:"+ DateUtil.getDateTimeConvertStr(JwtTokenUtil.getExpirationDateFromToken(s),"yyyy-MM-dd HH:mm:ss"));}
}

权限
权限
角色
角色
用户
在这里插入图片描述

其他工具类见上篇文章


http://chatgpt.dhexx.cn/article/C6migMYU.shtml

相关文章

注册、登录、退出登录

运营商系统登录与安全控制 2.1需求分析 完成运营商登陆功能 (1)、登录页面 (2)登录后页面 (3)、点击右上角头像后显示。 2.2登陆功能的实现 2.2.1配置文件 (1)修改mall-manager-web的pom.xml ,添加依赖 <!-- 身份验证 --> <dependency> &l…

小程序登录与退出登录

主要是通过在storage中缓存userInfo与清空userInfo的信息来实现登录与退出登录 wxml&#xff1a; <view class"setting"><view class"setting_thr" bindtap"login">登录</view></view><view class"setting&qu…

前端新用户注册,登录,退出登录功能实现

目录 新用户注册功能 用户登录功能 用户退出登录功能 新用户注册功能 基本思路&#xff1a; 将用户的信息通过接口存入数据库&#xff0c;接口会返回是否存入成功 使用elementui做表单验证 代码如下&#xff1a; <template><div class"register">&…

Linux的登录和退出

1. 图形用户界面的登录和退出 图形用户界面&#xff0c;直接输入用户名密码即可登录。 在终端中输入init 0命令即可关闭系统。或者我们点击这里&#xff1a; 2.命令行界面登录和退出 Linux提供了6个虚拟控制台&#xff0c;通过按键盘CtrlAltF[1~6]来切换。如图&#xff0…

登录退出页面

一.登录业务流程 1、在登录页面输入用户名和密码 2、调用后台接口进行验证 3、通过验证之后,根据后台的响应状态跳转到项目主页 二.登录业务的相关技术点 1、http是无状态的 2、通过cookie在客户端记录状态 3、通过session在服务器端记录状态 4、通过token方式维持状态(解决跨…

token清除,退出登录

当我点击的时候&#xff0c;并没有打印任何地方应该打印的console.log(111),这时候应该检查一下自己的标签&#xff0c;我的错误在于a标签并没有删掉herf所以并没有出发点击事件&#xff0c;后面的这一切流程都没有走&#xff0c;但是我比较疑惑的一点是为啥之前并没有删掉herf…

Java退出登录功能

有志者&#xff0c;事竟成 文章持续更新&#xff0c;可以关注【小奇JAVA面试】第一时间阅读&#xff0c;回复【资料】获取福利&#xff0c;回复【项目】获取项目源码&#xff0c;回复【简历模板】获取简历模板&#xff0c;回复【学习路线图】获取学习路线图。 文章目录 一、登录…

十六、退出登录

用户只需要向Spring Security项目中发送/logout退出请求即可。 1.退出实现 实现退出非常简单&#xff0c;只要在页面中添加/logout的超链接即可。 <a href"/logout">退出登录 为了实现更好的效果&#xff0c;通常添加退出的配置。默认的退出url为/logout&#…

STM32CubeMX配置DCMI+DMA之OV2640

STM32CubeMX配置DCMIDMA之OV2640 本文章只讲解如何使用STM32CubeMX配置STM32外设&#xff0c;其他驱动代码请别处移植 一、设备及软件 1、keil 2、STM32CubeMX 3、正点原子STM32F407探索者开发板配OV2640 二、配置步骤 1、配置RCC外部晶振、SYS为SW模式和USART1&#xff0…

STM32 DCMI调试

之前调试一款摄像头没有仔细读stm32数据手册&#xff0c;用库函数写的&#xff0c;sensor的数据手册配置和dcmi配置的HSYNC和VSYN都是低电平有效&#xff0c;读摄像头sensor示波器波形也是低电平有效&#xff0c;但是数据就是读不出来。 摄像头HSYNC和VSYN信号&#xff1a; 之…

DCMI(数字图像接口)与OV2640 stm32

本文先介绍了摄像头模块OV2640&#xff0c;又介绍了DCMI。 最后讲解在stm32上相关代码。 一、OV2640 1.OV2640基本概念 CMOS SCCB&#xff0c;所有图像处理过程可以通过SCCB接口编程 IIC 支持按比例缩小(从SXGA到40*30的任何尺寸)&#xff0c;通过DSP转换成需要的任何尺寸 P…

第46章 DCMI—OV5640摄像头—零死角玩转STM32-F429系列

第46章 DCMI—OV5640摄像头 全套200集视频教程和1000页PDF教程请到秉火论坛下载&#xff1a;www.firebbs.cn 野火视频教程优酷观看网址&#xff1a;http://i.youku.com/firege 本章参考资料&#xff1a;《STM32F4xx参考手册》、《STM32F4xx规格书》、库帮助文档《stm32…

基于STM32CubeIDE的STM32H750 DCMI接口驱动OV2640读取JPEG结合自编上位机实现可以用的数字图传

基于STM32CubeIDE的STM32H750 DCMI接口驱动OV2640读取JPEG结合自编上位机实现可以用的数字图传 最近的一个小项目方案介绍硬件连接下位机程序部分使用串口助手进行测试 播放视频写在最后 最近的一个小项目 本人最近在设计一个无人机飞控&#xff0c;无人机还在学校呢&#xff…

【单片机开发】OV2640在没有DCMI接口的情况下的STM32驱动

文章目录 (一)背景介绍&#xff08;二&#xff09;接线&#xff08;三&#xff09;软件实现 (一)背景介绍 在之前刚学STM32的时候完成了一个ov7670的驱动 ov7670驱动 已经快要两年过去了&#xff0c;最近抽了一点时间又将之前搞得ov2640的驱动完善了一下 看一下效果吧。 &…

第45章 DCMI—OV2640摄像头—零死角玩转STM32-F429系列

第45章 DCMI—OV2640摄像头 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/firege 本章参考资料:《STM32F4xx参考手册》、《STM32F4xx规格书》、库帮助文档《stm32f4xx_dsp_stdperiph_lib_um.…

stm32cubeMx---DCMI 配置与使用

最近需要使用stm32的DCMI外设&#xff0c;所以经过一段时间研究后&#xff0c;对现有的学习状态进行记录&#xff1a; 1&#xff1a;stm32cube的pinout处进行无脑配置就行了&#xff0c;不进行描述。时钟配置按照自己的需求进行配置。DCMI的DMA配置如下图&#xff1a; 2&#…

通过stm32cubemx配置DCMI驱动ov5640摄像头

打开stm32cubemx选择芯片 选择外部时钟源 选择debug方式 配置dcmi 打开dma 打开dcmi中断 选择合适的io 设置reset、pwdn、scl、sda引脚&#xff0c;注意scl和sda设置为开漏输出&#xff0c;之前参考别人的设置为推挽输出&#xff0c;导致一直没有成功&#xff0c;不知道什么原…

DCMI接口与OV2640原理与配置

OV2640是OmniVision公司生产的一颗1/4寸的CMOS UXGA&#xff08;1632*1232&#xff09;图像传感器。该传感器体积小、工作电压低&#xff0c;提供单片UXGA摄像头和影像处理器的所有功能。通过SCCB 总线控制&#xff0c;可以输出整帧、子采样、缩放和取窗口等方式的各种分辨率8/…

STM32H743中的DCMI无法进入行中断和场中断问题

今天在玩MT9V034摄像头时&#xff0c;用到了DCMI接口处理摄像头的数据&#xff0c;出现了一个BUG&#xff0c;怎么都进入不了行中断或者场中断。究其原因&#xff0c;原来是忘记设置其中断优先级了。 void Msp_DCMI_Init(void) {GPIO_InitTypeDef GPIO_InitStruct;__HAL_RCC_DC…

STM32 DCMI OV9655 直接在LCD显示

CUBEMX配置DCMI如下&#xff1a; 生成代码。DCMI初始化代码如下&#xff1a; void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi) {GPIO_InitTypeDef GPIO_InitStruct {0};if(hdcmi->InstanceDCMI){/* USER CODE BEGIN DCMI_MspInit 0 *//* USER CODE END DCMI_MspInit …