chenjiahe
2022-08-11 2b35339fd67969df7acb8c75bfceafa1ba134b41
src/main/java/com/platform/verification/VerificationTool.java
@@ -1,12 +1,14 @@
package com.platform.verification;
import com.hx.util.DateUtil;
import com.hx.util.StringUtils;
import com.hx.util.rsa.RSAUtil;
import com.platform.constants.LoginConstant;
import com.platform.entity.ThirtApplication;
import com.platform.resultTool.PlatformCode;
import com.platform.resultTool.PlatformResult;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -17,30 +19,33 @@
public class VerificationTool {
    /**校验方法请求
     * @param appId 用户的APPID
     * @param appId 用户的APPID `
     * @param sign 用户签名
     * @param sys_appId 系统的appid
     * @param sys_private_key 系统的RSA秘钥
     * @param thirtApplication ThirtApplication
     * @return
     */
    public static PlatformResult verification(String appId,String sign,String sys_appId,String sys_private_key){
    public static PlatformResult verification(String appId, String sign, ThirtApplication thirtApplication,HttpServletRequest request){
        if (StringUtils.isEmpty(sign)) {
            return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误01");
        }
        if (StringUtils.isEmpty(appId)) {
            return PlatformResult.failure(PlatformCode.ERROR_APPIS, "APPID错误01");
            return PlatformResult.failure(PlatformCode.ERROR_APPIS, "APPID错误");
        }
        //校验appid是否存在
        if(!sys_appId.equals(appId)){
            return PlatformResult.failure(PlatformCode.ERROR_APPIS, "APPID错误02");
        if(thirtApplication == null){
            return PlatformResult.failure(PlatformCode.ERROR_APPIS, "APPID无效");
        }
        if(StringUtils.isEmpty(thirtApplication.getPrivateKey())){
            return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误,APPID无效");
        }
        //解密RSA
        String decrypt = null;
        try{
            decrypt = RSAUtil.privateDecrypt(sign, sys_private_key);
            decrypt = RSAUtil.privateDecrypt(sign, thirtApplication.getPrivateKey());
        }catch (Exception e){
        }
@@ -68,11 +73,14 @@
            return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误05");
        }
        //接口有效2秒钟
        if(System.currentTimeMillis()-date.getTime() > 2000){
            return PlatformResult.failure(PlatformCode.ERROR_INVALID_VISIT, "访问无效");
        //接口有效30秒钟
        if(System.currentTimeMillis()-date.getTime() > 30000){
            return PlatformResult.failure(PlatformCode.ERRO_VISIT_OVERTIMR, "访问超时");
        }
        thirtApplication.setPrivateKey(null);
        request.getSession().setAttribute(LoginConstant.LOGIN_APPLY,thirtApplication);
        return PlatformResult.success();
    }