| | |
| | | package com.platform.verification; |
| | | |
| | | |
| | | import com.hx.util.DateUtil; |
| | | import com.hx.util.StringUtils; |
| | | import com.hx.util.rsa.RSAUtil; |
| | | import com.platform.resultTool.PlatformCode; |
| | | import com.platform.resultTool.PlatformResult; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | /**平台校验方法 |
| | | * @author CJH |
| | |
| | | if (!appId.equals(decrypts[0])) { |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
| | | } |
| | | |
| | | Date date = null; |
| | | try{ |
| | | |
| | | //判断接口时间 |
| | | SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String sd = sdf.format(new Date(Long.parseLong(String.valueOf(decrypts[1])))); // 时间戳转换成时间 |
| | | date = DateUtil.parseString(sd,"yyyy-MM-dd HH:mm:ss"); |
| | | }catch (Exception e){ |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
| | | } |
| | | |
| | | //接口有效2秒钟 |
| | | if(System.currentTimeMillis()-date.getTime() > 2000){ |
| | | return PlatformResult.failure(PlatformCode.ERROR_INVALID_VISIT, "访问无效"); |
| | | } |
| | | |
| | | return PlatformResult.success(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | |
| | | Long timeStamp = System.currentTimeMillis(); //获取当前时间戳 |
| | | SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String sd = sdf.format(new Date(Long.parseLong(String.valueOf(timeStamp)))); |
| | | |
| | | Date date = DateUtil.parseString(sd,"yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | System.out.println(); |
| | | |
| | | // 时间戳转换成时间 |
| | | System.out.println("格式化结果:" + sd); |
| | | |
| | | } |
| | | |
| | | } |