付款处理集成android

时间:2015-09-02 05:52:23

标签: android browser payu

我正在做我的第一个申请。现在我需要使用自定义浏览器在应用程序中集成payu集成。我不知道如何做到这一点。我搜索了这个,但我失败了。请任何人建议我或提供此集成的链接。提前谢谢你。

像这样:

https://drive.google.com/folderview?id=0B4URmsDLhGXmfjFmbDQ5b2V0bVhjdTZMNExMVHRFMG1PRFFYeUV0LU9nSWU4U0pqaW00OU0&usp=drive_web&ddrp=1#

1 个答案:

答案 0 :(得分:3)

虽然你必须至少尝试一次自己有很多可用的问题,但这是完整的解决方案,可以在你的app中集成payu。这很简单。

首先定义你喜欢的变量:

String hash,hashSequence;
String post_Data;
String merchant_key="your key";
String salt="your salt";
String surl = "your surl"; 
String furl = "your furl";
String productinfo = "your product info or you can put anything here";
String txnid ="";
String amount;
Handler mHandler = new Handler();
String firstname, email,phone;
WebView webView ;

定义值后,您的on createview应如下所示:

@SuppressLint("JavascriptInterface")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web_view);

        webView = (WebView) findViewById(R.id.webView);

        String hashSequence1 = merchant_key + "|" + txnid + "|" + amount + "|" + productinfo + "|" +
                               firstname+  "|" + email + "|||||||||||" + salt;

        hash=hashCal("SHA-512",hashSequence1);

        webView.setWebViewClient(new WebViewClient() {


            @Override
            public void onReceivedError(WebView view, int errorCode,
                                        String description, String failingUrl) {
                // TODO Auto-generated method stub
                System.out.println(">>>>>>>>>>>>>>onReceivedError>>>>>>>>>>>>>>>>>>");
                Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onReceivedSslError(WebView view,
                                           SslErrorHandler handler, SslError error) {
                // TODO Auto-generated method stub
                System.out.println(">>>>>>>>>>>>>>onReceivedSslError>>>>>>>>>>>>>>>>>>");
                Toast.makeText(activity, "SslError! " + error, Toast.LENGTH_SHORT).show();
                handler.proceed();
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                System.out.println(">>>>>>>>>>>>>>shouldOverrideUrlLoading>>>>>>>>>>>>>>>>>>");
                return true;

            }

            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                System.out.println(">>>>>>>>>>>>>>onPageFinished>>>>>>>>>>>>>>>>>>");

                super.onPageFinished(view, url);

            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                System.out.println(">>>>>>>>>>>>>>onPageStarted>>>>>>>>>>>>>>>>>>");
            }
        });


        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(true);
        webView.getSettings().setLoadWithOverviewMode(true);

        webView.addJavascriptInterface(new PayUJavaScriptInterface(this), "PayUMoney");

         post_Data = "hash="+hash+"&key="+merchant_key+"&txnid="+txnid+"&amount="+amount+
                "&productinfo="+productinfo+"&firstname="+firstname+ "&email="+email+"&phone="+phone+
                "&surl="+surl+"&furl="+ furl+ "&service_provider="+ "payu_paisa";

        webView.postUrl("https://secure.payu.in/_payment", EncodingUtils.getBytes(post_Data, "base64"));


    }

PayUJavaScriptInterface方法:

    public class PayUJavaScriptInterface {
        Context mContext;

        /** Instantiate the interface and set the context */
        PayUJavaScriptInterface(Context c) {
            mContext = c;
        }


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

            mHandler.post(new Runnable() {

                public void run() {

                    mHandler = null;

                    Intent intent = new Intent(PayMentGateWay.this, BoutiqueActivity.class);

                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

                    intent.putExtra("result", "success");

                    intent.putExtra("paymentId", paymentId);

                    startActivity(intent);

                    finish();

                }

            });

        }

    }

从此方法计算哈希值:

    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();


    }

}

就是这样。