50,530
社区成员
发帖
与我相关
我的任务
分享
public void jsmethod_getjson(UZModuleContext moduleContext)
{
JSONObject quickparams =moduleContext.optJSONObject("quickpay");
try {
mMerchantId =quickparams.getString("shopID");
mMerchantUserId =quickparams.getString("shopuserID");
mMerOrderId =quickparams.getString("shopIndent");
mAmountText =quickparams.getString("money");
mMobileId =quickparams.getString("phone");
//实例化ServiceManager对象
ServiceManager.getInstance().bindQuickPayService(mContext);
payOrder();
} catch (Exception e) {
// TODO: handle exception
}
}
public void payOrder() {
Bundle args = new Bundle();
args.putString("merchantId", mMerchantId);
args.putString("merchantUserId",mMerchantUserId);
args.putString("merOrderId",mMerOrderId);
mAmount =mAmountText;
// 将交易金额由元转成分
mAmount = Common.moneyTran(mAmount, 0);
args.putString("amount", mAmount);
args.putString("mobile",mMobileId);
args.putString("sign", getSignInfoData());
args.putString("mode", "2");
args.putString("notifyUrl", mNotifyUrl);
args.putString("signType", "RSA");
args.putBoolean("isProductEnv",true);
try {
if (ServiceManager.getInstance().mUmsQuickPayService == null) {
ServiceManager.getInstance().bindQuickPayService(mContext);
return;
}
ServiceManager.getInstance().mUmsQuickPayService.payOrder(args, new PayOrderResultListener());
} catch (RemoteException e) {
e.printStackTrace();
}
}
public class ServiceManager {
public IUmsQuickPayService mUmsQuickPayService;
private static ServiceManager instance;
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.v("sss", "111");
mUmsQuickPayService = IUmsQuickPayService.Stub.asInterface(service);
Log.v("sss", "112");
}
@Override
public void onServiceDisconnected(ComponentName name) {
mUmsQuickPayService = null;
}
};
synchronized public static ServiceManager getInstance() {
if (instance == null) {
instance = new ServiceManager();
}
return instance;
}
public void bindQuickPayService(Context context) {
// 绑定远程服务
Intent intent = new Intent();
String servicePkgname = "com.chinaums.pppay";
intent.setClassName(servicePkgname, "com.chinaums.pppay.quickpay.service.QuickPayService");
// 与服务端进行绑定,绑定成功会回调onServiceConnected里面
context.bindService(intent, mConnection, Service.BIND_AUTO_CREATE);
}
public void unbindQuickPayService(Context context) {
context.unbindService(mConnection);
}
}