当前位置:网站首页>【208】基于AccessToken方式实现API设计
【208】基于AccessToken方式实现API设计
2022-06-28 16:06:00 【米洛口】
一、举例说明:
需求:
A、B机构需要调用X服务器的接口,那么X服务器就需要提供开放的外网访问接口。
分析:
1、开放平台提供者X,为每一个合作机构提供对应的appid、app_secret。
2、appid是唯一的(不能改变),表示对应的第三方合作机构,用来区分不同机构的。
3、app_secret在传输中实现加密功能(秘钥),该秘钥可以发生改变的。
4、为什么app_secret是可以改变的?调用接口需要appid+app_secret生成对应的access_token(临时性),如果appid和app_secret被泄密,产生安全性问题,如果一但发现被泄密,可以重新生成一个app_secret。
原理:为每个合作机构创建对应的appid、app_secret,生成对应的access_token(有效期2小时),在调用外网开放接口的时候,必须传递有效的access_token。
二、开发步骤
1、使用appid+app_secret生成对应的access_token
1.获取生成的AppId和appSecret,并验证是否可用
2.删除之前的accessToken
2.AppId和appSecret保证生成对应唯一的accessToken
注意:以上第二步必须保证在同一事务中
3.返回最新的accessToken
2、使用accessToken调用第三方接口
1.获取对应的accessToken
2.使用AccessToken查询redis对应的value(appId)
3.如果没有获取到对应的appid,直接返回错误提示
4.如果能获取到对应的appid,使用appid查询对应的APP信息
5.使用appId查询数据库app信息,获取is_flag状态,如果为1,则不能调用接口,否则正常执行
6.直接调用接口业务
边栏推荐
- How can the sports app keep the end-to-side background alive to make the sports record more complete?
- 通过setTimeout解决子组件不会销毁的问题
- 3. Caller 服务调用 - dapr
- 【力扣】977. 有序数组的平方
- On the design principle of price discount in SAP software
- Azure Kinect Microsoft camera unity development summary
- 数字藏品热潮之下,你必须知道的那些事儿
- 中能融合携手天翼云打造“能源大脑”
- 昨日元宇宙|Meta “元宇宙”部门一季度亏损29.6亿美元,六福珠宝发行数字藏品
- 【Laravel】关于Laravel8的composer安装
猜你喜欢

全球陆续拥抱Web3.0,多国已明确开始抢占先机

岛屿类问题通用解法与DFS框架

Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse

Knowing these commands allows you to master shell's own tools

Slim gain (sgain) introduction and code implementation -- missing data filling based on generated countermeasure network

知道这几个命令让你掌握Shell自带工具

What are the most powerful small and medium-sized companies in Beijing?

Traffic management and control of firewall Foundation

The sadness of software testers is Their own technical ability can not meet the requirements of large manufacturers?

Visual studio 2019 software installation package and installation tutorial
随机推荐
Geoffrey Hinton:我的五十年深度学习生涯与研究心法
Visual studio 2019 software installation package and installation tutorial
Kiss in the metauniverse! CMU launched VR head display plug-in, reproducing the vivid touch of lips
General solution of island problems and DFS framework
On the design principle of price discount in SAP software
【Proteus仿真】L297驱动步进电机
[recommendation system] esmm model of multi task learning (updating)
【力扣】35. 搜索插入位置
MySQL self connection query "suggestions collection"
Redmibook Pro 14 enhanced version cannot open delta software drastudio_ v1.00.07.52
Internet of things cloud convergence Security Guide
媒体数据处理V2版本(VPC)图像缩放内容解析
Yesterday, metauniverse | Wal Mart set up an innovation department to explore metauniverse and Web3, and Dior released the metauniverse Exhibition
5 minutes to make a bouncing ball game
简单介绍一下tensorflow与pytorch的相互转换(主要是tensorflow转pytorch)
[high concurrency foundation] hidden dangers and solutions of MySQL concurrency under different transaction isolation levels
【力扣】977. 有序数组的平方
Knowing these commands allows you to master shell's own tools
What you have to know under the digital collection boom
平台即代码的未来是Kubernetes扩展