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