java微信小程序登录查MySQL_微信小程序登录JAVA后台

本文介绍了如何使用Java SpringBoot构建微信小程序登录系统,涉及微信API、MySQL数据库集成、JWT令牌以及Redis缓存。文章详细讲解了项目结构、配置、过滤器、权限配置以及登录流程,包括获取code、换取session_key、保存用户信息到数据库等关键步骤。
摘要由CSDN通过智能技术生成

登录流程时序登录流程时序

api-login.jpg?t=2018315

具体的登录说明查看 小程序官方API

项目的结构图:

603356580246d74760870aadb099844f.png

springboot项目搭建

使用idea作为开发工具,由gradle构建项目,搭建springboot项目,对这块儿不熟悉的可以自行去学习,此处不多赘述。下面是核心的配置文件。application.yml中配置springboot默认的参数,application.properties配置自定义的参数,可以统一配置在一个文件中,依据个人习惯。

buidle.gradle配置

buildscript {

ext {

springBootVersion = '1.5.10.RELEASE'

}

repositories {

mavenLocal()

maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }

mavenCentral()

}

dependencies {

classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")

}

}

apply plugin: 'java'

apply plugin: 'org.springframework.boot'

group = 'xin.yangmj'

version = '1.0.1'

sourceCompatibility = 1.8

repositories {

mavenLocal()

maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }

mavenCentral()

}

dependencies {

compile('org.springframework.boot:spring-boot-starter-cache')

compile('org.springframework.boot:spring-boot-starter-data-redis')

compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1')

compile('org.springframework.boot:spring-boot-starter-security')

compile('org.springframework.boot:spring-boot-starter-web')

compile('mysql:mysql-connector-java')

compile('org.springframework.security:spring-security-test')

testCompile('org.springframework.boot:spring-boot-starter-test')

compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'

}

application.yml

logging:

level:

root: DEBUG

spring:

datasource:

url: jdbc:mysql://localhost/remindme?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8

username: root

password: root

driver-class-name: com.mysql.jdbc.Driver

redis:

host: localhost

password:

port: 6379

mybatis:

mapperLocations: classpath:mapper/*.xml

configuration:

mapUnderscoreToCamelCase: true

default-enum-type-handler: org.apache.ibatis.type.EnumOrdinalTypeHandler

application.properties

# JWT相关配置

jwt.header=Authorization

# 过期时间

jwt.expiration=864000

# 注意有一个空格

jwt.tokenHead=Bearer

# wechat Auth

auth.wechat.sessionHost=https://api.weixin.qq.com/sns/jscode2session

auth.wechat.appId=***

auth.wechat.secret=***

auth.wechat.grantType=authorization_code

权限相关的配置

WebSecurityConfig.java

@Configuration

@EnableWebSecurity

@EnableGlobalMethodSecurity(prePostEnabled = true)

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired

priv

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值