payUmoney集成提供了一个错误
登录后,它正在生成一个哈希值,但仍然给出错误“发生了一些问题!再试一次”。payUmoney集成提供了一个错误
PayUmoneySdkInitilizer.PaymentParam.Builder builder =
new PayUmoneySdkInitilizer.PaymentParam.Builder();
builder.setAmount(10.0)
.setTnxId("0nf7" + System.currentTimeMillis())
.setPhone(<My phone>)
.setProductName("product_name")
.setFirstName(<My Name>)
.setEmail(<My email>)
.setsUrl("https://www.payumoney.com/mobileapp/payumoney/success.php")
.setfUrl("https://www.payumoney.com/mobileapp/payumoney/failure.php")
.setUdf1("").setUdf2("").setUdf3("").setUdf4("").setUdf5("")
.setIsDebug(false)
.setKey(<mykey>)
.setMerchantId(<my debug merchant id>);
String tnxId="0nf7" + System.currentTimeMillis();
PayUmoneySdkInitilizer.PaymentParam paymentParam = builder.build();
String hashSequence = "<...>|"+tnxId+"|10.0|product_name|<My name>|<My email>|||||||||||salt";
String serverCalculatedHash= hashCal("SHA-512", hashSequence);
Toast.makeText(getApplicationContext(),
serverCalculatedHash, Toast.LENGTH_SHORT).show();
paymentParam.setMerchantHash(serverCalculatedHash);
// calculateServerSideHashAndInitiatePayment(paymentParam);
PayUmoneySdkInitilizer.startPaymentActivityForResult(TrayActivity.this, paymentParam);
public static String hashCal(String type, String str) {
byte[] hashseq = str.getBytes();
StringBuffer hexString = new StringBuffer();
try {
MessageDigest algorithm = MessageDigest.getInstance(type);
algorithm.reset();
algorithm.update(hashseq);
byte messageDigest[] = algorithm.digest();
for (int i = 0; i<messageDigest.length; i++) {
String hex = Integer.toHexString(0xFF &messageDigest[i]);
if (hex.length() == 1) { hexString.append("0"); }
hexString.append(hex);
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} return hexString.toString();
}
你在代码中使用:
.setTnxId("0nf7" + System.currentTimeMillis())
再后来:
String tnxId="0nf7" + System.currentTimeMillis();
也许不是唯一的问题,但你真的想用这两个不同的值(两次调用之间的时间可能会改变)?两种情况下你不想要相同的tnxId
吗?
TransactionIdProvider.java:
import java.util.Locale;
public class TransactionIdProvider {
private final static String DEFAULT_PREFIX = "ID";
// Convenient prime number for incrementing the counter
private final static long ID_ADD = 0xF0AD; // "f*ck off and die"
// 64b counter with non-trivial start value
private static long idCounter = 0x0101F00DDEADBEEFL;
/**
* Returns ID consisting of prefix string and 64b counter interleaved
* with 32b per-4s-timestamp.
*
* May produce identical ID (collision) when:
* 1) class is reloaded within 4s
* (to fix: serialize "idCounter" upon shutdown/restart of VM, or
* modify prefix per start of VM)
* 2) more than 2^64 IDs are requested within 4s (no fix, unexpected)
* 3) more than 2^64 IDs are requested after cca. 550 years.
* (no fix, unexpected)
* 4) more than one static instance of TransactionIdProvider is used
* (two or more VMs running the app) (to fix put different prefix in
* every VM/server running this)
*
* Length of returned ID is prefix.length() + 24 alphanumeric symbols.
*/
public static synchronized String getNewId(final String prefix) {
idCounter += ID_ADD; // increment counter
// get 32b timestamp per ~4s (millis/4096) (good for ~550 years)
final int timeStamp = (int)(System.currentTimeMillis()>>12);
final int idPart1 = (int)(idCounter>>32);
final int idPart2 = (int)(idCounter);
return String.format(Locale.US, "%s%08X%08X%08X",
prefix, idPart1, timeStamp, idPart2);
}
public static String getNewId() {
return getNewId(DEFAULT_PREFIX);
}
}
不知道有多少可用的是这个,如果ID可能是这么久。随意使用/修改任何你想要的方式。
我还想知道,我是否没有忘记重要的事情,但什么都记不起来。
这一个的安全性方面还是相当薄弱的,因为在4s的时间范围内,ID就像简单的加法一样,但至少它不会产生1,2,3 ...系列。
难道发现了一些SDK文档,看起来像txnId可能是25个字符长,所以你有1个字符只有前缀。或者减少时间戳,使用%07X
的格式和掩码值与0x0FFFFFFF,这将使它重复每34年 - > 2个字母的前缀。或者更改计数器32b int
,应该还是绰绰有余,除非您希望每秒处理数千次事务 - >这将删除8个字符。或base32/base64整个身份证缩短它(取决于什么字母是合法的内容)...
或任何...已经花了足够的时间与此。聘请专业人士。
是的,我想..其实这是我第一次尝试付款网关 –
@AdityaReja所以移动上面的字符串tnxId只定义一次,然后使用相同的价值(每笔交易)无处不在,需要交易ID。其实'timeMillis'作为“后缀”也可能是个坏主意,如果你的解决方案几乎在同一时间被两个人使用,他们将创建具有相同ID的交易。你应该在单独的类中创建一些同步的静态计数器,并且每个事务调用一次getNewTxId()。出于安全原因,您可能仍想在流程中添加一些时间或散列以避免简单的1,2,3,4,5 ... ID。 – Ped7g
@AdityaReja顺便说一句,我不知道“PayUmoney SDK”,所以我不知道代码在做什么以及进一步的错误可能是什么,但交易id的问题是一般的,所以我只回答那个问题。 – Ped7g
什么是错误? –
发生了一些错误..稍后再试 –