成功生成哈希键后,payUmoney集成中出现一些错误消息



我试图整合payUmoney的支付网关。我正在遵循此方法 哈希密钥已成功生成,但我仍然无法使用实时凭据转到付款页面。 我正在使用此代码生成哈希键--

<?php
/**
* Created by PhpStorm.
* User: Mayur Dusane
* Date: 21-12-2017
* Time: 11:27
*/
/**************
Below is the test card details for doing a test transaction in the testing mode.
Card No - 5123456789012346
Expiry - 05/2020
CVV - 123
****************/
/***************** NECESSARY FIELDS GOES HERE ***********************/
$key=$_POST["key"]; //posted merchant key from client
$salt="e5iIg1jwi8"; // add salt here from your credentials in payUMoney dashboard
$txnId=$_POST["txnid"]; //posted txnid from client
$amount=$_POST["amount"]; //posted amount from client 
$productName=$_POST["productInfo"]; // posted product info from client
$firstName=$_POST["firstName"]; // posted firstname from and must be without space
$email=$_POST["email"]; // posted email from client
/***************** USER DEFINED VARIABLES GOES HERE ***********************/
//all varibles posted from client
$udf1=$_POST["udf1"];
$udf2=$_POST["udf2"];
$udf3=$_POST["udf3"];
$udf4=$_POST["udf4"];
$udf5=$_POST["udf5"];
/***************** DO NOT EDIT ***********************/
$payhash_str = $key . '|' . checkNull($txnId) . '|' .checkNull($amount)  . '|' .checkNull($productName)  . '|' . checkNull($firstName) . '|' . checkNull($email) . '|' . checkNull($udf1) . '|' . checkNull($udf2) . '|' . checkNull($udf3) . '|' . checkNull($udf4) . '|' . checkNull($udf5) . '||||||'. $salt;
function checkNull($value) {
if ($value == null) {
return '';
} else {
return $value;
}
}
$hash = strtolower(hash('sha512', $payhash_str));
/***************** DO NOT EDIT ***********************/
$arr['result'] = $hash;
$arr['status']=0;
$arr['errorCode']=null;
$arr['responseCode']=null;
$output=$arr;
echo json_encode($output);
?>

当我使用此方法发送从上述代码生成的哈希键时:

private class GetHashesFromServerTask extends AsyncTask<String, String, String> {
private ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Please wait...");
progressDialog.show();
}
@Override
protected String doInBackground(String... postParams) {
String merchantHash = "";
try {
//TODO Below url is just for testing purpose, merchant needs to replace this with their server side hash generation url
URL url = new URL("https://payu.herokuapp.com/get_hash");
String postParam = postParams[0];
byte[] postParamsByte = postParam.getBytes("UTF-8");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(postParamsByte.length));
conn.setDoOutput(true);
conn.getOutputStream().write(postParamsByte);
InputStream responseInputStream = conn.getInputStream();
StringBuffer responseStringBuffer = new StringBuffer();
byte[] byteContainer = new byte[1024];
for (int i; (i = responseInputStream.read(byteContainer)) != -1; ) {
responseStringBuffer.append(new String(byteContainer, 0, i));
}
JSONObject response = new JSONObject(responseStringBuffer.toString());
Iterator<String> payuHashIterator = response.keys();
while (payuHashIterator.hasNext()) {
String key = payuHashIterator.next();
switch (key) {
/**
* This hash is mandatory and needs to be generated from merchant's server side
*
*/
case "payment_hash":
merchantHash = response.getString(key);
break;
default:
break;
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return merchantHash;
}
@Override
protected void onPostExecute(String merchantHash) {
super.onPostExecute(merchantHash);
progressDialog.dismiss();
payNowButton.setEnabled(true);
if (merchantHash.isEmpty() || merchantHash.equals("")) {
Toast.makeText(MainActivity.this, "Could not generate hash", Toast.LENGTH_SHORT).show();
} else {
mPaymentParams.setMerchantHash(merchantHash);
if (AppPreference.selectedTheme != -1) {
PayUmoneyFlowManager.startPayUMoneyFlow(mPaymentParams, MainActivity.this, AppPreference.selectedTheme, mAppPreference.isOverrideResultScreen());
} else {
PayUmoneyFlowManager.startPayUMoneyFlow(mPaymentParams, MainActivity.this, R.style.AppTheme_default, mAppPreference.isOverrideResultScreen());
}
}
}
}

代码是否可以生成哈希键
感谢安德万斯

确保您发送到payUmoney网关的密钥与PHP脚本哈希生成中定义的密钥相同

例如:产品名称的键是productInfo确保每个字符相同。

否则代码是完美的,这只是你可能弄错的地方

使用关键字firstName和productInfo生成哈希,并检查udf参数。

最新更新