package com.sunyard.chsm.controller; import com.sunyard.chsm.auth.AuthCode; import com.sunyard.chsm.constant.AuthCodeConst; import com.sunyard.chsm.model.R; import com.sunyard.chsm.param.GenRandomReq; import com.sunyard.chsm.param.GenRandomResp; import com.sunyard.chsm.sdf.SdfApiService; import com.sunyard.chsm.utils.CodecUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; /** * 随机数接口 * * @author liulu * @since 2024/12/25 */ @RestController public class RandomController { @Resource private SdfApiService sdfApiService; /** * 获取随机数 * * @param req * @return */ @PostMapping("/gen/random") @AuthCode(AuthCodeConst.gen_random) public R hash(@RequestBody GenRandomReq req) { byte[] random = sdfApiService.generateRandom(req.getLength()); GenRandomResp resp = new GenRandomResp(); resp.setRandom(CodecUtils.encodeBase64(random)); return R.data(resp); } }