IT科技资讯
联系方式
当前位置: 主页 > IT科技资讯 >
Android-银联支付
编辑:918Õ 时间:2019-01-31

Android-银联支付

银联支付也是一般比较常用的支付功能,这里简单了介绍android app如果短期快速应用这一方面的东西。直接上代码:

1.导入银联支付的依赖包:

vcD4KPHA+PGltZyBzcmM9"http://www.2cto.com/uploadfile/Collfiles/20140809/2014080909044158.jpg" alt="\">

以下 我以测试接口为例

/**
 *		UnionPay Test
 *
 * 	@author Lean  @date:2014-8-8  
 */
public class MainActivity extends Activity implements Runnable {

	private String mMode = "01";//设置测试模式:01为测试 00为正式环境
	private static final String TN_URL_01 = "http://202.101.25.178:8080/sim/gettn";//自己后台需要实现的给予我们app的tn号接口

	private Handler mHandler=new Handler(){
		
		public void handleMessage(android.os.Message msg) {

	        String tn = "";
	        if (msg.obj == null || ((String) msg.obj).length() == 0) {
	            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
	            builder.setTitle("错误提示");
	            builder.setMessage("网络连接失败,请重试!");
	            builder.setNegativeButton("确定",
	                    new DialogInterface.OnClickListener() {
	                        @Override
	                        public void onClick(DialogInterface dialog, int which) {
	                            dialog.dismiss();
	                        }
	                    });
	            builder.create().show();
	        } else {
	            tn = (String) msg.obj;
	            doStartUnionPayPlugin(MainActivity.this, tn, mMode);
	        }
		}
	};
	
	/**
	 * 	启动支付界面
	 */
	public void doStartUnionPayPlugin(Activity activity, String tn, String mode) {
        UPPayAssistEx.startPayByJAR(activity, PayActivity.class, null, null,
                tn, mode);
    }
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		new Thread(MainActivity.this).start();

	}

	
	@Override
	public void run() {
		String tn = null;
		InputStream is;
		try {

			String url = TN_URL_01;

			URL myURL = new URL(url);
			URLConnection ucon = myURL.openConnection();
			ucon.setConnectTimeout(120000);
			is = ucon.getInputStream();
			int i = -1;
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			while ((i = is.read()) != -1) {
				baos.write(i);
			}

			tn = baos.toString();
			is.close();
			baos.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		Message msg = mHandler.obtainMessage();
		msg.obj = tn;
		mHandler.sendMessage(msg);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (data == null) {
			return;
		}
		String msg = "";
		/*
		 * 支付控件返回字符串:success、fail、cancel 分别代表支付成功,支付失败,支付取消
		 */
		String str = data.getExtras().getString("pay_result");
		Log.v("zftphone", "2 "+data.getExtras().getString("merchantOrderId"));
		if (str.equalsIgnoreCase("success")) {
			msg = "支付成功!";
			
		} else if (str.equalsIgnoreCase("fail")) {
			msg = "支付失败!";
			
		} else if (str.equalsIgnoreCase("cancel")) {
			
			msg = "用户取消了支付";
		}
		//支付完成,处理自己的业务逻辑!
	}

}

AAA:做这个的时候,你要保证你有个牛比的支持团队能够接受新事物,同时谴责下银联的客服 太垃圾了说!

http://www.bkjia.com/Androidjc/862031.htmlwww.bkjia.comtruehttp://www.bkjia.com/Androidjc/862031.htmlTechArticleAndroid-银联支付 银联支付也是一般比较常用的支付功能,这里简单了介绍android app如果短期快速应用这一方面的东西。直接上代码: 1.导入银...

本文源自: 环亚娱乐