19 changed files with 785 additions and 320 deletions
@ -0,0 +1,28 @@ |
|||
package com.bnyer.img.config; |
|||
|
|||
import lombok.Getter; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
/** |
|||
* 快手配置类 |
|||
* @author chengkun |
|||
* @date 2022/4/21 17:43 |
|||
*/ |
|||
@Configuration |
|||
@ConfigurationProperties(prefix = "bnyer.img.fasthand") |
|||
@Getter |
|||
@RefreshScope |
|||
public class FhConfig { |
|||
|
|||
@Value("${bnyer.img.fasthand.appId}") |
|||
private String appId; |
|||
|
|||
@Value("${bnyer.img.fasthand.secret}") |
|||
public String secret; |
|||
|
|||
@Value("${bnyer.img.fasthand.sessionInfoUrl}") |
|||
public String sessionInfoUrl; |
|||
} |
|||
@ -0,0 +1,226 @@ |
|||
package com.bnyer.img.controller; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.bnyer.common.core.web.controller.BaseController; |
|||
import com.bnyer.common.core.web.domain.AjaxResult; |
|||
import com.bnyer.common.core.web.page.TableDataInfo; |
|||
import com.bnyer.img.constants.TiktokConstant; |
|||
import com.bnyer.img.domain.Feedback; |
|||
import com.bnyer.img.dto.*; |
|||
import com.bnyer.img.service.*; |
|||
import com.bnyer.img.vo.CreatorTypeImgsVo; |
|||
import com.bnyer.img.vo.TiktokImgVo; |
|||
import com.github.pagehelper.PageHelper; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Api(value = "【快手小程序】接口",tags = "【快手小程序】接口") |
|||
@RestController |
|||
@RequestMapping("/img/mini/fh") |
|||
@Slf4j |
|||
public class FhMiniController extends BaseController { |
|||
|
|||
@Autowired |
|||
private BannerService bannerService; |
|||
|
|||
@Autowired |
|||
private FeedBackService feedBackService; |
|||
|
|||
@Autowired |
|||
private TypeService typeService; |
|||
|
|||
@Autowired |
|||
private TiktokImgService tiktokImgService; |
|||
|
|||
@Autowired |
|||
private FhUserService fhUserService; |
|||
|
|||
@Autowired |
|||
private CreatorService creatorService; |
|||
|
|||
@Autowired |
|||
private TiktokCollectionService tiktokCollectionService; |
|||
|
|||
@Autowired |
|||
private TiktokLikeService tiktokLikeService; |
|||
|
|||
@Autowired |
|||
private CreatorProfitService creatorProfitService; |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="查询banner列表") |
|||
@GetMapping(value = "/listBanner") |
|||
public AjaxResult listBanner(){ |
|||
return AjaxResult.success(bannerService.queryList("2")); |
|||
} |
|||
|
|||
@ApiOperation(value="新增feedback") |
|||
@PostMapping(value = "/insertFeedback") |
|||
public AjaxResult insertFeedback(@Validated @RequestBody @ApiParam("feedback对象") FeedBackDto dto){ |
|||
log.info("【快手图文小程序】新增反馈参数为:{}", JSON.toJSONString(dto)); |
|||
Feedback feedback = dto.extractParam(); |
|||
feedback.setSource("1"); |
|||
return AjaxResult.success(feedBackService.insert(feedback)); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="查询type列表") |
|||
@GetMapping(value = "/listType") |
|||
public AjaxResult listType(){ |
|||
return AjaxResult.success(typeService.queryList()); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
// @ApiOperation(value="查询指定艺术家图片集合")
|
|||
// @PostMapping(value = "/listTiktokImgOut")
|
|||
// public AjaxResult listTiktokImgOut(@Validated @RequestBody @ApiParam("TiktokImg对象") TiktokImgListMiniDto dto){
|
|||
// return AjaxResult.success(tiktokImgService.queryOutList(dto.getCreatorId(),dto.getTypeId()));
|
|||
// }
|
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="查询图片详情") |
|||
@GetMapping(value = "/detailsTiktokImg/{id}") |
|||
public AjaxResult detailsTiktokImg(@ApiParam("图片id") @PathVariable Long id){ |
|||
return AjaxResult.success(tiktokImgService.queryImgDetails(String.valueOf(id))); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="艺术家界面查询艺术家图片分页") |
|||
@PostMapping(value = "/creatorImgsPage") |
|||
public TableDataInfo creatorImgsPage(@RequestBody @ApiParam("分页对象") BasePageDto dto){ |
|||
PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); |
|||
return getDataTable(creatorService.queryThreeImgCreatorList()); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="根据搜索码查询艺术家图片列表") |
|||
@PostMapping(value = "/creatorImgsDetails") |
|||
public AjaxResult creatorImgsDetails(@Validated @RequestBody @ApiParam("搜索码对象") CreatorImgsDetailsDto params){ |
|||
CreatorTypeImgsVo creatorVo = creatorService.queryCreatorImgListByScanCode(params.getScanCode()); |
|||
if(creatorVo == null){ |
|||
return AjaxResult.error(TiktokConstant.TIKTOK_CREATOR_NOT_EXIST,"该艺术家不存在!"); |
|||
} |
|||
return AjaxResult.success(creatorVo); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="收藏") |
|||
@PostMapping(value = "/fhCollect") |
|||
public AjaxResult fhCollect(@Validated @RequestBody @ApiParam("收藏对象") CollectionDto dto){ |
|||
tiktokCollectionService.collect(dto.getUserId(),dto.getImgId(),"1"); |
|||
log.debug("【快手图文小程序】用户【{}】收藏了图片【{}】",dto.getUserId(),dto.getImgId()); |
|||
return AjaxResult.success(); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="取消收藏") |
|||
@PostMapping(value = "/fhUnCollect") |
|||
public AjaxResult fhUnCollect(@Validated @RequestBody @ApiParam("收藏对象") CollectionDto dto){ |
|||
tiktokCollectionService.unCollect(dto.getUserId(),dto.getImgId(),"1"); |
|||
log.debug("【快手图文小程序】用户【{}】取消收藏了图片【{}】",dto.getUserId(),dto.getImgId()); |
|||
return AjaxResult.success(); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="查询是否收藏过") |
|||
@PostMapping(value = "/judgeFhCollect") |
|||
public AjaxResult judgeFhCollect(@Validated @RequestBody @ApiParam("收藏对象") CollectionDto dto){ |
|||
log.debug("【快手图文小程序】查询是否收藏过参数为:{}", JSON.toJSONString(dto)); |
|||
return AjaxResult.success(tiktokCollectionService.judgeCollect(dto.getUserId(),dto.getImgId(),"1")); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="查看用户收藏分页") |
|||
@PostMapping(value = "/listFhCollection") |
|||
public TableDataInfo listFhCollection(@Validated @RequestBody @ApiParam("用户收藏对象") CollectionUserDto dto){ |
|||
PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); |
|||
log.debug("【快手图文小程序】查看用户【{}】收藏分页", dto.getUserId()); |
|||
return getDataTable(tiktokCollectionService.getCollectionByUserId(dto.getUserId(),"1")); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="点赞") |
|||
@PostMapping(value = "/fhLike") |
|||
public AjaxResult fhLike(@Validated @RequestBody @ApiParam("点赞对象") CollectionDto dto){ |
|||
tiktokLikeService.like(dto.getUserId(),dto.getImgId(),"1"); |
|||
log.debug("【快手图文小程序】用户【{}】点赞了图片【{}】",dto.getUserId(),dto.getImgId()); |
|||
return AjaxResult.success(); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="取消点赞") |
|||
@PostMapping(value = "/fhUnLike") |
|||
public AjaxResult fhUnLike(@Validated @RequestBody @ApiParam("点赞对象") CollectionDto dto){ |
|||
tiktokLikeService.unLike(dto.getUserId(),dto.getImgId(),"1"); |
|||
log.debug("【快手图文小程序】用户【{}】取消点赞了图片【{}】",dto.getUserId(),dto.getImgId()); |
|||
return AjaxResult.success(); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="查询是否点赞过") |
|||
@PostMapping(value = "/judgeFhLike") |
|||
public AjaxResult judgeTiktokLike(@Validated @RequestBody @ApiParam("点赞对象") CollectionDto dto){ |
|||
log.debug("【快手图文小程序】查询是否点赞过参数为:{}", JSON.toJSONString(dto)); |
|||
return AjaxResult.success(tiktokLikeService.judgeLike(dto.getUserId(),dto.getImgId(),"1")); |
|||
} |
|||
|
|||
@ApiOperation(value="用户登录") |
|||
@PostMapping(value = "/loginFh") |
|||
public AjaxResult loginWx(@Validated @RequestBody @ApiParam("登录对象") FhLoginDto dto){ |
|||
log.info("【快手图文小程序】用户【{}】授权登录了", dto.getCode()); |
|||
return AjaxResult.success(fhUserService.login(dto)); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="查询首页图片列表") |
|||
@PostMapping(value = "/imgLists") |
|||
public TableDataInfo imgLists(@RequestBody @ApiParam("分页对象") BasePageDto dto){ |
|||
PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); |
|||
List<TiktokImgVo> tiktokImgVos = tiktokImgService.queryFrontPage(); |
|||
return getDataTable(tiktokImgVos); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="新增/更新艺术家即将入账广告收益") |
|||
@PostMapping(value = "/insertOrUpdatePreAdProfit") |
|||
public AjaxResult insertOrUpdatePreAdProfit(@Validated @RequestBody @ApiParam("即将入账广告对象") CreatorProfitAdInsertDto dto){ |
|||
log.debug("【快手图文小程序】新增/更新艺术家即将入账广告收益参数为:{}", JSON.toJSONString(dto)); |
|||
return AjaxResult.success(creatorProfitService.insertCreatorProfit(dto.extractParam())); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="新增/更新艺术家即将入账邀请收益") |
|||
@PostMapping(value = "/insertOrUpdatePreInviteProfit") |
|||
public AjaxResult insertOrUpdatePreInviteProfit(@Validated @RequestBody @ApiParam("即将入账邀请对象") CreatorProfitAdInsertDto dto){ |
|||
log.debug("【快手图文小程序】新增/更新艺术家即将入账邀请收益参数为:{}", JSON.toJSONString(dto)); |
|||
creatorProfitService.insertInvitedProfit(dto.extractParam()); |
|||
return AjaxResult.success(); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="查询热门艺术家列表") |
|||
@GetMapping(value = "/listHotCreator") |
|||
public AjaxResult listHotCreator(){ |
|||
return AjaxResult.success(creatorService.queryHotCreatorList()); |
|||
} |
|||
|
|||
//@TokenCheck
|
|||
@ApiOperation(value="根据艺术家id获取搜索码") |
|||
@GetMapping(value = "/queryCreatorScanCodeById/{id}") |
|||
public AjaxResult queryCreatorScanCodeById(@PathVariable @ApiParam("艺术家id") Long id){ |
|||
Map<String, Object> result = creatorService.queryCreatorScanCodeById(id); |
|||
if(result != null){ |
|||
return AjaxResult.success(result); |
|||
}else{ |
|||
return AjaxResult.error("该艺术家不存在!"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,84 @@ |
|||
package com.bnyer.img.controller; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.bnyer.common.core.utils.Sm4Util; |
|||
import com.bnyer.common.core.utils.StringUtils; |
|||
import com.bnyer.common.core.web.controller.BaseController; |
|||
import com.bnyer.common.core.web.domain.AjaxResult; |
|||
import com.bnyer.common.core.web.page.TableDataInfo; |
|||
import com.bnyer.img.domain.FhUser; |
|||
import com.bnyer.img.dto.FhUserDto; |
|||
import com.bnyer.img.dto.FhUserPageDto; |
|||
import com.bnyer.img.dto.StatusDto; |
|||
import com.bnyer.img.service.FhUserService; |
|||
import com.github.pagehelper.PageHelper; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Api(value = "【图文平台】快手用户接口",tags = "【图文平台】快手用户接口") |
|||
@RestController |
|||
@RequestMapping("/img/fhUser") |
|||
@Slf4j |
|||
public class FhUserController extends BaseController { |
|||
|
|||
@Autowired |
|||
private FhUserService fhUserService; |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="查询快手用户分页") |
|||
@PostMapping("/page") |
|||
public TableDataInfo pageFhUser(@RequestBody @ApiParam("分页对象") FhUserPageDto dto){ |
|||
PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); |
|||
List<FhUser> fhUsers = fhUserService.queryPage(dto); |
|||
for (FhUser fhUser : fhUsers) { |
|||
if(fhUser != null){ |
|||
if(StringUtils.isNotBlank(fhUser.getFhCode())){ |
|||
fhUser.setFhCode(Sm4Util.sm4Decrypt(fhUser.getFhCode())); |
|||
} |
|||
} |
|||
} |
|||
return getDataTable(fhUsers); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="修改快手用户") |
|||
@PostMapping(value = "/update") |
|||
public AjaxResult update(@RequestBody @ApiParam("user对象") FhUserDto dto){ |
|||
log.debug("【图文平台后台】修改快手用户参数为:{}", JSON.toJSONString(dto)); |
|||
return AjaxResult.success(fhUserService.update(dto.extractParam())); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="删除快手用户") |
|||
@DeleteMapping(value = "/delete/{ids}") |
|||
public AjaxResult deleteFhUser(@PathVariable @ApiParam("主键ids") List<Long> ids){ |
|||
log.debug("【图文平台后台】删除快手用户参数为:{}", ids); |
|||
return AjaxResult.success(fhUserService.delete(ids)); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="查询快手用户详情") |
|||
@GetMapping(value = "/details/{id}") |
|||
public AjaxResult detailsFhUser(@PathVariable @ApiParam("主键id") Long id){ |
|||
FhUser fhUser = fhUserService.queryDetails(id); |
|||
if(StringUtils.isNotBlank(fhUser.getFhCode())){ |
|||
fhUser.setFhCode(Sm4Util.sm4Decrypt(fhUser.getFhCode())); |
|||
} |
|||
return AjaxResult.success(fhUser); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="变更type显示状态") |
|||
@PostMapping(value = "/changeStatus") |
|||
public AjaxResult changeStatus(@Validated @RequestBody @ApiParam("type状态对象") StatusDto dto){ |
|||
log.debug("【图文平台后台】变更type参数为:{}", JSON.toJSONString(dto)); |
|||
return AjaxResult.success(fhUserService.changeStatus(dto.getId(),dto.getStatus())); |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
package com.bnyer.img.dto; |
|||
|
|||
import com.bnyer.common.core.utils.bean.BeanUtils; |
|||
import com.bnyer.img.domain.FhUser; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("快手用户接收类") |
|||
public class FhUserDto implements Serializable { |
|||
|
|||
@ApiModelProperty(value="id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value="用户昵称") |
|||
private String username; |
|||
|
|||
@ApiModelProperty(value="快手id") |
|||
private String fhCode; |
|||
|
|||
@ApiModelProperty(value="头像img地址") |
|||
private String img; |
|||
|
|||
public FhUser extractParam(){ |
|||
FhUser fhUser = new FhUser(); |
|||
BeanUtils.copyProperties(this, fhUser); |
|||
return fhUser; |
|||
} |
|||
} |
|||
@ -1,206 +1,204 @@ |
|||
//package com.bnyer.img.service.impl;
|
|||
//
|
|||
//import cn.binarywang.wx.miniapp.api.WxMaUserService;
|
|||
//import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|||
//import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|||
//import com.alibaba.fastjson.JSONObject;
|
|||
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
//import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|||
//import com.bnyer.common.core.exception.ServiceException;
|
|||
//import com.bnyer.common.core.utils.Sm4Util;
|
|||
//import com.bnyer.common.core.utils.StringUtils;
|
|||
//import com.bnyer.common.core.utils.uuid.IdUtils;
|
|||
//import com.bnyer.common.redis.service.RedisService;
|
|||
//import com.bnyer.img.constants.RedisKeyConstant;
|
|||
//import com.bnyer.img.constants.TiktokConstant;
|
|||
//import com.bnyer.img.domain.TiktokCollection;
|
|||
//import com.bnyer.img.domain.TiktokLike;
|
|||
//import com.bnyer.img.domain.FhUser;
|
|||
//import com.bnyer.img.domain.TiktokUser;
|
|||
//import com.bnyer.img.dto.FhLoginDto;
|
|||
//import com.bnyer.img.dto.WxLoginDto;
|
|||
//import com.bnyer.img.dto.FhUserPageDto;
|
|||
//import com.bnyer.img.mapper.TiktokCollectionMapper;
|
|||
//import com.bnyer.img.mapper.TiktokLikeMapper;
|
|||
//import com.bnyer.img.mapper.FhUserMapper;
|
|||
//import com.bnyer.img.service.FhUserService;
|
|||
//import com.bnyer.img.vo.FhUserInfoVo;
|
|||
//import com.bnyer.img.vo.TiktokSessionInfoVo;
|
|||
//import com.bnyer.img.vo.TiktokUserInfoVo;
|
|||
//import lombok.extern.slf4j.Slf4j;
|
|||
//import me.chanjar.weixin.common.error.WxErrorException;
|
|||
//import org.springframework.beans.factory.annotation.Autowired;
|
|||
//import org.springframework.stereotype.Service;
|
|||
//import org.springframework.transaction.annotation.Transactional;
|
|||
//
|
|||
//import javax.crypto.Cipher;
|
|||
//import javax.crypto.spec.IvParameterSpec;
|
|||
//import javax.crypto.spec.SecretKeySpec;
|
|||
//import java.util.*;
|
|||
//import java.util.concurrent.TimeUnit;
|
|||
//
|
|||
//@Service
|
|||
//@Slf4j
|
|||
//public class FhUserServiceImpl implements FhUserService {
|
|||
//
|
|||
// @Autowired
|
|||
// private FhUserMapper fhUserMapper;
|
|||
//
|
|||
// @Autowired
|
|||
// private RedisService redisService;
|
|||
//
|
|||
// @Autowired
|
|||
// private TiktokLikeMapper tiktokLikeMapper;
|
|||
//
|
|||
// @Autowired
|
|||
// private TiktokCollectionMapper tiktokCollectionMapper;
|
|||
//
|
|||
// @Override
|
|||
// @Transactional(rollbackFor = Exception.class)
|
|||
// public int update(FhUser fhUser) {
|
|||
// fhUser.setUpdateTime(new Date());
|
|||
// if (StringUtils.isNotBlank(fhUser.getFhCode())) {
|
|||
// fhUser.setFhCode(Sm4Util.sm4Encryption(fhUser.getFhCode()));
|
|||
// }
|
|||
// return fhUserMapper.updateById(fhUser);
|
|||
// }
|
|||
//
|
|||
// @Override
|
|||
// @Transactional(rollbackFor = Exception.class)
|
|||
// public int delete(List<Long> ids) {
|
|||
// int delete = fhUserMapper.deleteBatchIds(ids);
|
|||
// //删除对应用户收藏及点赞记录
|
|||
// LambdaQueryWrapper<TiktokCollection> collectionWrapper = new LambdaQueryWrapper<>();
|
|||
// LambdaQueryWrapper<TiktokLike> likeWrapper = new LambdaQueryWrapper<>();
|
|||
// for (Long id : ids) {
|
|||
// collectionWrapper.eq(TiktokCollection::getUserId, id)
|
|||
// .eq(TiktokCollection::getPlatform, "1");
|
|||
// tiktokCollectionMapper.delete(collectionWrapper);
|
|||
// likeWrapper.eq(TiktokLike::getUserId, id)
|
|||
// .eq(TiktokLike::getPlatform, "1");
|
|||
// tiktokLikeMapper.delete(likeWrapper);
|
|||
// }
|
|||
// return delete;
|
|||
// }
|
|||
//
|
|||
// @Override
|
|||
// public List<FhUser> queryPage(FhUserPageDto dto) {
|
|||
// return fhUserMapper.queryPage(dto);
|
|||
// }
|
|||
//
|
|||
// @Override
|
|||
// public FhUser queryDetails(Long id) {
|
|||
// return fhUserMapper.selectById(id);
|
|||
// }
|
|||
//
|
|||
// /**
|
|||
// * 获取用户openId及sessionKey
|
|||
// * @param code 登录凭证code
|
|||
// * @return -
|
|||
// */
|
|||
// private TiktokSessionInfoVo getSessionInfo(String code) {
|
|||
// Map<String,String> map = new HashMap<>();
|
|||
// map.put("appid",tiktokConfig.getAppId());
|
|||
// map.put("secret", tiktokConfig.getSecret());
|
|||
// map.put("code", code);
|
|||
// map.put("grant_type", "client_credential");
|
|||
// JSONObject sessionInfo = restTemplate.postForObject(tiktokConfig.getSessionInfoUrl(), map, JSONObject.class);
|
|||
// if(!sessionInfo.getString("err_no").equals(TiktokConstant.SUCCESS)){
|
|||
// log.error("抖音授权session接口调用失败,错误状态码为:【{}】,错误信息为:【{}】",sessionInfo.getString("err_no"),sessionInfo.getString("err_tips"));
|
|||
// throw new ServiceException("抖音授权session接口调用失败!",TiktokConstant.TIKTOK_AUTH_ERROR);
|
|||
// }
|
|||
// //调用成功,组装返回数据
|
|||
// JSONObject data = sessionInfo.getJSONObject("data");
|
|||
// TiktokSessionInfoVo result = new TiktokSessionInfoVo();
|
|||
// result.setSessionKey(data.getString("session_key"));
|
|||
// result.setOpenId(data.getString("openid"));
|
|||
// result.setUnionId(data.getString("unionid"));
|
|||
// return result;
|
|||
// }
|
|||
//
|
|||
// /**
|
|||
// * 获取用户敏感信息
|
|||
// * @param sessionKey -
|
|||
// * @param encryptedData 敏感数据
|
|||
// * @param iv 加密向量
|
|||
// * @return -
|
|||
// */
|
|||
// private FhUserInfoVo getUserInfo(String sessionKey, String encryptedData, String iv){
|
|||
// Base64.Decoder decoder = Base64.getDecoder();
|
|||
// byte[] sessionKeyBytes = decoder.decode(sessionKey);
|
|||
// byte[] ivBytes = decoder.decode(iv);
|
|||
// byte[] encryptedBytes = decoder.decode(encryptedData);
|
|||
//
|
|||
// Cipher cipher = null;
|
|||
// try {
|
|||
// cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
|||
// SecretKeySpec skeySpec = new SecretKeySpec(sessionKeyBytes, "AES");
|
|||
// IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
|
|||
// cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivSpec);
|
|||
// byte[] ret = cipher.doFinal(encryptedBytes);
|
|||
// if (null != ret && ret.length > 0) {
|
|||
// String result = new String(ret, "UTF-8");
|
|||
// return JSONObject.parseObject(result,FhUserInfoVo.class);
|
|||
// }
|
|||
// } catch (Exception e) {
|
|||
// e.printStackTrace();
|
|||
// }
|
|||
// return null;
|
|||
// }
|
|||
//
|
|||
// private FhUser saveOrUpdate(String openId, String sessionKey, String encryptedData, String iv) {
|
|||
// //获取用户昵称和头像
|
|||
// FhUserInfoVo userInfo = this.getUserInfo(sessionKey, encryptedData, iv);
|
|||
// //创建用户
|
|||
// FhUser fhUser = new FhUser();
|
|||
// fhUser.setImg(userInfo.getAvatarUrl());
|
|||
// fhUser.setUsername(userInfo.getNickName());
|
|||
// fhUser.setFhCode(Sm4Util.sm4Encryption(openId));
|
|||
// fhUser.setCreateTime(new Date());
|
|||
// fhUser.setUpdateTime(new Date());
|
|||
// fhUserMapper.insert(fhUser);
|
|||
// log.info("快手用户【{}】创建成功!", openId);
|
|||
// return fhUser;
|
|||
// }
|
|||
//
|
|||
// @Override
|
|||
// public Map<String, Object> login(FhLoginDto param) {
|
|||
// TiktokSessionInfoVo sessionInfo = this.getSessionInfo(dto.getCode());
|
|||
// //检查数据库中是否存在该openId,存在则直接设置会话状态登录;不存在则新增
|
|||
// LambdaQueryWrapper<TiktokUser> wrapper = new LambdaQueryWrapper<>();
|
|||
// wrapper.eq(sessionInfo.getOpenId() != null,TiktokUser::getTiktokCode,Sm4Util.sm4Encryption(sessionInfo.getOpenId()));
|
|||
// TiktokUser tiktokUser = tiktokUserMapper.selectOne(wrapper);
|
|||
// if(tiktokUser == null){
|
|||
// //新用户,新增
|
|||
// tiktokUser = this.saveUserInfo(sessionInfo.getOpenId(), sessionInfo.getSessionKey(), dto.getEncryptedData(), dto.getIv());
|
|||
// }
|
|||
// //设置会话状态
|
|||
// String redisKey = RedisKeyConstant.TIKTOK_USER_LOGIN_KEY+Sm4Util.sm4Encryption(sessionInfo.getOpenId());
|
|||
// //存在该登录态则删除刷新
|
|||
// if(redisService.hasKey(redisKey)){
|
|||
// redisService.deleteObject(redisKey);
|
|||
// }
|
|||
// StringBuffer sb = new StringBuffer();
|
|||
// String randomId = IdUtils.fastSimpleUUID();
|
|||
// sb.append(randomId).append("#").append(sessionInfo.getOpenId());
|
|||
//
|
|||
// Map<String, Object> map = new HashMap<>(2);
|
|||
// map.put("token", sb.toString());
|
|||
// map.put("sessionKey", sessionInfo.getSessionKey());
|
|||
// map.put("userInfo",tiktokUser);
|
|||
// //设置登录会话
|
|||
// redisService.setCacheObject(redisKey,map,30L, TimeUnit.DAYS);
|
|||
// return map;
|
|||
// }
|
|||
//
|
|||
// @Override
|
|||
// @Transactional(rollbackFor = Exception.class)
|
|||
// public int changeStatus(Long id, String status) {
|
|||
// LambdaUpdateWrapper<FhUser> wrapper = new LambdaUpdateWrapper<>();
|
|||
// wrapper.eq(FhUser::getId, id);
|
|||
// FhUser user = new FhUser();
|
|||
// user.setIsShow(status);
|
|||
// return fhUserMapper.update(user, wrapper);
|
|||
// }
|
|||
//}
|
|||
package com.bnyer.img.service.impl; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|||
import com.bnyer.common.core.exception.ServiceException; |
|||
import com.bnyer.common.core.utils.Sm4Util; |
|||
import com.bnyer.common.core.utils.StringUtils; |
|||
import com.bnyer.common.core.utils.uuid.IdUtils; |
|||
import com.bnyer.common.redis.service.RedisService; |
|||
import com.bnyer.img.config.FhConfig; |
|||
import com.bnyer.img.constants.RedisKeyConstant; |
|||
import com.bnyer.img.constants.TiktokConstant; |
|||
import com.bnyer.img.domain.FhUser; |
|||
import com.bnyer.img.domain.TiktokCollection; |
|||
import com.bnyer.img.domain.TiktokLike; |
|||
import com.bnyer.img.dto.FhLoginDto; |
|||
import com.bnyer.img.dto.FhUserPageDto; |
|||
import com.bnyer.img.mapper.FhUserMapper; |
|||
import com.bnyer.img.mapper.TiktokCollectionMapper; |
|||
import com.bnyer.img.mapper.TiktokLikeMapper; |
|||
import com.bnyer.img.service.FhUserService; |
|||
import com.bnyer.img.vo.FhSessionInfoVo; |
|||
import com.bnyer.img.vo.FhUserInfoVo; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.web.client.RestTemplate; |
|||
|
|||
import javax.crypto.Cipher; |
|||
import javax.crypto.spec.IvParameterSpec; |
|||
import javax.crypto.spec.SecretKeySpec; |
|||
import java.util.*; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
@Service |
|||
@Slf4j |
|||
public class FhUserServiceImpl implements FhUserService { |
|||
|
|||
@Autowired |
|||
private FhUserMapper fhUserMapper; |
|||
|
|||
@Autowired |
|||
private RedisService redisService; |
|||
|
|||
@Autowired |
|||
private TiktokLikeMapper tiktokLikeMapper; |
|||
|
|||
@Autowired |
|||
private TiktokCollectionMapper tiktokCollectionMapper; |
|||
|
|||
@Autowired |
|||
private FhConfig fhConfig; |
|||
|
|||
@Autowired |
|||
private RestTemplate restTemplate; |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int update(FhUser fhUser) { |
|||
fhUser.setUpdateTime(new Date()); |
|||
if (StringUtils.isNotBlank(fhUser.getFhCode())) { |
|||
fhUser.setFhCode(Sm4Util.sm4Encryption(fhUser.getFhCode())); |
|||
} |
|||
return fhUserMapper.updateById(fhUser); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int delete(List<Long> ids) { |
|||
int delete = fhUserMapper.deleteBatchIds(ids); |
|||
//删除对应用户收藏及点赞记录
|
|||
LambdaQueryWrapper<TiktokCollection> collectionWrapper = new LambdaQueryWrapper<>(); |
|||
LambdaQueryWrapper<TiktokLike> likeWrapper = new LambdaQueryWrapper<>(); |
|||
for (Long id : ids) { |
|||
collectionWrapper.eq(TiktokCollection::getUserId, id) |
|||
.eq(TiktokCollection::getPlatform, "1"); |
|||
tiktokCollectionMapper.delete(collectionWrapper); |
|||
likeWrapper.eq(TiktokLike::getUserId, id) |
|||
.eq(TiktokLike::getPlatform, "1"); |
|||
tiktokLikeMapper.delete(likeWrapper); |
|||
} |
|||
return delete; |
|||
} |
|||
|
|||
@Override |
|||
public List<FhUser> queryPage(FhUserPageDto dto) { |
|||
return fhUserMapper.queryPage(dto); |
|||
} |
|||
|
|||
@Override |
|||
public FhUser queryDetails(Long id) { |
|||
return fhUserMapper.selectById(id); |
|||
} |
|||
|
|||
/** |
|||
* 获取用户openId及sessionKey |
|||
* @param code 登录凭证code |
|||
* @return - |
|||
*/ |
|||
private FhSessionInfoVo getSessionInfo(String code) { |
|||
Map<String,String> map = new HashMap<>(); |
|||
map.put("appid",fhConfig.getAppId()); |
|||
map.put("app_secret", fhConfig.getSecret()); |
|||
map.put("js_code", code); |
|||
JSONObject sessionInfo = restTemplate.postForObject(fhConfig.getSessionInfoUrl(), map, JSONObject.class); |
|||
if(!sessionInfo.getString("result").equals(TiktokConstant.FH_SUCCESS)){ |
|||
//log.error("快手授权session接口调用失败,错误状态码为:【{}】,错误信息为:【{}】",sessionInfo.getString("result"),sessionInfo.getString("err_tips"));
|
|||
throw new ServiceException("快手授权session接口调用失败!",TiktokConstant.FH_AUTH_ERROR); |
|||
} |
|||
//调用成功,组装返回数据
|
|||
JSONObject data = sessionInfo.getJSONObject("data"); |
|||
FhSessionInfoVo result = new FhSessionInfoVo(); |
|||
result.setSessionKey(data.getString("session_key")); |
|||
result.setOpenId(data.getString("open_id")); |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 获取用户敏感信息 |
|||
* @param sessionKey - |
|||
* @param encryptedData 敏感数据 |
|||
* @param iv 加密向量 |
|||
* @return - |
|||
*/ |
|||
private FhUserInfoVo getUserInfo(String sessionKey, String encryptedData, String iv){ |
|||
Base64.Decoder decoder = Base64.getDecoder(); |
|||
byte[] sessionKeyBytes = decoder.decode(sessionKey); |
|||
byte[] ivBytes = decoder.decode(iv); |
|||
byte[] encryptedBytes = decoder.decode(encryptedData); |
|||
|
|||
Cipher cipher = null; |
|||
try { |
|||
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); |
|||
SecretKeySpec skeySpec = new SecretKeySpec(sessionKeyBytes, "AES"); |
|||
IvParameterSpec ivSpec = new IvParameterSpec(ivBytes); |
|||
cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivSpec); |
|||
byte[] ret = cipher.doFinal(encryptedBytes); |
|||
if (null != ret && ret.length > 0) { |
|||
String result = new String(ret, "UTF-8"); |
|||
return JSONObject.parseObject(result,FhUserInfoVo.class); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
private FhUser saveOrUpdate(String openId, String sessionKey, String encryptedData, String iv) { |
|||
//获取用户昵称和头像
|
|||
FhUserInfoVo userInfo = this.getUserInfo(sessionKey, encryptedData, iv); |
|||
//创建用户
|
|||
FhUser fhUser = new FhUser(); |
|||
fhUser.setImg(userInfo.getAvatarUrl()); |
|||
fhUser.setUsername(userInfo.getNickName()); |
|||
fhUser.setFhCode(Sm4Util.sm4Encryption(openId)); |
|||
fhUser.setCreateTime(new Date()); |
|||
fhUser.setUpdateTime(new Date()); |
|||
fhUserMapper.insert(fhUser); |
|||
log.info("快手用户【{}】创建成功!", openId); |
|||
return fhUser; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, Object> login(FhLoginDto param) { |
|||
FhSessionInfoVo sessionInfo = this.getSessionInfo(param.getCode()); |
|||
//检查数据库中是否存在该openId,存在则直接设置会话状态登录;不存在则新增
|
|||
LambdaQueryWrapper<FhUser> wrapper = new LambdaQueryWrapper<>(); |
|||
wrapper.eq(sessionInfo.getOpenId() != null,FhUser::getFhCode,Sm4Util.sm4Encryption(sessionInfo.getOpenId())); |
|||
FhUser fhUser = fhUserMapper.selectOne(wrapper); |
|||
if(fhUser == null){ |
|||
//新用户,新增
|
|||
fhUser = this.saveOrUpdate(sessionInfo.getOpenId(), sessionInfo.getSessionKey(), param.getEncryptedData(), param.getIv()); |
|||
} |
|||
//设置会话状态
|
|||
String redisKey = RedisKeyConstant.FH_USER_LOGIN_KEY+Sm4Util.sm4Encryption(sessionInfo.getOpenId()); |
|||
//存在该登录态则删除刷新
|
|||
if(redisService.hasKey(redisKey)){ |
|||
redisService.deleteObject(redisKey); |
|||
} |
|||
StringBuffer sb = new StringBuffer(); |
|||
String randomId = IdUtils.fastSimpleUUID(); |
|||
sb.append(randomId).append("#").append(sessionInfo.getOpenId()); |
|||
|
|||
Map<String, Object> map = new HashMap<>(2); |
|||
map.put("token", sb.toString()); |
|||
map.put("sessionKey", sessionInfo.getSessionKey()); |
|||
map.put("userInfo",fhUser); |
|||
//设置登录会话
|
|||
redisService.setCacheObject(redisKey,map,30L, TimeUnit.DAYS); |
|||
return map; |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int changeStatus(Long id, String status) { |
|||
LambdaUpdateWrapper<FhUser> wrapper = new LambdaUpdateWrapper<>(); |
|||
wrapper.eq(FhUser::getId, id); |
|||
FhUser user = new FhUser(); |
|||
user.setIsShow(status); |
|||
return fhUserMapper.update(user, wrapper); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,27 @@ |
|||
package com.bnyer.img.vo; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("快手sessionInfo响应类") |
|||
public class FhSessionInfoVo implements Serializable { |
|||
|
|||
@ApiModelProperty(value="sessionKey") |
|||
private String sessionKey; |
|||
|
|||
@ApiModelProperty(value="openId") |
|||
private String openId; |
|||
|
|||
@ApiModelProperty(value="result") |
|||
private String result; |
|||
|
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
Loading…
Reference in new issue