Search in sources :

Example 6 with PayTask

use of com.alipay.sdk.app.PayTask 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 7 with PayTask

use of com.alipay.sdk.app.PayTask in project JustAndroid by chinaltz.

the class AliPayUtils method pay.

// subject 商品名称 body 商品详情  price 商品价格
public void pay(String OrderNo, String subject, String body, String price, String notifyUrl, String out_trade_no) {
    if (TextUtils.isEmpty(Constants.AliAppId) || TextUtils.isEmpty(Constants.RSA_PRIVATE) || TextUtils.isEmpty(Constants.RSA_PRIVATE)) {
        new AlertDialog.Builder(mContex).setTitle("警告").setMessage("需要配置PARTNER | RSA_PRIVATE| SELLER").setPositiveButton("确定", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialoginterface, int i) {
                // 
                ((Activity) mContex).finish();
            }
        }).show();
        return;
    }
    // 订单
    final String taskProductName = subject;
    final String taskProductbody = body;
    final String taskProductPrice = "" + price;
    final String taskNotifyUrl = notifyUrl;
    final String taskoutTradeNo = "" + out_trade_no;
    final String taskTradeNo = OrderNo;
    AsyncTask<Void, Void, String> asyncTask = new AsyncTask<Void, Void, String>() {

        @Override
        protected String doInBackground(Void... params) {
            String orderInfo = getOrderInfo(taskTradeNo, taskProductName, taskProductbody, taskProductPrice, taskNotifyUrl, taskoutTradeNo);
            Log.e("GFH", "订单信息=" + orderInfo);
            // 对订单做RSA 签名
            String sign = sign(orderInfo);
            try {
                // 仅需对sign 做URL编码
                Log.e("GFH", "00=" + sign);
                sign = URLEncoder.encode(sign, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            // 完整的符合支付宝参数规范的订单信息
            final String payInfo = orderInfo + "&sign=\"" + sign + "\"&" + getSignType();
            PayTask alipay = new PayTask((Activity) mContex);
            // 调用支付接口,获取支付结果
            String result = alipay.pay(payInfo, true);
            return result;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            PayResult payResult = new PayResult(result);
            // 
            // 
            // 支付宝返回此次支付结果及加签,建议对支付宝签名信息拿签约时支付宝提供的公钥做验签
            String resultInfo = payResult.getResult();
            if (callBack != null) {
                callBack.onAliPayResultCallBack(payResult);
            }
        // 
        }
    };
    asyncTask.execute();
}
Also used : PayTask(com.alipay.sdk.app.PayTask) DialogInterface(android.content.DialogInterface) AsyncTask(android.os.AsyncTask) Activity(android.app.Activity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PayResult(com.litingzhe.justandroid.pay.utils.AliPayUtils.v1.PayResult)

Example 8 with PayTask

use of com.alipay.sdk.app.PayTask in project expression by happy-yuxuan.

the class UMyOrdersActivity method payV2.

/**
 * 支付宝支付业务
 *
 * @param
 */
public void payV2() {
    if (TextUtils.isEmpty(APPID) || (TextUtils.isEmpty(RSA2_PRIVATE) && TextUtils.isEmpty(RSA_PRIVATE))) {
        new AlertDialog.Builder(this).setTitle("警告").setMessage("需要配置APPID | RSA_PRIVATE").setPositiveButton("确定", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialoginterface, int i) {
                // 
                finish();
            }
        }).show();
        return;
    }
    /**
     * 这里只是为了方便直接向商户展示支付宝的整个支付流程;所以Demo中加签过程直接放在客户端完成;
     * 真实App里,privateKey等数据严禁放在客户端,加签过程务必要放在服务端完成;
     * 防止商户私密数据泄露,造成不必要的资金损失,及面临各种安全风险;
     *
     * orderInfo的获取必须来自服务端;
     */
    boolean rsa2 = (RSA2_PRIVATE.length() > 0);
    Map<String, String> params = OrderInfoUtil2_0.buildOrderParamMap(APPID, rsa2);
    String orderParam = OrderInfoUtil2_0.buildOrderParam(params);
    String privateKey = rsa2 ? RSA2_PRIVATE : RSA_PRIVATE;
    String sign = OrderInfoUtil2_0.getSign(params, privateKey, rsa2);
    final String orderInfo = orderParam + "&" + sign;
    Runnable payRunnable = new Runnable() {

        @Override
        public void run() {
            EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX);
            PayTask alipay = new PayTask(UMyOrdersActivity.this);
            Map<String, String> result = alipay.payV2(orderInfo, true);
            Log.i("msp", result.toString());
            Message msg = new Message();
            msg.what = SDK_PAY_FLAG;
            msg.obj = result;
            handler.sendMessage(msg);
        }
    };
    Thread payThread = new Thread(payRunnable);
    payThread.start();
}
Also used : PayTask(com.alipay.sdk.app.PayTask) Message(android.os.Message) DialogInterface(android.content.DialogInterface)

