Helius
2022-08-09 ae50866f34212c007643c1744f78426676885c08
src/main/java/cc/mrbird/febs/common/interceptor/DappInterceptor.java
@@ -2,11 +2,15 @@
import cc.mrbird.febs.common.contants.AppContants;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.utils.LoginUserUtil;
import cc.mrbird.febs.common.utils.RedisUtils;
import cc.mrbird.febs.common.utils.SpringContextUtil;
import cc.mrbird.febs.dapp.entity.DappMemberEntity;
import cc.mrbird.febs.dapp.mapper.DappMemberDao;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -37,7 +41,6 @@
        String headAddress = request.getHeader("address");
        String key = request.getHeader("key");
        String path = request.getServletPath().replace("/dapi", "");
        log.info("进入拦截:{}, {}", headAddress, path);
        String chain = request.getHeader("chain");
        if (StrUtil.isBlank(headAddress) || StrUtil.isBlank(key)) {
@@ -54,7 +57,7 @@
        }
        String sign = (String) signObj;
        String calKey = Hash.sha3(sign + path + headAddress).replace("0x", "");
        String calKey = LoginUserUtil.sha3(sign + path + headAddress).replace("0x", "");
        if (!calKey.equals(key)) {
            responseUnAuth(response);
            return false;
@@ -73,6 +76,16 @@
    private void responseUnAuth(HttpServletResponse response) throws IOException {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        response.getWriter().write(new ObjectMapper().writeValueAsString(new FebsResponse().code(HttpStatus.UNAUTHORIZED)));
        FebsResponse code = new FebsResponse().code(HttpStatus.UNAUTHORIZED);
        String encryptBase64 = SecureUtil.rsa(AppContants.RESP_PRIVATE_KEY, AppContants.RESP_PUBLIC_KEY).encryptBase64(JSONObject.toJSONString(code).getBytes(), KeyType.PublicKey);
        response.getWriter().write(new ObjectMapper().writeValueAsString(encryptBase64));
    }
    public static void main(String[] args) {
        String headAddress = "0x971c09aa9735eb98459b17ec8b48932d24cbb931";
        String path = "/member/walletInfo";
        String sign = "0x1fd3f82895ca4615daa10ec245d628ca230358e08423df71c8f6c8d3d4163520";
//        System.out.println(Hash.sha3(sign + path + headAddress));
    }
}