43 changed files with 1526 additions and 167 deletions
@ -0,0 +1,51 @@ |
|||||
|
package com.bnyer.img.config; |
||||
|
|
||||
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
||||
|
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; |
||||
|
import cn.binarywang.wx.miniapp.config.WxMaConfig; |
||||
|
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; |
||||
|
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.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
|
||||
|
/** |
||||
|
* @author chengkun |
||||
|
* @date 2022/4/21 17:43 |
||||
|
*/ |
||||
|
@Configuration |
||||
|
@ConfigurationProperties(prefix = "bnyer.img.wechat") |
||||
|
@Getter |
||||
|
@RefreshScope |
||||
|
public class WxConfig { |
||||
|
|
||||
|
@Value("${bnyer.img.wechat.appId}") |
||||
|
private String appId; |
||||
|
|
||||
|
@Value("${bnyer.img.wechat.secret}") |
||||
|
public String secret; |
||||
|
|
||||
|
@Value("${bnyer.img.wechat.sessionInfoUrl}") |
||||
|
public String sessionInfoUrl; |
||||
|
|
||||
|
@Value("${bnyer.img.wechat.tokenUrl}") |
||||
|
public String tokenUrl; |
||||
|
|
||||
|
@Bean |
||||
|
public WxMaConfig wxMaConfig() { |
||||
|
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); |
||||
|
config.setAppid(appId); |
||||
|
config.setSecret(secret); |
||||
|
return config; |
||||
|
} |
||||
|
|
||||
|
@Bean |
||||
|
public WxMaService wxMaService(WxMaConfig maConfig) { |
||||
|
WxMaService service = new WxMaServiceImpl(); |
||||
|
service.setWxMaConfig(maConfig); |
||||
|
return service; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
package com.bnyer.img.constants; |
||||
|
|
||||
|
/** |
||||
|
* 平台常量 |
||||
|
* @author chengkun |
||||
|
* @date 2022/4/21 18:12 |
||||
|
*/ |
||||
|
public class PlatformConstant { |
||||
|
|
||||
|
/** |
||||
|
* 抖音 |
||||
|
*/ |
||||
|
public static final String TIKTOK = "0"; |
||||
|
|
||||
|
/** |
||||
|
* 快手 |
||||
|
*/ |
||||
|
public static final String FAST_HAND = "1"; |
||||
|
|
||||
|
/** |
||||
|
* 微信 |
||||
|
*/ |
||||
|
public static final String WECHAT = "2"; |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,225 @@ |
|||||
|
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/wx") |
||||
|
@Slf4j |
||||
|
public class WxMiniController extends BaseController { |
||||
|
|
||||
|
@Autowired |
||||
|
private BannerService bannerService; |
||||
|
|
||||
|
@Autowired |
||||
|
private FeedBackService feedBackService; |
||||
|
|
||||
|
@Autowired |
||||
|
private TypeService typeService; |
||||
|
|
||||
|
@Autowired |
||||
|
private TiktokImgService tiktokImgService; |
||||
|
|
||||
|
@Autowired |
||||
|
private WxUserService wxUserService; |
||||
|
|
||||
|
@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("3")); |
||||
|
} |
||||
|
|
||||
|
@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("2"); |
||||
|
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 = "/tiktokCollect") |
||||
|
public AjaxResult tiktokCollect(@Validated @RequestBody @ApiParam("收藏对象") CollectionDto dto){ |
||||
|
tiktokCollectionService.collect(dto.getUserId(),dto.getImgId(),"2"); |
||||
|
log.debug("【微信图文小程序】用户【{}】收藏了图片【{}】",dto.getUserId(),dto.getImgId()); |
||||
|
return AjaxResult.success(); |
||||
|
} |
||||
|
|
||||
|
//@TokenCheck
|
||||
|
@ApiOperation(value="取消收藏") |
||||
|
@PostMapping(value = "/tiktokUnCollect") |
||||
|
public AjaxResult tiktokUnCollect(@Validated @RequestBody @ApiParam("收藏对象") CollectionDto dto){ |
||||
|
tiktokCollectionService.unCollect(dto.getUserId(),dto.getImgId(),"2"); |
||||
|
log.debug("【微信图文小程序】用户【{}】取消收藏了图片【{}】",dto.getUserId(),dto.getImgId()); |
||||
|
return AjaxResult.success(); |
||||
|
} |
||||
|
|
||||
|
//@TokenCheck
|
||||
|
@ApiOperation(value="查询是否收藏过") |
||||
|
@PostMapping(value = "/judgeTiktokCollect") |
||||
|
public AjaxResult judgeTiktokCollect(@Validated @RequestBody @ApiParam("收藏对象") CollectionDto dto){ |
||||
|
log.debug("【微信图文小程序】查询是否收藏过参数为:{}", JSON.toJSONString(dto)); |
||||
|
return AjaxResult.success(tiktokCollectionService.judgeCollect(dto.getUserId(),dto.getImgId(),"2")); |
||||
|
} |
||||
|
|
||||
|
//@TokenCheck
|
||||
|
@ApiOperation(value="查看用户收藏列表") |
||||
|
@PostMapping(value = "/listTiktokCollection") |
||||
|
public AjaxResult listTiktokCollection(@Validated @RequestBody @ApiParam("用户收藏对象") CollectionUserDto dto){ |
||||
|
log.debug("【微信图文小程序】查看用户【{}】收藏列表", dto.getUserId()); |
||||
|
return AjaxResult.success(tiktokCollectionService.getCollectionByUserId(dto.getUserId(),"2")); |
||||
|
} |
||||
|
|
||||
|
//@TokenCheck
|
||||
|
@ApiOperation(value="点赞") |
||||
|
@PostMapping(value = "/tiktokLike") |
||||
|
public AjaxResult tiktokLike(@Validated @RequestBody @ApiParam("点赞对象") CollectionDto dto){ |
||||
|
tiktokLikeService.like(dto.getUserId(),dto.getImgId(),"2"); |
||||
|
log.debug("【微信图文小程序】用户【{}】点赞了图片【{}】",dto.getUserId(),dto.getImgId()); |
||||
|
return AjaxResult.success(); |
||||
|
} |
||||
|
|
||||
|
//@TokenCheck
|
||||
|
@ApiOperation(value="取消点赞") |
||||
|
@PostMapping(value = "/tiktokUnLike") |
||||
|
public AjaxResult tiktokUnLike(@Validated @RequestBody @ApiParam("点赞对象") CollectionDto dto){ |
||||
|
tiktokLikeService.unLike(dto.getUserId(),dto.getImgId(),"2"); |
||||
|
log.debug("【微信图文小程序】用户【{}】取消点赞了图片【{}】",dto.getUserId(),dto.getImgId()); |
||||
|
return AjaxResult.success(); |
||||
|
} |
||||
|
|
||||
|
//@TokenCheck
|
||||
|
@ApiOperation(value="查询是否点赞过") |
||||
|
@PostMapping(value = "/judgeTiktokLike") |
||||
|
public AjaxResult judgeTiktokLike(@Validated @RequestBody @ApiParam("点赞对象") CollectionDto dto){ |
||||
|
log.debug("【微信图文小程序】查询是否点赞过参数为:{}", JSON.toJSONString(dto)); |
||||
|
return AjaxResult.success(tiktokLikeService.judgeLike(dto.getUserId(),dto.getImgId(),"2")); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation(value="用户登录") |
||||
|
@PostMapping(value = "/loginWx") |
||||
|
public AjaxResult loginWx(@Validated @RequestBody @ApiParam("登录对象") WxLoginDto dto){ |
||||
|
log.info("【微信图文小程序】用户【{}】授权登录了", dto.getCode()); |
||||
|
return AjaxResult.success(wxUserService.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.WxUser; |
||||
|
import com.bnyer.img.dto.StatusDto; |
||||
|
import com.bnyer.img.dto.WxUserDto; |
||||
|
import com.bnyer.img.dto.WxUserPageDto; |
||||
|
import com.bnyer.img.service.WxUserService; |
||||
|
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/wxUser") |
||||
|
@Slf4j |
||||
|
public class WxUserController extends BaseController { |
||||
|
|
||||
|
@Autowired |
||||
|
private WxUserService wxUserService; |
||||
|
|
||||
|
//@RequiresPermissions("system:config:list")
|
||||
|
@ApiOperation(value="查询微信用户分页") |
||||
|
@PostMapping("/page") |
||||
|
public TableDataInfo pageWxUser(@RequestBody @ApiParam("分页对象") WxUserPageDto dto){ |
||||
|
PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); |
||||
|
List<WxUser> wxUsers = wxUserService.queryPage(dto); |
||||
|
for (WxUser wxUser : wxUsers) { |
||||
|
if(wxUser != null){ |
||||
|
if(StringUtils.isNotBlank(wxUser.getWxCode())){ |
||||
|
wxUser.setWxCode(Sm4Util.sm4Decrypt(wxUser.getWxCode())); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return getDataTable(wxUsers); |
||||
|
} |
||||
|
|
||||
|
//@RequiresPermissions("system:config:list")
|
||||
|
@ApiOperation(value="修改微信用户") |
||||
|
@PostMapping(value = "/update") |
||||
|
public AjaxResult update(@RequestBody @ApiParam("user对象") WxUserDto dto){ |
||||
|
log.debug("【图文平台后台】修改微信用户参数为:{}", JSON.toJSONString(dto)); |
||||
|
return AjaxResult.success(wxUserService.update(dto.extractParam())); |
||||
|
} |
||||
|
|
||||
|
//@RequiresPermissions("system:config:list")
|
||||
|
@ApiOperation(value="删除微信用户") |
||||
|
@DeleteMapping(value = "/delete/{ids}") |
||||
|
public AjaxResult deleteWxUser(@PathVariable @ApiParam("主键ids") List<Long> ids){ |
||||
|
log.debug("【图文平台后台】删除微信用户参数为:{}", ids); |
||||
|
return AjaxResult.success(wxUserService.delete(ids)); |
||||
|
} |
||||
|
|
||||
|
//@RequiresPermissions("system:config:list")
|
||||
|
@ApiOperation(value="查询微信用户详情") |
||||
|
@GetMapping(value = "/details/{id}") |
||||
|
public AjaxResult detailsWxUser(@PathVariable @ApiParam("主键id") Long id){ |
||||
|
WxUser wxUser = wxUserService.queryDetails(id); |
||||
|
if(StringUtils.isNotBlank(wxUser.getWxCode())){ |
||||
|
wxUser.setWxCode(Sm4Util.sm4Decrypt(wxUser.getWxCode())); |
||||
|
} |
||||
|
return AjaxResult.success(wxUser); |
||||
|
} |
||||
|
|
||||
|
//@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(wxUserService.changeStatus(dto.getId(),dto.getStatus())); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,61 @@ |
|||||
|
package com.bnyer.img.domain; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import java.io.Serializable; |
||||
|
import java.util.Date; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Getter; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.Setter; |
||||
|
import lombok.ToString; |
||||
|
|
||||
|
/** |
||||
|
* @author chengkun |
||||
|
* @date 2022/7/4 13:58 |
||||
|
*/ |
||||
|
/** |
||||
|
* img快手平台用户表 |
||||
|
*/ |
||||
|
@ApiModel(value="com-bnyer-img-domain-FhUser") |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@ToString |
||||
|
@AllArgsConstructor |
||||
|
@NoArgsConstructor |
||||
|
@TableName(value = "img_fh_user") |
||||
|
public class FhUser extends BaseDomain { |
||||
|
/** |
||||
|
* id |
||||
|
*/ |
||||
|
@TableId(value = "id", type = IdType.INPUT) |
||||
|
@ApiModelProperty(value="id") |
||||
|
private Long id; |
||||
|
|
||||
|
/** |
||||
|
* 用户昵称 |
||||
|
*/ |
||||
|
@TableField(value = "username") |
||||
|
@ApiModelProperty(value="用户昵称") |
||||
|
private String username; |
||||
|
|
||||
|
/** |
||||
|
* 快手id |
||||
|
*/ |
||||
|
@TableField(value = "fh_code") |
||||
|
@ApiModelProperty(value="快手id") |
||||
|
private String fhCode; |
||||
|
|
||||
|
/** |
||||
|
* 头像img地址 |
||||
|
*/ |
||||
|
@TableField(value = "img") |
||||
|
@ApiModelProperty(value="头像img地址") |
||||
|
private String img; |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
} |
||||
@ -0,0 +1,61 @@ |
|||||
|
package com.bnyer.img.domain; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import java.io.Serializable; |
||||
|
import java.util.Date; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Getter; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.Setter; |
||||
|
import lombok.ToString; |
||||
|
|
||||
|
/** |
||||
|
* @author chengkun |
||||
|
* @date 2022/7/4 13:58 |
||||
|
*/ |
||||
|
/** |
||||
|
* img微信平台用户表 |
||||
|
*/ |
||||
|
@ApiModel(value="com-bnyer-img-domain-WxUser") |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@ToString |
||||
|
@AllArgsConstructor |
||||
|
@NoArgsConstructor |
||||
|
@TableName(value = "img_wx_user") |
||||
|
public class WxUser extends BaseDomain { |
||||
|
/** |
||||
|
* id |
||||
|
*/ |
||||
|
@TableId(value = "id", type = IdType.INPUT) |
||||
|
@ApiModelProperty(value="id") |
||||
|
private Long id; |
||||
|
|
||||
|
/** |
||||
|
* 用户昵称 |
||||
|
*/ |
||||
|
@TableField(value = "username") |
||||
|
@ApiModelProperty(value="用户昵称") |
||||
|
private String username; |
||||
|
|
||||
|
/** |
||||
|
* 微信id |
||||
|
*/ |
||||
|
@TableField(value = "wx_code") |
||||
|
@ApiModelProperty(value="微信id") |
||||
|
private String wxCode; |
||||
|
|
||||
|
/** |
||||
|
* 头像img地址 |
||||
|
*/ |
||||
|
@TableField(value = "img") |
||||
|
@ApiModelProperty(value="头像img地址") |
||||
|
private String img; |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
package com.bnyer.img.dto; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
@ApiModel("快手登录入参") |
||||
|
public class FhLoginDto implements Serializable { |
||||
|
|
||||
|
@NotNull(message = "code不能为空!") |
||||
|
@ApiModelProperty(value = "微信code") |
||||
|
private String code; |
||||
|
|
||||
|
@NotNull(message = "加密数据不能为空!") |
||||
|
@ApiModelProperty(value = "加密数据") |
||||
|
private String encryptedData; |
||||
|
|
||||
|
@NotNull(message = "加密算法向量不能为空!") |
||||
|
@ApiModelProperty(value = "加密算法向量") |
||||
|
private String iv; |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
package com.bnyer.img.dto; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
@ApiModel("快手用户分页接收类") |
||||
|
public class FhUserPageDto extends BasePageDto { |
||||
|
|
||||
|
@ApiModelProperty(value="用户昵称") |
||||
|
private String username; |
||||
|
|
||||
|
@ApiModelProperty(value="是否展示") |
||||
|
private String isShow; |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
package com.bnyer.img.dto; |
||||
|
|
||||
|
import com.bnyer.common.core.utils.bean.BeanUtils; |
||||
|
import com.bnyer.img.domain.WxUser; |
||||
|
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 WxUserDto implements Serializable { |
||||
|
|
||||
|
@ApiModelProperty(value="id") |
||||
|
private Long id; |
||||
|
|
||||
|
@ApiModelProperty(value="用户昵称") |
||||
|
private String username; |
||||
|
|
||||
|
@ApiModelProperty(value="微信id") |
||||
|
private String wxCode; |
||||
|
|
||||
|
@ApiModelProperty(value="头像img地址") |
||||
|
private String img; |
||||
|
|
||||
|
public WxUser extractParam(){ |
||||
|
WxUser wxUser = new WxUser(); |
||||
|
BeanUtils.copyProperties(this, wxUser); |
||||
|
return wxUser; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
package com.bnyer.img.dto; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
@ApiModel("微信用户分页接收类") |
||||
|
public class WxUserPageDto extends BasePageDto { |
||||
|
|
||||
|
@ApiModelProperty(value="用户昵称") |
||||
|
private String username; |
||||
|
|
||||
|
@ApiModelProperty(value="是否展示") |
||||
|
private String isShow; |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package com.bnyer.img.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.bnyer.img.domain.FhUser; |
||||
|
import com.bnyer.img.dto.FhUserPageDto; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author chengkun |
||||
|
* @date 2022/7/4 13:58 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface FhUserMapper extends BaseMapper<FhUser> { |
||||
|
List<FhUser> queryPage(@Param("params") FhUserPageDto dto); |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package com.bnyer.img.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.bnyer.img.domain.WxUser; |
||||
|
import com.bnyer.img.dto.WxUserPageDto; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author chengkun |
||||
|
* @date 2022/7/4 13:58 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface WxUserMapper extends BaseMapper<WxUser> { |
||||
|
List<WxUser> queryPage(@Param("params") WxUserPageDto dto); |
||||
|
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
package com.bnyer.img.service; |
||||
|
|
||||
|
import com.bnyer.img.domain.FhUser; |
||||
|
import com.bnyer.img.dto.FhLoginDto; |
||||
|
import com.bnyer.img.dto.FhUserPageDto; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
public interface FhUserService { |
||||
|
|
||||
|
/** |
||||
|
* 修改快手用户 |
||||
|
* @param fhUser 快手用户 |
||||
|
* @return - |
||||
|
*/ |
||||
|
int update(FhUser fhUser); |
||||
|
|
||||
|
/** |
||||
|
* 批量删除快手用户 |
||||
|
* @param ids 主键Ids |
||||
|
* @return - |
||||
|
*/ |
||||
|
int delete(List<Long> ids); |
||||
|
|
||||
|
/** |
||||
|
* 查询快手用户分页 |
||||
|
* @param dto 分页条件对象 |
||||
|
* @return - |
||||
|
*/ |
||||
|
List<FhUser> queryPage(FhUserPageDto dto); |
||||
|
|
||||
|
/** |
||||
|
* 根据id获取用户 |
||||
|
* @param id 主键id |
||||
|
* @return - |
||||
|
*/ |
||||
|
FhUser queryDetails(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 快手登录参数 |
||||
|
* @param dto 登录参数 |
||||
|
* @return - |
||||
|
*/ |
||||
|
Map<String,Object> login(FhLoginDto dto); |
||||
|
|
||||
|
/** |
||||
|
* 变更显示状态 |
||||
|
* @param id 主键id |
||||
|
* @param status 状态 |
||||
|
* @return - |
||||
|
*/ |
||||
|
int changeStatus(Long id,String status); |
||||
|
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
package com.bnyer.img.service; |
||||
|
|
||||
|
import com.bnyer.img.domain.WxUser; |
||||
|
import com.bnyer.img.dto.WxLoginDto; |
||||
|
import com.bnyer.img.dto.WxUserPageDto; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
public interface WxUserService { |
||||
|
|
||||
|
/** |
||||
|
* 修改微信用户 |
||||
|
* @param wxUser 微信用户 |
||||
|
* @return - |
||||
|
*/ |
||||
|
int update(WxUser wxUser); |
||||
|
|
||||
|
/** |
||||
|
* 批量删除微信用户 |
||||
|
* @param ids 主键Ids |
||||
|
* @return - |
||||
|
*/ |
||||
|
int delete(List<Long> ids); |
||||
|
|
||||
|
/** |
||||
|
* 查询微信用户分页 |
||||
|
* @param dto 分页条件对象 |
||||
|
* @return - |
||||
|
*/ |
||||
|
List<WxUser> queryPage(WxUserPageDto dto); |
||||
|
|
||||
|
/** |
||||
|
* 根据id获取用户 |
||||
|
* @param id 主键id |
||||
|
* @return - |
||||
|
*/ |
||||
|
WxUser queryDetails(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 微信登录参数 |
||||
|
* @param param 登录参数 |
||||
|
* @return - |
||||
|
*/ |
||||
|
Map<String,Object> login(WxLoginDto param); |
||||
|
|
||||
|
/** |
||||
|
* 变更显示状态 |
||||
|
* @param id 主键id |
||||
|
* @param status 状态 |
||||
|
* @return - |
||||
|
*/ |
||||
|
int changeStatus(Long id,String status); |
||||
|
} |
||||
@ -0,0 +1,206 @@ |
|||||
|
//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);
|
||||
|
// }
|
||||
|
//}
|
||||
@ -0,0 +1,153 @@ |
|||||
|
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.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.WxUser; |
||||
|
import com.bnyer.img.dto.WxLoginDto; |
||||
|
import com.bnyer.img.dto.WxUserPageDto; |
||||
|
import com.bnyer.img.mapper.TiktokCollectionMapper; |
||||
|
import com.bnyer.img.mapper.TiktokLikeMapper; |
||||
|
import com.bnyer.img.mapper.WxUserMapper; |
||||
|
import com.bnyer.img.service.WxUserService; |
||||
|
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 java.util.Date; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.concurrent.TimeUnit; |
||||
|
|
||||
|
@Service |
||||
|
@Slf4j |
||||
|
public class WxUserServiceImpl implements WxUserService { |
||||
|
|
||||
|
@Autowired |
||||
|
private WxUserMapper wxUserMapper; |
||||
|
|
||||
|
@Autowired |
||||
|
private RedisService redisService; |
||||
|
|
||||
|
@Autowired |
||||
|
private TiktokLikeMapper tiktokLikeMapper; |
||||
|
|
||||
|
@Autowired |
||||
|
private TiktokCollectionMapper tiktokCollectionMapper; |
||||
|
|
||||
|
@Autowired |
||||
|
private WxMaUserService wxMaUserService; |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public int update(WxUser wxUser) { |
||||
|
wxUser.setUpdateTime(new Date()); |
||||
|
if (StringUtils.isNotBlank(wxUser.getWxCode())) { |
||||
|
wxUser.setWxCode(Sm4Util.sm4Encryption(wxUser.getWxCode())); |
||||
|
} |
||||
|
return wxUserMapper.updateById(wxUser); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public int delete(List<Long> ids) { |
||||
|
int delete = wxUserMapper.deleteBatchIds(ids); |
||||
|
//删除对应用户收藏及点赞记录
|
||||
|
LambdaQueryWrapper<TiktokCollection> collectionWrapper = new LambdaQueryWrapper<>(); |
||||
|
LambdaQueryWrapper<TiktokLike> likeWrapper = new LambdaQueryWrapper<>(); |
||||
|
for (Long id : ids) { |
||||
|
collectionWrapper.eq(TiktokCollection::getUserId, id) |
||||
|
.eq(TiktokCollection::getPlatform, "2"); |
||||
|
tiktokCollectionMapper.delete(collectionWrapper); |
||||
|
likeWrapper.eq(TiktokLike::getUserId, id) |
||||
|
.eq(TiktokLike::getPlatform, "2"); |
||||
|
tiktokLikeMapper.delete(likeWrapper); |
||||
|
} |
||||
|
return delete; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<WxUser> queryPage(WxUserPageDto dto) { |
||||
|
return wxUserMapper.queryPage(dto); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public WxUser queryDetails(Long id) { |
||||
|
return wxUserMapper.selectById(id); |
||||
|
} |
||||
|
|
||||
|
private WxUser saveOrUpdate(String openId, String sessionKey, String encryptedData, String iv) { |
||||
|
//获取用户昵称和头像
|
||||
|
WxMaUserInfo userInfo = wxMaUserService.getUserInfo(sessionKey, encryptedData, iv); |
||||
|
//创建用户
|
||||
|
WxUser wxUser = new WxUser(); |
||||
|
wxUser.setImg(userInfo.getAvatarUrl()); |
||||
|
wxUser.setUsername(userInfo.getNickName()); |
||||
|
wxUser.setWxCode(Sm4Util.sm4Encryption(openId)); |
||||
|
wxUser.setCreateTime(new Date()); |
||||
|
wxUser.setUpdateTime(new Date()); |
||||
|
wxUserMapper.insert(wxUser); |
||||
|
log.info("微信用户【{}】创建成功!", openId); |
||||
|
return wxUser; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Map<String, Object> login(WxLoginDto param) { |
||||
|
try { |
||||
|
//code换openId等相关信息
|
||||
|
WxMaJscode2SessionResult sessionInfo = wxMaUserService.getSessionInfo(param.getCode()); |
||||
|
//插入或更新艺术家到数据库
|
||||
|
QueryWrapper<WxUser> qw = new QueryWrapper<>(); |
||||
|
qw.eq("wx_code", Sm4Util.sm4Encryption(sessionInfo.getOpenid())); |
||||
|
WxUser wxUser = wxUserMapper.selectOne(qw); |
||||
|
if(wxUser == null){ |
||||
|
//新用户,新增
|
||||
|
wxUser = this.saveOrUpdate(sessionInfo.getOpenid(), sessionInfo.getSessionKey(), param.getEncryptedData(), param.getIv()); |
||||
|
} |
||||
|
//设置会话状态
|
||||
|
String redisKey = RedisKeyConstant.WECHAT_USER_LOGIN_KEY + Sm4Util.sm4Encryption(sessionInfo.getOpenid()); |
||||
|
//存在该登录态则删除刷新
|
||||
|
if (redisService.hasKey(redisKey)) { |
||||
|
redisService.deleteObject(redisKey); |
||||
|
} |
||||
|
//缓存到redis
|
||||
|
StringBuffer sb = new StringBuffer(); |
||||
|
String randomId = IdUtils.fastSimpleUUID(); |
||||
|
sb.append(randomId).append("#").append(sessionInfo.getOpenid()); |
||||
|
//设置登录会话
|
||||
|
redisService.setCacheObject(redisKey, sb.toString(), 10L, TimeUnit.DAYS); |
||||
|
Map<String, Object> map = new HashMap<>(2); |
||||
|
map.put("token", sb.toString()); |
||||
|
map.put("sessionKey", sessionInfo.getSessionKey()); |
||||
|
map.put("userInfo", wxUser); |
||||
|
return map; |
||||
|
} catch (WxErrorException e) { |
||||
|
throw new ServiceException(e.getMessage(), TiktokConstant.CALL_WECHAT_FAIL); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public int changeStatus(Long id, String status) { |
||||
|
LambdaUpdateWrapper<WxUser> wrapper = new LambdaUpdateWrapper<>(); |
||||
|
wrapper.eq(WxUser::getId, id); |
||||
|
WxUser user = new WxUser(); |
||||
|
user.setIsShow(status); |
||||
|
return wxUserMapper.update(user, wrapper); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
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("快手平台用户响应类") |
||||
|
public class FhUserInfoVo implements Serializable { |
||||
|
|
||||
|
@ApiModelProperty(value="用户昵称") |
||||
|
private String nickName; |
||||
|
|
||||
|
@ApiModelProperty(value="用户头像网络地址") |
||||
|
private String avatarUrl; |
||||
|
|
||||
|
@ApiModelProperty(value="用户性别,0: 未知;1:男性;2:女性") |
||||
|
private String gender; |
||||
|
|
||||
|
@ApiModelProperty(value="用户所在城市") |
||||
|
private String city; |
||||
|
|
||||
|
@ApiModelProperty(value="用户所在省份") |
||||
|
private String province; |
||||
|
|
||||
|
@ApiModelProperty(value="用户所在国家") |
||||
|
private String country; |
||||
|
|
||||
|
@ApiModelProperty(value="用户openId") |
||||
|
private String openId; |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
<mapper namespace="com.bnyer.img.mapper.FhUserMapper"> |
||||
|
<resultMap id="BaseResultMap" type="com.bnyer.img.domain.FhUser"> |
||||
|
<!--@mbg.generated--> |
||||
|
<!--@Table img_fh_user--> |
||||
|
<id column="id" jdbcType="BIGINT" property="id" /> |
||||
|
<result column="username" jdbcType="VARCHAR" property="username" /> |
||||
|
<result column="fh_code" jdbcType="VARCHAR" property="fhCode" /> |
||||
|
<result column="img" jdbcType="VARCHAR" property="img" /> |
||||
|
<result column="is_show" jdbcType="CHAR" property="isShow" /> |
||||
|
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
||||
|
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> |
||||
|
<result column="sort" jdbcType="INTEGER" property="sort" /> |
||||
|
</resultMap> |
||||
|
<sql id="Base_Column_List"> |
||||
|
<!--@mbg.generated--> |
||||
|
id, username, fh_code, img, is_show, create_time, update_time, sort |
||||
|
</sql> |
||||
|
|
||||
|
<select id="queryPage" resultMap="BaseResultMap"> |
||||
|
select |
||||
|
<include refid="Base_Column_List"/> |
||||
|
from img_fh_user |
||||
|
<where> |
||||
|
<if test="params.username != null and params.username != ''"> |
||||
|
username like concat('%',#{params.username},'%') |
||||
|
</if> |
||||
|
<if test="params.isShow != null and params.isShow != ''"> |
||||
|
and is_show = #{params.isShow} |
||||
|
</if> |
||||
|
</where> |
||||
|
order by create_time desc |
||||
|
</select> |
||||
|
</mapper> |
||||
@ -0,0 +1,35 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
<mapper namespace="com.bnyer.img.mapper.WxUserMapper"> |
||||
|
<resultMap id="BaseResultMap" type="com.bnyer.img.domain.WxUser"> |
||||
|
<!--@mbg.generated--> |
||||
|
<!--@Table img_wx_user--> |
||||
|
<id column="id" jdbcType="BIGINT" property="id" /> |
||||
|
<result column="username" jdbcType="VARCHAR" property="username" /> |
||||
|
<result column="wx_code" jdbcType="VARCHAR" property="wxCode" /> |
||||
|
<result column="img" jdbcType="VARCHAR" property="img" /> |
||||
|
<result column="is_show" jdbcType="CHAR" property="isShow" /> |
||||
|
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
||||
|
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> |
||||
|
<result column="sort" jdbcType="INTEGER" property="sort" /> |
||||
|
</resultMap> |
||||
|
<sql id="Base_Column_List"> |
||||
|
<!--@mbg.generated--> |
||||
|
id, username, wx_code, img, is_show, create_time, update_time, sort |
||||
|
</sql> |
||||
|
|
||||
|
<select id="queryPage" resultMap="BaseResultMap"> |
||||
|
select |
||||
|
<include refid="Base_Column_List"/> |
||||
|
from img_wx_user |
||||
|
<where> |
||||
|
<if test="params.username != null and params.username != ''"> |
||||
|
username like concat('%',#{params.username},'%') |
||||
|
</if> |
||||
|
<if test="params.isShow != null and params.isShow != ''"> |
||||
|
and is_show = #{params.isShow} |
||||
|
</if> |
||||
|
</where> |
||||
|
order by create_time desc |
||||
|
</select> |
||||
|
</mapper> |
||||
Loading…
Reference in new issue