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;
|
package com.bnyer.img.service.impl; |
||||
//
|
|
||||
//import cn.binarywang.wx.miniapp.api.WxMaUserService;
|
import com.alibaba.fastjson.JSONObject; |
||||
//import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
//import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||
//import com.alibaba.fastjson.JSONObject;
|
import com.bnyer.common.core.exception.ServiceException; |
||||
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.bnyer.common.core.utils.Sm4Util; |
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.bnyer.common.core.utils.StringUtils; |
||||
//import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.bnyer.common.core.utils.uuid.IdUtils; |
||||
//import com.bnyer.common.core.exception.ServiceException;
|
import com.bnyer.common.redis.service.RedisService; |
||||
//import com.bnyer.common.core.utils.Sm4Util;
|
import com.bnyer.img.config.FhConfig; |
||||
//import com.bnyer.common.core.utils.StringUtils;
|
import com.bnyer.img.constants.RedisKeyConstant; |
||||
//import com.bnyer.common.core.utils.uuid.IdUtils;
|
import com.bnyer.img.constants.TiktokConstant; |
||||
//import com.bnyer.common.redis.service.RedisService;
|
import com.bnyer.img.domain.FhUser; |
||||
//import com.bnyer.img.constants.RedisKeyConstant;
|
import com.bnyer.img.domain.TiktokCollection; |
||||
//import com.bnyer.img.constants.TiktokConstant;
|
import com.bnyer.img.domain.TiktokLike; |
||||
//import com.bnyer.img.domain.TiktokCollection;
|
import com.bnyer.img.dto.FhLoginDto; |
||||
//import com.bnyer.img.domain.TiktokLike;
|
import com.bnyer.img.dto.FhUserPageDto; |
||||
//import com.bnyer.img.domain.FhUser;
|
import com.bnyer.img.mapper.FhUserMapper; |
||||
//import com.bnyer.img.domain.TiktokUser;
|
import com.bnyer.img.mapper.TiktokCollectionMapper; |
||||
//import com.bnyer.img.dto.FhLoginDto;
|
import com.bnyer.img.mapper.TiktokLikeMapper; |
||||
//import com.bnyer.img.dto.WxLoginDto;
|
import com.bnyer.img.service.FhUserService; |
||||
//import com.bnyer.img.dto.FhUserPageDto;
|
import com.bnyer.img.vo.FhSessionInfoVo; |
||||
//import com.bnyer.img.mapper.TiktokCollectionMapper;
|
import com.bnyer.img.vo.FhUserInfoVo; |
||||
//import com.bnyer.img.mapper.TiktokLikeMapper;
|
import lombok.extern.slf4j.Slf4j; |
||||
//import com.bnyer.img.mapper.FhUserMapper;
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
//import com.bnyer.img.service.FhUserService;
|
import org.springframework.stereotype.Service; |
||||
//import com.bnyer.img.vo.FhUserInfoVo;
|
import org.springframework.transaction.annotation.Transactional; |
||||
//import com.bnyer.img.vo.TiktokSessionInfoVo;
|
import org.springframework.web.client.RestTemplate; |
||||
//import com.bnyer.img.vo.TiktokUserInfoVo;
|
|
||||
//import lombok.extern.slf4j.Slf4j;
|
import javax.crypto.Cipher; |
||||
//import me.chanjar.weixin.common.error.WxErrorException;
|
import javax.crypto.spec.IvParameterSpec; |
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
import javax.crypto.spec.SecretKeySpec; |
||||
//import org.springframework.stereotype.Service;
|
import java.util.*; |
||||
//import org.springframework.transaction.annotation.Transactional;
|
import java.util.concurrent.TimeUnit; |
||||
//
|
|
||||
//import javax.crypto.Cipher;
|
@Service |
||||
//import javax.crypto.spec.IvParameterSpec;
|
@Slf4j |
||||
//import javax.crypto.spec.SecretKeySpec;
|
public class FhUserServiceImpl implements FhUserService { |
||||
//import java.util.*;
|
|
||||
//import java.util.concurrent.TimeUnit;
|
@Autowired |
||||
//
|
private FhUserMapper fhUserMapper; |
||||
//@Service
|
|
||||
//@Slf4j
|
@Autowired |
||||
//public class FhUserServiceImpl implements FhUserService {
|
private RedisService redisService; |
||||
//
|
|
||||
// @Autowired
|
@Autowired |
||||
// private FhUserMapper fhUserMapper;
|
private TiktokLikeMapper tiktokLikeMapper; |
||||
//
|
|
||||
// @Autowired
|
@Autowired |
||||
// private RedisService redisService;
|
private TiktokCollectionMapper tiktokCollectionMapper; |
||||
//
|
|
||||
// @Autowired
|
@Autowired |
||||
// private TiktokLikeMapper tiktokLikeMapper;
|
private FhConfig fhConfig; |
||||
//
|
|
||||
// @Autowired
|
@Autowired |
||||
// private TiktokCollectionMapper tiktokCollectionMapper;
|
private RestTemplate restTemplate; |
||||
//
|
|
||||
// @Override
|
@Override |
||||
// @Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class) |
||||
// public int update(FhUser fhUser) {
|
public int update(FhUser fhUser) { |
||||
// fhUser.setUpdateTime(new Date());
|
fhUser.setUpdateTime(new Date()); |
||||
// if (StringUtils.isNotBlank(fhUser.getFhCode())) {
|
if (StringUtils.isNotBlank(fhUser.getFhCode())) { |
||||
// fhUser.setFhCode(Sm4Util.sm4Encryption(fhUser.getFhCode()));
|
fhUser.setFhCode(Sm4Util.sm4Encryption(fhUser.getFhCode())); |
||||
// }
|
} |
||||
// return fhUserMapper.updateById(fhUser);
|
return fhUserMapper.updateById(fhUser); |
||||
// }
|
} |
||||
//
|
|
||||
// @Override
|
@Override |
||||
// @Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class) |
||||
// public int delete(List<Long> ids) {
|
public int delete(List<Long> ids) { |
||||
// int delete = fhUserMapper.deleteBatchIds(ids);
|
int delete = fhUserMapper.deleteBatchIds(ids); |
||||
// //删除对应用户收藏及点赞记录
|
//删除对应用户收藏及点赞记录
|
||||
// LambdaQueryWrapper<TiktokCollection> collectionWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<TiktokCollection> collectionWrapper = new LambdaQueryWrapper<>(); |
||||
// LambdaQueryWrapper<TiktokLike> likeWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<TiktokLike> likeWrapper = new LambdaQueryWrapper<>(); |
||||
// for (Long id : ids) {
|
for (Long id : ids) { |
||||
// collectionWrapper.eq(TiktokCollection::getUserId, id)
|
collectionWrapper.eq(TiktokCollection::getUserId, id) |
||||
// .eq(TiktokCollection::getPlatform, "1");
|
.eq(TiktokCollection::getPlatform, "1"); |
||||
// tiktokCollectionMapper.delete(collectionWrapper);
|
tiktokCollectionMapper.delete(collectionWrapper); |
||||
// likeWrapper.eq(TiktokLike::getUserId, id)
|
likeWrapper.eq(TiktokLike::getUserId, id) |
||||
// .eq(TiktokLike::getPlatform, "1");
|
.eq(TiktokLike::getPlatform, "1"); |
||||
// tiktokLikeMapper.delete(likeWrapper);
|
tiktokLikeMapper.delete(likeWrapper); |
||||
// }
|
} |
||||
// return delete;
|
return delete; |
||||
// }
|
} |
||||
//
|
|
||||
// @Override
|
@Override |
||||
// public List<FhUser> queryPage(FhUserPageDto dto) {
|
public List<FhUser> queryPage(FhUserPageDto dto) { |
||||
// return fhUserMapper.queryPage(dto);
|
return fhUserMapper.queryPage(dto); |
||||
// }
|
} |
||||
//
|
|
||||
// @Override
|
@Override |
||||
// public FhUser queryDetails(Long id) {
|
public FhUser queryDetails(Long id) { |
||||
// return fhUserMapper.selectById(id);
|
return fhUserMapper.selectById(id); |
||||
// }
|
} |
||||
//
|
|
||||
// /**
|
/** |
||||
// * 获取用户openId及sessionKey
|
* 获取用户openId及sessionKey |
||||
// * @param code 登录凭证code
|
* @param code 登录凭证code |
||||
// * @return -
|
* @return - |
||||
// */
|
*/ |
||||
// private TiktokSessionInfoVo getSessionInfo(String code) {
|
private FhSessionInfoVo getSessionInfo(String code) { |
||||
// Map<String,String> map = new HashMap<>();
|
Map<String,String> map = new HashMap<>(); |
||||
// map.put("appid",tiktokConfig.getAppId());
|
map.put("appid",fhConfig.getAppId()); |
||||
// map.put("secret", tiktokConfig.getSecret());
|
map.put("app_secret", fhConfig.getSecret()); |
||||
// map.put("code", code);
|
map.put("js_code", code); |
||||
// map.put("grant_type", "client_credential");
|
JSONObject sessionInfo = restTemplate.postForObject(fhConfig.getSessionInfoUrl(), map, JSONObject.class); |
||||
// JSONObject sessionInfo = restTemplate.postForObject(tiktokConfig.getSessionInfoUrl(), map, JSONObject.class);
|
if(!sessionInfo.getString("result").equals(TiktokConstant.FH_SUCCESS)){ |
||||
// if(!sessionInfo.getString("err_no").equals(TiktokConstant.SUCCESS)){
|
//log.error("快手授权session接口调用失败,错误状态码为:【{}】,错误信息为:【{}】",sessionInfo.getString("result"),sessionInfo.getString("err_tips"));
|
||||
// log.error("抖音授权session接口调用失败,错误状态码为:【{}】,错误信息为:【{}】",sessionInfo.getString("err_no"),sessionInfo.getString("err_tips"));
|
throw new ServiceException("快手授权session接口调用失败!",TiktokConstant.FH_AUTH_ERROR); |
||||
// throw new ServiceException("抖音授权session接口调用失败!",TiktokConstant.TIKTOK_AUTH_ERROR);
|
} |
||||
// }
|
//调用成功,组装返回数据
|
||||
// //调用成功,组装返回数据
|
JSONObject data = sessionInfo.getJSONObject("data"); |
||||
// JSONObject data = sessionInfo.getJSONObject("data");
|
FhSessionInfoVo result = new FhSessionInfoVo(); |
||||
// TiktokSessionInfoVo result = new TiktokSessionInfoVo();
|
result.setSessionKey(data.getString("session_key")); |
||||
// result.setSessionKey(data.getString("session_key"));
|
result.setOpenId(data.getString("open_id")); |
||||
// result.setOpenId(data.getString("openid"));
|
return result; |
||||
// result.setUnionId(data.getString("unionid"));
|
} |
||||
// return result;
|
|
||||
// }
|
/** |
||||
//
|
* 获取用户敏感信息 |
||||
// /**
|
* @param sessionKey - |
||||
// * 获取用户敏感信息
|
* @param encryptedData 敏感数据 |
||||
// * @param sessionKey -
|
* @param iv 加密向量 |
||||
// * @param encryptedData 敏感数据
|
* @return - |
||||
// * @param iv 加密向量
|
*/ |
||||
// * @return -
|
private FhUserInfoVo getUserInfo(String sessionKey, String encryptedData, String iv){ |
||||
// */
|
Base64.Decoder decoder = Base64.getDecoder(); |
||||
// private FhUserInfoVo getUserInfo(String sessionKey, String encryptedData, String iv){
|
byte[] sessionKeyBytes = decoder.decode(sessionKey); |
||||
// Base64.Decoder decoder = Base64.getDecoder();
|
byte[] ivBytes = decoder.decode(iv); |
||||
// byte[] sessionKeyBytes = decoder.decode(sessionKey);
|
byte[] encryptedBytes = decoder.decode(encryptedData); |
||||
// byte[] ivBytes = decoder.decode(iv);
|
|
||||
// byte[] encryptedBytes = decoder.decode(encryptedData);
|
Cipher cipher = null; |
||||
//
|
try { |
||||
// Cipher cipher = null;
|
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); |
||||
// try {
|
SecretKeySpec skeySpec = new SecretKeySpec(sessionKeyBytes, "AES"); |
||||
// cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
IvParameterSpec ivSpec = new IvParameterSpec(ivBytes); |
||||
// SecretKeySpec skeySpec = new SecretKeySpec(sessionKeyBytes, "AES");
|
cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivSpec); |
||||
// IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
|
byte[] ret = cipher.doFinal(encryptedBytes); |
||||
// cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivSpec);
|
if (null != ret && ret.length > 0) { |
||||
// byte[] ret = cipher.doFinal(encryptedBytes);
|
String result = new String(ret, "UTF-8"); |
||||
// if (null != ret && ret.length > 0) {
|
return JSONObject.parseObject(result,FhUserInfoVo.class); |
||||
// String result = new String(ret, "UTF-8");
|
} |
||||
// return JSONObject.parseObject(result,FhUserInfoVo.class);
|
} catch (Exception e) { |
||||
// }
|
e.printStackTrace(); |
||||
// } catch (Exception e) {
|
} |
||||
// e.printStackTrace();
|
return null; |
||||
// }
|
} |
||||
// return null;
|
|
||||
// }
|
private FhUser saveOrUpdate(String openId, String sessionKey, String encryptedData, String iv) { |
||||
//
|
//获取用户昵称和头像
|
||||
// private FhUser saveOrUpdate(String openId, String sessionKey, String encryptedData, String iv) {
|
FhUserInfoVo userInfo = this.getUserInfo(sessionKey, encryptedData, iv); |
||||
// //获取用户昵称和头像
|
//创建用户
|
||||
// FhUserInfoVo userInfo = this.getUserInfo(sessionKey, encryptedData, iv);
|
FhUser fhUser = new FhUser(); |
||||
// //创建用户
|
fhUser.setImg(userInfo.getAvatarUrl()); |
||||
// FhUser fhUser = new FhUser();
|
fhUser.setUsername(userInfo.getNickName()); |
||||
// fhUser.setImg(userInfo.getAvatarUrl());
|
fhUser.setFhCode(Sm4Util.sm4Encryption(openId)); |
||||
// fhUser.setUsername(userInfo.getNickName());
|
fhUser.setCreateTime(new Date()); |
||||
// fhUser.setFhCode(Sm4Util.sm4Encryption(openId));
|
fhUser.setUpdateTime(new Date()); |
||||
// fhUser.setCreateTime(new Date());
|
fhUserMapper.insert(fhUser); |
||||
// fhUser.setUpdateTime(new Date());
|
log.info("快手用户【{}】创建成功!", openId); |
||||
// fhUserMapper.insert(fhUser);
|
return fhUser; |
||||
// log.info("快手用户【{}】创建成功!", openId);
|
} |
||||
// return fhUser;
|
|
||||
// }
|
@Override |
||||
//
|
public Map<String, Object> login(FhLoginDto param) { |
||||
// @Override
|
FhSessionInfoVo sessionInfo = this.getSessionInfo(param.getCode()); |
||||
// public Map<String, Object> login(FhLoginDto param) {
|
//检查数据库中是否存在该openId,存在则直接设置会话状态登录;不存在则新增
|
||||
// TiktokSessionInfoVo sessionInfo = this.getSessionInfo(dto.getCode());
|
LambdaQueryWrapper<FhUser> wrapper = new LambdaQueryWrapper<>(); |
||||
// //检查数据库中是否存在该openId,存在则直接设置会话状态登录;不存在则新增
|
wrapper.eq(sessionInfo.getOpenId() != null,FhUser::getFhCode,Sm4Util.sm4Encryption(sessionInfo.getOpenId())); |
||||
// LambdaQueryWrapper<TiktokUser> wrapper = new LambdaQueryWrapper<>();
|
FhUser fhUser = fhUserMapper.selectOne(wrapper); |
||||
// wrapper.eq(sessionInfo.getOpenId() != null,TiktokUser::getTiktokCode,Sm4Util.sm4Encryption(sessionInfo.getOpenId()));
|
if(fhUser == null){ |
||||
// TiktokUser tiktokUser = tiktokUserMapper.selectOne(wrapper);
|
//新用户,新增
|
||||
// if(tiktokUser == null){
|
fhUser = this.saveOrUpdate(sessionInfo.getOpenId(), sessionInfo.getSessionKey(), param.getEncryptedData(), param.getIv()); |
||||
// //新用户,新增
|
} |
||||
// tiktokUser = this.saveUserInfo(sessionInfo.getOpenId(), sessionInfo.getSessionKey(), dto.getEncryptedData(), dto.getIv());
|
//设置会话状态
|
||||
// }
|
String redisKey = RedisKeyConstant.FH_USER_LOGIN_KEY+Sm4Util.sm4Encryption(sessionInfo.getOpenId()); |
||||
// //设置会话状态
|
//存在该登录态则删除刷新
|
||||
// String redisKey = RedisKeyConstant.TIKTOK_USER_LOGIN_KEY+Sm4Util.sm4Encryption(sessionInfo.getOpenId());
|
if(redisService.hasKey(redisKey)){ |
||||
// //存在该登录态则删除刷新
|
redisService.deleteObject(redisKey); |
||||
// if(redisService.hasKey(redisKey)){
|
} |
||||
// redisService.deleteObject(redisKey);
|
StringBuffer sb = new StringBuffer(); |
||||
// }
|
String randomId = IdUtils.fastSimpleUUID(); |
||||
// StringBuffer sb = new StringBuffer();
|
sb.append(randomId).append("#").append(sessionInfo.getOpenId()); |
||||
// String randomId = IdUtils.fastSimpleUUID();
|
|
||||
// sb.append(randomId).append("#").append(sessionInfo.getOpenId());
|
Map<String, Object> map = new HashMap<>(2); |
||||
//
|
map.put("token", sb.toString()); |
||||
// Map<String, Object> map = new HashMap<>(2);
|
map.put("sessionKey", sessionInfo.getSessionKey()); |
||||
// map.put("token", sb.toString());
|
map.put("userInfo",fhUser); |
||||
// map.put("sessionKey", sessionInfo.getSessionKey());
|
//设置登录会话
|
||||
// map.put("userInfo",tiktokUser);
|
redisService.setCacheObject(redisKey,map,30L, TimeUnit.DAYS); |
||||
// //设置登录会话
|
return map; |
||||
// redisService.setCacheObject(redisKey,map,30L, TimeUnit.DAYS);
|
} |
||||
// return map;
|
|
||||
// }
|
@Override |
||||
//
|
@Transactional(rollbackFor = Exception.class) |
||||
// @Override
|
public int changeStatus(Long id, String status) { |
||||
// @Transactional(rollbackFor = Exception.class)
|
LambdaUpdateWrapper<FhUser> wrapper = new LambdaUpdateWrapper<>(); |
||||
// public int changeStatus(Long id, String status) {
|
wrapper.eq(FhUser::getId, id); |
||||
// LambdaUpdateWrapper<FhUser> wrapper = new LambdaUpdateWrapper<>();
|
FhUser user = new FhUser(); |
||||
// wrapper.eq(FhUser::getId, id);
|
user.setIsShow(status); |
||||
// FhUser user = new FhUser();
|
return fhUserMapper.update(user, wrapper); |
||||
// 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