package jnpf.im.controller;

import com.tencentyun.TLSSigAPIv2;
import jnpf.base.ActionResult;
import jnpf.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * describe
 *
 * @author HuangLinPan
 * @date 2023/08/16
 */
@Deprecated
@Slf4j
@RestController
@RequestMapping(value = "/im")
public class ImController {
    @Autowired
    private RedisUtil redisUtil;
    @Value("${config.SDKAPPID}")
    private long SDKAPPID;
    @Value("${config.KEY}")
    private String KEY;

    @GetMapping("/getUserSig/{userId}")
    public ActionResult getUserSig(@PathVariable("userId") String userId)  {
        String userSig = null;
        Object type = redisUtil.getString("userSig"+userId);
        if (null == type) {
            TLSSigAPIv2 tlsSigAPIv2 = new TLSSigAPIv2(SDKAPPID, KEY);
            userSig = tlsSigAPIv2.genUserSig(userId, 60 * 60 * 24 * 60);
            redisUtil.insert("userSig" + userId, userSig, 60 * 60 * 24 * 60);
        }else {
            userSig = type.toString();
        }
        return ActionResult.success(userSig);
    }
}
