1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package com.fdkankan.tk.service.impl;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkankan.redis.util.RedisUtil;
- import com.fdkankan.tk.common.ResultCode;
- import com.fdkankan.tk.common.util.RedisKeyUtil;
- import com.fdkankan.tk.entity.TencentYun;
- import com.fdkankan.tk.exception.BusinessException;
- import com.fdkankan.tk.mapper.ITencentYunMapper;
- import com.fdkankan.tk.service.ITencentYunService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.tencentyun.TLSSigAPIv2;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.List;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2022-09-27
- */
- @Service
- public class TencentYunServiceImpl extends ServiceImpl<ITencentYunMapper, TencentYun> implements ITencentYunService {
- @Autowired
- RedisUtil redisUtil;
- @Override
- public JSONObject getSign(String userId) {
- String redisKey = RedisKeyUtil.TENCENT_YUN_KEY + userId;
- if (!redisUtil.hasKey(redisKey)) {
- List<TencentYun> list = this.list();
- if(list == null || list.size() <=0){
- throw new BusinessException(ResultCode.TENCENT_YUN_EMPTY);
- }
- if(list.size() >1){
- throw new BusinessException(ResultCode.TENCENT_YUN_ERROR);
- }
- TencentYun tencentYun = list.get(0);
- TLSSigAPIv2 api = new TLSSigAPIv2(tencentYun.getSdkAppid(), tencentYun.getSecretkey());
- String sign = api.genUserSig(userId, tencentYun.getExTime() );
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("sdkAppId",tencentYun.getSdkAppid());
- jsonObject.put("expire",tencentYun.getExTime());
- jsonObject.put("sign",sign);
- redisUtil.set(redisKey ,jsonObject.toJSONString(),tencentYun.getExTime() - 60);
- return jsonObject;
- }
- JSONObject jsonObject = JSONObject.parseObject(redisUtil.get(redisKey));
- jsonObject.put("expire",redisUtil.getExpire(redisKey));
- return jsonObject;
- }
- }
|