java聚合支付之工行
package com.ruoyi.project.common.payUtil;import com.icbc.api.DefaultIcbcClient;import com.icbc.api.IcbcApiException;import com.icbc.api.IcbcConstants;import com.icbc.api.internal.util.internal.util.fa
·
import com.icbc.api.DefaultIcbcClient;
import com.icbc.api.IcbcApiException;
import com.icbc.api.IcbcConstants;
import com.icbc.api.internal.util.internal.util.fastjson.JSON;
import com.icbc.api.request.CardbusinessQrcodeQrgenerateRequestV1;
import com.icbc.api.request.QrcodeScannedPaystatusRequestV1;
import com.icbc.api.request.QrcodeScannedPaystatusRequestV1.QrcodeScannedPaystatusRequestV1Biz;
import com.icbc.api.request.QrcodeScannedReturnRequestV1;
import com.icbc.api.request.QrcodeScannedReturnRequestV1.QrcodeScannedReturnRequestV1Biz;
import com.icbc.api.request.QrcodeScannedReturnstatusRequestV1;
import com.icbc.api.response.CardbusinessQrcodeQrgenerateResponseV1;
import com.icbc.api.response.QrcodeScannedPaystatusResponseV1;
import com.icbc.api.response.QrcodeScannedReturnResponseV1;
import com.icbc.api.response.QrcodeScannedReturnstatusResponseV1;
import org.springframework.beans.factory.annotation.Value;
/**
* 二维码生成
* @author Administrator
*
*/
public class QRCodeCreate{
//App_id
static String App_id="";
//网关公钥
static String APIGW_PUBLIC_KEY="";
//私钥
static String MY_PRIVATE_KEY="";
//商户线下档案编号
static String mer_id="";
//e生活档案编号
static String store_code="" ;
//创建连接对象
static DefaultIcbcClient client = new DefaultIcbcClient(App_id,IcbcConstants.SIGN_TYPE_RSA2, MY_PRIVATE_KEY, APIGW_PUBLIC_KEY);
/**
*
* 二维码生成
* 请求参数: outTradeNo:商户订单号 orderAmt:金额 tradeDate:年月日 tradeTime:时分秒
* 响应参数 barcode 条码 return_code返回码
*/
public static CardbusinessQrcodeQrgenerateResponseV1 qrCodeCreate(String outTradeNo,String orderAmt,String tradeDate,String tradeTime){
//构建client 对象
// 设置请求对象request
CardbusinessQrcodeQrgenerateRequestV1 request = new CardbusinessQrcodeQrgenerateRequestV1();
request.setServiceUrl("");
CardbusinessQrcodeQrgenerateRequestV1.CardbusinessQrcodeQrgenerateRequestV1Biz bizContent = new CardbusinessQrcodeQrgenerateRequestV1.CardbusinessQrcodeQrgenerateRequestV1Biz();
request.setBizContent(bizContent);
//商户线下档案编号
bizContent.setMerId(mer_id);
//e生活档案编号
bizContent.setStoreCode(store_code);
//订单编号
bizContent.setOutTradeNo(outTradeNo);
//订单金额
bizContent.setOrderAmt(orderAmt);
//订单生成日期
bizContent.setTradeDate(tradeDate);
//订单生成时间
bizContent.setTradeTime(tradeTime);
//商户是否开启通知接口
bizContent.setTporderCreateIp("127.0.0.1");
bizContent.setNotifyFlag("1");
bizContent.setNotifyUrl("");
//二维码有效期
bizContent.setPayExpire("21600"); //二维码六小时失效
CardbusinessQrcodeQrgenerateResponseV1 response;
try {
response =client.execute(request, System.currentTimeMillis() + "");//msgId消息通讯唯一编号,要求每次调用独立生成,APP级唯一
if (response.getReturnCode() == 0) {
System.out.println("response:" + JSON.toJSONString(response));
return response;
} else {
// 失败
System.out.println("response:" + JSON.toJSONString(response));
System.out.println("ReturnCode:" + response.getReturnCode());
System.out.println("ReturnMsg:" + response.getReturnMsg());
return response;
}
} catch (IcbcApiException e) {
e.printStackTrace();
}
return null;
}
/**
* 二维码被扫支付状态接口 -1:下单失败,0:支付中,1:支付成功,2:支付失败
* 参数 merId: 商户编号 outTradeNo: 外部订单号 tradeDate:交易日期 (年月日)
*/
public static QrcodeScannedPaystatusResponseV1 isPalyMoney(String outTradeNo,String tradeDate,String msgId){
QrcodeScannedPaystatusRequestV1 request = new QrcodeScannedPaystatusRequestV1();
//4、根据测试环境和生产环境替换相应ip和端口
request.setServiceUrl("");
//5、请对照接口文档用bizContent.setxxx()方法对业务上送数据进行赋值
QrcodeScannedPaystatusRequestV1Biz bizContent = new QrcodeScannedPaystatusRequestV1Biz();
bizContent.setMerId(mer_id); //商户编号
bizContent.setOutTradeNo(outTradeNo); //外部订单号
bizContent.setTradeDate(tradeDate);//交易日期
request.setBizContent(bizContent);
QrcodeScannedPaystatusResponseV1 response;
try {
response = client.execute(request, msgId);//msgId消息通讯唯一编号,要求每次调用独立生成,APP级唯一
if (response.isSuccess()) {
// 6、业务成功处理,请根据接口文档用response.getxxx()获取同步返回的业务数据
return response;
} else {
// 失败
System.out.println("ReturnCode:"+response.getReturnCode());
System.out.println("ReturnMsg:"+response.getReturnMsg());
System.out.println("response:" + response);
return response;
}
} catch (IcbcApiException e) {
e.printStackTrace();
}
return null;
}
/**
* 商户请求退款
* 请求参数String merId 商户档案号,String cusId //用户唯一标识,String outTradeNo,String rejectNo,String jectAmyt,String operId
*/
public static QrcodeScannedReturnResponseV1 refundMoney(String cusId,String outTradeNo,String rejectNo,String jectAmyt,String operId,String msgId){
QrcodeScannedReturnRequestV1 request = new QrcodeScannedReturnRequestV1();
//请路径
request.setServiceUrl("");
//创建对象
QrcodeScannedReturnRequestV1Biz bizContent = new QrcodeScannedReturnRequestV1Biz();
//商户档案编号
bizContent.setMerId(mer_id);
//用户唯一标识
bizContent.setCustId(cusId);
bizContent.setOutTradeNo(outTradeNo);
//退单编号
bizContent.setRejectNo(rejectNo);
//退款金额
bizContent.setRejectAmt(jectAmyt);
//操作人员编号
bizContent.setOperId(operId);//该字段非必输项
request.setBizContent(bizContent);
QrcodeScannedReturnResponseV1 response;
try {
response = client.execute(request, msgId);//msgId消息通讯唯一编号,要求每次调用独立生成,APP级唯一
if (response.isSuccess()) {
// 6、业务成功处理,请根据接口文档用response.getxxx()获取同步返回的业务数据
return response;
} else {
// 失败
System.out.println("ReturnCode:"+response.getReturnCode());
System.out.println("ReturnMsg:"+response.getReturnMsg());
return response;
}
} catch (IcbcApiException e) {
e.printStackTrace();
}
return null;
}
/**
* t退款状态查询
* 请求参数: String cusId 用户表示:,String outTradeNo :订单号,String rejectNo :退单编号,String msgId:消息号
*/
public static QrcodeScannedReturnstatusResponseV1 refundMoneyStatus(String cusId,String outTradeNo,String rejectNo,String msgId){
QrcodeScannedReturnstatusRequestV1 request = new QrcodeScannedReturnstatusRequestV1();
request.setServiceUrl("");
QrcodeScannedReturnstatusRequestV1.QrcodeScannedReturnstatusRequestV1Biz bizContent = new QrcodeScannedReturnstatusRequestV1.QrcodeScannedReturnstatusRequestV1Biz();
bizContent.setMerId(mer_id);
bizContent.setCustId(cusId);
//该字段非必输项
bizContent.setOutTradeNo(outTradeNo);//该字段非必输项,out_trade_no和order_id选一项上送即可
bizContent.setRejectNo(rejectNo);
request.setBizContent(bizContent);
QrcodeScannedReturnstatusResponseV1 response;
try {
response = client.execute(request, msgId);//msgId消息通讯唯一编号,要求每次调用独立生成,APP级唯一
if (response.isSuccess()) {
// 6、业务成功处理,请根据接口文档用response.getxxx()获取同步返回的业务数据
System.out.println("ReturnCode:"+response.getReturnCode());
System.out.println("response:" + response);
return response;
} else {
// 失败
System.out.println("ReturnCode:"+response.getReturnCode());
System.out.println("ReturnMsg:"+response.getReturnMsg());
return response;
}
} catch (IcbcApiException e) {
e.printStackTrace();
}
return null;
}
}
更多推荐
已为社区贡献2条内容
所有评论(0)