需要来自payu money Android的JSON/String完整响应。仅获取PaymentId

需要来自payu money Android的JSON/String完整响应。仅获取PaymentId,android,payumoney,Android,Payumoney,我在Android中使用WebView客户端进行payu money,下面是我的源代码。在成功中,我只获得paymentId,但我需要其他信息,如(付款状态,付款方式等),请检查以下代码,并建议我如何获得它 公共类PayMentGateWay扩展活动{ private ArrayList<String> post_val = new ArrayList<String>(); private String post_Data=""; WebView webView ; fi

我在Android中使用WebView客户端进行payu money,下面是我的源代码。在成功中,我只获得paymentId,但我需要其他信息,如(付款状态,付款方式等),请检查以下代码,并建议我如何获得它

公共类PayMentGateWay扩展活动{

private ArrayList<String> post_val = new ArrayList<String>();
private String post_Data="";
WebView webView ;
final Activity activity = this;
private String tag = "PayMentGateWay";
private String hash,hashSequence;
ProgressDialog progressDialog ;

String merchant_key = "SHja8Z05";
String salt="0tR0sybux9";
String action1 ="";
String base_url="https://secure.payu.in";//
int error=0;
String hashString="";
Map<String,String> params;
String txnid ="";
String SUCCESS_URL = "https://www.payumoney.com/mobileapp/payumoney/success.php" ; 
String FAILED_URL = "https://www.payumoney.com/mobileapp/payumoney/failure.php" ;
Handler mHandler = new Handler();
static String getFirstName, getNumber, getEmailAddress, getRechargeAmt;
ProgressDialog pDialog ;

@SuppressLint("JavascriptInterface") @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    progressDialog = new ProgressDialog(activity);
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    webView = new WebView(this);
    setContentView(webView);
    Intent oIntent  = getIntent();
    getFirstName    = oIntent.getExtras().getString("FIRST_NAME");
    getNumber       = oIntent.getExtras().getString("PHONE_NUMBER");
    getEmailAddress = oIntent.getExtras().getString("EMAIL_ADDRESS");
    getRechargeAmt  = oIntent.getExtras().getString("RECHARGE_AMT");
    //post_val = getIntent().getStringArrayListExtra("post_val");
    //Log.d(tag, "post_val: "+post_val);
    params= new HashMap<String,String>();
    params.put("key", merchant_key);
    params.put("amount", getRechargeAmt);
    params.put("firstname", getFirstName);
    params.put("email", getEmailAddress);
    params.put("phone", getNumber);
    params.put("productinfo", "Recharge Wallet");
    params.put("surl", SUCCESS_URL);
    params.put("furl", FAILED_URL);
    params.put("service_provider", "payu_paisa");
    params.put("lastname", "");
    params.put("address1", "");
    params.put("address2", "");
    params.put("city", "");
    params.put("state", "");
    params.put("country", "");
    params.put("zipcode", "");
    params.put("udf1", "");
    params.put("udf2", "");
    params.put("udf3", "");
    params.put("udf4", "");
    params.put("udf5", "");
    params.put("pg", "");

    /*for(int i = 0;i<post_val.size();){
        params.put(post_val.get(i), post_val.get(i+1));
    i+=2;
    }*/
    if(empty(params.get("txnid"))){
        Random rand = new Random();
        String rndm = Integer.toString(rand.nextInt())+(System.currentTimeMillis() / 1000L);
        txnid=hashCal("SHA-256",rndm).substring(0,20);
        params.put("txnid", txnid);
    }
    else
        txnid=params.get("txnid");
    //String udf2 = txnid;
    String txn="abcd";
    hash="";
    String hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
    if(empty(params.get("hash")) && params.size()>0)
    {
        if( empty(params.get("key"))
                || empty(params.get("txnid"))
                || empty(params.get("amount"))
                || empty(params.get("firstname"))
                || empty(params.get("email"))
                || empty(params.get("phone"))
                || empty(params.get("productinfo"))
                || empty(params.get("surl"))
                || empty(params.get("furl"))
                || empty(params.get("service_provider"))

                ){
            error=1;
        }
        else{
            String[] hashVarSeq=hashSequence.split("\\|");

            for(String part : hashVarSeq)
            {
                hashString= (empty(params.get(part)))?hashString.concat(""):hashString.concat(params.get(part));
                hashString=hashString.concat("|");
            }
            hashString=hashString.concat(salt);


            hash=hashCal("SHA-512",hashString);
            action1=base_url.concat("/_payment");
        }
    }
    else if(!empty(params.get("hash")))
    {
        hash=params.get("hash");
        action1=base_url.concat("/_payment");
    }

    webView.setWebViewClient(new MyWebViewClient(){

        public void onPageFinished(WebView view, final String url) {
            progressDialog.dismiss();
        }

        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            //make sure dialog is showing
            if (!progressDialog.isShowing()) {
                progressDialog.show();
            }
        }

    });


    webView.setVisibility(View.VISIBLE);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setCacheMode(2);
    webView.getSettings().setDomStorageEnabled(true);
    webView.clearHistory();
    webView.clearCache(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setUseWideViewPort(false);
    webView.getSettings().setLoadWithOverviewMode(false);

    //webView.addJavascriptInterface(new PayUJavaScriptInterface(getApplicationContext()), "PayUMoney");
    webView.addJavascriptInterface(new PayUJavaScriptInterface(), "PayUMoney");
    Map<String, String> mapParams = new HashMap<String, String>();
    mapParams.put("key",merchant_key);
    mapParams.put("hash",PayMentGateWay.this.hash);
    mapParams.put("txnid",(empty(PayMentGateWay.this.params.get("txnid"))) ? "" : PayMentGateWay.this.params.get("txnid"));
    Log.d(tag, "txnid: "+PayMentGateWay.this.params.get("txnid"));
    mapParams.put("service_provider","payu_paisa");

    mapParams.put("amount",(empty(PayMentGateWay.this.params.get("amount"))) ? "" : PayMentGateWay.this.params.get("amount"));
    mapParams.put("firstname",(empty(PayMentGateWay.this.params.get("firstname"))) ? "" : PayMentGateWay.this.params.get("firstname"));
    mapParams.put("email",(empty(PayMentGateWay.this.params.get("email"))) ? "" : PayMentGateWay.this.params.get("email"));
    mapParams.put("phone",(empty(PayMentGateWay.this.params.get("phone"))) ? "" : PayMentGateWay.this.params.get("phone"));

    mapParams.put("productinfo",(empty(PayMentGateWay.this.params.get("productinfo"))) ? "" : PayMentGateWay.this.params.get("productinfo"));
    mapParams.put("surl",(empty(PayMentGateWay.this.params.get("surl"))) ? "" : PayMentGateWay.this.params.get("surl"));
    mapParams.put("furl",(empty(PayMentGateWay.this.params.get("furl"))) ? "" : PayMentGateWay.this.params.get("furl"));
    mapParams.put("lastname",(empty(PayMentGateWay.this.params.get("lastname"))) ? "" : PayMentGateWay.this.params.get("lastname"));

    mapParams.put("address1",(empty(PayMentGateWay.this.params.get("address1"))) ? "" : PayMentGateWay.this.params.get("address1"));
    mapParams.put("address2",(empty(PayMentGateWay.this.params.get("address2"))) ? "" : PayMentGateWay.this.params.get("address2"));
    mapParams.put("city",(empty(PayMentGateWay.this.params.get("city"))) ? "" : PayMentGateWay.this.params.get("city"));
    mapParams.put("state",(empty(PayMentGateWay.this.params.get("state"))) ? "" : PayMentGateWay.this.params.get("state"));

    mapParams.put("country",(empty(PayMentGateWay.this.params.get("country"))) ? "" : PayMentGateWay.this.params.get("country"));
    mapParams.put("zipcode",(empty(PayMentGateWay.this.params.get("zipcode"))) ? "" : PayMentGateWay.this.params.get("zipcode"));
    mapParams.put("udf1",(empty(PayMentGateWay.this.params.get("udf1"))) ? "" : PayMentGateWay.this.params.get("udf1"));
    mapParams.put("udf2",(empty(PayMentGateWay.this.params.get("udf2"))) ? "" : PayMentGateWay.this.params.get("udf2"));

    mapParams.put("udf3",(empty(PayMentGateWay.this.params.get("udf3"))) ? "" : PayMentGateWay.this.params.get("udf3"));
    mapParams.put("udf4",(empty(PayMentGateWay.this.params.get("udf4"))) ? "" : PayMentGateWay.this.params.get("udf4"));
    mapParams.put("udf5",(empty(PayMentGateWay.this.params.get("udf5"))) ? "" : PayMentGateWay.this.params.get("udf5"));
    mapParams.put("pg",(empty(PayMentGateWay.this.params.get("pg"))) ? "" : PayMentGateWay.this.params.get("pg"));
    webview_ClientPost(webView, action1, mapParams.entrySet());

}

private final class PayUJavaScriptInterface {

    PayUJavaScriptInterface() {
    }

    /**
     * This is not called on the UI thread. Post a runnable to invoke
     * loadUrl on the UI thread.
     */
    @JavascriptInterface
    public void success(long id, final String paymentId) {
        mHandler.post(new Runnable() {
            public void run() {
                mHandler = null;
                  /*Intent intent = new Intent();
                 intent.putExtra(Constants.RESULT, "success");
                 intent.putExtra(Constants.PAYMENT_ID, paymentId);
                 setResult(RESULT_OK, intent);
                 finish();*/
                // new PostRechargeData().execute();
                Intent intent=new Intent(PayMentGateWay.this,MainActivity.class);
                intent.putExtra("test",getFirstName);
                startActivity(intent);

                Toast.makeText(getApplicationContext(), "Successfully payment", Toast.LENGTH_LONG).show();

            }
        });
    }

    @JavascriptInterface
    public void failure(final String id, String error) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                //cancelPayment();
                Toast.makeText(getApplicationContext(),"Cancel payment" ,Toast.LENGTH_LONG).show();
            }
        });
    }

    @JavascriptInterface
    public void failure() {
        failure("");
    }

    @JavascriptInterface
    public void failure(final String params) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {

                  /*Intent intent = new Intent();
                 intent.putExtra(Constants.RESULT, params);
                 setResult(RESULT_CANCELED, intent);
                 finish();*/
                Toast.makeText(getApplicationContext(),"Failed payment" ,Toast.LENGTH_LONG).show();
            }
        });
    }

}


