gpt4 book ai didi

java - Android,SHA1 Base64 哈希并发布来自 WebView 的数据

转载 作者:行者123 更新时间:2023-12-02 03:19:18 26 4
gpt4 key购买 nike

我正在尝试通过 webView 上的卡付款。我从 html 网站尝试了相同的值,它工作没有问题,但我尝试从 webView 总是说“哈希是错误的!”。我认为编码类型可能有所不同。你有什么想法?我很累。我已经为此努力了很长时间。请帮助我。

    String postData = null;
try {
String plaintext = clientid + oid + amount + okUrl + failUrl + islemtipi + taksit + rnd + sanal_pos_key;
String hash = toSHA1(plaintext.getBytes());
postData = "clientid=" + URLEncoder.encode(clientid, "UTF-8")
+ "&storetype=" + URLEncoder.encode(storetype, "UTF-8")
+ "&islemtipi=" + URLEncoder.encode(islemtipi, "UTF-8")
+ "&amount=" + URLEncoder.encode(amount, "UTF-8")
+ "&oid=" + URLEncoder.encode(oid, "UTF-8")
+ "&pan=" + URLEncoder.encode(pan, "UTF-8")
+ "&cv2=" + URLEncoder.encode(cv2, "UTF-8")
+ "&Ecom_Payment_Card_ExpDate_Year=" + URLEncoder.encode(Ecom_Payment_Card_ExpDate_Year, "UTF-8")
+ "&Ecom_Payment_Card_ExpDate_Month=" + URLEncoder.encode(Ecom_Payment_Card_ExpDate_Month, "UTF-8")
+ "&cardType=" + URLEncoder.encode(cardType, "UTF-8")
+ "&firmaadi=" + URLEncoder.encode(firmaadi, "UTF-8")
+ "&taksit=" + URLEncoder.encode(taksit, "UTF-8")
+ "&okUrl=" + URLEncoder.encode(okUrl, "UTF-8")
+ "&failUrl=" + URLEncoder.encode(failUrl, "UTF-8")
+ "&rnd=" + URLEncoder.encode(rnd, "UTF-8")
+ "&hash=" + URLEncoder.encode(hash, "UTF-8");

Log.d("plaintext: ", plaintext);
Log.d("hash: ", hash);
Log.d("rnd: ", rnd);
} catch (Exception e) {
e.printStackTrace();
}
if (postData != null) {
webView.postUrl(url, postData.getBytes());
Log.d("Web View URL: ", webView.getUrl());
webView.setVisibility(View.VISIBLE);
layout.setVisibility(View.GONE);
}

public static String toSHA1(byte[] convertme) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return Base64.encodeToString((md.digest(convertme)),Base64.DEFAULT);
}

最佳答案

此代码正在运行。

public static String SHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
String result;
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(text.getBytes("iso-8859-1"), 0, text.length());
byte[] sha1hash = md.digest();
result = Base64.encodeToString(sha1hash, Base64.DEFAULT);
result = result.substring(0, result.length()-1);
return result;
}

关于java - Android,SHA1 Base64 哈希并发布来自 WebView 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56938321/

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