1
0
mirror of synced 2026-05-22 14:43:15 +00:00

docs: 合适的地方添加 ⚠️ 标识

This commit is contained in:
click33
2026-03-11 10:44:02 +08:00
parent 98a5f7934d
commit c0dbb1ecc8
6 changed files with 10 additions and 10 deletions
@@ -1493,7 +1493,7 @@ public AjaxJson doLogin(String username, String password) {
// 登录 // 登录
StpUtil.login(user.getId()); StpUtil.login(user.getId());
StpUtil.getSession().set("user", user); StpUtil.getSession().set("user", user);
return AjaxJson.getSuccess("登录成功").set("satoken", StpUtil.getTokenValue()); // 关键代码 return AjaxJson.getSuccess("登录成功").set("satoken", StpUtil.getTokenValue()); // ⚠️ 关键代码
} }
``` ```
@@ -1580,8 +1580,8 @@ public AjaxJson doLogin(String username, String password) {
Subject subject = SecurityUtils.getSubject(); Subject subject = SecurityUtils.getSubject();
try { try {
subject.login(new UsernamePasswordToken(username, password)); subject.login(new UsernamePasswordToken(username, password));
String token = subject.getSession().getId().toString(); // 关键代码 String token = subject.getSession().getId().toString(); // ⚠️ 关键代码
return AjaxJson.getSuccess("登录成功!").set("token", token); // 关键代码 return AjaxJson.getSuccess("登录成功!").set("token", token); // ⚠️ 关键代码
} catch (AuthenticationException e) { } catch (AuthenticationException e) {
e.printStackTrace(); e.printStackTrace();
return AjaxJson.getError(e.getMessage()); return AjaxJson.getError(e.getMessage());
+1 -1
View File
@@ -191,7 +191,7 @@ public class FeignInterceptor implements RequestInterceptor {
*/ */
@FeignClient( @FeignClient(
name = "sp-home", // 服务名称 name = "sp-home", // 服务名称
configuration = FeignInterceptor.class, // 请求拦截器 (关键代码) configuration = FeignInterceptor.class, // 请求拦截器 ⚠️ 关键代码)
fallbackFactory = SpCfgInterfaceFallback.class // 服务降级处理 fallbackFactory = SpCfgInterfaceFallback.class // 服务降级处理
) )
public interface SpCfgInterface { public interface SpCfgInterface {
+1 -1
View File
@@ -115,7 +115,7 @@ public class SaOAuth2DataLoaderImpl implements SaOAuth2DataLoader {
return new SaClientModel() return new SaClientModel()
.setClientId("xxxx") .setClientId("xxxx")
.setClientSecret("xxxx") .setClientSecret("xxxx")
.setSubjectId("1000001") // 关键代码:主体 id (可选) .setSubjectId("1000001") // ⚠️ 关键代码:主体 id (可选)
// .... // ....
; ;
} }
+2 -2
View File
@@ -300,7 +300,7 @@ public SaResult addMoney(long userId, long money, long timestamp, String nonce,
@RequestMapping("addMoney") @RequestMapping("addMoney")
public SaResult addMoney(long userId, long money, long timestamp, String nonce, String sign) { public SaResult addMoney(long userId, long money, long timestamp, String nonce, String sign) {
// 1、检查 timestamp 是否超出允许的范围 (重点一:此处需要取绝对值) // 1、检查 timestamp 是否超出允许的范围 (⚠️ 重点一:此处需要取绝对值)
long timestampDisparity = Math.abs(System.currentTimeMillis() - timestamp); long timestampDisparity = Math.abs(System.currentTimeMillis() - timestamp);
if(timestampDisparity > 1000 * 60 * 15) { if(timestampDisparity > 1000 * 60 * 15) {
return SaResult.error("timestamp 时间差超出允许的范围,请求无效"); return SaResult.error("timestamp 时间差超出允许的范围,请求无效");
@@ -312,7 +312,7 @@ public SaResult addMoney(long userId, long money, long timestamp, String nonce,
// 3、验证签名 // 3、验证签名
// 代码同上,不再赘述 // 代码同上,不再赘述
// 4、将 nonce 记入缓存,防止重复使用(重点二:此处需要将 ttl 设定为允许 timestamp 时间差的值 x 2 // 4、将 nonce 记入缓存,防止重复使用(⚠️ 重点二:此处需要将 ttl 设定为允许 timestamp 时间差的值 x 2
CacheUtil.set("nonce_" + nonce, "1", (1000 * 60 * 15) * 2); CacheUtil.set("nonce_" + nonce, "1", (1000 * 60 * 15) * 2);
// 5、业务代码 ... // 5、业务代码 ...
+2 -2
View File
@@ -140,11 +140,11 @@ public SaResult getData(String apiType, String loginId) {
System.out.println("apiType=" + apiType); System.out.println("apiType=" + apiType);
System.out.println("loginId=" + loginId); System.out.println("loginId=" + loginId);
// ↓↓↓ 重点代码 ↓↓↓ // ↓↓↓ ⚠️ 重点代码 ↓↓↓
// 校验签名:只有拥有正确秘钥发起的请求才能通过校验 // 校验签名:只有拥有正确秘钥发起的请求才能通过校验
String client = SaHolder.getRequest().getHeader("client"); String client = SaHolder.getRequest().getHeader("client");
SaSsoServerProcessor.instance.ssoServerTemplate.getSignTemplate(client).checkRequest(SaHolder.getRequest()); SaSsoServerProcessor.instance.ssoServerTemplate.getSignTemplate(client).checkRequest(SaHolder.getRequest());
// ↑↑↑ 重点代码 ↑↑↑ // ↑↑↑ ⚠️ 重点代码 ↑↑↑
// 自定义返回结果(模拟) // 自定义返回结果(模拟)
return SaResult.ok() return SaResult.ok()
+1 -1
View File
@@ -56,7 +56,7 @@ uni.request({
url: 'https://www.example.com/request', // 仅为示例,并非真实接口地址。 url: 'https://www.example.com/request', // 仅为示例,并非真实接口地址。
header: { header: {
"content-type": "application/x-www-form-urlencoded", "content-type": "application/x-www-form-urlencoded",
"satoken": uni.getStorageSync('tokenValue') // 关键代码, 注意参数名字是 satoken "satoken": uni.getStorageSync('tokenValue') // ⚠️ 关键代码, 注意参数名字是 satoken
}, },
success: (res) => { success: (res) => {
console.log(res.data); console.log(res.data);