项目中使用到银行卡支付,然后对接了连连支付。这里记录一下。
项目中用到连连支付的功能:实现绑卡,获取已绑定卡的信息,修改卡信息, 银行卡代扣,认证支付。
项目从开始到后来迭代,陆续使用了代扣功能,认证支付功能,而认证支付中又分为:标准方式,卡前置方式。
》银行卡代扣
项目图:
部分代码:
/**
* 银行卡代付(就是客户端发起支付请求到后台,后台去请求连连支付进行银行卡划扣操作,后台将连连的操作结果回调到客户端)
*/
private void bankPay(){
if(netHelper==null) {
netHelper = new PayBackHelper();
}
HashMap<String,String> params = new HashMap<>();
params.put("orderId",loanOrderId);
netHelper.bankPay(new RetrofitSubscriber<BaseRspBean<String>>(new RetrofitInterface<BaseRspBean<String>>() {
@Override
public void onNext(BaseRspBean<String> stringBaseRspBean) {
ToastUtil.show(mContext,StringUtil.isBlank(stringBaseRspBean.getDescription())?"操作成功!":stringBaseRspBean.getDescription());
SpCountUtils.addBankBancCount(SPUtils.getString(SPConstantUtils.USER_ID));
if(mContext!=null) {
((BackMoneyDetailActivity) mContext).onBack();
}
}
@Override
public void onError(int errorCode, String errorMsg) {
SpCountUtils.addBankBancCount(SPUtils.getString(SPConstantUtils.USER_ID));
ToastUtil.show(mContext,StringUtil.isBlank(errorMsg)?"还款失败":errorMsg);
}
},mContext),params);
}
项目中选择银行卡代扣,会弹出如图所示
的确认弹框,点击确认会调用上面的方法,从而实现银行卡代扣。
》认证支付(标准方式)
先发请求到后台,得到签名数据,然后将数据再加工,封装成连连认证支付需要的参数形式,再调用sdk的认证支付:
msp.payAuth(content4Pay, mHandler, Constants.RQF_PAY, (Activity) mContext, false);
![](https://i-blog.csdnimg.cn/blog_migrate/8da8435e8fd44d34052adedc7816aa3e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/80b730a9c0dcfc1a043d520f53e730f5.png)
/**
* 银行卡认证支付 */
private void bankPay(){
if(netHelper==null) {
netHelper = new PayBackHelper();
}
HashMap<String,Object> params = new HashMap<>();
params.put("orderId",loanOrderId);
params.put("ticketIds",chooseTickets);
netHelper.bankLianlianPay(new RetrofitSubscriber<BaseRspBean<OrderInfoData>>(new RetrofitInterface<BaseRspBean<OrderInfoData>>() {
@Override
public void onNext(BaseRspBean<OrderInfoData> orderInfoDataBaseRspBean) {
if(orderInfoDataBaseRspBean!=null&&orderInfoDataBaseRspBean.getData()!=null) {
payOrder(orderInfoDataBaseRspBean.getData());
}else {
ToastUtil.show(mContext, UrlConfig.NETWORKERRORMSG);
}
}
@Override
public void onError(int errorCode, String errorMsg) {
ToastUtil.show(mContext,StringUtil.isBlank(errorMsg)?UrlConfig.NETWORKERRORMSG:errorMsg);
}
},mContext),params);
}
/**
* 支付订单
*/
private void payOrder(OrderInfoData orderInfo){
PayOrder order = constructGesturePayOrder(orderInfo);
String content4Pay = BaseHelper.toJSONString(order);
MobileSecurePayer msp = new MobileSecurePayer();
boolean bRet = msp.payAuth(content4Pay, mHandler,
Constants.RQF_PAY, (Activity) mContext, false);
}
//创建连连订单
private PayOrder constructGesturePayOrder(OrderInfoData orderInfo) {
PayOrder order = new PayOrder();
order.setBusi_partner(orderInfo.getBusi_partner());
order.setNo_order(orderInfo.getNo_order());
order.setDt_order(orderInfo.getDt_order());
order.setNotify_url(orderInfo.getNotify_url());
order.setSign_type(orderInfo.getSign_type());
order.setValid_order(orderInfo.getValid_order());
order.setUser_id(orderInfo.getUser_id());
order.setId_no(orderInfo.getId_no());
order.setAcct_name(orderInfo.getAcct_name());
order.setMoney_order(orderInfo.getMoney_order());
order.setRisk_item(orderInfo.getRisk_item());
order.setOid_partner(orderInfo.getOid_partner());
String content = BaseHelper.sortParam(order);
order.setSign(orderInfo.getSign());
return order;
}
//连连回调
private Handler mHandler = createHandler();
//创建连连回调
private Handler createHandler() {
return new Handler() {
public void handleMessage(Message msg) {
String strRet = (String) msg.obj;
switch (msg.what) {
case Constants.RQF_PAY: {
JSONObject objContent = BaseHelper.string2JSON(strRet);
String retCode = objContent.optString("ret_code");
String retMsg = objContent.optString("ret_msg");
if (Constants.RET_CODE_SUCCESS.equals(retCode)||Constants.RET_CODE_PROCESS.equals(retCode)) {
//支付成功,或者支付确认中
showPaySuccessDialog();
}else {
ToastUtil.show(mContext,"交易失败,请重新支付");
lianlianReturn(retCode,retMsg);
}
break;
}
}
super.handleMessage(msg);
}
} ;
}
》认证支付(卡前置方式)
认证支付的逻辑是一样的,不同的是卡前置方式时,需要将选择的支付的银行卡号或是指定支付的银行卡号传给连连。
通过银行卡列表可以选择已经在平台上绑定过的或者曾经绑定过的银行卡,进行认证支付,或者直接添加银行卡进行认证支付。
同样的,选择银行卡支付的时候会弹出确认弹框,点击确认会调用连连的认证支付。
部分代码:
/**
* 银行卡认证支付
*/
private void bankPay() {
if (netHelper == null) {
netHelper = new PayBackHelper();
}
HashMap<String, Object> params = new HashMap<>();
params.put("orderId", loanOrderId);
params.put("ticketIds", chooseTickets);
params.put("bankCard",reallyPayNumber);
netHelper.bankLianlianPay(new RetrofitSubscriber<BaseRspBean<OrderInfoData>>(new RetrofitInterface<BaseRspBean<OrderInfoData>>() {
@Override
public void onNext(BaseRspBean<OrderInfoData> orderInfoDataBaseRspBean) {
if (orderInfoDataBaseRspBean != null && orderInfoDataBaseRspBean.getData() != null) {
payOrder(orderInfoDataBaseRspBean.getData());
} else {
ToastUtil.show(mContext, UrlConfig.NETWORKERRORMSG);
}
}
@Override
public void onError(int errorCode, String errorMsg) {
ToastUtil.show(mContext, StringUtil.isBlank(errorMsg) ? UrlConfig.NETWORKERRORMSG : errorMsg);
}
}, mContext), params);
}
//创建连连订单
private PayOrder constructGesturePayOrder(OrderInfoData orderInfo) {
PayOrder order = new PayOrder();
order.setBusi_partner(orderInfo.getBusi_partner());
order.setNo_order(orderInfo.getNo_order());
order.setDt_order(orderInfo.getDt_order());
order.setNotify_url(orderInfo.getNotify_url());
order.setSign_type(orderInfo.getSign_type());
order.setValid_order(orderInfo.getValid_order());
order.setUser_id(orderInfo.getUser_id());
order.setId_no(orderInfo.getId_no());
order.setAcct_name(orderInfo.getAcct_name());
order.setMoney_order(orderInfo.getMoney_order());
order.setRisk_item(orderInfo.getRisk_item());
order.setOid_partner(orderInfo.getOid_partner());
order.setCard_no(reallyPayNumber);//银行卡号
String content = BaseHelper.sortParam(order);
order.setSign(orderInfo.getSign());
return order;
}