| | |
| | | public static PlatformResult verification(String appId,String sign,String sys_appId,String sys_private_key){ |
| | | |
| | | if (StringUtils.isEmpty(sign)) { |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误01"); |
| | | } |
| | | if (StringUtils.isEmpty(appId)) { |
| | | return PlatformResult.failure(PlatformCode.ERROR_APPIS, "APPID错误"); |
| | | return PlatformResult.failure(PlatformCode.ERROR_APPIS, "APPID错误01"); |
| | | } |
| | | |
| | | //校验appid是否存在 |
| | | if(!sys_appId.equals("appId")){ |
| | | return PlatformResult.failure(PlatformCode.ERROR_APPIS, "APPID错误"); |
| | | if(!sys_appId.equals(appId)){ |
| | | return PlatformResult.failure(PlatformCode.ERROR_APPIS, "APPID错误02"); |
| | | } |
| | | |
| | | //解密RSA |
| | |
| | | |
| | | } |
| | | if(StringUtils.isEmpty(decrypt)){ |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误02"); |
| | | } |
| | | |
| | | //decrypt格式:appId_时间戳_随机数(尽量少) |
| | | String[] decrypts = decrypt.split("_"); |
| | | if(decrypts.length != 3){ |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误03"); |
| | | } |
| | | |
| | | if (!appId.equals(decrypts[0])) { |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误04"); |
| | | } |
| | | |
| | | 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, "签名错误"); |
| | | return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误05"); |
| | | } |
| | | |
| | | //接口有效2秒钟 |