增加api测试类,移动signature到service中
This commit is contained in:
@@ -36,12 +36,14 @@ public class Signature {
|
|||||||
ResultBean rb = ResultBean.fireFail();
|
ResultBean rb = ResultBean.fireFail();
|
||||||
Map<String, String> parameters = data;
|
Map<String, String> parameters = data;
|
||||||
//1、解析参数,校验_app是否正确,_t是否在5分钟内。
|
//1、解析参数,校验_app是否正确,_t是否在5分钟内。
|
||||||
|
|
||||||
|
//检验_app 参数,1参数中是否存在2该参数是否为空3_app参数值是否在数据库中存在
|
||||||
if (!parameters.containsKey("_app") ||
|
if (!parameters.containsKey("_app") ||
|
||||||
parameters.get("_app") == null ||
|
parameters.get("_app") == null ||
|
||||||
parameters.get("_app").trim().isEmpty()) {
|
parameters.get("_app").trim().isEmpty()) {
|
||||||
return rb.setMsg("_app参数缺失或无效");
|
return rb.setMsg("_app参数缺失或无效");
|
||||||
}
|
}
|
||||||
//2、根据_app参数获取对应的secret值。
|
//2、根据_app参数获取对应的secret值。后续考虑从数据库中获取。
|
||||||
String secret = getSecret(parameters.get("_app"));
|
String secret = getSecret(parameters.get("_app"));
|
||||||
if (StringUtils.isEmpty(secret)) {
|
if (StringUtils.isEmpty(secret)) {
|
||||||
return rb.setMsg("_app参数不正确");
|
return rb.setMsg("_app参数不正确");
|
||||||
@@ -23,9 +23,10 @@ public class SignatureUtil {
|
|||||||
* @return 签名
|
* @return 签名
|
||||||
*/
|
*/
|
||||||
public static String generateSignature(Map<String, String> parameters, String secret) throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
public static String generateSignature(Map<String, String> parameters, String secret) throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||||
|
//1.对参数进行排序
|
||||||
|
Map<tring, String> treeMap=new TreeMap<>(parameters);
|
||||||
// 2. 拼接参数字符串
|
// 2. 拼接参数字符串
|
||||||
String content = joinParameters(parameters);
|
String content = joinParameters(treeMap);
|
||||||
|
|
||||||
// 3. 将密钥加在参数字符串的前后
|
// 3. 将密钥加在参数字符串的前后
|
||||||
content = secret + content + secret;
|
content = secret + content + secret;
|
||||||
|
|||||||
Reference in New Issue
Block a user