修改
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.yxt.ss.gateway.api;
|
||||
|
||||
import com.yxt.ss.gateway.api.utils.AppKeyConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -16,19 +18,26 @@ import java.util.Map;
|
||||
@Service
|
||||
public class ClientService {
|
||||
|
||||
@Autowired
|
||||
private AppKeyConfig appKeyConfig;
|
||||
|
||||
public String getSecret(String appKey) {
|
||||
return appKeyConfig.getKeys().get(appKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求签名
|
||||
*
|
||||
* @param parameters 请求参数
|
||||
* @param secret 密钥
|
||||
* @return 签名
|
||||
*/
|
||||
public String generateSignature(Map<String, String> parameters, String secret) throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
public String generateSignature(Map<String, String> parameters) throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
|
||||
// 2. 拼接参数字符串
|
||||
String content = joinParameters(parameters);
|
||||
|
||||
// 3. 将密钥加在参数字符串的前后
|
||||
String secret = getSecret(parameters.get("_app"));
|
||||
content = secret + content + secret;
|
||||
|
||||
// 4. 计算签名 (MD5)
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.yxt.ss.gateway.api.ClientService;
|
||||
import com.yxt.ss.gateway.api.utils.ResultBean;
|
||||
import com.yxt.ss.gateway.api.utils.SignatureQuery;
|
||||
import com.yxt.ss.gateway.api.utils.SignatureUtil;
|
||||
import okhttp3.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -34,8 +33,6 @@ public class ClientRest {
|
||||
|
||||
//appkey
|
||||
static final String APPKEY = "appKey4";
|
||||
//secret
|
||||
static final String SECRET = "secret";
|
||||
|
||||
//开发端,生成签名并调用服务器端验证签名、appKey等值。
|
||||
@PostMapping("/getSign")
|
||||
@@ -49,7 +46,7 @@ public class ClientRest {
|
||||
tree.put("_t", String.valueOf(System.currentTimeMillis() / 1000));
|
||||
tree.put("_s", "");
|
||||
// 生成签名
|
||||
String sign = clientService.generateSignature(tree, SECRET);
|
||||
String sign = clientService.generateSignature(tree);
|
||||
//添加签名值map
|
||||
tree.put("_sign", sign);
|
||||
//发起请求
|
||||
|
||||
@@ -30,12 +30,6 @@ public class Signature {
|
||||
return appKeyConfig.getKeys().get(appKey);
|
||||
}
|
||||
|
||||
|
||||
//appkey
|
||||
static final String APPKEY = "appKey4";
|
||||
//secret
|
||||
static final String SECRET = "secret";
|
||||
|
||||
//验证
|
||||
@PostMapping("/validate")
|
||||
ResultBean validate(Map<String, String> data) {
|
||||
|
||||
Reference in New Issue
Block a user