前言:
而今兄弟们对“java框架smm是什么意思”都比较重视,朋友们都想要剖析一些“java框架smm是什么意思”的相关文章。那么小编在网上收集了一些有关“java框架smm是什么意思””的相关内容,希望你们能喜欢,同学们快快来学习一下吧!新建 mingyue-gateway
在 【从零搭建微服务-注册中心(二)】中就建好了模块
核心依赖
xml复制代码<!-- SpringCloud Gateway,内置 webflux 依赖--><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId></dependency><!-- LB 扩展 --><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId></dependency>核心配置
保存到 application.yml 或 nacos 中都可以
yaml复制代码spring: cloud: # 网关配置 gateway: # 打印请求日志(自定义) requestLog: true discovery: locator: enabled: true routes: # 认证中心 - id: mingyue-auth uri: lb://mingyue-auth predicates: - Path=/auth/** filters: - StripPrefix=1测试网关启动 mingyue-auth
直接调用登录接口:
less复制代码curl --location --request POST '; \--header 'User-Agent: Apifox/1.0.0 ()' \--header 'Content-Type: application/json' \--header 'Accept: */*' \--header 'Host: localhost:9000' \--header 'Connection: keep-alive'
返回结果:
css复制代码{ "code": 200, "msg": "ok", "data": { "access_token": "xHJR3aIsYOZxZiCpbXzDjKMS32JfLV2m5jtme1gEsItvKR8ZiEZ3GUVkJBom", "refresh_token": "O0SmM1Pb7MP18rE7Uz72MIY9uucCTBnAJ2CkWXCq4FeaTU7o8e0BPExfvQGX", "expires_in": 7199, "refresh_expires_in": 2591999, "client_id": "1001", "scope": "", "openid": "gr_SwoIN0MC1ewxHX_vfCW3BothWDZMMtx__" }}启动 mingyue-gateway
间接调用(通过网关)登录接口:
less复制代码curl --location --request POST '; \--header 'User-Agent: Apifox/1.0.0 ()' \--header 'Content-Type: application/json' \--header 'Accept: */*' \--header 'Host: localhost:9100' \--header 'Connection: keep-alive' \--header 'Cookie: Authorization=d7dc6f87-bf4a-4903-ad6c-2ac668f5e5a7'
返回结果:
css复制代码{ "code": 200, "msg": "ok", "data": { "access_token": "PRMy2RJXTA8SAtHChWLXYRHfANQiOeFPxyfilCdUnz8j0oZrnpXZqkkh06BB", "refresh_token": "najLtYrf2SZhtsayHTKEeG5yVeZEmcgu7ePVf00C8QcX0uVjh8yw2SaH8INP", "expires_in": 7199, "refresh_expires_in": 2591999, "client_id": "1001", "scope": "", "openid": "gr_SwoIN0MC1ewxHX_vfCW3BothWDZMMtx__" }}改造 mingyue-ui1.修改 vite.config.ts
=>
javascript复制代码'/api': { target: ';, ws: true, changeOrigin: true, rewrite: (path) => path.replace(/^/api/, ''),},2.修改登录相关接口地址
src/api/login/index.ts
ini复制代码signIn: (data: object) => { let client_id = 1001; let grant_type = 'password'; let client_secret = 'aaaa-bbbb-cccc-dddd-eeee'; // TODO 规范入参类型 let username = data.username; let password = data.password; return request({ url: '/api/auth/oauth2/token', method: 'post', params: {grant_type, client_id, client_secret, username, password} }); },signOut: () => { let client_id = 1001; let client_secret = 'aaaa-bbbb-cccc-dddd-eeee'; let access_token = Session.get('token'); // 调用回收 Access-Token 接口 return request({ url: '/api/auth/oauth2/revoke', method: 'post', params: {client_id, client_secret, access_token} }); }3.启动测试
可以登录、登出即可~
小结
至此,我们已经完成了 mingyue-ui => mingyue-gateway => mingyue-auth,如下图流程所示:
接下来,我们我们开始编写 mingyue-system 用户相关模块,改造 mingyue-auth 用户查询走数据库。
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #java框架smm是什么意思