Android 成功生成Hashkey后,payUmoney集成中出现错误消息
我试图整合payUmoney的支付网关。我在跟踪 哈希键已成功生成,但我仍然无法使用live credential转到付款页面。 我正在使用此代码生成哈希键--Android 成功生成Hashkey后,payUmoney集成中出现错误消息,android,android-studio,payumoney,Android,Android Studio,Payumoney,我试图整合payUmoney的支付网关。我在跟踪 哈希键已成功生成,但我仍然无法使用live credential转到付款页面。 我正在使用此代码生成哈希键-- 当我使用此方法发送由上述代码生成的哈希键时: private class GetHashesFromServerTask extends AsyncTask<String, String, String> { private ProgressDialog progressDialog; @Overr
当我使用此方法发送由上述代码生成的哈希键时:
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());
}
}
}
}
私有类GetHashesFromServerTask扩展了AsyncTask{
私有进程对话;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
progressDialog=新建progressDialog(MainActivity.this);
progressDialog.setMessage(“请稍候…”);
progressDialog.show();
}
@凌驾
受保护的字符串doInBackground(字符串…后参数){
字符串“=”;
试一试{
//下面的TODO url仅用于测试目的,商户需要用其服务器端哈希生成url替换此url
URL=新URL(“https://payu.herokuapp.com/get_hash");
字符串后参数=后参数[0];
字节[]后参数字节=后参数.getBytes(“UTF-8”);
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
conn.setRequestMethod(“POST”);
conn.setRequestProperty(“内容类型”、“应用程序/x-www-form-urlencoded”);
conn.setRequestProperty(“内容长度”,String.valueOf(postparamesbyte.Length));
连接设置输出(真);
conn.getOutputStream().write(后参数字节);
InputStream响应InputStream=conn.getInputStream();
StringBuffer responseStringBuffer=新的StringBuffer();
字节[]字节容器=新字节[1024];
对于(int i;(i=responseInputStream.read(字节容器))!=-1;){
append(新字符串(字节容器,0,i));
}
JSONObject response=newJSONObject(responseStringBuffer.toString());
迭代器payuHashIterator=response.keys();
while(payuHashIterator.hasNext()){
String key=payuHashIterator.next();
开关(钥匙){
/**
*此哈希是必需的,需要从商户的服务器端生成
*
*/
案例“付款散列”:
merchantHash=response.getString(键);
打破
违约:
打破
}
}
}捕获(格式错误){
e、 printStackTrace();
}捕获(协议例外e){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}捕获(JSONException e){
e、 printStackTrace();
}
返回曼彻斯特;
}
@凌驾
PostExecute上受保护的void(字符串merchantshash){
super.onPostExecute(Merchantshash);
progressDialog.disclose();
payNowButton.setEnabled(真);
if(merchantHash.isEmpty()| | merchantHash.equals(“”){
Toast.makeText(MainActivity.this,“无法生成哈希”,Toast.LENGTH_SHORT.show();
}否则{
mPaymentParams.setmerchantshash(merchantshash);
如果(AppPreference.selectedTheme!=-1){
PayUmoneyFlowManager.startPayUMoneyFlow(mPaymentParams,MainActivity.this,AppPreference.selectedTheme,MappReference.isOverrideResultScreen());
}否则{
PayUmoneyFlowManager.startPayUMoneyFlow(mPaymentParams,MainActivity.this,R.style.AppTheme_默认值,MappReference.isOverrideResultScreen());
}
}
}
}
生成哈希键的代码是否正确感谢Andvance确保发送到payUmoney网关的密钥与PHP脚本哈希生成中定义的密钥相同 例如:产品名称的键是
productInfo
确保每个字符都相同
否则代码是完美的,这只是您可能弄错的地方。使用关键字firstName和productInfo生成哈希,并检查udf参数。谢谢,我使用firstName和productInfo的字段“firstName”生成哈希,而不是productInfo。
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());
}
}
}
}