Android 支付宝支付随手笔记

第一步是进入支付宝开发者平台申请账号,按照文档集成sdk 这些不做介绍

直接上代码

 

//传入参数  用户id和钱数  从后台获取加签字符串,

private void aliPay() {
    OkGo.post(Urls.ALI_PAY)
            .params("uid", (int) PrefUtils.get(this, "id", -1))
            .params("money", EmptyUtils.getEditTextEmtity(price))
            .execute(new DialogCallback(RechargeActivity.this, 0) {
                @Override
                public void onSuccess(Response response) {
                    super.onSuccess(response);
                    if (response.body().getCode() == 0) {
                        String content = response.body().getContent();

                        aliPayStart(content);
                    } else {

                        showToast(response.body().getMsg());

                    }
                }
            });
}
//调起支付宝支付界面
private void aliPayStart(final String aliSign) {
    Runnable payRunnable = new Runnable() {
        @Override
        public void run() {

            PayTask alipay = new PayTask(RechargeActivity.this);
            Map result = alipay.payV2(aliSign, true);

            Message msg = new Message();
            msg.what = 2018;
            msg.obj = result;
            mHandler.sendMessage(msg);
        }
    };
    Thread payThread = new Thread(payRunnable);
    payThread.start();
}

//大功告成

你可能感兴趣的:(Android 支付宝支付随手笔记)