菜鸟猿坠机中 2019-04-25 11:11 采纳率: 0%
浏览 259

服务一直返回端验签失败

public void pay() {
PayWayRecord payWayRecord = psyService.getPayWay(PayWayEnum.TONGTONG.getCode());
Map sendParams = new HashMap<>();
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
sendParams.put("app_id", "s100000040");
sendParams.put("terminal_type", " web");
sendParams.put("version", "1.0");
sendParams.put("service", "fosun.sumpay.cashier.web.trade.order.apply");
sendParams.put("timestamp", simpleDateFormat.format(date.getTime()));
sendParams.put("mer_no", "s100000040");
sendParams.put("trade_code", "T0002");
sendParams.put("user_id", "111");
//sendParams.put("mer_id", "100001465");
sendParams.put("order_no", "D100174978");
sendParams.put("order_time", simpleDateFormat.format(date.getTime()));
sendParams.put("order_amount", "100.00");
sendParams.put("need_notify", "1");
sendParams.put("need_return", "0");
sendParams.put("goods_name", "Preety Toy");
sendParams.put("goods_num", "1");
sendParams.put("goods_type", "1");
// sendParams.put("mer_no", "100001465");
sendParams.put("amount", "1");
SignService signService = new SignServiceImpl();
String aesKey = AESUtil.getKey();
sendParams.put("aes_key", aesKey);
System.out.println(sendParams.get("aes_key"));
//sendParams.put("mor_id", "13131");
List keyList = new ArrayList(sendParams.keySet());
Collections.sort(keyList);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < keyList.size(); i++) {
String key = keyList.get(i);
String keyValue = sendParams.get(key);
sb.append(key).append("=").append(keyValue);
if (i < keyList.size() - 1) {
sb.append("&");
}
}
//SignServiceImpl signService=new SignServiceImpl();
String signMsg = signService.signMsg(sb.toString(), pricateKeyPath, password, charset);
System.out.println("签名之后是:" + signMsg);
sendParams.put("sign", signMsg);
sendParams.put("sign_type", "CERT");
FormBody.Builder builder = new FormBody.Builder();
for (String key : sendParams.keySet()) {
builder.add(key, sendParams.get(key));
}
RequestBody formBody = builder.build();
Request request3 = new Request.Builder()
.url(TEST_URL)
.post(formBody)
// .addHeader("Referer","domain")
//.get()
.build();
Response response= null;
try {
response = okHttpClient.newCall(request3).execute();
String returnMsg=response.body().string();
if (response.isSuccessful()){
// boolean ss= signService.verifyMsg(returnMsg, String.valueOf(sb),publicKeyPath);
// logger.info("[tong query] response is {}", ss);
logger.info("[tong query] response is {}", returnMsg);
}else{
logger.error("[tongfu query] failed");
}
} catch (IOException e) {
e.printStackTrace();
}
}

单元测试返回:

2019-04-25 10:55:25.560 INFO 10908 --- [ main] ALL : [tong query] response is {"resp_code":"EG000001","resp_msg":"验签失败"}

这类错误的问题一般是什么情况造成的,希望大佬给点意见

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-09 03:37
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    这个问题可能是由以下几个原因引起的:

    1. 密钥和证书失效:如果密钥或证书已经过期,Spring Cloud Gateway的认证流程可能会导致错误。确保密钥和证书的有效性。

    2. 请求参数格式问题:在请求中可能包含非法字符或者格式不正确,例如中文、空格等。

    3. 签名算法不匹配:使用了不同的签名算法(如SHA-1 vs SHA-256),可能导致验证失败。

    4. 服务器响应异常:检查返回的响应码是否为200 OK,如果不是则可能存在服务器端的问题。

    5. 网络连接问题:如果请求被重定向到其他URL,这可能导致错误。尝试直接访问目标URL来确认问题。

    解决方法:

    1. 检查密钥和证书有效性:确保密钥和证书的有效性和时效性。

    2. 校验请求参数:检查请求参数的格式和内容,防止出现中文乱码等问题。

    3. 调整签名算法:如果需要支持多个签名算法,可以考虑使用一个通用的签名算法,并根据实际情况选择合适的密钥和证书。

    4. 检查服务器响应状态码:如果请求成功但返回的状态码不是200 OK,则可能需要进一步分析错误信息。

    5. 检查网络连接:如果可能的话,尝试直接访问目标URL以查看是否有任何问题。

    以下是一个简单的示例代码片段,用于模拟上述步骤:

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
    import org.springframework.cloud.openfeign.EnableFeignClients;
    import org.springframework.context.annotation.Bean;
    import org.springframework.web.client.RestTemplate;
    
    @SpringBootApplication
    @EnableEurekaClient
    @EnableFeignClients
    @EnableHystrixDashboard
    public class PaymentServiceApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(PaymentServiceApplication.class, args);
        }
    }
    

    在这个例子中,我们创建了一个PaymentServiceApplication类作为主类,并注入了必要的依赖。然后,在main方法中启动应用。这样做的目的是为了展示如何配置Spring Boot应用程序以及其中的一些关键组件。

    评论

报告相同问题?