public static void getConsumeTokenAndConsume( final String title, int amount, final PayType paytype) { LogD("111111111111111getConsumeTokenAndConsume 获取token"); McBaodianPay pay = McBaodianPay.init(); GetTokenParams params2 = new GetTokenParams(); // 宝点数量 params2.setAmount(amount); // 宝点 params2.setOption(0); // cp产生的订单id, 这个id需要cp服务端保存,消费成功后阿里服务器会通过notifyUrl通知到cp服务端,附带参数就是这个orderid。 params2.setOrderId(mAlipayTV_orderid); // 商品名称 params2.setTitle(title); // 消费成功后阿里服务端通知给cp服务端的notifyUrl params2.setNotifyUrl("http://mapi2.bianfeng.com/v1/pay/notify/alitv2"); // LogD("111111111获取token title:"+title+"amount:"+amount+"orderid:"+mAlipayTV_orderid); pay.getCousumeToken( params2, new IGetConsumeTokenListener() { @Override public void onSuccess(TokenBean tokenBean) { // TODO Auto-generated method stub LogD("111111111111111getConsumeTokenAndConsume token获取成功"); mTokenBean = tokenBean; // LogD("111111get tokenBean success:"+tokenBean); consumeBaodian(tokenBean, title, paytype); isGettingConsumeToken = false; } @Override public void onError(int errCode, String errMsg) { // TODO Auto-generated method stub LogD("111111111111111getConsumeTokenAndConsume token获取失败"); // LogD("111111get tokenBean error:"+errMsg); Message msg = mHandler.obtainMessage(); msg.arg1 = 2; msg.what = 2; msg.sendToTarget(); isGettingConsumeToken = false; return; } }); }
public static void consumeBaodian( TokenBean tokenBean, final String title, final PayType payType) { LogD("111111111111111consumeBaodian 开始支付"); McBaodianPay pay = McBaodianPay.init(); if (PayType.TYPE_QR_CODE.equals(payType)) { LogD("111111111111111consumeBaodian 二维码支付"); pay.startQRPay( tokenBean.getToken(), new IConsumeListener() { @Override public void onSuccess() { // TestToast.show("二维码扫码支付成功"); LogD("111111111111111consumeBaodian 二维码扫码支付成功"); Message msg = mHandler.obtainMessage(); msg.arg1 = 3; msg.what = 3; msg.sendToTarget(); return; } @Override public void onError(int errCode, String errMsg) { // TestToast.show("二维码扫码支付失败"); LogD("111111111111111consumeBaodian 二维码扫码支付失败"); Message msg = mHandler.obtainMessage(); msg.arg1 = 4; msg.what = 4; msg.sendToTarget(); return; } @Override public void onBaodianPay() { // TestToast.show("用户使用宝点支付,请唤起登陆授权页面后支付"); LogD("111111111111111consumeBaodian 二维码支付 中的宝点支付"); payByBaodian(); return; } }); } else { LogD("111111111111111consumeBaodian 宝点支付"); pay.consumeBaodian( tokenBean, title, new IConsumeListener() { @Override public void onSuccess() { // McLog.d(TAG, "consume " + title + " success!"); payResult(PayWrapper.PAYRESULT_SUCCESS, "宝点支付成功!"); return; } @Override public void onError(int errCode, String errMsg) { // McLog.d(TAG, "consume " + title + " error : " + errMsg // + " errCode:" + errCode); // String msg = "consume " + title + " error : " + errMsg + " errCode:" + errCode; payResult(PayWrapper.PAYRESULT_FAIL, "取消支付"); return; } @Override public void onBaodianPay() { return; /** 宝点支付,不必care这个回调 */ } }); } }