public void webview_ClientPost(WebView webView, String url, Collection< Map.Entry<String, String>> postData){
    StringBuilder sb = new StringBuilder();

    sb.append("<html><head></head>");
    sb.append("<body onload='form1.submit()'>");
    sb.append(String.format("<form id='form1' action='%s' method='%s'>", url, "post"));
    for (Map.Entry<String, String> item : postData) {
        sb.append(String.format("<input name='%s' type='hidden' value='%s' />", item.getKey(), item.getValue()));
    }
    sb.append("</form></body></html>");
    Log.d(tag, "webview_ClientPost called");

    //setup and load the progress bar
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage("Loading. Please wait...");
    webView.loadData(sb.toString(), "text/html", "utf-8");
}


public void success(long id, final String paymentId) {

    mHandler.post(new Runnable() {
        public void run() {
            mHandler = null;
            //  new PostRechargeData().execute();

            Toast.makeText(getApplicationContext(),"Successfully payment\n redirect from Success Function" ,Toast.LENGTH_LONG).show();

        }
    });
}


public boolean empty(String s)
{
    if(s== null || s.trim().equals(""))
        return true;
    else
        return false;
}

public 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 nsae){ }

    return hexString.toString();


}

//String SUCCESS_URL = "https://pay.in/sccussful" ; // failed
//String FAILED_URL = "https://pay.in/failed" ;
//override the override loading method for the webview client
private class MyWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

     /*if(url.contains("response.php") || url.equalsIgnoreCase(SUCCESS_URL)){

      new PostRechargeData().execute();

      Toast.makeText(getApplicationContext(),"Successfully payment\n redirect from webview" ,Toast.LENGTH_LONG).show();

            return false;
     }else  */if(url.startsWith("http")){
            //Toast.makeText(getApplicationContext(),url ,Toast.LENGTH_LONG).show();
            progressDialog.show();
            view.loadUrl(url);
            System.out.println("myresult "+url);
            //return true;
        } else {
            return false;
        }

        return true;
    }
}

