gpt4 book ai didi

java - 错误 :- {"code" :"403", "message":"HMAC validation Failure"}

转载 作者:搜寻专家 更新时间:2023-11-01 02:43:04 25 4
gpt4 key购买 nike

我在这里附上代码和一个包含完整代码的链接,看看它:-我的授权 header 接缝的长度与 payeezy 官方网站中提到的长度相同。我还使我的 hmacString 的顺序与此链接 (https://developer.payeezy.com/content/hmac-validation-failure) 中提到的相同。完成所有这些后,我仍然遇到同样的问题

public static String excutePost(String urlParameters) throws IOException {
URL url = new URL("https://api-cert.payeezy.com/v1/transactions");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
// Create connection
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", headerContentType);
connection.setRequestProperty("apikey ", apikey);
connection.setRequestProperty("token", MerchantToken);
connection
.setRequestProperty("Authorization", authorizationHeader);
connection.setRequestProperty("timestamp", ""+epoch);
connection.setRequestProperty("nonce", ""+nonce);
connection.setDoOutput(true);
connection.setReadTimeout(30000);

// Send request
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();

// Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while ((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
return response.toString();

} catch (Exception e) {

e.printStackTrace();
return null;

} finally {

if (connection != null) {
connection.disconnect();
}
}
}

这是完整的 java 类代码:- http://piratepad.net/ep/pad/view/ro.WwZ9v6FX1a6/latest

最佳答案

我最终通过在 api url hit 中发送直接字符串作为参数解决了这个错误。在这里我发布了一些解决我的错误的代码:-

String str = "{\"amount\":\"1299\",\"merchant_ref\":\"Astonishing-Sale\",\"transaction_type\":\"authorize\",\"credit_card\":{\"card_number\":\"4788250000028291\",\"cvv\":\"123\",\"exp_date\": \"1020\",\"cardholder_name\": \"John Smith\",\"type\": \"visa\"},\"method\": \"credit_card\",\"currency_code\": \"USD\"}";

现在这个字符串将用于生成我的授权 key 。整个过程定义如下:-

getSecurityKeys(apikey, pzsecret,str);

private static Map<String, String> getSecurityKeys(String appId,
String secureId, String payLoad) throws Exception {
Map<String, String> returnMap = new HashMap<String, String>();
try {
returnMap.put(NONCE, Long.toString(nonce));
returnMap.put(APIKEY, appId);
returnMap.put(TIMESTAMP, Long.toString(System.currentTimeMillis()));
returnMap.put(TOKEN, MerchantToken);
returnMap.put(APISECRET, pzsecret);
returnMap.put(PAYLOAD, payLoad);
returnMap.put(AUTHORIZE, getMacValue(returnMap));
authorizationHeader = returnMap.get(AUTHORIZE);
return returnMap;

} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e.getMessage(), e);
}
}

public static String getMacValue(Map<String, String> data) throws Exception {
Mac mac = Mac.getInstance("HmacSHA256");
String apiSecret = data.get(APISECRET);
SecretKeySpec secret_key = new SecretKeySpec(apiSecret.getBytes(),
"HmacSHA256");
mac.init(secret_key);
StringBuilder buff = new StringBuilder();
buff.append(data.get(APIKEY)).append(data.get(NONCE))
.append(data.get(TIMESTAMP));
if (data.get(TOKEN) != null)
buff.append(data.get(TOKEN));
if (data.get(PAYLOAD) != null)
buff.append(data.get(PAYLOAD));
byte[] macHash = mac.doFinal(buff.toString().getBytes("UTF-8"));
String authorizeString = Base64.encodeBase64String(toHex(macHash));
return authorizeString;
}
现在终于可以将直接字符串(即 str)作为参数传递给 java 中的 post api。

希望它能帮助其他人在不使用任何依赖项的情况下集成 payeezy 支付网关。快乐编码!!!

关于java - 错误 :- {"code" :"403", "message":"HMAC validation Failure"},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29367152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com