Code Monkey home page Code Monkey logo

alipay's Introduction

支付标准sdk_demo

核心代码

支付核心代码

final String orderInfo = "服务端返回";

Runnable payRunnable = new Runnable() {

	@Override
	public void run() {
		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();

orderInfo由服务端加签完成后返回,客户端只需要使用

处理返回结果

@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")) {
				// 该笔订单是否真实支付成功,需要依赖服务端的异步通知。
				Toast.makeText(PayDemoActivity.this, "支付成功", Toast.LENGTH_SHORT).show();
			} else {
				// 该笔订单真实的支付结果,需要依赖服务端的异步通知。
				Toast.makeText(PayDemoActivity.this, "支付失败", Toast.LENGTH_SHORT).show();
			}
			break;
		}
		default:
			break;
		}
	};
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.