/******************************************* send record to back end ******************************************/
/*class PostRechargeData extends AsyncTask<String, String, String>
{
    @Override
    protected void onPreExecute()
    {
        super.onPreExecute();
        pDialog = new ProgressDialog(PayMentGateWay.this);
        pDialog.setMessage("Please wait...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();

    }
    protected String doInBackground(String... args)
    {
        String strStatus = null;
        ProfileSessionManager ProSessionManager = new ProfileSessionManager(PayMentGateWay.this);

        String getUserid   = ProSessionManager.getSpeculatorId();
        String getSpeculationId  = "0";
        String rechargeAmt = getRechargeAmt;
        String postAction = "1";
        //http://speculometer.com/webService/stockApp/speculationMoneyreports.php?
        //access_token=ISOFTINCstockAppCheckDevelop&speculator=1&speculation=&amount=1000&action=1
        ServiceHandler sh = new ServiceHandler();
        String upLoadServerUri = ServiceList.payment_money_url+"speculator="+getUserid+"&speculation="+getSpeculationId+"&amount="+rechargeAmt+"&action="+postAction;

        try{
            String jsonStr = sh.makeServiceCall(upLoadServerUri, ServiceHandler.POST);
            JSONObject jsonObj  = new JSONObject(jsonStr);

            JSONObject jobjDoc = jsonObj.optJSONObject("document");
            JSONObject jobjRes = jobjDoc.optJSONObject("response");

            strStatus   = jobjRes.getString("status");
            //strMessage  = jobjRes.getString("message");
            String strUserId = jobjRes.getString("user_id");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return strStatus;
    }

    protected void onPostExecute(final String strStatus)
    {

        runOnUiThread(new Runnable()
        {
            public void run()
            {
                pDialog.dismiss();
                if(strStatus != null && strStatus.equalsIgnoreCase("0")){
                    Toast.makeText(getApplicationContext(),"Your recharge amount not added in wallet." ,Toast.LENGTH_LONG).show();
                }else if(strStatus != null && strStatus.equalsIgnoreCase("1")){

                    Toast.makeText(getApplicationContext(),"Your recharge amount added in wallet." ,Toast.LENGTH_LONG).show();
                }
                Intent intent = new Intent(activity, MainActivity.class);
                startActivity(intent);
            }
        });

    }
}*/

