提交 | 用户 | age
|
6c1bfc
|
1 |
package com.platform.verification; |
C |
2 |
|
|
3 |
|
|
4 |
import com.hx.util.StringUtils; |
|
5 |
import com.hx.util.rsa.RSAUtil; |
|
6 |
import com.platform.resultTool.PlatformCode; |
|
7 |
import com.platform.resultTool.PlatformResult; |
|
8 |
|
|
9 |
/**平台校验方法 |
|
10 |
* @author CJH |
|
11 |
* @date 2021-10-20 |
|
12 |
*/ |
|
13 |
public class VerificationTool { |
|
14 |
|
|
15 |
/**校验方法请求 |
|
16 |
* @param appId 用户的APPID |
|
17 |
* @param sign 用户签名 |
|
18 |
* @param sys_appId 系统的appid |
|
19 |
* @param sys_private_key 系统的RSA秘钥 |
|
20 |
* @return |
|
21 |
*/ |
|
22 |
public static PlatformResult verification(String appId,String sign,String sys_appId,String sys_private_key){ |
|
23 |
|
|
24 |
if (StringUtils.isEmpty(sign)) { |
|
25 |
return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
|
26 |
} |
|
27 |
if (StringUtils.isEmpty(appId)) { |
|
28 |
return PlatformResult.failure(PlatformCode.ERROR_APPIS, "APPID错误"); |
|
29 |
} |
|
30 |
|
|
31 |
//校验appid是否存在 |
|
32 |
if(!sys_appId.equals("appId")){ |
|
33 |
return PlatformResult.failure(PlatformCode.ERROR_APPIS, "APPID错误"); |
|
34 |
} |
|
35 |
|
|
36 |
//解密RSA |
|
37 |
String decrypt = null; |
|
38 |
try{ |
|
39 |
decrypt = RSAUtil.privateDecrypt(sign, sys_private_key); |
|
40 |
}catch (Exception e){ |
|
41 |
|
|
42 |
} |
|
43 |
if(StringUtils.isEmpty(decrypt)){ |
|
44 |
return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
|
45 |
} |
|
46 |
|
|
47 |
//decrypt格式:appId_时间戳_随机数(尽量少) |
|
48 |
String[] decrypts = decrypt.split("_"); |
|
49 |
if(decrypts.length != 3){ |
|
50 |
return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
|
51 |
} |
|
52 |
|
|
53 |
if (!appId.equals(decrypts[0])) { |
|
54 |
return PlatformResult.failure(PlatformCode.ERROR_SIGN, "签名错误"); |
|
55 |
} |
|
56 |
return PlatformResult.success(); |
|
57 |
} |
|
58 |
|
|
59 |
} |