Search in sources :

Example 1 with H5PayCallback

use of com.alipay.sdk.app.H5PayCallback in project AgentWeb by Justson.

the class DefaultWebClient method isAlipay.

private boolean isAlipay(final WebView view, String url) {
    try {
        Activity mActivity = null;
        if ((mActivity = mWeakReference.get()) == null) {
            return false;
        }
        /**
         * 推荐采用的新的二合一接口(payInterceptorWithUrl),只需调用一次
         */
        if (mPayTask == null) {
            Class clazz = Class.forName("com.alipay.sdk.app.PayTask");
            Constructor<?> mConstructor = clazz.getConstructor(Activity.class);
            mPayTask = mConstructor.newInstance(mActivity);
        }
        final PayTask task = (PayTask) mPayTask;
        boolean isIntercepted = task.payInterceptorWithUrl(url, true, new H5PayCallback() {

            @Override
            public void onPayResult(final H5PayResultModel result) {
                final String url = result.getReturnUrl();
                if (!TextUtils.isEmpty(url)) {
                    AgentWebUtils.runInUiThread(new Runnable() {

                        @Override
                        public void run() {
                            view.loadUrl(url);
                        }
                    });
                }
            }
        });
        if (isIntercepted) {
            LogUtils.i(TAG, "alipay-isIntercepted:" + isIntercepted + "  url:" + url);
        }
        return isIntercepted;
    } catch (Throwable ignore) {
        if (AgentWebConfig.DEBUG) {
        // ignore.printStackTrace();
        }
    }
    return false;
}
Also used : PayTask(com.alipay.sdk.app.PayTask) H5PayResultModel(com.alipay.sdk.util.H5PayResultModel) Activity(android.app.Activity) H5PayCallback(com.alipay.sdk.app.H5PayCallback)

Example 2 with H5PayCallback

use of com.alipay.sdk.app.H5PayCallback in project AgentWebX5 by Justson.

the class DefaultWebClient method isAlipay.

private boolean isAlipay(final android.webkit.WebView view, String url) {
    try {
        Activity mActivity = null;
        if ((mActivity = mWeakReference.get()) == null)
            return false;
        /**
         * 推荐采用的新的二合一接口(payInterceptorWithUrl),只需调用一次
         */
        if (mPayTask == null) {
            Class clazz = Class.forName("com.alipay.sdk.app.PayTask");
            Constructor<?> mConstructor = clazz.getConstructor(Activity.class);
            mPayTask = mConstructor.newInstance(mActivity);
        }
        final PayTask task = (PayTask) mPayTask;
        boolean isIntercepted = task.payInterceptorWithUrl(url, true, new H5PayCallback() {

            @Override
            public void onPayResult(final H5PayResultModel result) {
                final String url = result.getReturnUrl();
                if (!TextUtils.isEmpty(url)) {
                    AgentWebX5Utils.runInUiThread(new Runnable() {

                        @Override
                        public void run() {
                            view.loadUrl(url);
                        }
                    });
                }
            }
        });
        LogUtils.i(TAG, "alipay-isIntercepted:" + isIntercepted + "  url:" + url);
        return isIntercepted;
    } catch (Throwable ignore) {
        if (AgentWebX5Config.DEBUG) {
            ignore.printStackTrace();
        }
    }
    return false;
}
Also used : PayTask(com.alipay.sdk.app.PayTask) H5PayResultModel(com.alipay.sdk.util.H5PayResultModel) Activity(android.app.Activity) H5PayCallback(com.alipay.sdk.app.H5PayCallback)

Aggregations

Activity (android.app.Activity)2 H5PayCallback (com.alipay.sdk.app.H5PayCallback)2 PayTask (com.alipay.sdk.app.PayTask)2 H5PayResultModel (com.alipay.sdk.util.H5PayResultModel)2