android付款功能,android 应用中加入支付功能(支付宝集成)

/**

* 向支付宝发送支付请求

*

* @param strOrderInfo

*            订单信息

* @param callback

*            回调handler

* @param myWhat

*            回调信息

* @param activity

*            目标activity

* @return

*/

public boolean pay(final String strOrderInfo, final Handler callback,

final int myWhat, final Activity activity) {

if (mbPaying)

return false;

mbPaying = true;

//

mActivity = activity;

// bind the service.

// 绑定服务

if (mAlixPay == null) {

// 绑定安全支付服务需要获取上下文环境,

// 如果绑定不成功使用mActivity.getApplicationContext().bindService

// 解绑时同理

mActivity.getApplicationContext().bindService(

new Intent(IAlixPay.class.getName()), mAlixPayConnection,

Context.BIND_AUTO_CREATE);

}

// else ok.

// 实例一个线程来进行支付

new Thread(new Runnable() {

public void run() {

try {

// wait for the service bind operation to completely

// finished.

// Note: this is important,otherwise the next mAlixPay.Pay()

// will fail.

// 等待安全支付服务绑定操作结束

// 注意:这里很重要,否则mAlixPay.Pay()方法会失败

synchronized (lock) {

if (mAlixPay == null)

lock.wait();

}

// register a Callback for the service.

// 为安全支付服务注册一个回调

mAlixPay.registerCallback(mCallback);

// call the MobileSecurePay service.

// 调用安全支付服务的pay方法

String strRet = mAlixPay.Pay(strOrderInfo);

BaseHelper.log(TAG, "After Pay: " + strRet);

// set the flag to indicate that we have finished.

// unregister the Callback, and unbind the service.

// 将mbPaying置为false,表示支付结束

// 移除回调的注册,解绑安全支付服务

mbPaying = false;

mAlixPay.unregisterCallback(mCallback);

mActivity.getApplicationContext().unbindService(

mAlixPayConnection);

// send the result back to caller.

// 发送交易结果

Message msg = new Message();

msg.what = myWhat;

msg.obj = strRet;

callback.sendMessage(msg);

} catch (Exception e) {

e.printStackTrace();

// send the result back to caller.

// 发送交易结果

Message msg = new Message();

msg.what = myWhat;

msg.obj = e.toString();

callback.sendMessage(msg);

}

}

}).start();

return true;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值