Example 9 with PayTask

use of com.alipay.sdk.app.PayTask in project expression by happy-yuxuan.

the class PayDemoActivity method payV2.

/**
 * 支付宝支付业务
 *
 * @param v
 */
public void payV2(View v) {
    if (TextUtils.isEmpty(APPID) || (TextUtils.isEmpty(RSA2_PRIVATE) && TextUtils.isEmpty(RSA_PRIVATE))) {
        new AlertDialog.Builder(this).setTitle("警告").setMessage("需要配置APPID | RSA_PRIVATE").setPositiveButton("确定", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialoginterface, int i) {
                // 
                finish();
            }
        }).show();
        return;
    }
    /**
     * 这里只是为了方便直接向商户展示支付宝的整个支付流程;所以Demo中加签过程直接放在客户端完成;
     * 真实App里,privateKey等数据严禁放在客户端,加签过程务必要放在服务端完成;
     * 防止商户私密数据泄露,造成不必要的资金损失,及面临各种安全风险;
     *
     * orderInfo的获取必须来自服务端;
     */
    boolean rsa2 = (RSA2_PRIVATE.length() > 0);
    Map<String, String> params = OrderInfoUtil2_0.buildOrderParamMap(APPID, rsa2);
    String orderParam = OrderInfoUtil2_0.buildOrderParam(params);
    String privateKey = rsa2 ? RSA2_PRIVATE : RSA_PRIVATE;
    String sign = OrderInfoUtil2_0.getSign(params, privateKey, rsa2);
    final String orderInfo = orderParam + "&" + sign;
    Runnable payRunnable = new Runnable() {

        @Override
        public void run() {
            EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX);
            PayTask alipay = new PayTask(PayDemoActivity.this);
            Map<String, String> result = alipay.payV2(orderInfo, true);
            Log.i("msp", result.toString());
            Message msg = new Message();
            msg.what = SDK_PAY_FLAG;
            msg.obj = result;
            mHandler.sendMessage(msg);
        }
    };
    Thread payThread = new Thread(payRunnable);
    payThread.start();
}
Also used : PayTask(com.alipay.sdk.app.PayTask) Message(android.os.Message) DialogInterface(android.content.DialogInterface)

Example 10 with PayTask

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

the class DefaultWebClient method isAlipay.

private boolean isAlipay(final WebView view, String url) {
    Activity mActivity = null;
    if ((mActivity = mWeakReference.get()) == null)
        return false;
    final PayTask task = new PayTask(mActivity);
    final String ex = task.fetchOrderInfoFromH5PayUrl(url);
    LogUtils.i("Info", "alipay:" + ex);
    if (!TextUtils.isEmpty(ex)) {
        // System.out.println("paytask:::::" + url);
        AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {

            public void run() {
                System.out.println("payTask:::" + ex);
                final H5PayResultModel result = task.h5Pay(ex, true);
                if (!TextUtils.isEmpty(result.getReturnUrl())) {
                    AgentWebX5Utils.runInUiThread(new Runnable() {

                        @Override
                        public void run() {
                            view.loadUrl(result.getReturnUrl());
                        }
                    });
                }
            }
        });
        return true;
    }
    return false;
}
Also used : PayTask(com.alipay.sdk.app.PayTask) H5PayResultModel(com.alipay.sdk.util.H5PayResultModel) Activity(android.app.Activity)

Aggregations

PayTask (com.alipay.sdk.app.PayTask)11 Activity (android.app.Activity)5 DialogInterface (android.content.DialogInterface)4 Message (android.os.Message)4 H5PayResultModel (com.alipay.sdk.util.H5PayResultModel)3 AsyncTask (android.os.AsyncTask)2 H5PayCallback (com.alipay.sdk.app.H5PayCallback)2 BCPayResult (cn.beecloud.entity.BCPayResult)1 PayResult (com.litingzhe.justandroid.pay.utils.AliPayUtils.v1.PayResult)1 PayResultV2 (com.litingzhe.justandroid.pay.utils.AliPayUtils.v2.PayResultV2)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1