支付宝支付配置代码

首先导入paylibrary库

其次在Activity 中的配置代码

 /**
     * 支付宝支付
     *
     * @param payInfo
     */
    private void alipay(final String payInfo) {
        final String orderInfo = payInfo;   // 订单信息

        Runnable payRunnable = new Runnable() {

            @Override
            public void run() {
                PayTask alipay = new PayTask(RechargeActivity.this);
                String result = alipay.pay(orderInfo, true);
                Message msg = new Message();
                msg.what = PAY_FLAG_ALIPAY;
                msg.obj = result;
                handler.sendMessage(msg);
            }
        };
        // 必须异步调用
        Thread payThread = new Thread(payRunnable);
        payThread.start();
    }

    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case PAY_FLAG_ALIPAY:
                    PayResult payResult = new PayResult((String) msg.obj);
                    String resultStatus = payResult.getResultStatus();
                    if ("9000".equals(resultStatus)) {
                        show("支付成功");
                        RxBus.getInstance().send(new WalletRefreshEvent());
                        finish();
                    } else if ("8000".equals(resultStatus)) {
                        show("支付结果确认中");
                    } else {
                        show("支付失败");
                    }

                    break;

                default:
                    break;
            }
        }

    };


你可能感兴趣的:(支付宝支付配置代码)