0

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

像这样 :

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

4

1 回答 1

3

尽管您必须自己至少尝试一次,但无论如何都有很多 SO 问题可用,这是将 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 ;

定义值后,您的 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"));


    }

PayUJavaScript接口方法:

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


    }

}

而已。

于 2015-09-02T07:43:23.533 回答