| | |
| | | */ |
| | | public static final String MONTH = "month"; |
| | | |
| | | /** |
| | | * 错误码 |
| | | */ |
| | | public static final String ERR_CODE = "errcode"; |
| | | |
| | | } |
| | |
| | | |
| | | /** |
| | | * Token的Key常量 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class TokenConstants |
| | | { |
| | | public class TokenConstants { |
| | | /** |
| | | * 令牌自定义标识 |
| | | */ |
| | |
| | | */ |
| | | public final static String SECRET = "abcdefghijklmnopqrstuvwxyz"; |
| | | |
| | | /** |
| | | * 微信分享token地址 |
| | | */ |
| | | public final static String VX_TOKEN_API_PREFIX = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"; |
| | | |
| | | /** |
| | | * 微信分享获取票据地址 |
| | | */ |
| | | public final static String VX_TICKET_API_PREFIX = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi"; |
| | | |
| | | } |
| | |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.goods.domain.*; |
| | | import com.ruoyi.goods.dto.GoodExchangeDTO; |
| | | import com.ruoyi.goods.dto.GoodQueryDTO; |
| | | import com.ruoyi.goods.dto.GoodsTypeQuery; |
| | | import com.ruoyi.goods.service.*; |
| | | import com.ruoyi.goods.vo.TGoodsVO; |
| | | import com.ruoyi.system.api.model.LoginUserParent; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private IRecipientService recipientService; |
| | | @Resource |
| | | private IRegionService regionService; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | @PostMapping("/listType") |
| | | @ApiOperation(value = "列表查询", tags = {"后台-商品类型管理"}) |
| | |
| | | */ |
| | | @GetMapping("/exchangeRecord") |
| | | @ApiOperation(value = "兑换记录", tags = {"兑换记录"}) |
| | | public R<List<TOrder>> exchangeRecord() { |
| | | return R.ok(orderService.lambdaQuery().eq(TOrder::getUserId, SecurityUtils.getUserId()) |
| | | public AjaxResult<List<TOrder>> exchangeRecord() { |
| | | return AjaxResult.success(orderService.lambdaQuery().eq(TOrder::getUserId, tokenService.getLoginUserStudy().getUserid()) |
| | | .orderByDesc(TOrder::getCreateTime).list()); |
| | | } |
| | | |
| | | /** |
| | | * 兑换记录 |
| | | */ |
| | |
| | | */ |
| | | @GetMapping("/shopAddress") |
| | | @ApiOperation(value = "获取用户收货地址", tags = {"获取用户收货地址"}) |
| | | public R<List<Recipient>> shopAddress() { |
| | | return R.ok(recipientService.lambdaQuery().eq(Recipient::getUserId, |
| | | SecurityUtils.getUserId()).list()); |
| | | public AjaxResult<List<Recipient>> shopAddress() { |
| | | return AjaxResult.success(recipientService.lambdaQuery().eq(Recipient::getUserId, |
| | | tokenService.getLoginUserStudy().getUserid()).list()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PostMapping("/addressSaveOrUpdate") |
| | | @ApiOperation(value = "新增收货地址/修改收货地址", tags = {"新增收货地址/修改收货地址"}) |
| | | public R<String> addressSave(@RequestBody Recipient recipient) { |
| | | recipient.setUserId(SecurityUtils.getUserId().intValue()); |
| | | return R.ok(recipientService.addressSaveOrUpdate(recipient)); |
| | | public AjaxResult<String> addressSave(@RequestBody Recipient recipient) { |
| | | recipient.setUserId(tokenService.getLoginUserStudy().getUserid()); |
| | | return AjaxResult.success(recipientService.addressSaveOrUpdate(recipient)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/addressDelete") |
| | | @ApiOperation(value = "删除收货地址", tags = {"删除收货地址"}) |
| | | public R<String> addressDelete(@RequestParam String id) { |
| | | return R.ok(recipientService.removeById(id) ? "删除成功!" : "删除失败!"); |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "地址信息id", name = "id", dataType = "String", required = true) |
| | | }) |
| | | public AjaxResult<String> addressDelete(@RequestParam String id) { |
| | | return AjaxResult.success(recipientService.removeById(id) ? "删除成功!" : "删除失败!"); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/updateOrderAddress") |
| | | @ApiOperation(value = "修改订单收货地址", tags = {"修改订单收货地址"}) |
| | | public R<Boolean> updateOrderAddress(@RequestParam String orderId, @RequestParam String address) { |
| | | return R.ok(orderService.lambdaUpdate().set(TOrder::getConsigneeAddress, address) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true), |
| | | @ApiImplicitParam(value = "完整收货地址", name = "address", dataType = "String", required = true) |
| | | }) |
| | | public AjaxResult<Boolean> updateOrderAddress(@RequestParam String orderId, @RequestParam String address) { |
| | | return AjaxResult.success(orderService.lambdaUpdate().set(TOrder::getConsigneeAddress, address) |
| | | .eq(TOrder::getId, orderId).eq(TOrder::getState, 1).update()); |
| | | } |
| | | |
| | |
| | | */ |
| | | @GetMapping("/addressTree") |
| | | @ApiOperation(value = "收货地址省市区三级联动", tags = {"收货地址省市区三级联动"}) |
| | | public R<List<Region>> addressTree() { |
| | | return R.ok(regionService.addressTree()); |
| | | public AjaxResult<List<Region>> addressTree() { |
| | | return AjaxResult.success(regionService.addressTree()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/goodRecommend") |
| | | @ApiOperation(value = "可兑换商品推荐", tags = {"可兑换商品推荐"}) |
| | | public R<List<TGoodsVO>> goodRecommend(String userId) { |
| | | return R.ok(goodsService.goodRecommend(userId)); |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) |
| | | }) |
| | | public R<List<TGoodsVO>> goodRecommend() { |
| | | return R.ok(goodsService.goodRecommend(tokenService.getLoginUserStudy().getUserid())); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/goodDetail") |
| | | @ApiOperation(value = "商品详情", tags = {"商品详情"}) |
| | | public R<Map<String, Object>> goodDetail(@RequestParam String goodId) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> goodDetail(@RequestParam String goodId) { |
| | | Map<String, Object> result = new HashMap<>(8); |
| | | // 商品详情 |
| | | TGoods goods = goodsService.lambdaQuery().eq(TGoods::getId, goodId).one(); |
| | |
| | | // 已兑换人数 |
| | | result.put("number", goods.getBasicCount() + orderService.getGoodBuyNumber(goods.getId())); |
| | | // 用户收货地址 |
| | | if (SecurityUtils.getUserId() != null) { |
| | | if (tokenService.getLoginUserStudy().getUserid() != null) { |
| | | result.put("address", recipientService.lambdaQuery() |
| | | .eq(Recipient::getUserId, SecurityUtils.getUserId()).eq(Recipient::getIsDefault, 1).one()); |
| | | .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid()).eq(Recipient::getIsDefault, 1).one()); |
| | | } |
| | | return R.ok(result); |
| | | return AjaxResult.success(result); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/redeemNow") |
| | | @ApiOperation(value = "商城-立即兑换", tags = {"立即兑换"}) |
| | | public R<Map<String, Object>> redeemNow(@RequestParam String goodId) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> redeemNow(@RequestParam String goodId) { |
| | | Recipient recipient = recipientService.lambdaQuery() |
| | | .eq(Recipient::getUserId, SecurityUtils.getUserId()).eq(Recipient::getIsDefault, 1).one(); |
| | | return R.ok(goodsService.redeemNow(goodId, recipient)); |
| | | .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid()).eq(Recipient::getIsDefault, 1).one(); |
| | | return AjaxResult.success(goodsService.redeemNow(goodId, recipient)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PostMapping("/goodExchange") |
| | | @ApiOperation(value = "商品兑换-确认", tags = {"商品兑换-确认"}) |
| | | public R<Object> goodExchange(@RequestBody GoodExchangeDTO goodExchange) { |
| | | public AjaxResult<Object> goodExchange(@RequestBody GoodExchangeDTO goodExchange) { |
| | | Recipient recipient = recipientService.getById(goodExchange.getRecipientId()); |
| | | return R.ok(goodsService.goodExchange(goodExchange, recipient)); |
| | | return AjaxResult.success(goodsService.goodExchange(goodExchange, recipient)); |
| | | } |
| | | |
| | | } |
| | |
| | | * @param userId 用户id |
| | | * @return 推荐商品 |
| | | */ |
| | | List<TGoodsVO> goodRecommend(String userId); |
| | | List<TGoodsVO> goodRecommend(Integer userId); |
| | | |
| | | } |
| | |
| | | * @param userId 用户id |
| | | * @return 推荐商品 |
| | | */ |
| | | List<TGoodsVO> goodRecommend(String userId); |
| | | List<TGoodsVO> goodRecommend(Integer userId); |
| | | |
| | | /** |
| | | * 立即兑换 |
| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.goods.domain.Recipient; |
| | | import com.ruoyi.goods.mapper.RecipientMapper; |
| | | import com.ruoyi.goods.service.IRecipientService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class RecipientServiceImpl extends ServiceImpl<RecipientMapper, Recipient> implements IRecipientService { |
| | | |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String addressSaveOrUpdate(Recipient recipient) { |
| | | boolean result; |
| | | // 主键ID为空,新增收货地址 |
| | | if (StringUtils.isEmpty(String.valueOf(recipient.getId()))) { |
| | | recipient.setUserId(SecurityUtils.getUserId().intValue()); |
| | | recipient.setUserId(tokenService.getLoginUserStudy().getUserid()); |
| | | result = this.save(recipient); |
| | | } else { |
| | | result = this.updateById(recipient); |
| | |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.constant.RedisConstants; |
| | | import com.ruoyi.common.core.exception.GlobalException; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.goods.domain.Recipient; |
| | | import com.ruoyi.goods.domain.TGoods; |
| | | import com.ruoyi.goods.domain.TOrder; |
| | |
| | | private StudyClient studyClient; |
| | | @Resource |
| | | private ITOrderService orderService; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | @Override |
| | | public List<TGoodsVO> goodRecommend(String userId) { |
| | | public List<TGoodsVO> goodRecommend(Integer userId) { |
| | | return baseMapper.goodRecommend(userId); |
| | | } |
| | | |
| | |
| | | private TOrder orderInfo(GoodExchangeDTO goodExchange, Recipient recipient, Integer number, Integer goodId, int needIntegral) { |
| | | TOrder order = new TOrder(); |
| | | order.setOrderNumber(goodExchange.getOrderNumber()); |
| | | order.setUserId(SecurityUtils.getUserId().intValue()); |
| | | order.setUserId(tokenService.getLoginUserStudy().getUserid()); |
| | | order.setInsertTime(new Date()); |
| | | order.setGoodsId(goodId); |
| | | order.setCount(number); |
| | |
| | | import com.ruoyi.common.core.constant.RedisConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.GlobalException; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.goods.api.feignClient.GoodsClient; |
| | | import com.ruoyi.goods.api.model.TGoodsVO; |
| | | import com.ruoyi.study.domain.*; |
| | |
| | | */ |
| | | @GetMapping("/weekList") |
| | | @ApiOperation(value = "周目列表", tags = {"周目列表"}) |
| | | public R<List<StudyWeekDTO>> weekList(@RequestParam(defaultValue = "1") Integer type, @RequestParam Integer quarter) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "所属类型", name = "type", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "季度", name = "quarter", dataType = "Integer", required = true) |
| | | }) |
| | | public AjaxResult<List<StudyWeekDTO>> weekList(@RequestParam(defaultValue = "1") Integer type, @RequestParam Integer quarter) { |
| | | List<StudyWeekDTO> result = studyService.weekList(type, quarter); |
| | | return R.ok(result); |
| | | return AjaxResult.success(result); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/studySchedule") |
| | | @ApiOperation(value = "获取用户学习进度", tags = {"获取用户学习进度"}) |
| | | public R<TUserStudy> studySchedule(Integer week, Integer day) { |
| | | TUserStudy result = studyService.studySchedule(String.valueOf(SecurityUtils.getUserId()), week, day); |
| | | return R.ok(result); |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) |
| | | }) |
| | | public AjaxResult<TUserStudy> studySchedule(@RequestParam Integer week,@RequestParam Integer day) { |
| | | TUserStudy result = studyService.studySchedule(String.valueOf(tokenService.getLoginUserStudy().getUserid()), week, day); |
| | | return AjaxResult.success(result); |
| | | } |
| | | |
| | | /** |
| | |
| | | @GetMapping("/goodRecommend") |
| | | @ApiOperation(value = "可兑换商品推荐", tags = {"可兑换商品推荐"}) |
| | | public R<List<TGoodsVO>> studySchedule() { |
| | | return goodsClient.goodRecommend(String.valueOf(SecurityUtils.getUserId())); |
| | | return goodsClient.goodRecommend(String.valueOf(tokenService.getLoginUserStudy().getUserid())); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PostMapping("/exitLearning") |
| | | @ApiOperation(value = "退出学习(记录学习进度等信息)", tags = {"退出学习(记录学习进度等信息)"}) |
| | | public R<Boolean> exitLearning(@RequestBody TUserStudy userStudy) { |
| | | public AjaxResult<Boolean> exitLearning(@RequestBody TUserStudy userStudy) { |
| | | // 学习时长处理 |
| | | return R.ok(userStudyService.updateById(userStudy)); |
| | | return AjaxResult.success(userStudyService.updateById(userStudy)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/listenSelectPicture") |
| | | @ApiOperation(value = "自主学习1-听音选图", tags = {"自主学习1-听音选图"}) |
| | | public R<Map<String, Object>> listenSelectPicture(@RequestParam Integer week, @RequestParam Integer day) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> listenSelectPicture(@RequestParam Integer week, @RequestParam Integer day) { |
| | | // 判断当前登录用户是否为 会员 |
| | | Boolean isVip = userService.isVip(); |
| | | List<TStudyListen> studyListens = studyListenService.lambdaQuery().eq(TStudyListen::getWeek, week) |
| | | .eq(TStudyListen::getDay, day).eq(TStudyListen::getDisabled, 0).list(); |
| | | return R.ok(studyService.listenSelectPicture(week, day, studyListens)); |
| | | return AjaxResult.success(studyService.listenSelectPicture(week, day, studyListens)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/pictureSelectVoice") |
| | | @ApiOperation(value = "自主学习2-看图选音", tags = {"自主学习2-看图选音"}) |
| | | public R<Map<String, Object>> pictureSelectVoice(@RequestParam Integer week, @RequestParam Integer day) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> pictureSelectVoice(@RequestParam Integer week, @RequestParam Integer day) { |
| | | // 判断当前登录用户是否为 会员 |
| | | Boolean isVip = userService.isVip(); |
| | | LambdaQueryChainWrapper<TStudyLook> wrapper = studyLookService.lambdaQuery().eq(TStudyLook::getWeek, week) |
| | |
| | | } |
| | | List<TStudyLook> lookList = studyLookService.lambdaQuery().eq(TStudyLook::getWeek, week) |
| | | .eq(TStudyLook::getDay, day).eq(TStudyLook::getDisabled, 0).list(); |
| | | return R.ok(studyService.pictureSelectVoice(week, day, lookList)); |
| | | return AjaxResult.success(studyService.pictureSelectVoice(week, day, lookList)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/induceExclude") |
| | | @ApiOperation(value = "自主学习3-归纳排除", tags = {"自主学习3-归纳排除"}) |
| | | public R<Map<String, Object>> induceExclude(@RequestParam Integer week, @RequestParam Integer day) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> induceExclude(@RequestParam Integer week, @RequestParam Integer day) { |
| | | // 判断当前登录用户是否为 会员 |
| | | Boolean isVip = userService.isVip(); |
| | | LambdaQueryChainWrapper<TStudyInduction> wrapper = studyInductionService.lambdaQuery().eq(TStudyInduction::getWeek, week) |
| | |
| | | wrapper.eq(TStudyInduction::getIsVip, 0); |
| | | } |
| | | List<TStudyInduction> inductionList = wrapper.list(); |
| | | return R.ok(studyService.induceExclude(week, day, inductionList)); |
| | | return AjaxResult.success(studyService.induceExclude(week, day, inductionList)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/questionsAndAnswers") |
| | | @ApiOperation(value = "自主学习4-有问有答", tags = {"自主学习4-有问有答"}) |
| | | public R<Map<String, Object>> questionsAndAnswers(@RequestParam Integer week, @RequestParam Integer day) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> questionsAndAnswers(@RequestParam Integer week, @RequestParam Integer day) { |
| | | // 判断当前登录用户是否为 会员 |
| | | Boolean isVip = userService.isVip(); |
| | | LambdaQueryChainWrapper<TStudyAnswer> wrapper = studyAnswerService.lambdaQuery().eq(TStudyAnswer::getWeek, week) |
| | |
| | | wrapper.eq(TStudyAnswer::getIsVip, 0); |
| | | } |
| | | List<TStudyAnswer> answerList = wrapper.list(); |
| | | return R.ok(studyService.questionsAndAnswers(week, day, answerList)); |
| | | return AjaxResult.success(studyService.questionsAndAnswers(week, day, answerList)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/pictureMateVoice") |
| | | @ApiOperation(value = "自主学习5-音图相配", tags = {"自主学习5-音图相配"}) |
| | | public R<Map<String, Object>> pictureMateVoice(@RequestParam Integer week, @RequestParam Integer day) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "周目", name = "week", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "所属day", name = "day", dataType = "Integer", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> pictureMateVoice(@RequestParam Integer week, @RequestParam Integer day) { |
| | | // 判断当前登录用户是否为 会员 todo |
| | | TStudyPair pair = studyPairService.lambdaQuery().eq(TStudyPair::getWeek, week) |
| | | .eq(TStudyPair::getDay, day).eq(TStudyPair::getDisabled, 0).one(); |
| | | return R.ok(studyService.pictureMateVoice(week, day, pair)); |
| | | return AjaxResult.success(studyService.pictureMateVoice(week, day, pair)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/gameHearing") |
| | | @ApiOperation(value = "自主游戏1-超级听力", tags = {"自主游戏1-超级听力(difficulty: 0入门、1中级、2高级)"}) |
| | | public R<Map<String, Object>> gameHearing(@RequestParam Integer difficulty, @RequestParam Integer week) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "难度(0入门、1中级、2困难)", name = "difficulty", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "所属周目", name = "week", dataType = "Integer", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> gameHearing(@RequestParam Integer difficulty, @RequestParam Integer week) { |
| | | Map<String, Object> result = new HashMap<>(8); |
| | | TGame game = gameService.lambdaQuery().eq(TGame::getWeek, week) |
| | | .eq(TGame::getDisabled, 0).one(); |
| | |
| | | subjectData.add(subjectId.get(randomIndex)); |
| | | } |
| | | result.put("subject", subjectService.lambdaQuery().in(TSubject::getId, subjectData).eq(TSubject::getState, 1).list()); |
| | | return R.ok(result); |
| | | return AjaxResult.success(result); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/gameMemory") |
| | | @ApiOperation(value = "自主游戏2-超级记忆", tags = {"自主游戏2-超级记忆(difficulty: 0入门、1中级、2高级)"}) |
| | | public R<Map<String, Object>> gameMemory(@RequestParam Integer difficulty, @RequestParam Integer week) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "难度(0入门、1中级、2困难)", name = "difficulty", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "所属周目", name = "week", dataType = "Integer", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> gameMemory(@RequestParam Integer difficulty, @RequestParam Integer week) { |
| | | Map<String, Object> result = new HashMap<>(8); |
| | | TGame game = gameService.lambdaQuery().eq(TGame::getWeek, week).eq(TGame::getDisabled, 0).one(); |
| | | result.put("game", game); |
| | |
| | | subjectData.add(subjectId.get(randomIndex)); |
| | | } |
| | | result.put("subject", subjectService.lambdaQuery().in(TSubject::getId, subjectData).eq(TSubject::getState, 1).list()); |
| | | return R.ok(result); |
| | | return AjaxResult.success(result); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PostMapping("/gameAchievement") |
| | | @ApiOperation(value = "完成游戏-记录游戏测试成绩", tags = {"完成游戏-记录游戏测试成绩"}) |
| | | public R<?> gameAchievement(@RequestBody CompleteGameDTO completeStudy) { |
| | | public AjaxResult<?> gameAchievement(@RequestBody CompleteGameDTO completeStudy) { |
| | | TGame game = gameService.getById(completeStudy.getGameId()); |
| | | // 游戏测试记录 |
| | | Boolean add = gameRecordService.add(completeStudy); |
| | | // 添加积分明细记录 |
| | | add = add && integralRecordService.add(game.getIntegral(), completeStudy.getMethod()); |
| | | // 用户账户添加积分 |
| | | return R.ok(add); |
| | | return AjaxResult.success(add); |
| | | } |
| | | |
| | | private List<String> getSubjectId(Integer week) { |
| | |
| | | */ |
| | | @GetMapping("/lookPictureDbu") |
| | | @ApiOperation(value = "自主故事1-看图配音", tags = {"自主故事1-看图配音"}) |
| | | public R<Map<String, Object>> lookPictureDbu(@RequestParam Integer week) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "所属周目", name = "week", dataType = "Integer", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> lookPictureDbu(@RequestParam Integer week) { |
| | | // 看图配音信息 |
| | | TStoryListen listen = storyListenService.lambdaQuery().eq(TStoryListen::getWeek, week).one(); |
| | | // 获取对应图片语音 |
| | |
| | | Map<String, Object> result = new HashMap<>(8); |
| | | result.put("listen", listen); |
| | | result.put("info", subjectService.lambdaQuery().in(TSubject::getId, list).list()); |
| | | return R.ok(result); |
| | | return AjaxResult.success(result); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/frameworkMemory") |
| | | @ApiOperation(value = "自主故事2-框架记忆", tags = {"自主故事2-框架记忆"}) |
| | | public R<Map<String, Object>> frameworkMemory(@RequestParam Integer week) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "所属周目", name = "week", dataType = "Integer", required = true) |
| | | }) |
| | | public AjaxResult<Map<String, Object>> frameworkMemory(@RequestParam Integer week) { |
| | | // 看图配音信息 |
| | | TStoryListen listen = storyListenService.lambdaQuery().eq(TStoryListen::getWeek, week).one(); |
| | | // 获取对应图片语音 |
| | |
| | | Map<String, Object> result = new HashMap<>(8); |
| | | result.put("listen", listen); |
| | | result.put("info", subjectService.lambdaQuery().in(TSubject::getId, list).list()); |
| | | return R.ok(result); |
| | | return AjaxResult.success(result); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PostMapping("/completeLearning") |
| | | @ApiOperation(value = "完成学习", tags = {"完成学习"}) |
| | | public R<Boolean> completeLearning(@RequestBody CompleteStudyDTO completeStudy) { |
| | | public AjaxResult<Boolean> completeLearning(@RequestBody CompleteStudyDTO completeStudy) { |
| | | // 登录用户id |
| | | Long userId = SecurityUtils.getUserId(); |
| | | Integer userId = tokenService.getLoginUserStudy().getUserid(); |
| | | // 获取user详细信息,改变积分 |
| | | TUser user = userService.getById(userId); |
| | | user.setIntegral(user.getIntegral() + completeStudy.getIntegral()); |
| | |
| | | TIntegralRecord integralRecord = new TIntegralRecord(); |
| | | integralRecord.setIntegral(String.valueOf(completeStudy.getIntegral())); |
| | | integralRecord.setMethod(completeStudy.getMethod()); |
| | | integralRecord.setUserId(SecurityUtils.getUserId().intValue()); |
| | | return R.ok(update && integralRecordService.save(integralRecord)); |
| | | integralRecord.setUserId(tokenService.getLoginUserStudy().getUserid()); |
| | | return AjaxResult.success(update && integralRecordService.save(integralRecord)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/completeStory") |
| | | @ApiOperation(value = "完成故事学习", tags = {"完成故事学习"}) |
| | | public R<?> completeStory(@RequestParam Integer integral, @RequestParam Integer storyId, |
| | | @RequestParam @ApiParam("完成答题/完成听故事") String method) { |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "积分数量", name = "integral", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "故事id", name = "storyId", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "完成答题/完成听故事", name = "method", dataType = "String", required = true) |
| | | }) |
| | | public AjaxResult<Boolean> completeStory(@RequestParam Integer integral, @RequestParam Integer storyId, |
| | | @RequestParam String method) { |
| | | // 添加积分明细记录 |
| | | Boolean add = integralRecordService.add(String.valueOf(integral), method); |
| | | // 用户信息 |
| | | Long userId = SecurityUtils.getUserId(); |
| | | Integer userId = tokenService.getLoginUserStudy().getUserid(); |
| | | TUser user = userService.lambdaQuery().eq(TUser::getId, userId).one(); |
| | | // 返回结果 |
| | | user.setIntegral(user.getIntegral() + integral); |
| | | return R.ok(add && userService.updateById(user)); |
| | | return AjaxResult.success(add && userService.updateById(user)); |
| | | } |
| | | |
| | | @GetMapping("/studyRecord") |
| | | @ApiOperation(value = "个人中心-学习记录", tags = {"个人中心-学习记录"}) |
| | | public R<Map<String, Object>> studyRecord() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | public AjaxResult<Map<String, Object>> studyRecord() { |
| | | Integer userId = tokenService.getLoginUserStudy().getUserid(); |
| | | Map<String, Object> result = new HashMap<>(8); |
| | | // 学习记录 |
| | | result.put("record", userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId) |
| | |
| | | // 游戏测试成绩 |
| | | result.put("gameAchievement", gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userId) |
| | | .eq(TGameRecord::getDisabled, 0).list()); |
| | | return R.ok(result); |
| | | return AjaxResult.success(result); |
| | | } |
| | | |
| | | @GetMapping("/integralDetail") |
| | | @ApiOperation(value = "个人中心-积分明细", tags = {"个人中心-积分明细"}) |
| | | public R<IPage<TIntegralRecord>> integralDetail(String time, |
| | | @RequestParam("pageNum") Integer pageNum, |
| | | @RequestParam("pageSize") Integer pageSize) { |
| | | return R.ok(integralRecordService.integralDetail(new Page<>(pageNum, pageSize), SecurityUtils.getUserId(), time)); |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "查询时间", name = "time", dataType = "Integer"), |
| | | @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "每页显示条数", name = "pageSize", dataType = "Integer", required = true) |
| | | }) |
| | | public AjaxResult<IPage<TIntegralRecord>> integralDetail(String time, |
| | | @RequestParam("pageNum") Integer pageNum, |
| | | @RequestParam("pageSize") Integer pageSize) { |
| | | return AjaxResult.success(integralRecordService.integralDetail(new Page<>(pageNum, pageSize), tokenService.getLoginUserStudy().getUserid(), time)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/addIntegralDetail") |
| | | @ApiOperation(value = "添加-积分明细", tags = {"添加-积分明细"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "积分数量", name = "integral", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "变动源(完成学习、完成游戏...)", name = "method", dataType = "String", required = true) |
| | | }) |
| | | public R<Boolean> addIntegralDetail(@RequestParam("integral") String integral, @RequestParam("method") String method) { |
| | | TIntegralRecord integralRecord = new TIntegralRecord(); |
| | | integralRecord.setIntegral(integral); |
| | | integralRecord.setMethod(method); |
| | | integralRecord.setUserId(SecurityUtils.getUserId().intValue()); |
| | | integralRecord.setUserId(tokenService.getLoginUserStudy().getUserid()); |
| | | integralRecord.setDisabled(Boolean.FALSE); |
| | | return R.ok(integralRecordService.save(integralRecord)); |
| | | } |
| | |
| | | */ |
| | | @GetMapping("/sendPhoneCode") |
| | | @ApiOperation(value = "发送手机验证码", tags = {"家长端/学习端-发送手机验证码"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "手机号", name = "phone", dataType = "string", required = true), |
| | | }) |
| | | public AjaxResult sendPhoneCode(@RequestParam String phone) { |
| | | return userService.phoneCode(phone) ? AjaxResult.success() : AjaxResult.error(); |
| | | } |
| | | |
| | | /** |
| | | * 家长端 学习端都可用 |
| | | * |
| | | * @param url app网页链接 |
| | | */ |
| | | @GetMapping("/weiXinShare") |
| | | @ApiOperation(value = "微信分享", tags = {"微信分享"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "应用分享url地址", name = "url", dataType = "string", required = true), |
| | | }) |
| | | public AjaxResult weiXinShare(@RequestParam String url) { |
| | | return AjaxResult.success(userService.weiXinShare(url)); |
| | | } |
| | | |
| | | @PostMapping("/deleteUser") |
| | | @ApiOperation(value = "注销当前帐号", tags = {"家长端-个人中心"}) |
| | | @ApiImplicitParams({ |
| | |
| | | * @param time yyyy-mm格式时间 |
| | | * @return 分页列表 |
| | | */ |
| | | IPage<TIntegralRecord> integralDetail(@Param("userId") Long userId, @Param("time") String time, Page<TIntegralRecord> page); |
| | | IPage<TIntegralRecord> integralDetail(@Param("userId") Integer userId, @Param("time") String time, Page<TIntegralRecord> page); |
| | | } |
| | |
| | | * @param time yyyy-mm格式时间 |
| | | * @return 分页列表 |
| | | */ |
| | | IPage<TIntegralRecord> integralDetail(Page<TIntegralRecord> page, Long userId, String time); |
| | | IPage<TIntegralRecord> integralDetail(Page<TIntegralRecord> page, Integer userId, String time); |
| | | |
| | | /** |
| | | * 生成积分明细 |
| | |
| | | import com.ruoyi.study.vo.AppUserVO; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @return 判断结果 |
| | | */ |
| | | Boolean isVip(); |
| | | |
| | | /** |
| | | * 微信分享app |
| | | * |
| | | * @param url app网页链接 |
| | | * @return 返回信息 |
| | | */ |
| | | Map<String, Object> weiXinShare(String url); |
| | | } |
| | |
| | | package com.ruoyi.study.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.study.domain.TGameRecord; |
| | | import com.ruoyi.study.dto.CompleteGameDTO; |
| | | import com.ruoyi.study.mapper.TGameRecordMapper; |
| | | import com.ruoyi.study.service.ITGameRecordService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class TGameRecordServiceImpl extends ServiceImpl<TGameRecordMapper, TGameRecord> implements ITGameRecordService { |
| | | |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean add(CompleteGameDTO gameAchievement) { |
| | | TGameRecord data = new TGameRecord(); |
| | | data.setUserId(SecurityUtils.getUserId().intValue()); |
| | | data.setUserId(tokenService.getLoginUserStudy().getUserid()); |
| | | data.setAccuracy(gameAchievement.getAccuracy()); |
| | | data.setGameName(gameAchievement.getGameName()); |
| | | data.setUseTime(gameAchievement.getUseTime()); |
| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.study.domain.TIntegralRecord; |
| | | import com.ruoyi.study.mapper.TIntegralRecordMapper; |
| | | import com.ruoyi.study.service.ITIntegralRecordService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class TIntegralRecordServiceImpl extends ServiceImpl<TIntegralRecordMapper, TIntegralRecord> implements ITIntegralRecordService { |
| | | |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | @Override |
| | | public IPage<TIntegralRecord> integralDetail(Page<TIntegralRecord> page, Long userId, String time) { |
| | | public IPage<TIntegralRecord> integralDetail(Page<TIntegralRecord> page, Integer userId, String time) { |
| | | return baseMapper.integralDetail(userId, time, page); |
| | | } |
| | | |
| | |
| | | TIntegralRecord integralRecord = new TIntegralRecord(); |
| | | integralRecord.setIntegral(integral); |
| | | integralRecord.setMethod(method); |
| | | integralRecord.setUserId(SecurityUtils.getUserId().intValue()); |
| | | integralRecord.setUserId(tokenService.getLoginUserStudy().getUserid()); |
| | | return this.save(integralRecord); |
| | | } |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.exception.GlobalException; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.study.domain.*; |
| | | import com.ruoyi.study.dto.StudyWeekDTO; |
| | | import com.ruoyi.study.mapper.TStudyMapper; |
| | | import com.ruoyi.study.service.*; |
| | | import com.ruoyi.study.service.ITGameRecordService; |
| | | import com.ruoyi.study.service.ITStudyService; |
| | | import com.ruoyi.study.service.ITSubjectService; |
| | | import com.ruoyi.study.service.ITUserStudyService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Resource |
| | | private ITUserStudyService userStudyService; |
| | | @Resource |
| | | private ITStudyListenService studyListenService; |
| | | @Resource |
| | | private ITSubjectService subjectService; |
| | | @Resource |
| | | private ITGameRecordService gameRecordService; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | private final static Map<String, Integer> GAME_DIFFICULTY_MAP = new HashMap<>(); |
| | | |
| | |
| | | throw new GlobalException("游戏等级异常,请重试!"); |
| | | } |
| | | // 获取用户游戏进度 |
| | | Long userId = SecurityUtils.getUserId(); |
| | | Integer userId = tokenService.getLoginUserStudy().getUserid(); |
| | | List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userId).eq(TGameRecord::getGameId, game.getId()).list(); |
| | | boolean contains = list.stream().map(TGameRecord::getGameDifficulty).collect(Collectors.toList()).contains(level); |
| | | if (!contains) { |
| | |
| | | package com.ruoyi.study.service.impl; |
| | | |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.constant.RedisConstants; |
| | | import com.ruoyi.common.core.constant.TokenConstants; |
| | | import com.ruoyi.common.core.exception.GlobalException; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.study.domain.TUser; |
| | | import com.ruoyi.study.dto.AppUserQuery; |
| | | import com.ruoyi.study.mapper.TUserMapper; |
| | | import com.ruoyi.study.service.ITUserService; |
| | | import com.ruoyi.study.utils.RandomVxUtil; |
| | | import com.ruoyi.study.utils.SignatureUtil; |
| | | import com.ruoyi.study.vo.AppUserVO; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.HttpStatus; |
| | | import org.apache.http.client.HttpClient; |
| | | import org.apache.http.client.methods.HttpGet; |
| | | import org.apache.http.impl.client.HttpClients; |
| | | import org.apache.http.util.EntityUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | /** |
| | | * 微信公众号的appid |
| | | */ |
| | | @Value("appId") |
| | | private String appId; |
| | | |
| | | /** |
| | | * 微信公众号的appSecret |
| | | */ |
| | | @Value("secret") |
| | | private String secret; |
| | | |
| | | @Override |
| | | public List<AppUserVO> listAll(AppUserQuery query) { |
| | |
| | | return null != vipEndTime && System.currentTimeMillis() <= vipEndTime.getTime(); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> weiXinShare(String url) { |
| | | // 初始化微信API,并注册AppID |
| | | long timestamp = System.currentTimeMillis() / 1000; |
| | | String noncestr = RandomVxUtil.createRandomString(16); |
| | | String ticket = getTicket(getToken(appId, secret)); |
| | | String str = "jsapi_ticket=" + ticket + "&noncestr=" + noncestr + "×tamp=" + timestamp + "&url=" + url; |
| | | // 获取加密后的签名 |
| | | String signature = SignatureUtil.getSignature(str); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("appId", appId); |
| | | map.put("timestamp", timestamp); |
| | | map.put("nonceStr", noncestr); |
| | | map.put("signature", signature); |
| | | return map; |
| | | } |
| | | |
| | | public String getToken(String appid, String secret) { |
| | | //拼接访问地址 |
| | | String apiUrl = String.format(TokenConstants.VX_TOKEN_API_PREFIX, appid, secret); |
| | | HttpClient client = HttpClients.createDefault(); |
| | | //get请求 |
| | | HttpGet get = new HttpGet(apiUrl); |
| | | // 初始化解析json格式的对象 |
| | | String result = null; |
| | | try { |
| | | HttpResponse res = client.execute(get); |
| | | // 初始化响应内容 |
| | | String responseContent; |
| | | HttpEntity entity = res.getEntity(); |
| | | //设置编码格式 |
| | | responseContent = EntityUtils.toString(entity, "UTF-8"); |
| | | // 将json字符串转换为json对象 |
| | | JSONObject json = JSONObject.parseObject(responseContent); |
| | | if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { |
| | | if (json.get(Constants.ERR_CODE) != null) { |
| | | // 错误时微信会返回错误码等信息,{"errcode":40013,"errmsg":"invalid appid"} |
| | | throw new GlobalException("微信授权失败!"); |
| | | } else { |
| | | // 正常情况下{"access_token":"ACCESS_TOKEN","expires_in":7200} |
| | | result = String.valueOf(json.get("access_token")); |
| | | } |
| | | } |
| | | return result; |
| | | } catch (IOException e) { |
| | | throw new GlobalException("微信授权失败!"); |
| | | } |
| | | } |
| | | |
| | | public static String getTicket(String accessToken) { |
| | | String turl = String.format(TokenConstants.VX_TICKET_API_PREFIX, accessToken); |
| | | HttpClient client = HttpClients.createDefault(); |
| | | HttpGet get = new HttpGet(turl); |
| | | String result = null; |
| | | try { |
| | | HttpResponse res = client.execute(get); |
| | | // 响应内容 |
| | | String responseContent; |
| | | HttpEntity entity = res.getEntity(); |
| | | responseContent = EntityUtils.toString(entity, "UTF-8"); |
| | | JSONObject jsonObject = JSONObject.parseObject(responseContent); |
| | | // 将json字符串转换为json对象 |
| | | if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { |
| | | if (jsonObject.get(Constants.ERR_CODE) == null) { |
| | | // 错误时微信会返回错误码等信息,{"errcode":40013,"errmsg":"invalid appid"} |
| | | throw new GlobalException("微信授权失败!"); |
| | | } else { |
| | | // 正常情况下{"access_token":"ACCESS_TOKEN","expires_in":7200} |
| | | result = String.valueOf(jsonObject.get("ticket")); |
| | | } |
| | | } |
| | | return result; |
| | | } catch (IOException e) { |
| | | throw new GlobalException("微信授权失败!"); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | private static Logger logger = LoggerFactory.getLogger(HttpClientUtil.class); |
| | | |
| | | /** |
| | | * get请求 |
| | | */ |
| | | public static final String GET = "GET"; |
| | | |
| | | /** |
| | | * post请求 |
| | | */ |
| | | public static final String POST = "POST"; |
| | | |
| | | private static PoolingHttpClientConnectionManager connectionManager; |
| | | |
| | | |
| | |
| | | logger.info(sdf.format(new Date()) + "----(" + randome + ")请求参数:" + JSON.toJSONString(params)); |
| | | CloseableHttpResponse httpResponse = null; |
| | | switch (mothed) { |
| | | case "GET": |
| | | case GET: |
| | | httpResponse = setGetHttpRequset(url, params, header); |
| | | break; |
| | | case "POST": |
| | | case POST: |
| | | httpResponse = setPostHttpRequset(url, params, header, contentType); |
| | | break; |
| | | } |
New file |
| | |
| | | package com.ruoyi.study.utils; |
| | | |
| | | import java.util.Random; |
| | | |
| | | /** |
| | | * @author HJL |
| | | * @version 1.0 |
| | | * @since 2024-05-21 14:22 |
| | | */ |
| | | public class RandomVxUtil { |
| | | |
| | | /** |
| | | * 最后又重复两个0和1,因为需要凑足数组长度为64 |
| | | */ |
| | | private static final char[] CH = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', |
| | | 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', |
| | | 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', |
| | | 'x', 'y', 'z', '0', '1'}; |
| | | |
| | | private static final Random RANDOM = new Random(); |
| | | |
| | | /** |
| | | * 生成指定长度的随机字符串 |
| | | * |
| | | * @param length 长度 |
| | | * @return 随机字符串 |
| | | */ |
| | | public static String createRandomString(int length) { |
| | | if (length > 0) { |
| | | int index = 0; |
| | | char[] temp = new char[length]; |
| | | int num = RANDOM.nextInt(); |
| | | for (int i = 0; i < length % 5; i++) { |
| | | //取后面六位,记得对应的二进制是以补码形式存在的 |
| | | temp[index++] = CH[num & 63]; |
| | | //63的二进制为:111111 |
| | | num >>= 6; |
| | | // 为什么要右移6位?因为数组里面一共有64个有效字符。为什么要除5取余?因为一个int型要用4个字节表示,也就是32位。 |
| | | } |
| | | for (int i = 0; i < length / 5; i++) { |
| | | num = RANDOM.nextInt(); |
| | | for (int j = 0; j < 5; j++) { |
| | | temp[index++] = CH[num & 63]; |
| | | num >>= 6; |
| | | } |
| | | } |
| | | return new String(temp, 0, length); |
| | | } else if (length == 0) { |
| | | return ""; |
| | | } else { |
| | | throw new IllegalArgumentException(); |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(createRandomString(16)); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ruoyi.study.utils; |
| | | |
| | | import java.security.MessageDigest; |
| | | |
| | | /** |
| | | * @author HJL |
| | | * @version 1.0 |
| | | * @since 2024-05-21 14:22 |
| | | */ |
| | | public class SignatureUtil { |
| | | |
| | | private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', |
| | | '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; |
| | | |
| | | private static String getFormattedText(byte[] bytes) { |
| | | int len = bytes.length; |
| | | StringBuilder buf = new StringBuilder(len * 2); |
| | | // 把密文转换成十六进制的字符串形式 |
| | | for (byte aByte : bytes) { |
| | | buf.append(HEX_DIGITS[(aByte >> 4) & 0x0f]); |
| | | buf.append(HEX_DIGITS[aByte & 0x0f]); |
| | | } |
| | | return buf.toString(); |
| | | } |
| | | |
| | | public static String getSignature(String str) { |
| | | if (str == null) { |
| | | return null; |
| | | } |
| | | try { |
| | | MessageDigest messageDigest = MessageDigest.getInstance("SHA1"); |
| | | messageDigest.reset(); |
| | | messageDigest.update(str.getBytes()); |
| | | return getFormattedText(messageDigest.digest()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |