支付宝支付

 

首先导入依赖和jar包

implementation (name: 'alipaySdk-15.5.9-20181123210601', ext: 'aar')

支付宝最新Jar包

 

权限

    
    
    
    
    
    

 

在我们主build.gradle加入三方库

支付宝支付_第1张图片

        maven { url 'https://jitpack.io' }
        //支付宝支付要导入的仓库
        flatDir {
            dirs 'libs'
        }

 

 PayResult

public class PayResult {
	private String resultStatus;
	private String result;
	private String memo;

	public PayResult(Map rawResult) {
		if (rawResult == null) {
			return;
		}

		for (String key : rawResult.keySet()) {
			if (TextUtils.equals(key, "resultStatus")) {
				resultStatus = rawResult.get(key);
			} else if (TextUtils.equals(key, "result")) {
				result = rawResult.get(key);
			} else if (TextUtils.equals(key, "memo")) {
				memo = rawResult.get(key);
			}
		}
	}

	@Override
	public String toString() {
		return "resultStatus={" + resultStatus + "};memo={" + memo
				+ "};result={" + result + "}";
	}

	/**
	 * @return the resultStatus
	 */
	public String getResultStatus() {
		return resultStatus;
	}

	/**
	 * @return the memo
	 */
	public String getMemo() {
		return memo;
	}

	/**
	 * @return the result
	 */
	public String getResult() {
		return result;
	}
}

AliPayBean

private String message;
    private String status;
    private String result;
    private final String SUCCESS_STATUS = "0000";
    public boolean isSuccess(){
        return status.equals(SUCCESS_STATUS);
    }
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }
//接收返回消息
MyHandler myHandler = new MyHandler(this);
    private static class MyHandler extends Handler {
        private final WeakReference mActivity;
        public MyHandler(SeatActivity activity){
            mActivity = new WeakReference(activity);
        }
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(mActivity.get() == null){
                PayResult payResult = new PayResult((Map) msg.obj);
                ToastUtil.showToast(payResult.getMemo());
                return;
            }
        }
    }


//成功方法

                final String result = aliPayBean.getResult();
                final Runnable payRunnnable = new Runnable() {
                    @Override
                    public void run() {
                        PayTask payTask = new PayTask(SeatActivity.this);
                        Map map = payTask.payV2(result, true);
                        Message message = new Message();
                        message.obj = map;
                        myHandler.sendMessage(message);
                    }
                };
                // 必须异步调用
                Thread payThread = new Thread(payRunnnable);
                payThread.start();
                popupWindow.dismiss();

 

你可能感兴趣的:(支付宝支付)