/** * 支付宝付款流程 * * @param vipTime 调接口拿到支付宝返回的alipay */ private void getOrderInfo(String vipTime) { Api.getDefault(ApiType.DOMAIN).AliPayVIP(String.valueOf(chooseMoney), vipTime) .enqueue (new Callback<AliPayBean>() { private String alipay; @Override public void onResponse(Call<AliPayBean> call, Response<AliPayBean> response) { if (response.code() == 200) { if (response.body() != null) { alipay = response.body().getBody().getAlipay(); //支付宝返回的alipay if (alipay != null) { //付款 pay(alipay); } else { ToastUtil.showNorToast("没有订单信息"); } } } } @Override public void onFailure(Call<AliPayBean> call, Throwable t) { ToastUtil.showErrorToast(); } }); } /** * 调起支付宝付款 * * @param orderInfo */ private static final int SDK_PAY_FLAG = 1; private void pay(final String orderInfo) { Runnable payRunnable = new Runnable() { @Override public void run() { PayTask alipay = new PayTask(getActivity()); Map<String, String> result = alipay.payV2(orderInfo, true); Message msg = new Message(); msg.what = SDK_PAY_FLAG; msg.obj = result; mHandler.sendMessage(msg); } }; Thread payThread = new Thread(payRunnable); payThread.start(); } @SuppressLint("HandlerLeak") private Handler mHandler = new Handler() { @SuppressWarnings("unused") public void handleMessage(Message msg) { switch (msg.what) { case SDK_PAY_FLAG: { @SuppressWarnings("unchecked") PayResult payResult = new PayResult((Map<String, String>) msg.obj); /** 对于支付结果,请商户依赖服务端的异步通知结果。同步通知结果,仅作为支付结束的通知。 */ String resultInfo = payResult.getResult();// 同步返回需要验证的信息 String resultStatus = payResult.getResultStatus(); // 判断resultStatus 为9000则代表支付成功 if (TextUtils.equals(resultStatus, "9000")) { // 该笔订单是否真实支付成功,需要依赖服务端的异步通知。 ToastUtil.showNorToast("支付成功"); btBuy.setVisibility(View.GONE); // TODO: 2018/8/15 查看票证 //支付成功 } else { //想拿其他状态在这里处理 } break; } default: break; } } };
Android调用支付宝付款
最新推荐文章于 2024-06-05 22:53:03 发布