我正在尝试集成payUmoney的支付网关。我正在关注this method 哈希密钥已成功生成,但是我仍然无法使用实时证书转到付款页面。 我正在使用此代码生成HashKey-
<?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());
}
}
}
}
生成哈希密钥的代码是否正确
在Andvance中感谢
答案 0 :(得分:0)
确保要发送到payUmoney网关的密钥与PHP脚本哈希生成中定义的密钥相同
例如:产品名称的密钥为productInfo
,请确保每个字符都相同。
否则代码很完美,这只是在您可能会误输入的地方
答案 1 :(得分:0)
使用关键字firstName和productInfo生成哈希,并同时检查udf参数。