Bladeren bron

VIP接口加了sign

小么熊🐻 3 jaren geleden
bovenliggende
commit
77d2a837e9

+ 55 - 2
jsjp-admin/src/main/java/com/miaxis/app/controller/gzpt/GzptVideoVipController.java

@@ -7,13 +7,22 @@ import com.miaxis.common.core.domain.Response;
 import com.miaxis.newgzpt.domain.GzptVideoVip;
 import com.miaxis.newgzpt.dto.GzptVideoVipDTO;
 import com.miaxis.newgzpt.service.IGzptVideoVipService;
+import com.miaxis.newgzpt.vo.GzptVideoVipVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.security.KeyFactory;
+import java.security.PrivateKey;
+import java.security.Signature;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.util.Base64;
+import java.util.Date;
+
 /**
  * <p>
  * 学员基本信息表 前端控制器
@@ -30,16 +39,60 @@ public class GzptVideoVipController extends BaseController {
     private IGzptVideoVipService gzptVideoVipService;
 
 
+    private String  rsaPrivateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMLNHTgsyYOXDJVF8r4qCyb+8Uw4" +
+            "XKq8aThAhUIaPYIop+HJxETGbXk3e0o46i4iOX8RTv0i3jmhL6W0mSxy9ismfXPP7VtKgEt6VnMm" +
+            "ufsrQ2kcXyRsKmuwUd3rTH5gniXwLdIPF8V5ujiSq94nPHok1krDMWbss8Q7lcH2kQFHAgMBAAEC" +
+            "gYBh6Eu2TzRdMg79+7EciO8gA2Tt5SoWGipcPnl7lsqxX5O5dPpzgrPFB/CshlyVIVh6mA12Rw8g" +
+            "MfZLt7CA2asFdgGHfgCvMjsCnL2U1Nf1QFnsnGXmFXeVUvdy7XPILi75rVyOEAw+/f3KzjSA7B3w" +
+            "URE8M2QlIUcjm8LLyCVC4QJBAO+taJH7pVZGVn2upsOk14X08QU0lsQ7ufe/8VXe+IujwGMh34U6" +
+            "BHGV7grodtA7TvQ3mDggQLHB2+IxBWdDCrcCQQDQEVMI+CD7afEyN9rK/MAJwevtxNaTyEd1bhKw" +
+            "t6WKr1YbAdUz2gvnpCQjD1Gqt5yXHKu279msX9W4euXePG3xAkBUCYZn4UdIp+L9sHZSlQLoukik" +
+            "HZtbdOGw58Ez7blSJPl5CNB5wyz5sqtDcdzvCEyXvsKFs3FbonB5r9yIJ26jAkEAugGC1dXcxmWj" +
+            "dl1wf18M3qw6GkmJ+ntlRpmso8bJev3cYDB3RO99DQw0MhOT0qZqmrzK1bP+SJc0HMPhk5c6QQJA" +
+            "WRLIxmeM/P9X2mDjMrI46Wnn27QoKGgYSHdPxmLD0y7NUytf5HyCsY2vhA9FZcnikibax7SwzC/B" +
+            "D7yOXFAy/Q==";
+
     /**
      * 获取用户vip信息
      */
     @GetMapping
     @ApiOperation("获取用户vip信息")
-    public Response<GzptVideoVip> getVideoVip(GzptVideoVipDTO gzptVideoVipDTO){
+    public Response<GzptVideoVipVO> getVideoVip(GzptVideoVipDTO gzptVideoVipDTO) throws Exception {
         GzptVideoVip gzptVideoVip  = gzptVideoVipService.getGzptVideoVipByUserId(gzptVideoVipDTO);
-        return Response.success(gzptVideoVip);
+        GzptVideoVipVO vo = new GzptVideoVipVO();
+        if(gzptVideoVip!=null) {
+            BeanUtils.copyProperties(gzptVideoVip, vo);
+            String sign = getSign(vo.getUserId(), vo.getSubject2(), vo.getSubject3());
+            vo.setSign(sign);
+            return Response.success(vo);
+        } else {
+            return Response.success(vo);
+        }
     }
 
 
+    private String getSign(Long userId, Date subject2, Date subject3) throws Exception  {
+        String str = userId+"";
+       // System.out.println(userId);
+        if(subject2!=null){
+            str += subject2.getTime()+"";
+        //   System.out.println(subject2.getTime());
+        }
+        if(subject3!=null){
+            str += subject3.getTime()+"";
+         //   System.out.println(subject3.getTime());
+        }
+     //   System.out.println("str:"+str);
+        // 进行签名服务
+        Signature signature = Signature.getInstance("SHA256withRSA");
+        KeyFactory kf = KeyFactory.getInstance("RSA");
+        PrivateKey privateKey =  kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(rsaPrivateKey)));
+        signature.initSign(privateKey);
+        signature.update(str.getBytes("UTF-8"));
+        byte[] signedData = signature.sign();
+        return Base64.getEncoder().encodeToString(signedData);
+
+    }
+
 }
 

+ 51 - 0
jsjp-service/src/main/java/com/miaxis/newgzpt/vo/GzptVideoVipVO.java

@@ -0,0 +1,51 @@
+package com.miaxis.newgzpt.vo;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ * 视频VIP表
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-01-27
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class GzptVideoVipVO implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "ID")
+    private Long id;
+
+    @ApiModelProperty(value = "用户ID")
+    private Long userId;
+
+    @ApiModelProperty(value = "用户名")
+    private String userName;
+
+
+    @ApiModelProperty(value = "科目2  到期时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date subject2;
+
+    @ApiModelProperty(value = "科目3  到期时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date subject3;
+
+    @ApiModelProperty(value = "签名")
+    private String sign;
+
+
+}