私のAndroidアプリと統合するpay u payment gatewayの統合に問題があります。特定のパラメーターのハッシュを生成してアプリで使用するときに、自分のサーバーでハッシュを生成していますが、API は無効なハッシュと言っています。
私のphpコードは次のとおりです。
<?php
// Merchant key here as provided by Payu
$MERCHANT_KEY = "0MQaQP";
// Merchant Salt as provided by Payu
$SALT = "13p0PXZk";
// End point - change to https://secure.payu.in for LIVE mode
$PAYU_BASE_URL = "https://test.payu.in";
$action = '';
$make_op=array();
$posted = array();
if(!empty($_POST)) {
//print_r($_POST);
foreach($_POST as $key => $value) {
//echo " key-".$key." value-".$value."\n";
$posted[$key] = $value;
}
}
$formError = 0;
if(empty($posted['txnid'])) {
// Generate random transaction id
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
} else {
$txnid = $posted['txnid'];
}
$hash = '';
// Hash Sequence
$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
if(empty($posted['hash']) && sizeof($posted) > 0)
{
if(
empty($posted['key'])
|| empty($posted['txnid'])
|| empty($posted['amount'])
|| empty($posted['firstname'])
|| empty($posted['email'])
|| empty($posted['productinfo'])
|| empty($posted['surl'])
|| empty($posted['furl'])
) {
$formError = 1;
echo "in if block";
}
else {
//$posted['productinfo'] = json_encode(json_decode('[{"name":"tutionfee","description":"","value":"500","isRequired":"false"},{"name":"developmentfee","description":"monthly tution fee","value":"1500","isRequired":"false"}]'));
$hashVarsSeq = explode('|', $hashSequence);
$hash_string = '';
foreach($hashVarsSeq as $hash_var)
{
//echo $hash_var;
$hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : '';
$hash_string .= '|';
}
$hash_string .= $SALT;
$hash = strtolower(hash('sha512', $hash_string));
//echo "hash string==".$hash_string;
//echo $hash;
$action = $PAYU_BASE_URL . '/_payment';
}
$make_op['payment_related_details_for_mobile_sdk_hash']=$hash;
$make_op['message']="successfully generated hash";
$make_op['status']=0;
echo json_encode($make_op);
} elseif(!empty($posted['hash']))
{
echo "Hash is present";
echo $posted['hash'];
$hash = $posted['hash'];
$action = $PAYU_BASE_URL . '/_payment';
$make_op['payment_related_details_for_mobile_sdk_hash']=$hash;
$make_op['message']="successfully generated hashs";
$make_op['status']=0;
echo json_encode($make_op);
}
?>
データを送信するための私のアンドロイド アクティビティ コードは次のとおりです。
public void generateHashFromServer(PaymentParams mPaymentParams)
{
nextButton.setEnabled(false); // lets not allow the user to click the button again and again.
// lets create the post params
Log.e("Demo","In genrate hash from Server");
StringBuffer postParamsBuffer = new StringBuffer();
postParamsBuffer.append(concatParams(PayuConstants.KEY, mPaymentParams.getKey()));
postParamsBuffer.append(concatParams(PayuConstants.AMOUNT, mPaymentParams.getAmount()));
postParamsBuffer.append(concatParams(PayuConstants.TXNID, mPaymentParams.getTxnId()));
postParamsBuffer.append(concatParams(PayuConstants.EMAIL, null == mPaymentParams.getEmail() ? "" : mPaymentParams.getEmail()));
postParamsBuffer.append(concatParams(PayuConstants.PRODUCT_INFO, mPaymentParams.getProductInfo()));
postParamsBuffer.append(concatParams(PayuConstants.SURL, mPaymentParams.getSurl()));
postParamsBuffer.append(concatParams(PayuConstants.FURL, mPaymentParams.getFurl()));
//postParamsBuffer.append(concatParams(PayuConstants.HASH, mPaymentParams.getHash()));
postParamsBuffer.append(concatParams(PayuConstants.FIRST_NAME, null == mPaymentParams.getFirstName() ? "" : mPaymentParams.getFirstName()));
postParamsBuffer.append(concatParams(PayuConstants.UDF1, mPaymentParams.getUdf1() == null ? "" : mPaymentParams.getUdf1()));
postParamsBuffer.append(concatParams(PayuConstants.UDF2, mPaymentParams.getUdf2() == null ? "" : mPaymentParams.getUdf2()));
postParamsBuffer.append(concatParams(PayuConstants.UDF3, mPaymentParams.getUdf3() == null ? "" : mPaymentParams.getUdf3()));
postParamsBuffer.append(concatParams(PayuConstants.UDF4, mPaymentParams.getUdf4() == null ? "" : mPaymentParams.getUdf4()));
postParamsBuffer.append(concatParams(PayuConstants.UDF5, mPaymentParams.getUdf5() == null ? "" : mPaymentParams.getUdf5()));
postParamsBuffer.append(concatParams(PayuConstants.USER_CREDENTIALS, mPaymentParams.getUserCredentials() == null ? PayuConstants.DEFAULT : mPaymentParams.getUserCredentials()));
// for offer_key
if(null != mPaymentParams.getOfferKey())
postParamsBuffer.append(concatParams(PayuConstants.OFFER_KEY, mPaymentParams.getOfferKey()));
// for check_isDomestic
if(null != cardBin)
postParamsBuffer.append(concatParams("card_bin", cardBin));
Log.e("Demo","postParamsBuffer ="+postParamsBuffer.toString());
String postParams = postParamsBuffer.charAt(postParamsBuffer.length() - 1) == '&' ? postParamsBuffer.substring(0, postParamsBuffer.length() - 1).toString() : postParamsBuffer.toString();
// make api call
Log.e("Demo","postParams ="+postParams);
GetHashesFromServerTask getHashesFromServerTask = new GetHashesFromServerTask();
getHashesFromServerTask.execute(postParams);
}
class GetHashesFromServerTask extends AsyncTask<String, String, PayuHashes>{
@Override
protected PayuHashes doInBackground(String ... postParams) {
PayuHashes payuHashes = new PayuHashes();
try {
// URL url = new URL(PayuConstants.MOBILE_TEST_FETCH_DATA_URL);
// URL url = new URL("http://10.100.81.49:80/merchant/postservice?form=2");;
//URL url = new URL("https://payu.herokuapp.com/get_hash");
URL url = new URL("http://vasatech.in/er_app/PayUMoney/PayUMoney_test.php");
// get the payuConfig first
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));
}
Log.e("response",responseStringBuffer.toString());
JSONObject response = new JSONObject(responseStringBuffer.toString());
Log.e("response",response.toString());
Iterator<String> payuHashIterator = response.keys();
while(payuHashIterator.hasNext()){
String key = payuHashIterator.next();
switch (key){
case "payment_hash":
payuHashes.setPaymentHash(response.getString(key));
break;
case "get_merchant_ibibo_codes_hash": //
payuHashes.setMerchantIbiboCodesHash(response.getString(key));
break;
case "vas_for_mobile_sdk_hash":
payuHashes.setVasForMobileSdkHash(response.getString(key));
break;
case "payment_related_details_for_mobile_sdk_hash":
payuHashes.setPaymentRelatedDetailsForMobileSdkHash(response.getString(key));
break;
case "delete_user_card_hash":
payuHashes.setDeleteCardHash(response.getString(key));
break;
case "get_user_cards_hash":
payuHashes.setStoredCardsHash(response.getString(key));
break;
case "edit_user_card_hash":
payuHashes.setEditCardHash(response.getString(key));
break;
case "save_user_card_hash":
payuHashes.setSaveCardHash(response.getString(key));
break;
case "check_offer_status_hash":
payuHashes.setCheckOfferStatusHash(response.getString(key));
break;
case "check_isDomestic_hash":
payuHashes.setCheckIsDomesticHash(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 payuHashes;
}
私はAndroid統合に有料のデモコードを使用していますが、ハッシュ生成にサーバーを使用するかどうかわかりません。正しいハッシュを提供します。彼らはSHA512でMD5を使用していると言いましたが、同じことを試みましたが、ハッシュが間違っていました...これ