/******************************************* closed send record to back end ************************************/
private ArrayList post_val=new ArrayList();
私有字符串post_Data=“”;
网络视图;
最终活动=此;
私有字符串tag=“PayMentGateWay”;
私有字符串哈希,哈希序列;
进行对话进行对话;
字符串\u key=“SHja8Z05”;
字符串salt=“0tR0sybux9”;
字符串action1=“”;
字符串base_url=”https://secure.payu.in";//
整数误差=0;
字符串hashString=“”;
映射参数;
字符串txnid=“”;
字符串成功\u URL=”https://www.payumoney.com/mobileapp/payumoney/success.php" ; 
字符串失败。\u URL=”https://www.payumoney.com/mobileapp/payumoney/failure.php" ;
Handler mHandler=新的Handler();
静态字符串getFirstName、getNumber、getEmailAddress、GetAmt;
ProgressDialog;
@SuppressLint(“JavascriptInterface”)@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
progressDialog=新建progressDialog(活动);
getWindow().requestFeature(Window.FEATURE\u进度);
webView=新的webView(此);
setContentView(网络视图);
Intent oIntent=getIntent();
getFirstName=oIntent.getExtras().getString(“名字”);
getNumber=oIntent.getExtras().getString(“电话号码”);
getEmailAddress=oIntent.getExtras().getString(“电子邮件地址”);
getRechargeAmt=oint.getExtras().getString(“充值金额”);
//post_val=getIntent().getStringArrayListExtra(“post_val”);
//Log.d(标签“post_val:+post_val”);
params=新的HashMap();
参数put(“密钥”,商户密钥);
参数put(“金额”,GetAmt);
参数put(“firstname”,getFirstName);
参数put(“email”,getEmailAddress);
参数put(“电话”,getNumber);
参数put(“产品信息”、“充值钱包”);
参数put(“surl”,SUCCESS_URL);
参数put(“furl”,失败的URL);
参数put(“服务提供商”、“支付方”);
参数put(“lastname”,即“);
参数put(“地址1”和“);
参数put(“地址2”,”);
参数put(“城市”、“城市”);
参数put(“状态”,“状态”);
参数put(“国家”,“国家”);
参数put(“zipcode”,”);
参数put(“udf1”,“udf1”);
参数put(“udf2”和“);
参数put(“udf3”,“udf3”);
参数put(“udf4”,“udf4”);
参数put(“udf5”,即“);
参数put(“pg”,“pg”);
/*对于(int i=0;i0)
{
if(空(参数get(“key”))
||空(参数get(“txnid”))
||空(参数获取(“金额”))
||空(params.get(“firstname”))
||空(参数获取(“电子邮件”))
||空(参数获取(“电话”))
||空(参数get(“productinfo”))
||空(参数get(“surl”))
||空(参数get(“furl”))
||空(参数get(“服务提供者”))
){
误差=1;
}
否则{
字符串[]hashVarSeq=hashSequence.split(“\\\\”);
for(字符串部分:hashVarSeq)
{
hashString=(空(params.get(part))?hashString.concat(“”):hashString.concat(params.get(part));
hashString=hashString.concat(“|”);
}
hashString=hashString.concat(salt);
hash=hashCal(“SHA-512”,hashString);
action1=基本url.concat(“/”付款”);
}
}
else如果(!empty(params.get(“hash”))
{
hash=params.get(“hash”);
action1=基本url.concat(“/”付款”);
}
setWebViewClient(新的MyWebViewClient(){
公共void onPageFinished(WebView视图,最终字符串url){
progressDialog.disclose();
}
public void onPageStarted(WebView视图、字符串url、位图favicon){
//确保对话框正在显示
如果(!progressDialog.isShowing()){
progressDialog.show();
}
}
});
设置可见性(View.VISIBLE);
webView.getSettings().setBuilTinZoomControl(true);
webView.getSettings().setCacheMode(2);
webView.getSettings().setDomStorageEnabled(true);
webView.clearHistory();
clearCache(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setUseWideViewPort(false);
webView.getSettings().setLoadWithOverview模式(false);
//addJavascriptInterface(新的PayUJavaScriptInterface(getApplicationContext()),“PayUMoney”);
addJavascriptInterface(新的PayUJavaScriptInterface(),“PayUMoney”);
Map mapParams=新HashMap();
mapParams.put(“密钥”,商户密钥);
mapParams.put(“hash”,PayMentGateWay.this.hash);
mapParams.put(“txnid”)(空(PayMentGateWay.this.params.get(“txnid”))?“”:PayMentGateWay.this.params.get(“txnid”);
Log.d(标记“txnid:+PayMentGateWay.this.params.get”(“txnid”);
mapParams.put(“服务提供商”、“payu paisa”);
mapParams.put(“金额”),(空(PayMentGateWay.this.params.get(“金额”))?“”:PayMentGateWay.this.params.get(“金额”);
mapParams.put(“firstname”),(空(PayMentGateWay.this.params.get(“firstname”))?“”:PayMentGateWay.this.params.get(“firstname”);
mapParams.put(“email”),(空(PayMentGateWay.this.params.get(“email”))?“”:PayMentGateWay.this.params.get(“email”);
mapParams.put(“电话”),(空(PayMentGateWay.this.params.get(“电话”))?“”:PayMentGateWay.this.params.get(“电话”);
mapParams.put(“产品信息”),(空(PayMentGateWay.this.params.get(“产品信息”))?“”:PayMentGateWay.this.params.get(“产品信息”);
mapParams.put(“surl”),(空(PayMentGateWay.this.params.get(“surl”))?“”:PayMentGateWay.this.params.get(“surl”);
mapParams.put(“f