Merge branch 'HuiFu' into dev

# Conflicts:
#	jsowell-admin/src/main/java/com/jsowell/service/OrderService.java
This commit is contained in:
2023-05-20 10:16:32 +08:00
22 changed files with 3731 additions and 32 deletions

View File

@@ -90,6 +90,37 @@ public class PayController extends BaseController {
/**
* 会员充值余额
*/
@PostMapping("/rechargeBalance")
public RestApiResponse<?> rechargeBalance(HttpServletRequest request, @RequestBody WeixinPayDTO dto) {
logger.info("微信支付 param:{}", dto.toString());
RestApiResponse<?> response;
try {
if (StringUtils.isBlank(dto.getCode()) || StringUtils.isBlank(dto.getAmount())) {
return new RestApiResponse<>(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 鉴权
String memberId = getMemberIdByAuthorization(request);
if (StringUtils.isBlank(memberId)) {
throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);
}
dto.setMemberId(memberId);
String openId = memberService.getOpenIdByCode(dto.getCode());
if (StringUtils.isBlank(openId)) {
throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
}
dto.setOpenId(openId);
// 充值余额 附加参数
Map<String, Object> weixinMap = memberService.rechargeBalanceWithAdapay(dto);
response = new RestApiResponse<>(ImmutableMap.of("weixinMap", weixinMap));
} catch (Exception e) {
response = new RestApiResponse<>();
}
return response;
}
/**
* 7002 支付订单
* http://localhost:8080/uniapp/pay/payOrder

View File

@@ -1,7 +1,13 @@
package com.jsowell.service;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.ImmutableMap;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Payment;
import com.jsowell.adapay.common.CreateAdaPaymentParam;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.page.PageResponse;
@@ -9,7 +15,9 @@ import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.TitleTypeEnum;
import com.jsowell.common.enums.uniapp.BalanceChangesEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.enums.ykc.ScenarioEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.AdapayUtil;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.id.IdUtils;
@@ -23,8 +31,10 @@ import com.jsowell.pile.dto.BindingCardDTO;
import com.jsowell.pile.dto.CreateInvoiceTitleDTO;
import com.jsowell.pile.dto.MemberRegisterAndLoginDTO;
import com.jsowell.pile.dto.MemberRegisterDTO;
import com.jsowell.pile.dto.PaymentScenarioDTO;
import com.jsowell.pile.dto.UniAppQueryMemberBalanceDTO;
import com.jsowell.pile.dto.WechatLoginDTO;
import com.jsowell.pile.dto.WeixinPayDTO;
import com.jsowell.pile.service.IMemberBasicInfoService;
import com.jsowell.pile.service.IMemberInvoiceTitleService;
import com.jsowell.pile.service.IMemberPlateNumberRelationService;
@@ -42,10 +52,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
@Service
@@ -76,6 +88,9 @@ public class MemberService {
@Autowired
private IMemberInvoiceTitleService memberInvoiceTitleService;
@Autowired
private OrderService orderService;
/**
* 校验短信验证码
* @param dto
@@ -381,4 +396,42 @@ public class MemberService {
int i = memberInvoiceTitleService.insertMemberInvoiceTitle(title);
log.info("新增{}条发票抬头", i);
}
public Map<String, Object> rechargeBalance(WeixinPayDTO dto) throws Exception {
PaymentScenarioDTO paymentScenarioDTO = new PaymentScenarioDTO();
paymentScenarioDTO.setType(ScenarioEnum.BALANCE.getValue());
paymentScenarioDTO.setMemberId(dto.getMemberId());
dto.setAttach(JSONObject.toJSONString(paymentScenarioDTO));
dto.setDescription("会员充值余额");
return orderService.weixinPayV3(dto);
}
public Map<String, Object> rechargeBalanceWithAdapay(WeixinPayDTO dto) throws Exception {
// 封装对象
CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam();
createAdaPaymentParam.setOrder_no(IdUtils.fastSimpleUUID());
createAdaPaymentParam.setPay_amt(AdapayUtil.formatAmount(dto.getAmount()));
createAdaPaymentParam.setApp_id("app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa"); // todo 后面移动到配置文件中
createAdaPaymentParam.setPay_channel("wx_lite"); // todo 如果以后有支付宝等别的渠道,这里需要做修改,判断是什么渠道的请求
createAdaPaymentParam.setGoods_title("充电费用1");
createAdaPaymentParam.setGoods_desc("充电费用2");
createAdaPaymentParam.setDescription("充电费用3");
createAdaPaymentParam.setExpend(JSONObject.toJSONString( ImmutableMap.of("open_id", dto.getOpenId())));
//异步通知地址url为http/https路径服务器POST回调URL 上请勿附带参数
createAdaPaymentParam.setNotify_url("https://api.jsowellcloud.com/uniapp/pay/adapayCallback");
try {
log.info("创建汇付支付参数:{}", JSONObject.toJSONString(createAdaPaymentParam));
Map<String, Object> response = Payment.create(BeanMap.create(createAdaPaymentParam));
log.info("创建汇付支付参数反参:{}", JSONObject.toJSONString(response));
if (response != null && !response.isEmpty()) {
JSONObject jsonObject = JSONObject.parseObject(response.get("expend").toString());
JSONObject pay_info = jsonObject.getJSONObject("pay_info");
Map<String, Object> resultMap = JSONObject.parseObject(pay_info.toJSONString(), new TypeReference<Map<String, Object>>() {});
return resultMap;
}
} catch (BaseAdaPayException e) {
log.error("汇付-获取支付对象发生异常", e);
}
return null;
}
}

View File

@@ -1,11 +1,16 @@
package com.jsowell.service;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Payment;
import com.jsowell.adapay.common.CreateAdaPaymentParam;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
@@ -24,6 +29,7 @@ import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.enums.ykc.ScenarioEnum;
import com.jsowell.common.enums.ykc.StartTypeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.AdapayUtil;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.SecurityUtils;
import com.jsowell.common.util.StringUtils;
@@ -66,7 +72,6 @@ import com.jsowell.pile.transaction.service.TransactionService;
import com.jsowell.pile.vo.base.OrderAmountDetailVO;
import com.jsowell.pile.vo.base.OrderPeriodAmountVO;
import com.jsowell.pile.vo.base.PileInfoVO;
import com.jsowell.pile.vo.base.StationInfoVO;
import com.jsowell.pile.vo.uniapp.InvoiceRecordVO;
import com.jsowell.pile.vo.uniapp.MemberVO;
import com.jsowell.pile.vo.uniapp.OrderVO;
@@ -83,6 +88,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
@@ -151,6 +157,8 @@ public class OrderService {
@Autowired
private RedisCache redisCache;
private List<String> stationIdList = Lists.newArrayList("1", "2");
/**
* 生成订单
*
@@ -191,7 +199,42 @@ public class OrderService {
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
// 微信支付
dto.setOrderBasicInfo(orderInfo);
Map<String, Object> weixinMap = wechatPayOrder(dto);
Map<String, Object> weixinMap = null;
if (stationIdList.contains("all") || stationIdList.contains(orderInfo.getStationId())) {
weixinMap = adapayPayOrder(dto);
} else {
weixinMap = wechatPayOrder(dto);
}
// 返回微信支付参数
resultMap.put("weixinMap", weixinMap);
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { // 支付宝支付
// TODO 返回支付宝支付参数
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WHITELIST.getValue())) { // 白名单支付
// 白名单支付可以直接调支付回调方法
dto.setPayAmount(new BigDecimal("500"));
whiteListPayOrder(dto);
}
return resultMap;
}
public Map<String, Object> payOrderWithAdapay(PayOrderDTO dto) {
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getOrderCode());
if (orderInfo == null) {
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_NULL_ERROR);
}
if (!StringUtils.equals(orderInfo.getPayStatus(), "0")) {
// 订单已支付
throw new BusinessException(ReturnCodeEnum.CODE_ORDER_IS_NOT_TO_BE_PAID_ERROR);
}
Map<String, Object> resultMap = Maps.newHashMap();
if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) {
// 余额支付
balancePayOrder(dto);
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
// 微信支付 使用adapay
dto.setOrderBasicInfo(orderInfo);
Map<String, Object> weixinMap = adapayPayOrder(dto);
// 返回微信支付参数
resultMap.put("weixinMap", weixinMap);
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { // 支付宝支付
@@ -206,7 +249,6 @@ public class OrderService {
/**
* 白名单支付订单逻辑
*
* @param dto
*/
private void whiteListPayOrder(PayOrderDTO dto) {
@@ -221,14 +263,70 @@ public class OrderService {
payOrderSuccessCallback(callbackDTO);
}
/**
* 使用汇付支付
* @param dto
* @return
*/
private Map<String, Object> adapayPayOrder(PayOrderDTO dto) {
log.info("===============使用汇付支付");
// 相同参数重复请求,返回同一个支付对象
String redisKey = "ADAPAY_ORDER_PARAM:" + dto.getOrderCode();
Map<String, Object> cacheObject = redisCache.getCacheObject(redisKey);
if (cacheObject != null) {
return cacheObject;
}
OrderBasicInfo orderInfo = dto.getOrderBasicInfo();
if (orderInfo == null) {
// 订单为空重新查询
orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getOrderCode());
}
// 获取openId
String openId = memberService.getOpenIdByCode(dto.getCode());
if (StringUtils.isBlank(openId)) {
throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
}
// 封装对象
CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam();
createAdaPaymentParam.setOrder_no(orderInfo.getOrderCode());
// createAdaPaymentParam.setPay_amt(new DecimalFormat("#.00").format(dto.getPayAmount()));
createAdaPaymentParam.setPay_amt(AdapayUtil.formatAmount(dto.getPayAmount()));
createAdaPaymentParam.setApp_id("app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa"); // todo 后面移动到配置文件中
createAdaPaymentParam.setPay_channel("wx_lite"); // todo 如果以后有支付宝等别的渠道,这里需要做修改,判断是什么渠道的请求
createAdaPaymentParam.setGoods_title("充电费用1");
createAdaPaymentParam.setGoods_desc("充电费用2"); // 这个字段是微信支付凭证的商品名
createAdaPaymentParam.setDescription("充电费用3");
createAdaPaymentParam.setExpend(JSONObject.toJSONString( ImmutableMap.of("open_id", openId)));
try {
log.info("创建汇付支付参数:{}", JSONObject.toJSONString(createAdaPaymentParam));
Map<String, Object> response = Payment.create(BeanMap.create(createAdaPaymentParam));
if (response != null && !response.isEmpty()) {
JSONObject jsonObject = JSONObject.parseObject(response.get("expend").toString());
JSONObject pay_info = jsonObject.getJSONObject("pay_info");
Map<String, Object> resultMap = JSONObject.parseObject(pay_info.toJSONString(), new TypeReference<Map<String, Object>>() {
});
if (resultMap != null) {
// 表示已经获取到支付参数了,后续再有支付请求就拒绝
redisCache.setCacheObject(redisKey, resultMap, 15, TimeUnit.MINUTES);
}
return resultMap;
}
} catch (BaseAdaPayException e) {
log.error("汇付-获取支付对象发生异常", e);
}
return null;
}
/**
* 微信支付订单逻辑 获取支付参数
*
* @param dto
* @return
* @throws Exception
*/
private Map<String, Object> wechatPayOrder(PayOrderDTO dto) throws Exception {
// 相同参数重复请求,返回同一个支付对象
String redisKey = "WECHAT_PAY_ORDER_PARAM:" + dto.getOrderCode();
Map<String, Object> cacheObject = redisCache.getCacheObject(redisKey);
if (cacheObject != null) {
@@ -264,7 +362,6 @@ public class OrderService {
/**
* 余额支付订单逻辑
*
* @param dto
*/
private void balancePayOrder(PayOrderDTO dto) {
@@ -689,7 +786,6 @@ public class OrderService {
/**
* 查询订单详情信息
*
* @param orderCode 订单编号
* @return
*/
@@ -778,7 +874,7 @@ public class OrderService {
// 使用余额支付
payInfo.setPayMode(OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue());
payInfo.setPayModeDesc(OrderPayModeEnum.PAYMENT_OF_BALANCE.getLabel());
} else if (StringUtils.equals(payMode, OrderPayRecordEnum.WECHATPAY_PAYMENT.getValue())) {
} else if (StringUtils.equals(payMode, OrderPayRecordEnum.WECHATPAY_PAYMENT.getValue())){
// 使用微信支付
payInfo.setPayMode(OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue());
payInfo.setPayModeDesc(OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getLabel());
@@ -788,7 +884,7 @@ public class OrderService {
payInfo.setOutTradeNo(wxpayCallbackRecord.getOutTradeNo());
payInfo.setTransactionId(wxpayCallbackRecord.getTransactionId());
}
} else if (StringUtils.equals(payMode, OrderPayRecordEnum.WHITELIST_PAYMENT.getValue())) {
} else if (StringUtils.equals(payMode, OrderPayRecordEnum.WHITELIST_PAYMENT.getValue())){
// 使用白名单支付
payInfo.setPayMode(OrderPayModeEnum.PAYMENT_OF_WHITELIST.getValue());
payInfo.setPayModeDesc(OrderPayModeEnum.PAYMENT_OF_WHITELIST.getLabel());
@@ -831,7 +927,6 @@ public class OrderService {
/**
* 获取小程序订单详情
*
* @param orderCode
* @return
*/
@@ -907,7 +1002,7 @@ public class OrderService {
// monitorDataList是按照时间倒序的chargingDataList需要按照时间正序
Collections.reverse(chargingDataList);
vo.setChargingDataList(chargingDataList);
}
}
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode);
if (orderDetail != null) {
@@ -930,7 +1025,6 @@ public class OrderService {
/**
* 根据订单号查询充电桩启动状态
*
* @param orderCode
* @return
*/
@@ -950,7 +1044,6 @@ public class OrderService {
/**
* 人工结算订单
*
* @param dto
*/
public boolean manualSettlementOrder(ManualSettlementDTO dto) {
@@ -1004,7 +1097,6 @@ public class OrderService {
/**
* 当前登录会员 获取支付方式
*
* @param dto
*/
public List<PayModeVO> getPayMode(GetPayModeDTO dto) {
@@ -1040,9 +1132,11 @@ public class OrderService {
public List<OrderVO> queryUninvoicedOrderList(QueryOrderDTO dto) {
int i = 15;
// 查询最近15天完成的订单
LocalDateTime dateTime = LocalDateTime.now().plusDays(-i);
List<OrderVO> orderList = orderBasicInfoService.getListByMemberIdAndOrderStatus(dto.getMemberId(), Lists.newArrayList("6"), dateTime, dto.getStationId());
List<OrderVO> orderList = orderBasicInfoService.getListByMemberIdAndOrderStatus(dto.getMemberId(), Lists.newArrayList("6"), dateTime);
// 过滤掉订单金额为0的
orderList = orderList.stream()
.filter(x -> x.getOrderAmount().compareTo(BigDecimal.ZERO) > 0)
@@ -1050,6 +1144,7 @@ public class OrderService {
if (CollectionUtils.isEmpty(orderList)) {
return orderList;
}
// 查询最近60天申请开票记录
QueryInvoiceRecordDTO build = QueryInvoiceRecordDTO.builder()
.memberId(dto.getMemberId())
@@ -1059,37 +1154,22 @@ public class OrderService {
if (CollectionUtils.isEmpty(orderInvoiceRecords)) {
return orderList;
}
// 排除掉已经申请过的订单
List<String> orderCodeList = orderInvoiceRecords.stream() // 转化为 Stream
.map(OrderInvoiceRecord::getOrderCodes) // 获取 OrderInvoiceRecord 中的 orderCodes 字符串
.flatMap(str -> Arrays.stream(str.split(","))) // 分隔逗号并转化为 Stream
.collect(Collectors.toList()); // 收集为 List<String>
orderList = orderList.stream()
.filter(x -> !orderCodeList.contains(x.getOrderCode()))
.collect(Collectors.toList());
return orderList;
}
public List<StationInfoVO> queryUninvoicedStationList(QueryOrderDTO dto) {
dto.setStationId(null);
List<OrderVO> orderVOS = queryUninvoicedOrderList(dto);
if (CollectionUtils.isEmpty(orderVOS)) {
return Lists.newArrayList();
}
// 根据站点分组
List<StationInfoVO> stationInfoVOS = orderVOS.stream()
.map(
x -> StationInfoVO.builder()
.stationId(x.getStationId())
.stationName(x.getStationName())
.build()
).distinct().collect(Collectors.toList());
return stationInfoVOS;
return orderList;
}
/**
* 申请开票
*
* @param dto
*/
public void applyOrderInvoice(ApplyOrderInvoiceDTO dto) {
@@ -1168,4 +1248,7 @@ public class OrderService {
.build();
}
public void adapayCallback(HttpServletRequest request, WechatPayNotifyParameter body) {
log.info("");
}
}

View File

@@ -94,6 +94,10 @@ public enum ReturnCodeEnum {
CODE_STATION_IS_NOT_OPEN("00100045", "该站点暂未营业"),
CODE_MEMBER_RECHARGE_BALANCE_ERROR("00100046", "会员充值余额失败"),
/* 个人桩 start */
CODE_PILE_HAS_BEEN_BINDING_ERROR("00400001", "此桩已被绑定,请联系管理员!"),
CODE_AUTHENTICATION_ERROR("00400002", "您的身份信息验证有误,请重试!"),
@@ -114,6 +118,8 @@ public enum ReturnCodeEnum {
CODE_GET_PERSONAL_PILE_CONNECTOR_INFO_ERROR("00400010", "获取个人桩枪口实时数据异常"),
/* 个人桩 end */
CODE_THIS_CARNO_HAS_BEEN_BINDING("00500001", "当前车牌号已经绑定,请检查!"),
CODE_USER_BINDING_CARNO_ERROR("00500002", "用户绑定车牌号异常"),

View File

@@ -0,0 +1,42 @@
package com.jsowell.common.util;
import java.math.BigDecimal;
import java.text.DecimalFormat;
/**
* 汇付支付的工具类
*/
public class AdapayUtil {
public static void main(String[] args) {
String amount = "1110.5309";
String s = formatAmount(amount);
System.out.println(s);
BigDecimal bigDecimal = new BigDecimal(amount);
String s2 = formatAmount(bigDecimal);
System.out.println(s2);
}
/**
* 格式化数字 保留两位小数不足补0
* @param amount
* @return
*/
public static String formatAmount(String amount) {
//保留2位小数
double d = new BigDecimal(amount).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//不足两位则补0
DecimalFormat decimalFormat = new DecimalFormat("0.00#");
return decimalFormat.format(d);
}
/**
* 格式化数字 保留两位小数不足补0
* @param amount
* @return
*/
public static String formatAmount(BigDecimal amount) {
return formatAmount(amount.toString());
}
}

View File

@@ -78,6 +78,16 @@
<artifactId>jackson-dataformat-avro</artifactId>
</dependency>
<dependency>
<groupId>com.huifu.adapay.core</groupId>
<artifactId>adapay-core-sdk</artifactId>
</dependency>
<dependency>
<groupId>com.huifu.adapay</groupId>
<artifactId>adapay-java-sdk</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>

View File

@@ -0,0 +1,154 @@
package com.jsowell.adapay.common;
import lombok.Data;
/**
* 关于支付Adapay 系统内数据是通过 Payment对象 的形式进行流转,所有的支付相关信息都会存储在这个对象中,
* 您可以通过 Adapay 开放的方法创建一个新的 Payment对象也可以通过 Payment对象 的唯一标识 id 来查询一个已经存在的 Payment对象 状态
*/
@Data
public class AdaPayment {
/**
* String(64)
*
* 由 Adapay 生成的支付对象 id 该 id 在 Adapay 系统内唯一
*/
private String id;
/**
*
* String(20)
*
* 支付对象payment
*/
private String object;
/**
* Timestamp
*
* 支付创建时的 10 位时间戳
*/
private String created_time;
/**
* String(64)
*
* 请求订单号只能为英文、数字或者下划线的一种或多种组合保证在app_id下唯一
*/
private String order_no;
/**
* String(5)
*
* 是否 prod模式true 是 prod模式false 是 mock模式
*/
private String prod_mode;
/**
* String(64)
*
* 控制台 主页面应用的app_id
*/
private String app_id;
/**
* String(20)
*
* 支付渠道,参见 支付渠道 说明
*/
private String pay_channel;
/**
* String(16)
*
* 交易金额(必须大于 0保留两位小数点如0.10、100.05等
*/
private String pay_amt;
/**
*
* String(3)
*
* 详见 货币代码
*/
private String currency;
/**
* String(128)
*
* 可临时用来查询支付订单状态的链接此链接的有效期只有30分钟
*/
private String query_url;
/**
* String(128)
*
* 订单附加说明
*/
private String description;
/**
* Map
*
* 支付渠道请求成功返回的额外参数。详见 支付渠道 expend参数 说明
*/
private String expend;
/**
* String(64)
*
* 用户账单上的商户订单号
*/
private String party_order_id;
/**
* String(64)
*
* 用户账单上的交易订单号
*/
private String out_trans_id;
/**
* String(14)
*
* 用户支付完成时间
*/
private String end_time;
/**
* String(16)
*
* 当前交易状态,参见 状态 说明
*/
private String status;
/**
*
* String(32)
*
* 错误码,详见 错误
*/
private String error_code;
/**
* String(128)
*
* 错误描述,详见 错误
*/
private String error_msg;
/**
* String(32)
*
* 错误类型,详见 错误
*/
private String error_type;
/**
* String(32)
*
* 当发生参数错误时返回具体的参数名,便于定位错误原因,详见 错误
*/
private String invalid_param;
}

View File

@@ -0,0 +1,114 @@
package com.jsowell.adapay.common;
import lombok.Data;
/**
* 创建Adapay 支付对象参数
*/
@Data
public class CreateAdaPaymentParam {
/**
* String(64)
* Y
* 请求订单号只能为英文、数字或者下划线的一种或多种组合保证在app_id下唯一
*/
private String order_no;
/**
* String(64)
* Y
* 控制台 主页面应用的app_id
*/
private String app_id;
/**
* String(20)
* Y
* 支付渠道,参见 支付渠道
*/
private String pay_channel;
/**
* String(14)
* Y
* 交易金额必须大于0保留两位小数点如0.10、100.05等
*/
private String pay_amt;
/**
* String(20)
* N
* 支付模式delay- 延时分账模式(值为 delay 时div_members 字段必须为空值为空时并且div_mermbers不为空时表示实时分账值为空时并且div_mermbers也为空时表示不分账
*/
private String pay_mode;
/**
* String(64)
* Y
* 商品标题
*/
private String goods_title;
/**
* String(127)
* Y
* 商品描述信息微信小程序和微信公众号该字段最大长度42个字符
*/
private String goods_desc;
/**
* String(3)
* N
* 3位 ISO 货币代码小写字母默认为人民币cny详见 货币代码
*/
private String currency;
/**
* String
* N
* 分账对象信息列表最多仅支持7个分账方json 数组形式,详见 分账对象信息列表
*/
private String div_members;
/**
* String(128)
* N
* 订单附加说明
*/
private String description;
/**
* String(20)
* N
* 订单失效时间输入格式yyyyMMddHHmmss最长失效时间为微信、支付宝反扫类3分钟非反扫类2小时云闪付1天值为空时默认最长时效时间
*/
private String time_expire;
/**
* Map
* Y
* 前端设备信息,详见 设备信息
*/
private String device_info;
/**
* Map
* N
* 支付渠道额外参数JSON格式条件可输入详见 支付渠道 expend参数
*/
private String expend;
/**
* String(250)
* N
* 异步通知地址url为http/https路径服务器POST回调URL 上请勿附带参数
*/
private String notify_url;
/**
* String(1)
* N
* 手续费收取模式O-商户手续费账户扣取手续费I-交易金额中扣取手续费值为空时默认值为I若为O时分账对象列表中不支持传入手续费承担方
*/
private String fee_mode;
}

View File

@@ -0,0 +1,72 @@
package com.jsowell.adapay.common;
import lombok.Data;
/**
* 设备信息
*/
@Data
public class DeviceInfo {
/**
* String(2)
* N
* 设备类型1 :手机, 2 :平板, 3:手表, 4:PC
*/
private String device_type;
/**
* String(64)
* Y
* 交易设备所在的公网 IP
*/
private String device_ip;
/**
* String(8)
* N
* 终端设备号收单机构为商户终端分配的唯一编号。当pay_channel的值为alipay_scan或wx_scan时必填。
*/
private String device_id;
/**
* String(64)
* N
* 交易设备 MAC
*/
private String device_mac;
/**
* String(64)
* N
* 交易设备 IMEI
*/
private String device_imei;
/**
* String(64)
* N
* 交易设备 IMSI
*/
private String device_imsi;
/**
* String(64)
* N
* 交易设备 ICCID
*/
private String device_iccId;
/**
* String(64)
* N
* 交易设备 WIFIMAC
*/
private String device_wifi_mac;
/**
* String(64)
* N
* 交易设备 GPS
*/
private String device_gps;
}

View File

@@ -0,0 +1,40 @@
package com.jsowell.adapay.config;
import com.huifu.adapay.Adapay;
import com.huifu.adapay.model.MerConfig;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Order(value = 3)
@Component
public class AdapayConfig implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
/**
* debug 模式,开启后有详细的日志
*/
Adapay.debug = true;
/**
* prodMode 模式默认为生产模式false可以使用mock模式
*/
Adapay.prodMode = false;
/**
* 初始化商户配置,服务器启动前,必须通过该方式初始化商户配置完成
* apiKey为prod模式的API KEY
* mockApiKey为mock模式的API KEY
* rsaPrivateKey为商户发起请求时用于请求参数加签所需要的RSA私钥
*/
String apiKey = "api_live_b9bff039-0598-4491-88e7-06ca6dc7289e";
String mockApiKey = "api_test_15662261-8123-4b51-95d9-ad0af60eab53";
String rsaPrivateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAOl7qJyrkrks7FKnBPr/Sngub897Ni5Bkn5pEa81zfs+4LrYsuWZQ8G1n7Q8/rjH4G/T7vPX+So41vNU74Sqn6E1b3BpW+wWBULhs9p1JSPT7Kzima4FmPigUr80NLrlVKn5bW+V4/odpN+bJWvpxdd024edHAD8mXX1M1N1lU5ZAgMBAAECgYA+mxbiM6tbFe2kV/6g4vVv9luq0cn8az7BwKCqT44U8Y5G67ZElG0zsuTI6pYOrCHFOpnXLrE0HhudEchL1YiJqW/SDKaoC4oDZf5nybhh11kOR3N5maLqvUz/WxdNy17th/2XxqVfTTu752X9yeeoXDj89N5OxyMl0jmxlhWbgQJBAPeoitR7FCxcjKtcKsEyrtV3T0H2WtQ2Pbku7CGe6VCtL4+DJNeUentn7plBj4IhbH3EwNmyCYzNlfp0X2d8fWkCQQDxWONjt1vV/dyKQYRvSVw/SWQWlR7g2OnHZokU2SNeewiCX2umCdYKh0doN0JHbSTLOGG5IA3+6Vxam+9hzPtxAkEAjr+QHf8/Vn6V+mOqpSdgjNwzS/MC0ZTeKPI52vsswnrAkjjmMHh9zMnQRnf6juhTD38sJY6wYH9TdkRDhXPFGQJATiFYe4+AS2ZDXv6WwPAezN4VaLodpOyTwdmPxxAEQzHRL2N0levZPs9MbpB1BGpw3tkBycx2u28QVsTkWeTiAQJAGRsAVr6Rhhdaq2vTjt9orhMVwt6BCoSQ0zzHSYilv4PMOtSu1Pyt4K8BDv3gjEyAi1GtE7kkJ0dcbsvOGiLzqQ==";
MerConfig merConfig = new MerConfig();
merConfig.setApiKey(apiKey);
merConfig.setApiMockKey(mockApiKey);
merConfig.setRSAPrivateKey(rsaPrivateKey);
Adapay.initWithMerConfig(merConfig);
}
}

View File

@@ -0,0 +1,134 @@
package com.jsowell.adapay.demo;
import com.alibaba.fastjson.JSON;
import com.huifu.adapay.model.AdapayTools;
import com.huifu.adapay.model.Bill;
import com.huifu.adapay.model.Wallet;
import java.util.HashMap;
import java.util.Map;
/**
* @author yingyong.wang
*/
public class AdapayToolsDemo extends BaseDemo {
/**
* 获取银联用户号
*
* @throws Exception 异常
*/
public static void executeToolsTest(String appId, String merchantKey) throws Exception {
Map<String, Object> unionParam = new HashMap<String, Object>(2);
unionParam.put("order_no", "20190912");
unionParam.put("app_id", appId);
unionParam.put("user_auth_code", "20190912");
unionParam.put("app_up_identifier", "20190912");
Map<String, Object> result = AdapayTools.unionUserId(unionParam, merchantKey);
String errorCode = (String) result.get("error_code");
if (null != errorCode) {
System.out.println("对账单下载,请求参数:" + JSON.toJSONString(unionParam));
System.out.println("对账单下载,返回参数:" + JSON.toJSONString(result));
} else {
System.out.println("对账单下载,成功");
}
}
/**
* 获取银联用户号
*
* @throws Exception 异常
*/
public static void executeToolsTest(String appId) throws Exception {
Map<String, Object> unionParam = new HashMap<String, Object>(2);
unionParam.put("order_no", "jsdk_payment_" + System.currentTimeMillis());
unionParam.put("app_id", appId);
unionParam.put("user_auth_code", "5yRGbi+IRda5khIQoQf1Hw==");
unionParam.put("app_up_identifier", "CloudPay");
Map<String, Object> result = AdapayTools.unionUserId(unionParam);
System.out.println("获取银联云闪付用户标识:" + JSON.toJSONString(result));
String errorCode = (String) result.get("error_code");
if (null != errorCode) {
System.out.println("获取银联云闪付用户标识,请求参数:" + JSON.toJSONString(unionParam));
System.out.println("获取银联云闪付用户标识,返回参数:" + JSON.toJSONString(result));
} else {
System.out.println("获取银联云闪付用户标识,成功");
}
}
/**
* 钱包登录申请
*
* @throws Exception 异常
*/
public static void executeLoginTest(String appId, String merchantKey) throws Exception {
Map<String, Object> queryParams = new HashMap<String, Object>(5);
queryParams.put("ip", "127.0.0.1");
queryParams.put("member_id", "0");
//queryParams.put("member_id", "iris1234_14151");
queryParams.put("app_id", appId);
Map<String, Object> login = Wallet.login(queryParams, merchantKey);
if (login != null && "succeeded".equals(login.get("status"))) {
String formString = login.get("redirect_url").toString();
System.out.println("跳转地址:" + formString);
}
}
/**
* 钱包登录申请
*
* @throws Exception 异常
*/
public static void executeLoginTest(String appId) throws Exception {
Map<String, Object> queryParams = new HashMap<String, Object>(5);
queryParams.put("ip", "127.0.0.1");
queryParams.put("member_id", "0");
//queryParams.put("member_id", "iris1234_14151");
queryParams.put("app_id", appId);
Map<String, Object> login = Wallet.login(queryParams);
if (login != null && "succeeded".equals(login.get("status"))) {
String formString = login.get("redirect_url").toString();
System.out.println("跳转地址:" + formString);
}
}
/**
* 执行一个下载对账文件操作
*
* @return 下载链接
* @throws Exception 异常
*/
public Map<String, Object> executeBillDownLoad() throws Exception {
Map<String, Object> downloadParam = new HashMap<String, Object>(2);
downloadParam.put("bill_date", "20190912");
Map<String, Object> download = Bill.download(downloadParam);
String errorCode = (String) download.get("error_code");
if (null != errorCode) {
System.out.println("对账单下载,请求参数:" + JSON.toJSONString(downloadParam));
System.out.println("对账单下载,返回参数:" + JSON.toJSONString(download));
} else {
System.out.println("对账单下载,成功");
}
return download;
}
}

View File

@@ -0,0 +1,7 @@
package com.jsowell.adapay.demo;
/**
* @author jane.zhao
*/
public class BaseDemo {
}

View File

@@ -0,0 +1,90 @@
package com.jsowell.adapay.demo;
import com.alibaba.fastjson.JSON;
import com.huifu.adapay.model.AdapayTools;
import com.huifu.adapay.model.Bill;
import java.util.HashMap;
import java.util.Map;
/**
* @author yingyong.wang
*/
public class BillDemo extends BaseDemo{
/**
* 运行账单下载接口
* @throws Exception 异常
*/
public static void executeBillTest(String merchantKey) throws Exception{
BillDemo demo = new BillDemo();
Map<String, Object> download = demo.executeBillDownLoad(merchantKey);
}
/**
* 运行账单下载接口
* @throws Exception 异常
*/
public static void executeBillTest() throws Exception{
BillDemo demo = new BillDemo();
Map<String, Object> download = demo.executeBillDownLoad();
}
/**
* 执行一个下载对账文件操作
* @return 下载链接
* @throws Exception 异常
*/
public Map<String, Object> executeBillDownLoad(String merchantKey) throws Exception {
System.out.println("=======execute download begin=======");
Map<String, Object> downloadParam = new HashMap<String, Object>(2);
downloadParam.put("bill_date", "20190912");
Map<String, Object> download = Bill.download(downloadParam, merchantKey);
String errorCode = (String)download.get("error_code");
if(null != errorCode){
System.out.println("对账单下载,请求参数:" + JSON.toJSONString(downloadParam));
System.out.println("对账单下载,返回参数:" + JSON.toJSONString(download));
}else{
System.out.println("对账单下载,成功");
}
return download;
}
/**
* 执行一个下载对账文件操作
* @return 下载链接
* @throws Exception 异常
*/
public Map<String, Object> executeBillDownLoad() throws Exception {
Map<String, Object> downloadParam = new HashMap<String, Object>(2);
downloadParam.put("bill_date", "20190912");
Map<String, Object> download = AdapayTools.downloadBill(downloadParam);
String errorCode = (String)download.get("error_code");
if(null != errorCode){
System.out.println("对账单下载,请求参数:" + JSON.toJSONString(downloadParam));
System.out.println("对账单下载,返回参数:" + JSON.toJSONString(download));
}else{
System.out.println("对账单下载,成功");
}
return download;
}
}

View File

@@ -0,0 +1,173 @@
package com.jsowell.adapay.demo;
import com.alibaba.fastjson.JSON;
import com.huifu.adapay.model.CorpMember;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/**
* @author yingyong.wang
*/
public class CorpMemberDemo extends BaseDemo {
/**
* 运行 CorpMember 类接口
*
* @throws Exception 异常
*/
public static void executeCorpMemberTest(String merchantKey, String app_id) throws Exception {
CorpMemberDemo demo = new CorpMemberDemo();
Map<String, Object> member = demo.executeCreateMember(merchantKey, app_id);
demo.executeQueryMember(merchantKey, (String) member.get("member_id"), app_id);
}
/**
* 创建 CorpMember
*
* @return 创建的CorpMember 对象
* @throws Exception 异常
*/
public Map<String, Object> executeCreateMember(String merchantKey, String app_id) throws Exception {
System.out.println("=======execute Create CorpMember begin=======");
Map<String, Object> memberParams = new HashMap<String, Object>(2);
memberParams.put("member_id", "jsdk_member_" + System.currentTimeMillis());
memberParams.put("app_id", app_id);
memberParams.put("order_no", "jsdk_order_" + System.currentTimeMillis());
memberParams.put("social_credit_code_expires", "1111");
memberParams.put("business_scope", "123");
memberParams.put("name", "中国测试有限公司");
memberParams.put("prov_code", "0011");
memberParams.put("area_code", "1100");
memberParams.put("social_credit_code", "201932658452655");
memberParams.put("legal_person", "张测试");
memberParams.put("legal_cert_id", "321485199014234852");
memberParams.put("legal_cert_id_expires", "20220112");
memberParams.put("legal_mp", "13958465215");
memberParams.put("address", "中国上海");
memberParams.put("zip_code", "225485");
memberParams.put("telphone", "41164452");
memberParams.put("email", "ceshi@qq.com");
memberParams.put("bank_code", "652142");
memberParams.put("bank_acct_type", "1");
memberParams.put("card_no", "622546895642156");
memberParams.put("card_name", "中国测试有限公司");
File file = new File("/Users/will/Project/Adapay/AdapayJava/AdapayDemo/src/main/java/com/huifu/adapay/demo/归档.zip");
System.out.println("创建企业用户,请求参数:" + JSON.toJSONString(memberParams) );
Map<String, Object> member = CorpMember.create(memberParams, file, merchantKey);
System.out.println("创建企业用户,返回参数:" + JSON.toJSONString(member) );
System.out.println("=======execute Create CorpMember end=======");
return member;
}
/**
* 查询 CorpMember
*
* @param member_id 待查询的member_id
* @return 查询的 CorpMember 对象
* @throws Exception 异常
*/
public Map<String, Object> executeQueryMember(String merchantKey, String member_id,String app_id) throws Exception {
System.out.println("=======execute query CorpMember begin=======");
Map<String, Object> memberParams = new HashMap<String, Object>(2);
memberParams.put("member_id", member_id);
memberParams.put("app_id", app_id);
System.out.println("查询企业用户,请求参数:"+JSON.toJSONString(memberParams));
Map<String, Object> member = CorpMember.query(memberParams, merchantKey);
System.out.println("查询企业用户,返回参数:"+JSON.toJSONString(member));
System.out.println("=======execute query CorpMember end=======");
return member;
}
/**
* 运行 CorpMember 类接口
*
* @throws Exception 异常
*/
public static void executeCorpMemberTest( String app_id) throws Exception {
CorpMemberDemo demo = new CorpMemberDemo();
Map<String, Object> member = demo.executeCreateMember( app_id);
demo.executeQueryMember( (String) member.get("member_id"), app_id);
}
/**
* 创建 CorpMember
*
* @return 创建的CorpMember 对象
* @throws Exception 异常
*/
public Map<String, Object> executeCreateMember( String app_id) throws Exception {
System.out.println("=======execute Create CorpMember begin=======");
Map<String, Object> memberParams = new HashMap<String, Object>(2);
memberParams.put("member_id", "jsdk_member_" + System.currentTimeMillis());
memberParams.put("app_id", app_id);
memberParams.put("order_no", "jsdk_order_" + System.currentTimeMillis());
memberParams.put("social_credit_code_expires", "1111");
memberParams.put("business_scope", "123");
memberParams.put("name", "中国测试有限公司");
memberParams.put("prov_code", "0011");
memberParams.put("area_code", "1100");
memberParams.put("social_credit_code", "201932658452655");
memberParams.put("legal_person", "张测试");
memberParams.put("legal_cert_id", "321485199014234852");
memberParams.put("legal_cert_id_expires", "20220112");
memberParams.put("legal_mp", "13958465215");
memberParams.put("address", "中国上海");
memberParams.put("zip_code", "225485");
memberParams.put("telphone", "41164452");
memberParams.put("email", "ceshi@qq.com");
memberParams.put("bank_code", "652142");
memberParams.put("bank_acct_type", "1");
memberParams.put("card_no", "622546895642156");
memberParams.put("card_name", "中国测试有限公司");
String path= CorpMemberDemo.class.getClassLoader().getResource("").getPath()+"test.zip";
File file = new File(path);
System.out.println("创建企业用户,请求参数:" + JSON.toJSONString(memberParams) );
Map<String, Object> member = CorpMember.create(memberParams, file);
System.out.println("创建企业用户,返回参数:" + JSON.toJSONString(member) );
System.out.println("=======execute Create CorpMember end=======");
return member;
}
/**
* 查询 CorpMember
*
* @param member_id 待查询的member_id
* @return 查询的 CorpMember 对象
* @throws Exception 异常
*/
public Map<String, Object> executeQueryMember( String member_id,String app_id) throws Exception {
System.out.println("=======execute query CorpMember begin=======");
Map<String, Object> memberParams = new HashMap<String, Object>(2);
memberParams.put("member_id", member_id);
memberParams.put("app_id", app_id);
System.out.println("查询企业用户请求参数1"+JSON.toJSONString(memberParams));
Map<String, Object> member = CorpMember.query(memberParams);
System.out.println("查询企业用户,返回参数:"+JSON.toJSONString(member));
System.out.println("=======execute query CorpMember end=======");
return member;
}
}

View File

@@ -0,0 +1,122 @@
package com.jsowell.adapay.demo;
import com.alibaba.fastjson.JSON;
import com.huifu.adapay.model.FastPay;
import java.util.HashMap;
import java.util.Map;
/**
* @author gxw
* @date 2020-12-04
*/
public class FastPayDemo extends BaseDemo{
/**
* 运行 member 类接口
* @throws Exception 异常
*/
public static Map<String, Object> executeCardTest(String app_id) throws Exception{
FastPayDemo fastPayDemo = new FastPayDemo();
Map<String, Object> result = new HashMap<>();
result = fastPayDemo.executeCardApply(app_id);
result = fastPayDemo.executeCardConfirm(app_id);
result = fastPayDemo.executeCardList(app_id);
result = fastPayDemo.executeConfirm(app_id);
result = fastPayDemo.executeSendSms(app_id);
return result;
}
/**
* 创建快捷绑卡
* @return 创建快捷绑卡 对象
* @throws Exception 异常
*/
public Map<String, Object> executeCardApply(String app_id) throws Exception {
System.out.println("=======execute executeCardApply begin=======");
Map<String, Object> applyParam = new HashMap<String, Object>();
applyParam.put("app_id", app_id);
applyParam.put("member_id", "member_id_test");
applyParam.put("card_id", "666666666666666666666666");
applyParam.put("tel_no", "13888888888");
applyParam.put("vip_code", "321");
applyParam.put("expiration", "0225");
Map<String, Object> result = FastPay.cardApply(applyParam);
System.out.println("=======execute executeCardApply end=======");
return result;
}
/**
* 创建快捷绑卡确认
* @return 创建快捷绑卡确认 对象
* @throws Exception 异常
*/
public Map<String, Object> executeCardConfirm(String app_id) throws Exception {
System.out.println("=======execute executeCardConfirm begin=======");
Map<String, Object> confirmParam = new HashMap<String, Object>();
confirmParam.put("apply_id", app_id);
confirmParam.put("sms_code", "123456");
confirmParam.put("notify_url", "https://xxxx.com/xxxx");
Map<String, Object> result = FastPay.cardConfirm(confirmParam);
System.out.println("创建用户,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute executeCardConfirm end=======");
return result;
}
/**
* 查询快捷卡对象列表
* @return 查询快捷卡对象列表
* @throws Exception 异常
*/
public Map<String, Object> executeCardList( String app_id) throws Exception {
System.out.println("=======execute executeCardList begin=======");
Map<String, Object> listParam = new HashMap<String, Object>();
listParam.put("app_id", app_id);
listParam.put("member_id", "member_id_test");
listParam.put("token_no", "10000067502");
Map<String, Object> result = FastPay.cardList(listParam);
System.out.println("查询用户,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute executeCardList end=======");
return result;
}
/**
* 创建支付对象
* @return 创建支付对象
* @throws Exception 异常
*/
public Map<String, Object> executeConfirm( String app_id) throws Exception {
System.out.println("=======execute executeConfirm begin=======");
Map<String, Object> confirmParams = new HashMap<String, Object>();
confirmParams.put("payment_id", "002112020012010545810065165317376983040");
confirmParams.put("sms_code", "123456");
confirmParams.put("app_id", app_id);
Map<String, Object> result = FastPay.confirm(confirmParams);
System.out.println("=======execute executeConfirm end=======");
return result;
}
/**
* 创建快捷支付短信重发
* @return 创建快捷支付短信重发
* @throws Exception 异常
*/
public Map<String, Object> executeSendSms( String app_id) throws Exception {
System.out.println("=======execute executeSendSms begin=======");
Map<String, Object> smsCodeParam = new HashMap<String, Object>();
smsCodeParam.put("payment_id", "20190912");
Map<String, Object> result = FastPay.smsCode(smsCodeParam);
System.out.println("=======execute executeSendSms end=======");
return result;
}
}

View File

@@ -0,0 +1,165 @@
package com.jsowell.adapay.demo;
import com.huifu.adapay.Adapay;
import com.huifu.adapay.model.MerConfig;
import java.util.HashMap;
import java.util.Map;
/**
* @author jane.zhao
*/
public class MainDemo {
public static void main(String[] args) throws Exception {
//若是商户只是自己对接adapay请使用如下demo
testMerchant();
//若是技术性渠道商为其它商户提供服务功能,请使用多商户模式
// testMultiMerchant();
}
public static void testMerchant() throws Exception {
/**
* 初始化完成,可以开始交易
*/
String appId = "app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa";
// 运行支付类接口
// String pamentId = PaymentDemo.executePaymentTest(appId);
// 带区域和超时参数的支付请求Demo
String pamentId = PaymentRegionAndRequestTimeOutDemo.executePaymentTest(appId);
// //运行退款类接口
// RefundDemo.executeRefundTest("002112020010618571810060213271697731584");
// /**用户类接口*/
Map<String, Object> member = MemberDemo.executeMemberTest(appId);
String memberId = (String) member.get("member_id");
// /** 结算户绑定*/
SettleAccountDemo.executeSettleAccountTest("app_7d87c043-aae3-4357-9b2c-269349a980d6", memberId);
/**企业开户*/
CorpMemberDemo.executeCorpMemberTest("app_7d87c043-aae3-4357-9b2c-269349a980d6");
/**
* 对账单下载
*/
// BillDemo.executeBillTest();
// /**
// * 获取云闪付用户号
// */
// AdapayToolsDemo.executeToolsTest(appId);
// /**
// * 余额查询
// */
// SettleAccountDemo.executeQueryBalance(appId, "member_id", "settleCount_id");
// /**
// *用户取现
// */
// SettleAccountDemo.executeDrawCash(appId, "member_id");
// /**
// * 钱包登录申请
// */
// AdapayToolsDemo.executeLoginTest(appId,"member_id");
//银行卡管理
//FastPayDemo.executeCardTest(appId);
}
public static void testMultiMerchant() throws Exception {
/**
* debug 模式,开启后与详细的日志
*/
Adapay.debug = true;
/**
* prodMode 模式默认为生产模式false可以使用mock模式
*/
Adapay.prodMode = true;
/**
* 初始化每个商户配置,服务器启动前,必须通过该方式初始化商户配置完成
* apiKey为prod模式的API KEY
* mockApiKey为mock模式的API KEY
* rsaPrivateKey为商户发起请求时用于请求参数加签所需要的RSA私钥
*/
// 创建商户A的商户配置对象
Map<String, MerConfig> configPathMap = new HashMap<>();
String apiKeyA = "api_live_9c14f264-e390-41df-984d-df15a6952031";
String mockApiKeyA = "api_test_e640fa26-bbe6-458f-ac44-a71723ee2176";
String rsaPrivateKeyA = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMQhsygJ2pp4nCiDAXiqnZm6AzKSVAh+C0BgGR6QaeXzt0TdSi9VR0OQ7Qqgm92NREB3ofobXvxxT+wImrDNk6R6lnHPMTuJ/bYpm+sx397rPboRAXpV3kalQmbZ3P7oxtEWOQch0zV5B1bgQnTvxcG3REAsdaUjGs9Xvg0iDS2tAgMBAAECgYAqGFmNdF/4234Yq9V7ApOE1Qmupv1mPTdI/9ckWjaAZkilfSFY+2KqO8bEiygo6xMFCyg2t/0xDVjr/gTFgbn4KRPmYucGG+FzTRLH0nVIqnliG5Ekla6a4gwh9syHfstbOpIvJR4DfldicZ5n7MmcrdEwSmMwXrdinFbIS/P1+QJBAOr6NpFtlxVSGzr6haH5FvBWkAsF7BM0CTAUx6UNHb+RCYYQJbk8g3DLp7/vyio5uiusgCc04gehNHX4laqIdl8CQQDVrckvnYy+NLz+K/RfXEJlqayb0WblrZ1upOdoFyUhu4xqK0BswOh61xjZeS+38R8bOpnYRbLf7eoqb7vGpZ9zAkEAobhdsA99yRW+WgQrzsNxry3Ua1HDHaBVpnrWwNjbHYpDxLn+TJPCXvI7XNU7DX63i/FoLhOucNPZGExjLYBH/wJATHNZQAgGiycjV20yicvgla8XasiJIDP119h4Uu21A1Su8G15J2/9vbWn1mddg1pp3rwgvxhw312oInbHoFMxsQJBAJlyDDu6x05MeZ2nMor8gIokxq2c3+cnm4GYWZgboNgq/BknbIbOMBMoe8dJFj+ji3YNTvi1MSTDdSDqJuN/qS0=";
MerConfig merConfigA = new MerConfig();
merConfigA.setApiKey(apiKeyA);
merConfigA.setApiMockKey(mockApiKeyA);
merConfigA.setRSAPrivateKey(rsaPrivateKeyA);
// 定义一个商户的A的唯一标识交易发起时用于定位是哪个商户发起交易
configPathMap.put("商户A的唯一标识", merConfigA);
// 创建商户B的商户配置对象
String apiKeyB = "api_live_9c14f264-e390-41df-984d-df15a6952031";
String mockApiKeyB = "api_test_e640fa26-bbe6-458f-ac44-a71723ee2176";
String rsaPrivateKeyB = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMQhsygJ2pp4nCiDAXiqnZm6AzKSVAh+C0BgGR6QaeXzt0TdSi9VR0OQ7Qqgm92NREB3ofobXvxxT+wImrDNk6R6lnHPMTuJ/bYpm+sx397rPboRAXpV3kalQmbZ3P7oxtEWOQch0zV5B1bgQnTvxcG3REAsdaUjGs9Xvg0iDS2tAgMBAAECgYAqGFmNdF/4234Yq9V7ApOE1Qmupv1mPTdI/9ckWjaAZkilfSFY+2KqO8bEiygo6xMFCyg2t/0xDVjr/gTFgbn4KRPmYucGG+FzTRLH0nVIqnliG5Ekla6a4gwh9syHfstbOpIvJR4DfldicZ5n7MmcrdEwSmMwXrdinFbIS/P1+QJBAOr6NpFtlxVSGzr6haH5FvBWkAsF7BM0CTAUx6UNHb+RCYYQJbk8g3DLp7/vyio5uiusgCc04gehNHX4laqIdl8CQQDVrckvnYy+NLz+K/RfXEJlqayb0WblrZ1upOdoFyUhu4xqK0BswOh61xjZeS+38R8bOpnYRbLf7eoqb7vGpZ9zAkEAobhdsA99yRW+WgQrzsNxry3Ua1HDHaBVpnrWwNjbHYpDxLn+TJPCXvI7XNU7DX63i/FoLhOucNPZGExjLYBH/wJATHNZQAgGiycjV20yicvgla8XasiJIDP119h4Uu21A1Su8G15J2/9vbWn1mddg1pp3rwgvxhw312oInbHoFMxsQJBAJlyDDu6x05MeZ2nMor8gIokxq2c3+cnm4GYWZgboNgq/BknbIbOMBMoe8dJFj+ji3YNTvi1MSTDdSDqJuN/qS0=";
MerConfig merConfigB = new MerConfig();
merConfigB.setApiKey(apiKeyB);
merConfigB.setApiMockKey(mockApiKeyB);
merConfigB.setRSAPrivateKey(rsaPrivateKeyB);
// 定义一个商户的B的唯一标识交易发起时用于定位是哪个商户发起交易
configPathMap.put("商户B的唯一标识", merConfigB);
// 将商户A和B的商户配置放入本地缓存
Adapay.initWithMerConfigs(configPathMap);
/**
* 商户配置初始化完成后,可以发起交易
*/
// 运行支付类接口其中app_id必须是商户A下的app_id
String pamentId = PaymentDemo.executePaymentTest("商户A的唯一标识", "app_7d87c043-aae3-4357-9b2c-269349a980d6");
// String pamentI2 = PaymentDemo.executePaymentTest("yidian", "app_67ba475b-26e0-4cfa-847c-0f115cae5029");
// //运行退款类接口
// RefundDemo.executeRefundTest("yifuyun", "002112019101420422510029799145265012736");
// RefundDemo.executeRefundTest("yifuyun", "002112019101420422610029799148904755200");
// /**
// * 分账使用配套接口 begin
// */
// /**用户类接口*/
// Map<String, Object> member = MemberDemo.executeMemberTest("yifuyun", "app_67ba475b-26e0-4cfa-847c-0f115cae5029");
// String memberId = (String) member.get("member_id");
// /** 结算户绑定*/
// SettleAccountDemo.executeSettleAccountTest("yidian", "app_67ba475b-26e0-4cfa-847c-0f115cae5029", memberId);
// /**企业开户*/
// CorpMemberDemo.executeCorpMemberTest("yidian", "app_67ba475b-26e0-4cfa-847c-0f115cae5029");
// /**
// * 分账使用配套接口 end
// */
// //对账单下载
// BillDemo.executeBillTest("yifuyun");
// String appId = "app_67ba475b-26e0-4cfa-847c-0f115cae5029";
// /**
// * 获取云闪付用户号
// */
// AdapayToolsDemo.executeToolsTest(appId, "yifuyun");
// /**
// * 余额查询
// */
// SettleAccountDemo.executeQueryBalance("yifuyun", appId, "member_id", "settleCount_id");
// /**
// *用户取现
// */
// SettleAccountDemo.executeDrawCash("yifuyun", appId, "member_id");
// /**
// * 钱包登录申请
// */
// AdapayToolsDemo.executeLoginTest(appId,"yifuyun");
}
}

View File

@@ -0,0 +1,244 @@
package com.jsowell.adapay.demo;
import com.alibaba.fastjson.JSON;
import com.huifu.adapay.model.Member;
import java.util.HashMap;
import java.util.Map;
/**
* @author yingyong.wang
*/
public class MemberDemo extends BaseDemo{
/**
* 运行 member 类接口
* @throws Exception 异常
*/
public static Map<String, Object> executeMemberTest(String merchantKey, String app_id) throws Exception{
MemberDemo demo = new MemberDemo();
Map<String, Object> member = demo.executeCreateMember(merchantKey, app_id);
demo.executeQueryMember(merchantKey, (String)member.get("member_id"),app_id);
demo.executeUpdateMember(merchantKey, (String)member.get("member_id"),app_id);
demo.executeQueryMember(merchantKey, (String)member.get("member_id"),app_id);
demo.executeListMember(merchantKey, app_id);
return member;
}
/**
* 创建 member
* @return 创建的member 对象
* @throws Exception 异常
*/
public Map<String, Object> executeCreateMember(String merchantKey, String app_id) throws Exception {
System.out.println("=======execute CreateMember begin=======");
Map<String, Object> memberParams = new HashMap<String, Object>(2);
memberParams.put("member_id", "jsdk_member_"+System.currentTimeMillis());
memberParams.put("app_id",app_id);
memberParams.put("location", "上海市徐汇区宜山路");
memberParams.put("email", "123@163.com");
memberParams.put("gender", "MALE");
memberParams.put("tel_no", "13153333333");
memberParams.put("nickname", "nick_name");
System.out.println("创建用户,请求参数:" + JSON.toJSONString(memberParams));
Map<String, Object> member = Member.create(memberParams, merchantKey);
System.out.println("创建用户,返回参数:" + JSON.toJSONString(member));
System.out.println("=======execute CreateMember end=======");
return member;
}
/**
* 查询 member
* @param member_id 待查询的member_id
* @return 创建的member 对象
* @throws Exception 异常
*/
public Map<String, Object> executeQueryMember(String merchantKey, String member_id,String app_id) throws Exception {
System.out.println("=======execute queryMember begin=======");
Map<String, Object> memberParams = new HashMap<String, Object>(2);
memberParams.put("member_id", member_id);
memberParams.put("app_id", app_id);
System.out.println("查询用户,请求参数:" + JSON.toJSONString(memberParams));
Map<String, Object> member = Member.query(memberParams, merchantKey);
System.out.println("查询用户,返回参数:" + JSON.toJSONString(member));
System.out.println("=======execute queryMember end=======");
return member;
}
/**
* 更新 member
* @param member_id 待更新的member_id
* @return 更新的member 对象
* @throws Exception 异常
*/
public Map<String, Object> executeUpdateMember(String merchantKey, String member_id,String app_id) throws Exception {
System.out.println("=======execute update Member begin=======");
Map<String, Object> memberParams = new HashMap<String, Object>(2);
memberParams.put("member_id", member_id);
memberParams.put("app_id", app_id);
memberParams.put("location", "上海市徐汇区宜山路1");
memberParams.put("email", "1234@163.com");
memberParams.put("gender", "MALE");
memberParams.put("tel_no", "13153333333");
memberParams.put("nickname", "nick_name2");
System.out.println("更新用户,请求参数:"+JSON.toJSONString(memberParams));
Map<String, Object> member = Member.update(memberParams, merchantKey);
System.out.println("更新用户,返回参数:"+JSON.toJSONString(member));
System.out.println("=======execute update Member end=======");
return member;
}
/**
* 查询 member list
* @param app_id app_id
* @return 查询的member list
* @throws Exception 异常
*/
public Map<String, Object> executeListMember(String merchantKey, String app_id) throws Exception {
System.out.println("=======execute list Member begin=======");
Map<String, Object> memberParams = new HashMap<String, Object>(2);
memberParams.put("page_index", "1");
memberParams.put("app_id", app_id);
memberParams.put("page_size", "20");
memberParams.put("created_gte", String.valueOf(System.currentTimeMillis() - 5 * 60 * 1000));
memberParams.put("created_lte", String.valueOf(System.currentTimeMillis()));
System.out.println("查询用户列表,请求参数:"+JSON.toJSONString(memberParams));
Map<String, Object> member = Member.queryList(memberParams, merchantKey);
System.out.println("查询用户列表,返回参数:"+JSON.toJSONString(member));
System.out.println("=======execute list Member end=======");
return member;
}
/**
* 运行 member 类接口
* @throws Exception 异常
*/
public static Map<String, Object> executeMemberTest( String app_id) throws Exception{
MemberDemo demo = new MemberDemo();
Map<String, Object> member = demo.executeCreateMember( app_id);
demo.executeQueryMember( (String)member.get("member_id"),app_id);
demo.executeUpdateMember( (String)member.get("member_id"),app_id);
demo.executeQueryMember( (String)member.get("member_id"),app_id);
demo.executeListMember( app_id);
return member;
}
/**
* 创建 member
* @return 创建的member 对象
* @throws Exception 异常
*/
public Map<String, Object> executeCreateMember( String app_id) throws Exception {
System.out.println("=======execute CreateMember begin=======");
Map<String, Object> memberParams = new HashMap<String, Object>(2);
memberParams.put("member_id", "jsdk_member_"+System.currentTimeMillis());
memberParams.put("app_id",app_id);
memberParams.put("location", "上海市徐汇区宜山路");
memberParams.put("email", "123@163.com");
memberParams.put("gender", "MALE");
memberParams.put("tel_no", "13153333333");
memberParams.put("nickname", "nick_name");
System.out.println("创建用户,请求参数:" + JSON.toJSONString(memberParams));
Map<String, Object> member = Member.create(memberParams);
System.out.println("创建用户,返回参数:" + JSON.toJSONString(member));
System.out.println("=======execute CreateMember end=======");
return member;
}
/**
* 查询 member
* @param member_id 待查询的member_id
* @return 创建的member 对象
* @throws Exception 异常
*/
public Map<String, Object> executeQueryMember( String member_id,String app_id) throws Exception {
System.out.println("=======execute queryMember begin=======");
Map<String, Object> memberParams = new HashMap<String, Object>(2);
memberParams.put("member_id", member_id);
memberParams.put("app_id", app_id);
System.out.println("查询用户,请求参数:" + JSON.toJSONString(memberParams));
Map<String, Object> member = Member.query(memberParams);
System.out.println("查询用户,返回参数:" + JSON.toJSONString(member));
System.out.println("=======execute queryMember end=======");
return member;
}
/**
* 更新 member
* @param member_id 待更新的member_id
* @return 更新的member 对象
* @throws Exception 异常
*/
public Map<String, Object> executeUpdateMember( String member_id,String app_id) throws Exception {
System.out.println("=======execute update Member begin=======");
Map<String, Object> memberParams = new HashMap<String, Object>(2);
memberParams.put("member_id", member_id);
memberParams.put("app_id", app_id);
memberParams.put("location", "上海市徐汇区宜山路1");
memberParams.put("email", "1234@163.com");
memberParams.put("gender", "MALE");
memberParams.put("tel_no", "13153333333");
memberParams.put("nickname", "nick_name2");
System.out.println("更新用户,请求参数:"+JSON.toJSONString(memberParams));
Map<String, Object> member = Member.update(memberParams);
System.out.println("更新用户,返回参数:"+JSON.toJSONString(member));
System.out.println("=======execute update Member end=======");
return member;
}
/**
* 查询 member list
* @param app_id app_id
* @return 查询的member list
* @throws Exception 异常
*/
public Map<String, Object> executeListMember( String app_id) throws Exception {
System.out.println("=======execute list Member begin=======");
Map<String, Object> memberParams = new HashMap<String, Object>(2);
memberParams.put("page_index", "1");
memberParams.put("app_id", app_id);
memberParams.put("page_size", "20");
memberParams.put("created_gte", String.valueOf(System.currentTimeMillis() - 5 * 60 * 1000));
memberParams.put("created_lte", String.valueOf(System.currentTimeMillis()));
System.out.println("查询用户列表,请求参数:"+JSON.toJSONString(memberParams));
Map<String, Object> member = Member.queryList(memberParams);
System.out.println("查询用户列表,返回参数:"+JSON.toJSONString(member));
System.out.println("=======execute list Member end=======");
return member;
}
}

View File

@@ -0,0 +1,964 @@
package com.jsowell.adapay.demo;
import com.alibaba.fastjson.JSON;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Checkout;
import com.huifu.adapay.model.Payment;
import com.huifu.adapay.model.PaymentConfirm;
import com.huifu.adapay.model.PaymentReverse;
import java.util.HashMap;
import java.util.Map;
/**
* @author jane.zhao
*/
public class PaymentDemo extends BaseDemo {
/**
* 运行支付类接口
*
* @return paymentId
* @throws Exception 异常
*/
public static String executePaymentTest(String merchantKey, String app_id) throws Exception {
PaymentDemo demo = new PaymentDemo();
//支付接口
Map<String, Object> payment = demo.executePayment(merchantKey, app_id);
payment = demo.executeDelayPayment(merchantKey, app_id);
// payment = demo.createReverse(merchantKey, "002112019102420545010033426145952493568",app_id);
// payment = demo.queryReverse(merchantKey,"002112019102420545010033426145952493568", app_id);
// payment = demo.queryReverseList(merchantKey,"002112019102420545010033426145952493568", app_id);
// payment = demo.createConfirm(merchantKey,"002112019102420545010033426145952493568", app_id);
// payment = demo.queryConfirm(merchantKey,"002112019102420545010033426145952493568", app_id);
// payment = demo.queryConfirmList(merchantKey, "002112019102420545010033426145952493568",app_id);
//payment = demo.executePagePayment(merchantKey, app_id);
payment = demo.executeCheckOutPayment(merchantKey, app_id);
System.out.println("钱包支付地址:" + payment.get("pay_url"));
payment = demo.queryList(merchantKey,app_id);
//支付查询接口
demo.queryPayment(merchantKey, (String) payment.get("id"));
// //关单接口
demo.closePayment(merchantKey, (String) payment.get("id"));
return (String) payment.get("id");
}
/**
* 运行支付类接口
*
* @return paymentId
* @throws Exception 异常
*/
public static String executePaymentTest(String app_id) throws Exception {
PaymentDemo demo = new PaymentDemo();
//支付接口
Map<String, Object> payment = demo.executePayment(app_id);
// payment = demo.executeDelayPayment( app_id);
// payment = demo.createReverse("002112019102420545010033426145952493568", app_id);
// payment = demo.queryReverse("002112019102420545010033426145952493568", app_id);
// payment = demo.queryReverseList("002112019102420545010033426145952493568", app_id);
// payment = demo.createConfirm("002112019102420545010033426145952493568", app_id);
// payment = demo.queryConfirm("002112019102420545010033426145952493568", app_id);
// payment = demo.queryConfirmList("002112019102420545010033426145952493568", app_id);
//
// payment = demo.executePagePayment(app_id);
// payment = demo.executeCheckOutPayment(app_id);
// payment = demo.queryCheckoutList("002112019102420545010033426145952493568",app_id);
//
// System.out.println("钱包支付地址:" + payment.get("pay_url"));
//
// //支付查询接口
// demo.queryPayment((String) payment.get("id"));
// // //关单接口
// demo.closePayment((String) payment.get("id"));
return (String) payment.get("id");
}
/**
* 执行一个支付交易
*
* @return 创建的支付对象
* @throws Exception 异常
*/
public Map<String, Object> executeDelayPayment(String merchantKey, String app_id) throws Exception {
System.out.println("=======execute payment begin=======");
//创建支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/index.html
Map<String, Object> paymentParams = new HashMap<>(10);
paymentParams.put("app_id", app_id);
paymentParams.put("order_no", "jsdk_payment_" + System.currentTimeMillis());
paymentParams.put("pay_channel", "alipay");
paymentParams.put("pay_amt", "0.01");
paymentParams.put("goods_title", "your goods title");
paymentParams.put("goods_desc", "your goods desc");
paymentParams.put("div_members", "");
paymentParams.put("pay_mode", "delay");
//调用sdk方法创建支付得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
payment = Payment.create(paymentParams, merchantKey);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
String error_code = (String) payment.get("error_code");
if (null != error_code) {
String error_msg = (String) payment.get("error_msg");
System.out.println("error_code:" + error_code + "............." + error_msg);
}
return payment;
}
/**
* 执行一个支付交易
*
* @return 创建的支付对象
* @throws Exception 异常
*/
public Map<String, Object> executePayment(String merchantKey, String app_id) throws Exception {
System.out.println("=======execute payment begin=======");
//创建支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/index.html
Map<String, Object> paymentParams = new HashMap<>(10);
paymentParams.put("app_id", app_id);
paymentParams.put("order_no", "jsdk_payment_" + System.currentTimeMillis());
paymentParams.put("pay_channel", "alipay");
paymentParams.put("pay_amt", "0.01");
paymentParams.put("goods_title", "your goods title");
paymentParams.put("goods_desc", "your goods desc");
paymentParams.put("div_members", "");
Map<String, Object> deviceInfo = new HashMap<>(2);
deviceInfo.put("device_ip", "127.0.0.1");
deviceInfo.put("device_mac", "交易设备 MAC");
deviceInfo.put("device_type", "1");
deviceInfo.put("device_imei", "交易设备 IMEI");
deviceInfo.put("device_imsi", "交易设备 IMSI");
deviceInfo.put("device_iccId", "ICCID");
deviceInfo.put("device_wifi_mac", "WIFIMAC");
paymentParams.put("device_info", deviceInfo);
Map<String, Object> expendParams = new HashMap<>(2);
String openId = "";//微信授权获取
expendParams.put("open_id", openId);
expendParams.put("is_raw", "1");
expendParams.put("callback_url", "绝对路径");
expendParams.put("limit_pay", "1");
paymentParams.put("expend", expendParams);
//调用sdk方法创建支付得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
payment = Payment.create(paymentParams, merchantKey);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
String error_code = (String) payment.get("error_code");
if (null != error_code) {
System.out.println("创建支付返回参数:" + JSON.toJSONString(payment));
String error_msg = (String) payment.get("error_msg");
System.out.println("error_code:" + error_code + "............." + error_msg);
}
return payment;
}
/**
* 关闭一个支付交易
*
* @param paymentId 要关闭的支付id
* @return 关闭的支付对象
* @throws Exception 异常
*/
public Map<String, Object> closePayment(String merchantKey, String paymentId) throws Exception {
System.out.println("=======close payment begin=======");
//关闭支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/index.html
//调用sdk方法关闭支付得到支付对象
Map<String, Object> payment = new HashMap<>();
Map<String, Object> paymentParams = new HashMap<>(10);
paymentParams.put("payment_id", paymentId);
try {
paymentParams.put("payment_id", paymentId);
paymentParams.put("reason", "reason");
paymentParams.put("expend", "expend");
paymentParams.put("notify_url", "notify_url");
System.out.println("关单请求参数:" + JSON.toJSONString(paymentId));
payment = Payment.close(paymentParams, merchantKey);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
String error_code = (String) payment.get("error_code");
if (null != error_code) {
System.out.println("关单返回参数:" + JSON.toJSONString(payment));
String error_msg = (String) payment.get("error_msg");
System.out.println("error_code:" + error_code + "............." + error_msg);
}
return payment;
}
/**
* 查询一个支付交易
*
* @param paymentId 要查询的支付id
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> queryPayment(String merchantKey, String paymentId) throws Exception {
System.out.println("=======query payment begin=======");
//查询支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/index.html
//调用sdk方法查询支付交易得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
System.out.println("支付查询请求参数:" + JSON.toJSONString(paymentId));
payment = Payment.query(paymentId, merchantKey);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("支付查询返回参数:" + JSON.toJSONString(payment));
String error_code = (String) payment.get("error_code");
if (null == error_code) {
String error_msg = (String) payment.get("error_msg");
System.out.println("error_code:" + error_code + "............." + error_msg);
}
System.out.println("=======query payment end=======");
return payment;
}
/**
* 创建撤销对象
*
* @param paymentId 要查询的支付id
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> createReverse(String merchantKey, String paymentId, String app_id) throws Exception {
System.out.println("=======create Reverse begin=======");
Map<String, Object> reverse = new HashMap<>();
reverse.put("payment_id", paymentId);
reverse.put("app_id", app_id);
reverse.put("order_no", "jsdk_reverse_" + System.currentTimeMillis());
reverse.put("app_id", app_id);
reverse.put("notify_url", "");
reverse.put("reverse_amt", "0.01");
reverse.put("reason", "reason");
reverse.put("expand", "expend");
reverse.put("device_info", "device_info");
try {
System.out.println("创建撤销对象" + JSON.toJSONString(reverse));
reverse = PaymentReverse.create(reverse, merchantKey);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("创建撤销对象返回参数:" + JSON.toJSONString(reverse));
String error_code = (String) reverse.get("error_code");
if (null == error_code) {
String error_msg = (String) reverse.get("error_msg");
System.out.println("error_code:" + error_code + "............." + error_msg);
}
System.out.println("=======create Reverse end=======");
return reverse;
}
/**
* 查询撤销对象
*
* @param reverse_id 要查询的支付id
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> queryReverse(String merchantKey, String reverse_id, String app_id) throws Exception {
System.out.println("=======query Reverse begin=======");
Map<String, Object> reverse = new HashMap<>();
reverse.put("reverse_id", reverse_id);
try {
System.out.println("查询撤销对象请求参数:" + JSON.toJSONString(reverse));
reverse = PaymentReverse.query(reverse, merchantKey);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
String error_code = (String) reverse.get("error_code");
if (null == error_code) {
String error_msg = (String) reverse.get("error_msg");
System.out.println("error_code:" + error_code + "............." + error_msg);
}
System.out.println("查询撤销对象返回参数:" + JSON.toJSONString(reverse));
System.out.println("=======query Reverse end=======");
return reverse;
}
/**
* 查询撤销对象列表
*
* @param
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> queryReverseList(String merchantKey, String payment_id, String app_id) throws Exception {
System.out.println("=======query Reverse list begin=======");
Map<String, Object> reverse = new HashMap<>();
reverse.put("payment_id", payment_id);
reverse.put("app_id", app_id);
reverse.put("page_index", "1");
reverse.put("page_size", "20");
reverse.put("created_gte", "1571913923");
reverse.put("created_lte", "1571913924");
try {
System.out.println("查询撤销对象列表请求参数:" + JSON.toJSONString(reverse));
reverse = PaymentReverse.queryList(reverse, merchantKey);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
String error_code = (String) reverse.get("error_code");
if (null == error_code) {
String error_msg = (String) reverse.get("error_msg");
System.out.println("error_code:" + error_code + "............." + error_msg);
}
System.out.println("查询撤销对象列表返回参数:" + JSON.toJSONString(reverse));
System.out.println("=======query Reverse list end=======");
return reverse;
}
/**
* 创建确认对象
*
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> createConfirm(String merchantKey, String paymentId, String app_id) throws Exception {
System.out.println("=======create confirm begin=======");
Map<String, Object> confirm = new HashMap<>();
confirm.put("payment_id", paymentId);
confirm.put("order_no", "jsdk_confirm_" + System.currentTimeMillis());
confirm.put("confirm_amt", "0.01");
confirm.put("description", "description");
confirm.put("div_members", "");
try {
System.out.println("创建确认对象" + JSON.toJSONString(confirm));
confirm = PaymentConfirm.create(confirm, merchantKey);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
String error_code = (String) confirm.get("error_code");
if (null == error_code) {
String error_msg = (String) confirm.get("error_msg");
System.out.println("error_code:" + error_code + "............." + error_msg);
}
System.out.println("创建确认对象返回参数:" + JSON.toJSONString(confirm));
System.out.println("=======create confirm end=======");
return confirm;
}
/**
* 查询撤销对象
*
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> queryConfirm(String merchantKey, String payment_confirm_id, String app_id) throws Exception {
System.out.println("=======query confirm begin=======");
Map<String, Object> confirm = new HashMap<>();
confirm.put("payment_confirm_id", payment_confirm_id);
try {
System.out.println("查询确认对象请求参数:" + JSON.toJSONString(confirm));
confirm = PaymentConfirm.query(confirm, merchantKey);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
String error_code = (String) confirm.get("error_code");
if (null == error_code) {
String error_msg = (String) confirm.get("error_msg");
System.out.println("error_code:" + error_code + "............." + error_msg);
}
System.out.println("查询撤销对象返回参数:" + JSON.toJSONString(confirm));
System.out.println("=======query confirm end=======");
return confirm;
}
/**
* 查询确认对象列表
*
* @param
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> queryConfirmList(String merchantKey, String payment_id, String app_id) throws Exception {
System.out.println("=======query confirm list begin=======");
Map<String, Object> confirm = new HashMap<>();
confirm.put("payment_id", payment_id);
confirm.put("app_id", app_id);
confirm.put("page_index", "1");
confirm.put("page_size", "20");
confirm.put("created_gte", "1571913867");
confirm.put("created_lte", "1571913923");
try {
System.out.println("查询撤销对象列表请求参数:" + JSON.toJSONString(confirm));
confirm = PaymentConfirm.queryList(confirm, merchantKey);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
String error_code = (String) confirm.get("error_code");
if (null == error_code) {
String error_msg = (String) confirm.get("error_msg");
System.out.println("error_code:" + error_code + "............." + error_msg);
}
System.out.println("查询撤销对象列表返回参数:" + JSON.toJSONString(confirm));
System.out.println("=======query Reverse list end=======");
return confirm;
}
/**
* 执行一个支付交易
*
* @return 创建的支付对象
* @throws Exception 异常
*/
public Map<String, Object> executeDelayPayment(String app_id) throws Exception {
System.out.println("=======execute payment begin=======");
//创建支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/index.html
Map<String, Object> paymentParams = new HashMap<>(10);
paymentParams.put("app_id", app_id);
paymentParams.put("order_no", "jsdk_payment_" + System.currentTimeMillis());
paymentParams.put("pay_channel", "alipay");
paymentParams.put("pay_amt", "0.10");
paymentParams.put("goods_title", "your goods title");
paymentParams.put("goods_desc", "your goods desc");
paymentParams.put("div_members", "");
paymentParams.put("pay_mode", "delay");
//调用sdk方法创建支付得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
System.out.println("支付交易,请求参数:" + JSON.toJSONString(paymentParams));
payment = Payment.create(paymentParams);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("支付交易,返回参数:" + JSON.toJSONString(payment));
String error_code = (String) payment.get("error_code");
if (null == error_code) {
String error_msg = (String) payment.get("error_msg");
System.out.println("error_code:" + error_code + "............." + error_msg);
}
System.out.println("=======execute payment end=======");
return payment;
}
/**
* 执行一个支付交易
*
* @return 创建的支付对象
* @throws Exception 异常
*/
public Map<String, Object> executePayment(String app_id) throws Exception {
System.out.println("=======execute payment begin=======");
//创建支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/index.html
Map<String, Object> paymentParams = new HashMap<>(10);
paymentParams.put("adapay_connection_request_timeout", 500);
paymentParams.put("adapay_connect_timeout", 500);
paymentParams.put("adapay_socket_timeout", 500);
paymentParams.put("adapay_region", "beijing");
paymentParams.put("app_id", app_id);
paymentParams.put("order_no", "jsdk_payment_" + System.currentTimeMillis());
paymentParams.put("pay_channel", "alipay");
paymentParams.put("pay_amt", "0.01");
paymentParams.put("goods_title", "your goods title");
paymentParams.put("goods_desc", "your goods desc");
paymentParams.put("div_members", "");
//调用sdk方法创建支付得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
System.out.println("支付交易,请求参数:" + JSON.toJSONString(paymentParams));
payment = Payment.create(paymentParams);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("支付交易,返回参数:" + JSON.toJSONString(payment));
System.out.println("=======execute payment end=======");
return payment;
}
/**
* 执行一个包支付交易
*
* @return 创建的支付对象
* @throws Exception 异常
*/
public Map<String, Object> executePagePayment(String app_id) throws Exception {
System.out.println("=======execute pagePayment begin=======");
//请参考 https://docs.adapay.tech/api/index.html
Map<String, Object> params = new HashMap<>();
params.put("order_no", System.currentTimeMillis());
params.put("pay_amt", "0.01");
params.put("currency", "cny");
params.put("goods_title", "goods");
params.put("goods_desc", "goodsdesc");
params.put("app_id", app_id);
// params.put("app_id", "app_f8b14a77-dc24-433b-864f-98a62209d6c4");
params.put("callback_url", "https://www.baidu.com/");
//调用sdk方法创建支付得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
System.out.println("钱包支付交易,请求参数:" + JSON.toJSONString(params));
payment = Payment.createPage(params);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("钱包交易,返回参数:" + JSON.toJSONString(payment));
System.out.println("=======execute pagePayment end=======");
return payment;
}
/**
* 执行一个包支付交易
*
* @return 创建的支付对象
* @throws Exception 异常
*/
public Map<String, Object> executePagePayment(String merchantKey, String app_id) throws Exception {
System.out.println("=======execute pagePayment begin=======");
//请参考 https://docs.adapay.tech/api/index.html
Map<String, Object> params = new HashMap<>();
params.put("order_no", System.currentTimeMillis());
params.put("pay_amt", "0.01");
params.put("currency", "cny");
params.put("goods_title", "goods");
params.put("goods_desc", "goodsdesc");
params.put("app_id", "app_f8b14a77-dc24-433b-864f-98a62209d6c4");
params.put("callback_url", "https://www.baidu.com/");
//调用sdk方法创建支付得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
System.out.println("钱包支付交易,请求参数:" + JSON.toJSONString(params));
payment = Payment.createPage(params, merchantKey);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("钱包交易,返回参数:" + JSON.toJSONString(payment));
System.out.println("=======execute pagePayment end=======");
return payment;
}
/**
* 执行一个收银台支付交易
*
* @return 创建的支付对象
* @throws Exception 异常
*/
public Map<String, Object> executeCheckOutPayment(String app_id) throws Exception {
System.out.println("=======execute quickPayment begin=======");
//请参考 https://docs.adapay.tech/api/index.html
Map<String, Object> params = new HashMap<>();
params.put("order_no", "jdskjdd_200000014");
params.put("member_id", "user_00013");
params.put("pay_amt", "0.01");
params.put("currency", "cny");
params.put("goods_title", "商品标题");
params.put("goods_desc", "商品描述");
params.put("app_id", "app_7d87c043-aae3-4357-9b2c-269349a980d6");
params.put("callback_url", "https://www.cnblogs.com/wanlibingfeng/p/7080581.html");
//调用sdk方法创建支付得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
System.out.println("收银台支付交易,请求参数:" + JSON.toJSONString(params));
payment = Checkout.create(params);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("收银台交易,返回参数:" + JSON.toJSONString(payment));
System.out.println("=======execute quickPayment end=======");
return payment;
}
/**
* 执行一个收银台支付交易
*
* @return 创建的支付对象
* @throws Exception 异常
*/
public Map<String, Object> executeCheckOutPayment(String merchantKey, String app_id) throws Exception {
System.out.println("=======execute quickPayment begin=======");
//请参考 https://docs.adapay.tech/api/index.html
Map<String, Object> params = new HashMap<>();
params.put("order_no", "jdskjdd_200000013");
params.put("member_id", "user_00013");
params.put("pay_amt", "0.01");
params.put("currency", "cny");
params.put("goods_title", "商品标题");
params.put("goods_desc", "商品描述");
params.put("app_id", "app_7d87c043-aae3-4357-9b2c-269349a980d6");
params.put("callback_url", "https://www.cnblogs.com/wanlibingfeng/p/7080581.html");
//调用sdk方法创建支付得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
System.out.println("收银台支付交易,请求参数:" + JSON.toJSONString(params));
payment = Checkout.create(params, merchantKey);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("收银台交易,返回参数:" + JSON.toJSONString(payment));
System.out.println("=======execute quickPayment end=======");
return payment;
}
/**
* 关闭一个支付交易
*
* @param paymentId 要关闭的支付id
* @return 关闭的支付对象
* @throws Exception 异常
*/
public Map<String, Object> closePayment(String paymentId) throws Exception {
System.out.println("=======close payment begin=======");
//关闭支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/index.html
//调用sdk方法关闭支付得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
Map<String, Object> paymentParams = new HashMap<>(10);
paymentParams.put("payment_id", paymentId);
paymentParams.put("reason", "reason");
paymentParams.put("expend", "expend");
paymentParams.put("notify_url", "notify_url");
System.out.println("关单请求参数:" + JSON.toJSONString(paymentId));
payment = Payment.close(paymentParams);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("关单返回参数:" + JSON.toJSONString(payment));
System.out.println("=======close payment end=======");
return payment;
}
/**
* 查询一个支付交易
*
* @param paymentId 要查询的支付id
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> queryPayment(String paymentId) throws Exception {
System.out.println("=======query payment begin=======");
//查询支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/index.html
//调用sdk方法查询支付交易得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
System.out.println("支付查询请求参数:" + JSON.toJSONString(paymentId));
payment = Payment.query(paymentId);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("支付查询返回参数:" + JSON.toJSONString(payment));
System.out.println("=======query payment end=======");
return payment;
}
/**
* 创建撤销对象
*
* @param paymentId 要查询的支付id
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> createReverse(String paymentId, String app_id) throws Exception {
System.out.println("=======create Reverse begin=======");
Map<String, Object> reverse = new HashMap<>();
reverse.put("payment_id", paymentId);
reverse.put("app_id", app_id);
reverse.put("order_no", "jsdk_reverse_" + System.currentTimeMillis());
reverse.put("app_id", app_id);
reverse.put("notify_url", app_id);
reverse.put("reverse_amt", "0.01");
reverse.put("reason", app_id);
reverse.put("expand", app_id);
reverse.put("device_info", app_id);
try {
System.out.println("创建撤销对象" + JSON.toJSONString(reverse));
reverse = PaymentReverse.create(reverse);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("创建撤销对象返回参数:" + JSON.toJSONString(reverse));
System.out.println("=======create Reverse end=======");
return reverse;
}
/**
* 查询撤销对象
*
* @param reverse_id 要查询的支付id
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> queryReverse(String reverse_id, String app_id) throws Exception {
System.out.println("=======query Reverse begin=======");
Map<String, Object> reverse = new HashMap<>();
reverse.put("reverse_id", reverse_id);
try {
System.out.println("查询撤销对象请求参数:" + JSON.toJSONString(reverse));
reverse = PaymentReverse.query(reverse);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("查询撤销对象返回参数:" + JSON.toJSONString(reverse));
System.out.println("=======query Reverse end=======");
return reverse;
}
/**
* 查询撤销对象列表
*
* @param
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> queryReverseList(String payment_id, String app_id) throws Exception {
System.out.println("=======query Reverse list begin=======");
Map<String, Object> reverse = new HashMap<>();
reverse.put("payment_id", payment_id);
reverse.put("app_id", app_id);
reverse.put("page_index", "1");
reverse.put("page_size", "20");
reverse.put("created_gte", "");
reverse.put("created_lte", "");
try {
System.out.println("查询撤销对象列表请求参数:" + JSON.toJSONString(reverse));
reverse = PaymentReverse.queryList(reverse);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("查询撤销对象列表返回参数:" + JSON.toJSONString(reverse));
System.out.println("=======query Reverse list end=======");
return reverse;
}
/**
* 创建确认对象
*
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> createConfirm(String paymentId, String app_id) throws Exception {
System.out.println("=======create confirm begin=======");
Map<String, Object> confirm = new HashMap<>();
confirm.put("payment_id", paymentId);
confirm.put("order_no", "jsdk_confirm_" + System.currentTimeMillis());
confirm.put("confirm_amt", "0.01");
confirm.put("description", "description");
confirm.put("div_members", "");
try {
System.out.println("创建确认对象" + JSON.toJSONString(confirm));
confirm = PaymentConfirm.create(confirm);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("创建确认对象返回参数:" + JSON.toJSONString(confirm));
System.out.println("=======create confirm end=======");
return confirm;
}
/**
* 查询撤销对象
*
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> queryConfirm(String payment_confirm_id, String app_id) throws Exception {
System.out.println("=======query confirm begin=======");
Map<String, Object> confirm = new HashMap<>();
confirm.put("payment_confirm_id", payment_confirm_id);
try {
System.out.println("查询确认对象请求参数:" + JSON.toJSONString(confirm));
confirm = PaymentConfirm.query(confirm);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("查询撤销对象返回参数:" + JSON.toJSONString(confirm));
System.out.println("=======query confirm end=======");
return confirm;
}
/**
* 查询确认对象列表
*
* @param
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> queryConfirmList(String payment_id, String app_id) throws Exception {
System.out.println("=======query confirm list begin=======");
Map<String, Object> confirm = new HashMap<>();
confirm.put("payment_id", payment_id);
confirm.put("app_id", app_id);
confirm.put("page_index", "1");
confirm.put("page_size", "20");
confirm.put("created_gte", "");
confirm.put("created_lte", "");
try {
System.out.println("查询撤销对象列表请求参数:" + JSON.toJSONString(confirm));
confirm = PaymentConfirm.queryList(confirm);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("查询撤销对象列表返回参数:" + JSON.toJSONString(confirm));
System.out.println("=======query Reverse list end=======");
return confirm;
}
//add beg
/**
* 查询确认对象列表
*
* @param
* @return 查询的支付对象列表
* @throws Exception 异常
*/
public Map<String, Object> queryList(String payment_id, String app_id) throws Exception {
System.out.println("=======query list begin=======");
Map<String, Object> querylist = new HashMap<>();
querylist.put("payment_id", payment_id);
querylist.put("app_id", app_id);
querylist.put("page_index", "1");
querylist.put("page_size", "20");
querylist.put("created_gte", "");
querylist.put("created_lte", "");
try {
System.out.println("查询支付对象列表请求参数:" + JSON.toJSONString(querylist));
querylist = Payment.queryList(querylist);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("查询支付对象列表返回参数:" + JSON.toJSONString(querylist));
System.out.println("=======query list end=======");
return querylist;
}
/**
* 查询收银台对象列表
*
* @param
* @return 查询的收银台对象列表
* @throws Exception 异常
*/
public Map<String, Object> queryCheckoutList(String payment_id, String app_id) throws Exception {
System.out.println("=======query list begin=======");
Map<String, Object> checklist = new HashMap<>();
checklist.put("payment_id", payment_id);
checklist.put("app_id", app_id);
checklist.put("page_index", "1");
checklist.put("page_size", "20");
checklist.put("created_gte", "");
checklist.put("created_lte", "");
try {
System.out.println("查询收银台对象列表请求参数:" + JSON.toJSONString(checklist));
checklist = Checkout.queryList(checklist);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("查询收银台对象列表返回参数:" + JSON.toJSONString(checklist));
System.out.println("=======query check list end=======");
return checklist;
}
//add end
}

View File

@@ -0,0 +1,148 @@
package com.jsowell.adapay.demo;
import com.alibaba.fastjson.JSON;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Payment;
import java.util.HashMap;
import java.util.Map;
/**
* @author chunying.jia
*/
public class PaymentRegionAndRequestTimeOutDemo extends BaseDemo {
public static String executePaymentTest(String app_id)throws Exception{
PaymentRegionAndRequestTimeOutDemo demo = new PaymentRegionAndRequestTimeOutDemo();
//支付接口
Map<String, Object> payment = demo.executePayment(app_id);
return (String) payment.get("id");
}
/**
* 执行一个支付交易
*
* @return 创建的支付对象
* @throws Exception 异常
*/
public Map<String, Object> executePayment(String app_id) throws Exception {
System.out.println("=======execute payment begin=======");
//创建支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/index.html
Map<String, Object> paymentParams = new HashMap<>(10);
// 设置超时时间 单位毫秒 类型 int
// adapay_connection_request_timeout 类型 int, 单位:毫秒 ms
// 非必须, 默认 10000 指从连接池获取连接的 timeout
paymentParams.put("adapay_connection_request_timeout", 1500);
// adapay_connect_timeout 单位:毫秒 ms
// 非必须, 默认 30000 指客户端和服务器建立连接的timeout
paymentParams.put("adapay_connect_timeout", 1500);
// adapay_socket_timeout 单位:毫秒 ms
// 非必须, 默认 30000 指客户端从服务器读取数据的timeout超出后会抛出SocketTimeOutException
paymentParams.put("adapay_socket_timeout", 1500);
// 设置网络区域
// 非必须, 默认 shanghai, 如果要使用其他区域请提交工单备注服务器公网出口IP地址申请开通beijing
paymentParams.put("adapay_region", "beijing");
paymentParams.put("app_id", app_id);
paymentParams.put("order_no", "jsdk_payment_" + System.currentTimeMillis());
paymentParams.put("pay_channel", "alipay");
paymentParams.put("pay_amt", "0.01");
paymentParams.put("goods_title", "your goods title");
paymentParams.put("goods_desc", "your goods desc");
paymentParams.put("div_members", "");
//调用sdk方法创建支付得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
System.out.println("支付交易,请求参数:" + JSON.toJSONString(paymentParams));
payment = Payment.create(paymentParams);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("支付交易,返回参数:" + JSON.toJSONString(payment));
System.out.println("=======execute payment end=======");
return payment;
}
/**
* 关闭一个支付交易
*
* @param paymentId 要关闭的支付id
* @return 关闭的支付对象
* @throws Exception 异常
*/
public Map<String, Object> closePayment(String paymentId) throws Exception {
System.out.println("=======close payment begin=======");
//关闭支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/index.html
//调用sdk方法关闭支付得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
Map<String, Object> paymentParams = new HashMap<>(10);
paymentParams.put("payment_id", paymentId);
// 设置超时时间 单位毫秒 类型 int
// adapay_connection_request_timeout 类型 int, 单位:毫秒 ms
// 非必须, 默认 10000 指从连接池获取连接的 timeout
paymentParams.put("adapay_connection_request_timeout", 1500);
// adapay_connect_timeout 单位:毫秒 ms
// 非必须, 默认 30000 指客户端和服务器建立连接的timeout
paymentParams.put("adapay_connect_timeout", 1500);
// adapay_socket_timeout 单位:毫秒 ms
// 非必须, 默认 30000 指客户端从服务器读取数据的timeout超出后会抛出SocketTimeOutException
paymentParams.put("adapay_socket_timeout", 1500);
// 设置网络区域
// 非必须, 默认 shanghai, 如果要使用其他区域请提交工单备注服务器公网出口IP地址申请开通beijing
paymentParams.put("adapay_region", "beijing");
paymentParams.put("reason", "reason");
paymentParams.put("expend", "expend");
paymentParams.put("notify_url", "notify_url");
System.out.println("关单请求参数:" + JSON.toJSONString(paymentId));
payment = Payment.close(paymentParams);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("关单返回参数:" + JSON.toJSONString(payment));
System.out.println("=======close payment end=======");
return payment;
}
/**
* 查询一个支付交易
*
* @param paymentId 要查询的支付id
* @return 查询的支付对象
* @throws Exception 异常
*/
public Map<String, Object> queryPayment(String paymentId) throws Exception {
System.out.println("=======query payment begin=======");
//查询支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/index.html
//调用sdk方法查询支付交易得到支付对象
Map<String, Object> payment = new HashMap<>();
try {
System.out.println("支付查询请求参数:" + JSON.toJSONString(paymentId));
payment = Payment.query(paymentId);
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
System.out.println("支付查询返回参数:" + JSON.toJSONString(payment));
System.out.println("=======query payment end=======");
return payment;
}
}

View File

@@ -0,0 +1,157 @@
package com.jsowell.adapay.demo;
import com.alibaba.fastjson.JSON;
import com.huifu.adapay.model.Refund;
import java.util.HashMap;
import java.util.Map;
/**
* @author jane.zhao
*/
public class RefundDemo extends BaseDemo {
/**
* 运行退款类接口
*
* @throws Exception 异常
*/
public static void executeRefundTest(String merchantKey, String paymentId) throws Exception {
RefundDemo demo = new RefundDemo();
//退款接口
Map<String, Object> refund = demo.executeRefund(merchantKey, paymentId);
//退款查询接口通过pamentId查询
demo.queryByPaymentId(merchantKey, paymentId);
//退款查询接口通过refundId查询
demo.queryByRefundId(merchantKey, (String) refund.get("id"));
}
/**
* 执行一个退款交易
*
* @param paymentId 要退款的原支付paymentId
* @return 创建的退款对象
* @throws Exception 异常
*/
public Map<String, Object> executeRefund(String merchantKey, String paymentId) throws Exception {
System.out.println("=======execute refund begin=======");
Map<String, Object> refundParams = new HashMap<String, Object>(2);
refundParams.put("refund_amt", "0.01");
refundParams.put("app_id", "your appid");
refundParams.put("refund_order_no", "jsdk_refund_"+System.currentTimeMillis());
System.out.println("退款请求参数:" + JSON.toJSONString(refundParams));
Map<String, Object> refund = Refund.create(paymentId, refundParams, merchantKey);
System.out.println("退款返回参数:" + JSON.toJSONString(refund));
System.out.println("=======execute refund end=======");
return refund;
}
/**
* 根据原支付id查询一个退款交易
*
* @param paymentId 要查询退款的原支付paymentId
* @return 查询的退款对象可能含多个退款明细RefundDetail
* @throws Exception 异常
*/
public Map<String, Object> queryByPaymentId(String merchantKey, String paymentId) throws Exception {
System.out.println("=======query refund by paymentId begin=======");
Map<String, Object> refundParams = new HashMap<String, Object>(1);
refundParams.put("payment_id", paymentId);
System.out.println("通过原支付ID查询退款交易请求参数" + JSON.toJSONString(refundParams));
Map<String, Object> refund = Refund.query(refundParams, merchantKey);
System.out.println("通过原支付ID查询退款交易返回参数" + JSON.toJSONString(refund));
System.out.println("=======query refund by paymentId end=======");
return refund;
}
/**
* 根据退款refundId查询一个退款交易
*
* @param refundId 要查询的退款refundId
* @return 查询的退款对象
* @throws Exception 异常
*/
public Map<String, Object> queryByRefundId(String merchantKey, String refundId) throws Exception {
System.out.println("=======query refund by refundid begin=======");
Map<String, Object> refundParams = new HashMap<String, Object>(1);
refundParams.put("refund_id", refundId);
System.out.println("通过refundId查询退款交易请求参数" + JSON.toJSONString(refundParams));
Map<String, Object> refund = Refund.query(refundParams, merchantKey);
System.out.println("通过refundId查询退款交易返回参数" + JSON.toJSONString(refund));
System.out.println("=======query refund by refundid end=======");
return refund;
}
/**
* 运行退款类接口
*
* @throws Exception 异常
*/
public static void executeRefundTest( String paymentId) throws Exception {
RefundDemo demo = new RefundDemo();
//退款接口
Map<String, Object> refund = demo.executeRefund( paymentId);
//退款查询接口通过pamentId查询
demo.queryByPaymentId( paymentId);
//退款查询接口通过refundId查询
demo.queryByRefundId( (String) refund.get("id"));
}
/**
* 执行一个退款交易
*
* @param paymentId 要退款的原支付paymentId
* @return 创建的退款对象
* @throws Exception 异常
*/
public Map<String, Object> executeRefund( String paymentId) throws Exception {
System.out.println("=======execute refund begin=======");
Map<String, Object> refundParams = new HashMap<String, Object>(2);
refundParams.put("refund_amt", "0.01");
refundParams.put("app_id", "your appid");
refundParams.put("refund_order_no", "jsdk_refund_"+System.currentTimeMillis());
System.out.println("退款请求参数:" + JSON.toJSONString(refundParams));
Map<String, Object> refund = Refund.create(paymentId, refundParams);
System.out.println("退款返回参数:" + JSON.toJSONString(refund));
System.out.println("=======execute refund end=======");
return refund;
}
/**
* 根据原支付id查询一个退款交易
*
* @param paymentId 要查询退款的原支付paymentId
* @return 查询的退款对象可能含多个退款明细RefundDetail
* @throws Exception 异常
*/
public Map<String, Object> queryByPaymentId( String paymentId) throws Exception {
System.out.println("=======query refund by paymentId begin=======");
Map<String, Object> refundParams = new HashMap<String, Object>(1);
refundParams.put("payment_id", paymentId);
System.out.println("通过原支付ID查询退款交易请求参数" + JSON.toJSONString(refundParams));
Map<String, Object> refund = Refund.query(refundParams);
System.out.println("通过原支付ID查询退款交易返回参数" + JSON.toJSONString(refund));
System.out.println("=======query refund by paymentId end=======");
return refund;
}
/**
* 根据退款refundId查询一个退款交易
*
* @param refundId 要查询的退款refundId
* @return 查询的退款对象
* @throws Exception 异常
*/
public Map<String, Object> queryByRefundId( String refundId) throws Exception {
System.out.println("=======query refund by refundid begin=======");
Map<String, Object> refundParams = new HashMap<String, Object>(1);
refundParams.put("refund_id", refundId);
System.out.println("通过refundId查询退款交易请求参数" + JSON.toJSONString(refundParams));
Map<String, Object> refund = Refund.query(refundParams);
System.out.println("通过refundId查询退款交易返回参数" + JSON.toJSONString(refund));
System.out.println("=======query refund by refundid end=======");
return refund;
}
}

View File

@@ -0,0 +1,853 @@
package com.jsowell.adapay.demo;
import com.alibaba.fastjson.JSON;
import com.huifu.adapay.model.Drawcash;
import com.huifu.adapay.model.SettleAccount;
import java.util.HashMap;
import java.util.Map;
/**
* @author yingyong.wang
*/
public class SettleAccountDemo extends BaseDemo {
/**
* 运行结算账户类接口
*
* @throws Exception 异常
*/
public static void executeSettleAccountTest(String merchantKey, String app_id, String member_id) throws Exception {
SettleAccountDemo demo = new SettleAccountDemo();
// 创建结算账户
Map<String, Object> settlecount = demo.executeCreateSettleAccount(merchantKey, app_id, member_id);
String settleCount_id = (String) settlecount.get("id");
// 查询结算账户
demo.executeQuerySettleAccount(merchantKey, settleCount_id, app_id, member_id);
// 查询结算账户明细列表
demo.executeQuerySettleDetails(merchantKey, app_id, member_id, settleCount_id);
// 删除结算账户
demo.executeDeleteSettleAccount(merchantKey, settleCount_id, app_id, member_id);
member_id = "user_test_10001";
settleCount_id = "0023056905335360";
demo.executeModifySettleAccount(merchantKey, settleCount_id, app_id, member_id);
// SettleAccountDemo.executeDrawCash(merchantKey, app_id, member_id);
//
// SettleAccountDemo.executeQueryBalance(merchantKey, app_id, member_id, settleCount_id);
demo.executeTransfer(app_id,member_id);
demo.executeTransferList(app_id,member_id,settleCount_id);
demo.executeCommission(app_id,member_id);
demo.executeCommissionList(app_id);
}
/**
* 运行查询结算明细列表接口
*
* @throws Exception 异常
*/
// public static void executeQuerySettleDetailTest(String merchantKey, String appId, String memberId, String settleAccountId, String beginDate, String endDate) throws Exception {
// SettleAccountDemo demo = new SettleAccountDemo();
// demo.executeQuerySettleDetails(merchantKey, appId, memberId, settleAccountId, beginDate, endDate);
// }
/**
* 创建 settleCount
*
* @return 创建的settleCount 对象
* @throws Exception 异常
*/
public Map<String, Object> executeCreateSettleAccount(String merchantKey, String app_id, String member_id) throws Exception {
System.out.println("=======execute Create SettleAccount begin=======");
Map<String, Object> settleCountParams = new HashMap<String, Object>(2);
Map<String, Object> accountInfo = new HashMap<String, Object>(2);
accountInfo.put("card_id", "6222021703001692221");
accountInfo.put("card_name", "袁电茜");
accountInfo.put("cert_id", "310109200006062491");
accountInfo.put("cert_type", "00");
accountInfo.put("tel_no", "18888888881");
accountInfo.put("bank_code", "03060000");
accountInfo.put("bank_acct_type", "1");
accountInfo.put("prov_code", "0031");
accountInfo.put("area_code", "3100");
settleCountParams.put("member_id", member_id);
settleCountParams.put("app_id", app_id);
settleCountParams.put("channel", "bank_account");
settleCountParams.put("account_info", accountInfo);
System.out.println("创建结算账户,请求参数:" + JSON.toJSONString(settleCountParams));
Map<String, Object> settleCount = SettleAccount.create(settleCountParams, merchantKey);
System.out.println("创建结算账户,返回参数:" + JSON.toJSONString(settleCount));
System.out.println("=======execute Create SettleAccount end=======");
return settleCount;
}
/**
* 查询 SettleAccount
*
* @param settleCount_id 待查询的settleCount_id
* @param app_id app_id
* @return 查询的settleCount 对象
* @throws Exception 异常
*/
public Map<String, Object> executeQuerySettleAccount(String merchantKey, String settleCount_id, String app_id, String member_id) throws Exception {
System.out.println("=======execute query SettleAccount begin=======");
Map<String, Object> settleCountParams = new HashMap<String, Object>(2);
settleCountParams.put("settle_account_id", settleCount_id);
settleCountParams.put("member_id", member_id);
settleCountParams.put("app_id", app_id);
System.out.println("查询结算账户,请求参数:" + JSON.toJSONString(settleCountParams));
Map<String, Object> settleCount = SettleAccount.query(settleCountParams, merchantKey);
System.out.println("查询结算账户,返回参数:" + JSON.toJSONString(settleCount));
System.out.println("=======execute query SettleAccount end=======");
return settleCount;
}
/**
* 删除 SettleAccount
*
* @param settleCount_id 待删除的settleCount_id
* @param app_id app_id
* @return delete的settleCount 对象
* @throws Exception 异常
*/
public Map<String, Object> executeDeleteSettleAccount(String merchantKey, String settleCount_id, String app_id, String member_id) throws Exception {
System.out.println("=======execute delete SettleAccount begin=======");
Map<String, Object> settleCountParams = new HashMap<String, Object>(2);
settleCountParams.put("settle_account_id", settleCount_id);
settleCountParams.put("member_id", member_id);
settleCountParams.put("app_id", app_id);
System.out.println("删除结算账户,请求参数:" + JSON.toJSONString(settleCountParams));
Map<String, Object> settleCount = SettleAccount.delete(settleCountParams, merchantKey);
System.out.println("删除结算账户,返回参数:" + JSON.toJSONString(settleCount));
System.out.println("=======execute delete SettleAccount end=======");
return settleCount;
}
/**
* 查询结算明细列表
*
* @param merchantKey
* @param app_id app_id
* @param member_id 待查询的member_id
* @param settleAccountId 待查询的settleAccountId
* @return
* @throws Exception 异常
*/
public Map<String, Object> executeQuerySettleDetails(String merchantKey, String app_id, String member_id,
String settleAccountId) throws Exception {
System.out.println("=======execute query settle details begin=======");
Map<String, Object> querySettleDetailParams = new HashMap<String, Object>(2);
querySettleDetailParams.put("app_id", app_id);
querySettleDetailParams.put("member_id", member_id);
querySettleDetailParams.put("settle_account_id", settleAccountId);
querySettleDetailParams.put("begin_date", "20191008");
querySettleDetailParams.put("end_date", "20191010");
System.out.println("查询结算明细列表,请求参数:" + JSON.toJSONString(querySettleDetailParams));
Map<String, Object> settleCount = SettleAccount.detail(querySettleDetailParams, merchantKey);
System.out.println("查询结算明细列表,返回参数:" + JSON.toJSONString(settleCount));
System.out.println("=======execute query settle details end=======");
return settleCount;
}
/**
* 运行结算账户类接口
*
* @throws Exception 异常
*/
public static void executeSettleAccountTest(String app_id, String member_id) throws Exception {
SettleAccountDemo demo = new SettleAccountDemo();
// 创建结算账户
Map<String, Object> settlecount = demo.executeCreateSettleAccount(app_id, member_id);
String settleCount_id = (String) settlecount.get("id");
// 查询结算账户
demo.executeQuerySettleAccount(settleCount_id, app_id, member_id);
// 查询结算账户明细列表
demo.executeQuerySettleDetails(app_id, member_id, settleCount_id);
demo.executeTransfer(app_id,member_id);
demo.executeTransferList(app_id,member_id,settleCount_id);
demo.executeFreeze(app_id,member_id);
demo.executeFreezeList(app_id,member_id,settleCount_id);
demo.executeUnFreeze(app_id,member_id);
demo.executeUnFreezeList(app_id,member_id,settleCount_id);
demo.executeCommission(app_id,member_id);
demo.executeCommissionList(app_id);
}
/**
* 运行查询结算明细列表接口
*
* @throws Exception 异常
*/
// public static void executeQuerySettleDetailTest( String appId, String memberId, String settleAccountId, String beginDate, String endDate) throws Exception {
// SettleAccountDemo demo = new SettleAccountDemo();
// demo.executeQuerySettleDetails( appId, memberId, settleAccountId, beginDate, endDate);
// }
/**
* 创建 settleCount
*
* @return 创建的settleCount 对象
* @throws Exception 异常
*/
public Map<String, Object> executeCreateSettleAccount(String app_id, String member_id) throws Exception {
System.out.println("=======execute Create SettleAccount begin=======");
Map<String, Object> settleCountParams = new HashMap<String, Object>(2);
Map<String, Object> accountInfo = new HashMap<String, Object>(2);
accountInfo.put("card_id", "6222021703001692221");
accountInfo.put("card_name", "袁电茜");
accountInfo.put("cert_id", "310109200006062491");
accountInfo.put("cert_type", "00");
accountInfo.put("tel_no", "18888888881");
accountInfo.put("bank_code", "03060000");
accountInfo.put("bank_acct_type", "1");
accountInfo.put("prov_code", "0031");
accountInfo.put("area_code", "3100");
settleCountParams.put("member_id", member_id);
settleCountParams.put("app_id", app_id);
settleCountParams.put("channel", "bank_account");
settleCountParams.put("account_info", accountInfo);
System.out.println("创建结算账户,请求参数:" + JSON.toJSONString(settleCountParams));
Map<String, Object> settleCount = SettleAccount.create(settleCountParams);
System.out.println("创建结算账户,返回参数:" + JSON.toJSONString(settleCount));
System.out.println("=======execute Create SettleAccount end=======");
return settleCount;
}
/**
* 查询 SettleAccount
*
* @param settleCount_id 待查询的settleCount_id
* @param app_id app_id
* @return 查询的settleCount 对象
* @throws Exception 异常
*/
public Map<String, Object> executeQuerySettleAccount(String settleCount_id, String app_id, String member_id) throws Exception {
System.out.println("=======execute query SettleAccount begin=======");
Map<String, Object> settleCountParams = new HashMap<String, Object>(2);
settleCountParams.put("settle_account_id", settleCount_id);
settleCountParams.put("member_id", member_id);
settleCountParams.put("app_id", app_id);
System.out.println("查询结算账户,请求参数:" + JSON.toJSONString(settleCountParams));
Map<String, Object> settleCount = SettleAccount.query(settleCountParams);
System.out.println("查询结算账户,返回参数:" + JSON.toJSONString(settleCount));
System.out.println("=======execute query SettleAccount end=======");
return settleCount;
}
/**
* 修改 SettleAccount
*
* @param settleCount_id 待修改的settleCount_id
* @param app_id app_id
* @return 修改的settleCount 对象
* @throws Exception 异常
*/
public Map<String, Object> executeModifySettleAccount(String settleCount_id, String app_id, String member_id) throws Exception {
System.out.println("=======execute modify SettleAccount begin=======");
Map<String, Object> settleCountParams = new HashMap<String, Object>(2);
settleCountParams.put("settle_account_id", settleCount_id);
settleCountParams.put("member_id", member_id);
settleCountParams.put("app_id", app_id);
settleCountParams.put("min_amt", "0.10");
settleCountParams.put("remained_amt", "0.10");
System.out.println("修改结算账户,请求参数:" + JSON.toJSONString(settleCountParams));
Map<String, Object> settleCount = SettleAccount.update(settleCountParams);
System.out.println("修改结算账户,返回参数:" + JSON.toJSONString(settleCount));
System.out.println("=======execute modify SettleAccount end=======");
return settleCount;
}
/**
* 修改 SettleAccount
*
* @param settleCount_id 待修改的settleCount_id
* @param app_id app_id
* @return 修改的settleCount 对象
* @throws Exception 异常
*/
public Map<String, Object> executeModifySettleAccount(String merchantKey, String settleCount_id, String app_id, String member_id) throws Exception {
System.out.println("=======execute modify SettleAccount begin=======");
Map<String, Object> settleCountParams = new HashMap<String, Object>(2);
settleCountParams.put("settle_account_id", settleCount_id);
settleCountParams.put("member_id", member_id);
settleCountParams.put("app_id", app_id);
settleCountParams.put("min_amt", "");
settleCountParams.put("remained_amt", "");
System.out.println("修改结算账户,请求参数:" + JSON.toJSONString(settleCountParams));
Map<String, Object> settleCount = SettleAccount.modify(settleCountParams, merchantKey);
System.out.println("修改结算账户,返回参数:" + JSON.toJSONString(settleCount));
System.out.println("=======execute modify SettleAccount end=======");
return settleCount;
}
/**
* 删除 SettleAccount
*
* @param settleCount_id 待删除的settleCount_id
* @param app_id app_id
* @return delete的settleCount 对象
* @throws Exception 异常
*/
public Map<String, Object> executeDeleteSettleAccount(String settleCount_id, String app_id, String member_id) throws Exception {
System.out.println("=======execute delete SettleAccount begin=======");
Map<String, Object> settleCountParams = new HashMap<String, Object>(2);
settleCountParams.put("settle_account_id", settleCount_id);
settleCountParams.put("member_id", member_id);
settleCountParams.put("app_id", app_id);
System.out.println("删除结算账户,请求参数:" + JSON.toJSONString(settleCountParams));
Map<String, Object> settleCount = SettleAccount.delete(settleCountParams);
System.out.println("删除结算账户,返回参数:" + JSON.toJSONString(settleCount));
System.out.println("=======execute delete SettleAccount end=======");
return settleCount;
}
/**
* 查询结算明细列表
*
* @param app_id app_id
* @param member_id 待查询的member_id
* @param settleAccountId 待查询的settleAccountId
* @return
* @throws Exception 异常
*/
public Map<String, Object> executeQuerySettleDetails(String app_id, String member_id,
String settleAccountId) throws Exception {
System.out.println("=======execute query settle details begin=======");
Map<String, Object> querySettleDetailParams = new HashMap<String, Object>(2);
querySettleDetailParams.put("app_id", app_id);
querySettleDetailParams.put("member_id", member_id);
querySettleDetailParams.put("settle_account_id", settleAccountId);
querySettleDetailParams.put("begin_date", "20191008");
querySettleDetailParams.put("end_date", "20191010");
System.out.println("查询结算明细列表,请求参数:" + JSON.toJSONString(querySettleDetailParams));
Map<String, Object> settleCount = SettleAccount.detail(querySettleDetailParams);
System.out.println("查询结算明细列表,返回参数:" + JSON.toJSONString(settleCount));
System.out.println("=======execute query settle details end=======");
return settleCount;
}
/**
* 取现
*
* @param merchantKey
* @param app_id
* @param member_id
* @return
* @throws Exception
*/
public static Map<String, Object> executeDrawCash(String merchantKey, String app_id, String member_id) throws Exception {
System.out.println("=======execute modify SettleAccount begin=======");
Map<String, Object> settleCountParams = new HashMap<String, Object>();
settleCountParams.put("order_no", "jsdk_payment_" + System.currentTimeMillis());
settleCountParams.put("cash_amt", "0.01");
settleCountParams.put("member_id", "user_00008");
settleCountParams.put("app_id", app_id);
// settleCountParams.put("settle_account_id", "0008919797515968");
settleCountParams.put("cash_type", "T1");
settleCountParams.put("notify_url", "");
System.out.println("取现接口,请求参数:" + JSON.toJSONString(settleCountParams));
Map<String, Object> settleCount = Drawcash.create(settleCountParams, merchantKey);
System.out.println("取现接口返回参数" + JSON.toJSONString(settleCount));
System.out.println("=======execute modify SettleAccount end=======");
return settleCount;
}
/**
* 查询余额
*
* @param merchantKey
* @param app_id
* @param member_id
* @param settleCount_id
* @return
* @throws Exception
*/
public static Map<String, Object> executeQueryBalance(String merchantKey, String app_id, String member_id, String settleCount_id) throws Exception {
System.out.println("=======execute modify SettleAccount begin=======");
Map<String, Object> settleCountParams = new HashMap<String, Object>();
settleCountParams.put("app_id", app_id);
settleCountParams.put("member_id", "user_00008");
settleCountParams.put("settle_account_id", "0035172521665088");
System.out.println("查询余额账户,请求参数:" + JSON.toJSONString(settleCountParams));
Map<String, Object> settleCount = SettleAccount.balance(settleCountParams, merchantKey);
System.out.println("查询余额账户,返回参数:" + JSON.toJSONString(settleCount));
System.out.println("=======execute modify SettleAccount end=======");
return settleCount;
}
/**
* 取现
*
* @param app_id
* @param member_id
* @return
* @throws Exception
*/
public static Map<String, Object> executeDrawCash(String app_id, String member_id) throws Exception {
System.out.println("=======execute modify SettleAccount begin=======");
Map<String, Object> settleCountParams = new HashMap<String, Object>();
settleCountParams.put("order_no", "jsdk_payment_" + System.currentTimeMillis());
settleCountParams.put("cash_amt", "0.01");
settleCountParams.put("member_id", "user_00008");
settleCountParams.put("app_id", app_id);
// settleCountParams.put("settle_account_id", "0008919797515968");
settleCountParams.put("cash_type", "T1");
settleCountParams.put("notify_url", "");
System.out.println("取现接口,请求参数:" + JSON.toJSONString(settleCountParams));
Map<String, Object> settleCount = Drawcash.create(settleCountParams);
System.out.println("取现接口返回参数" + JSON.toJSONString(settleCount));
System.out.println("=======execute modify SettleAccount end=======");
return settleCount;
}
/**
* 查询余额
*
* @param app_id
* @param member_id
* @param settleCount_id
* @return
* @throws Exception
*/
public static Map<String, Object> executeQueryBalance(String app_id, String member_id, String settleCount_id) throws Exception {
System.out.println("=======execute modify SettleAccount begin=======");
Map<String, Object> settleCountParams = new HashMap<String, Object>();
settleCountParams.put("app_id", app_id);
settleCountParams.put("member_id", "user_00008");
settleCountParams.put("settle_account_id", "0035172521665088");
System.out.println("查询余额账户,请求参数:" + JSON.toJSONString(settleCountParams));
Map<String, Object> settleCount = SettleAccount.balance(settleCountParams);
System.out.println("查询余额账户,返回参数:" + JSON.toJSONString(settleCount));
System.out.println("=======execute modify SettleAccount end=======");
return settleCount;
}
/**
* 创建转账对象
*
* @param app_id
* @param member_id
* @return
* @throws Exception
*/
public Map<String, Object> executeTransfer(String app_id, String member_id) throws Exception {
System.out.println("=======execute transfer SettleAccount begin=======");
Map<String, Object> transferParams = new HashMap<>();
transferParams.put("order_no", "order_no_123");
transferParams.put("trans_amt", "0.01");
transferParams.put("app_id", "app_XXXXXXXX");
transferParams.put("in_member_id", "0");
transferParams.put("out_member_id", "user_member_id_test");
System.out.println("创建转账对象,请求参数:" + JSON.toJSONString(transferParams));
Map<String, Object> result = SettleAccount.transfer(transferParams);
System.out.println("创建转账对象,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute transfer SettleAccount end=======");
return result;
}
/**
* 创建转账对象
*
* @param app_id
* @param member_id
* @return
* @throws Exception
*/
public Map<String, Object> executeTransfer(String merchantKey, String app_id, String member_id) throws Exception {
System.out.println("=======execute transfer SettleAccount begin=======");
Map<String, Object> transferParams = new HashMap<>();
transferParams.put("order_no", "order_no_124");
transferParams.put("trans_amt", "0.01");
transferParams.put("app_id", "app_XXXXXXXX");
transferParams.put("in_member_id", "0");
transferParams.put("out_member_id", "user_member_id_test");
System.out.println("创建转账对象,请求参数:" + JSON.toJSONString(transferParams));
Map<String, Object> result = SettleAccount.transfer(transferParams);
System.out.println("创建转账对象,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute transfer SettleAccount end=======");
return result;
}
/**
* 查询账户转账对象列表
*
* @param app_id
* @param member_id
* @param settleCount_id
* @return
* @throws Exception
*/
public Map<String, Object> executeTransferList(String app_id, String member_id, String settleCount_id) throws Exception {
System.out.println("=======execute query transferList begin=======");
Map<String, Object> transferListParams = new HashMap<String, Object>();
transferListParams.put("app_id", "app_XXXXXXXX");
transferListParams.put("status", "succeeded");
transferListParams.put("page_index", "1");
transferListParams.put("page_size", "10");
transferListParams.put("created_gte", "1571466657929");
transferListParams.put("created_lte", "1571898657929");
System.out.println("查询账户转账对象列表,请求参数:" + JSON.toJSONString(transferListParams));
Map<String, Object> result = SettleAccount.transferList(transferListParams);
System.out.println("查询账户转账对象列表,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute query transferList end=======");
return result;
}
/**
* 查询账户转账对象列表
*
* @param app_id
* @param member_id
* @param settleCount_id
* @return
* @throws Exception
*/
public Map<String, Object> executeTransferList(String merchantKey, String app_id, String member_id, String settleCount_id) throws Exception {
System.out.println("=======execute query transferList begin=======");
Map<String, Object> transferListParams = new HashMap<String, Object>();
transferListParams.put("app_id", "app_XXXXXXXX");
transferListParams.put("status", "succeeded");
transferListParams.put("page_index", "1");
transferListParams.put("page_size", "10");
transferListParams.put("created_gte", "1571466657928");
transferListParams.put("created_lte", "1571898657928");
System.out.println("查询账户转账对象列表,请求参数:" + JSON.toJSONString(transferListParams));
Map<String, Object> result = SettleAccount.transferList(transferListParams);
System.out.println("查询账户转账对象列表,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute query transferList end=======");
return result;
}
/**
* 创建冻结对象
*
* @param app_id
* @param member_id
* @return
* @throws Exception
*/
public Map<String, Object> executeFreeze(String app_id, String member_id) throws Exception {
System.out.println("=======execute freeze SettleAccount begin=======");
Map<String, Object> freezeParam = new HashMap<String, Object>(4);
freezeParam.put("order_no", "1579163031383");
freezeParam.put("app_id", "app_XXXXXXXX");
freezeParam.put("account_freeze_id", "002112020111717230410174704123849117696");
Map<String, Object> result = SettleAccount.freeze(freezeParam);
System.out.println("创建冻结对象,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute freeze SettleAccount end=======");
return result;
}
/**
* 创建冻结对象
*
* @param app_id
* @param member_id
* @return
* @throws Exception
*/
public Map<String, Object> executeFreeze(String merchantKey, String app_id, String member_id) throws Exception {
System.out.println("=======execute freeze SettleAccount begin=======");
Map<String, Object> freezeParam = new HashMap<String, Object>(4);
freezeParam.put("order_no", "1579163031384");
freezeParam.put("app_id", "app_XXXXXXXX");
freezeParam.put("account_freeze_id", "002112020111717230410174704123849117696");
Map<String, Object> result = SettleAccount.freeze(freezeParam);
System.out.println("创建冻结对象,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute freeze SettleAccount end=======");
return result;
}
/**
* 查询账户冻结对象列表
*
* @param app_id
* @param member_id
* @param settleCount_id
* @return
* @throws Exception
*/
public Map<String, Object> executeFreezeList(String app_id, String member_id, String settleCount_id) throws Exception {
System.out.println("=======execute query freezeList begin=======");
Map<String, Object> params = new HashMap<>();
System.out.println("查询账户冻结对象列表,请求参数:" + JSON.toJSONString(params));
params.put("app_id", "app_XXXXXXXX");
params.put("status", "succeeded");
params.put("page_index", "1");
params.put("page_size", "10");
params.put("created_gte", "1571466657929");
params.put("created_lte", "1571898657929");
Map<String, Object> result = SettleAccount.freezeList(params);
System.out.println("查询账户冻结对象列表,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute query freezeList end=======");
return result;
}
/**
* 查询账户冻结对象列表
*
* @param app_id
* @param member_id
* @param settleCount_id
* @return
* @throws Exception
*/
public Map<String, Object> executeFreezeList(String merchantKey, String app_id, String member_id, String settleCount_id) throws Exception {
System.out.println("=======execute query freezeList begin=======");
Map<String, Object> params = new HashMap<>();
System.out.println("查询账户冻结对象列表,请求参数:" + JSON.toJSONString(params));
params.put("app_id", "app_XXXXXXXX");
params.put("status", "succeeded");
params.put("page_index", "1");
params.put("page_size", "10");
params.put("created_gte", "1571466657928");
params.put("created_lte", "1571898657928");
Map<String, Object> result = SettleAccount.freezeList(params);
System.out.println("查询账户冻结对象列表,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute query freezeList end=======");
return result;
}
/**
* 创建解冻对象
*
* @param app_id
* @param member_id
* @return
* @throws Exception
*/
public Map<String, Object> executeUnFreeze(String app_id, String member_id) throws Exception {
System.out.println("=======execute unfreeze SettleAccount begin=======");
Map<String, Object> unfreezeParam = new HashMap<String, Object>(4);
unfreezeParam.put("order_no", "1579163031383");
unfreezeParam.put("app_id", "app_XXXXXXXX");
unfreezeParam.put("account_freeze_id", "002112020111717230410174704123849117696");
Map<String, Object> result = SettleAccount.unfreeze(unfreezeParam);
System.out.println("创建解冻对象,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute unfreeze SettleAccount end=======");
return result;
}
/**
* 创建解冻对象
*
* @param app_id
* @param member_id
* @return
* @throws Exception
*/
public Map<String, Object> executeUnFreeze(String merchantKey, String app_id, String member_id) throws Exception {
System.out.println("=======execute unfreeze SettleAccount begin=======");
Map<String, Object> unfreezeParam = new HashMap<String, Object>(4);
unfreezeParam.put("order_no", "1579163031384");
unfreezeParam.put("app_id", "app_XXXXXXXX");
unfreezeParam.put("account_freeze_id", "002112020111717230410174704123849117696");
Map<String, Object> result = SettleAccount.unfreeze(unfreezeParam);
System.out.println("创建解冻对象,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute unfreeze SettleAccount end=======");
return result;
}
/**
* 查询账户解冻对象列表
*
* @param app_id
* @param member_id
* @param settleCount_id
* @return
* @throws Exception
*/
public Map<String, Object> executeUnFreezeList(String app_id, String member_id, String settleCount_id) throws Exception {
System.out.println("=======execute query unfreezeList begin=======");
Map<String, Object> params = new HashMap<>();
System.out.println("查询账户解冻对象列表,请求参数:" + JSON.toJSONString(params));
params.put("app_id", "app_XXXXXXXX");
params.put("status", "succeeded");
params.put("page_index", "1");
params.put("page_size", "10");
params.put("created_gte", "1571466657928");
params.put("created_lte", "1571898657928");
Map<String, Object> result = SettleAccount.unfreezeList(params);
System.out.println("查询账户解冻对象列表,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute query unfreezeList end=======");
return result;
}
/**
* 查询账户解冻对象列表
*
* @param app_id
* @param member_id
* @param settleCount_id
* @return
* @throws Exception
*/
public Map<String, Object> executeUnFreezeList(String merchantKey, String app_id, String member_id, String settleCount_id) throws Exception {
System.out.println("=======execute query unfreezeList begin=======");
Map<String, Object> params = new HashMap<>();
System.out.println("查询账户解冻对象列表,请求参数:" + JSON.toJSONString(params));
params.put("app_id", "app_XXXXXXXX");
params.put("status", "succeeded");
params.put("page_index", "1");
params.put("page_size", "10");
params.put("created_gte", "1571466657929");
params.put("created_lte", "1571898657929");
Map<String, Object> result = SettleAccount.unfreezeList(params);
System.out.println("查询账户解冻对象列表,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute query unfreezeList end=======");
return result;
}
/**
* 创建服务商分账对象
*
* @param app_id
* @return
* @throws Exception
*/
public Map<String, Object> executeCommission(String app_id, String member_id) throws Exception {
System.out.println("=======execute commissions SettleAccount begin=======");
Map<String, Object> params = new HashMap<String, Object>(4);
params.put("order_no", "commissions_10414212480035000003");
params.put("payment_id", "002112021011909284110197415174743904256");
params.put("trans_amt", "0.01");
System.out.println("创建服务商分账对象,请求参数:" + JSON.toJSONString(params));
Map<String, Object> result = SettleAccount.commission(params);
System.out.println("创建服务商分账对象,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute commissions SettleAccount end=======");
return result;
}
/**
* 创建服务商分账对象
*
* @param app_id
* @return
* @throws Exception
*/
public Map<String, Object> executeCommission(String merchantKey, String app_id, String member_id) throws Exception {
System.out.println("=======execute commissions SettleAccount begin=======");
Map<String, Object> params = new HashMap<String, Object>(4);
params.put("order_no", "1579163031383");
params.put("payment_id", "002112020111717230410174704123849117696");
params.put("trans_amt", "0.01");
System.out.println("创建服务商分账对象,请求参数:" + JSON.toJSONString(params));
Map<String, Object> result = SettleAccount.commission(params,merchantKey);
System.out.println("创建服务商分账对象,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute commissions SettleAccount end=======");
return result;
}
/**
* 查询服务商分账对象列表
*
* @param app_id
* @return
* @throws Exception
*/
public Map<String, Object> executeCommissionList(String app_id) throws Exception {
System.out.println("=======execute query unfreezeList begin=======");
Map<String, Object> params = new HashMap<>();
params.put("app_id", app_id);
params.put("status", "succeeded");
params.put("page_index", "1");
params.put("page_size", "10");
params.put("created_gte", "1571466657929");
params.put("created_lte", "1571898657929");
System.out.println("查询服务商分账对象列表,请求参数:" + JSON.toJSONString(params));
Map<String, Object> result = SettleAccount.commissionList(params);
System.out.println("查询服务商分账对象列表,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute query unfreezeList end=======");
return result;
}
/**
* 查询服务商分账对象列表
*
* @param app_id
* @return
* @throws Exception
*/
public Map<String, Object> executeCommissionList(String merchantKey, String app_id) throws Exception {
System.out.println("=======execute query unfreezeList begin=======");
Map<String, Object> params = new HashMap<>();
params.put("app_id", app_id);
params.put("status", "succeeded");
params.put("page_index", "1");
params.put("page_size", "10");
params.put("created_gte", "1571466657929");
params.put("created_lte", "1571898657929");
System.out.println("查询服务商分账对象列表,请求参数:" + JSON.toJSONString(params));
Map<String, Object> result = SettleAccount.commissionList(params,merchantKey);
System.out.println("查询服务商分账对象列表,返回参数:" + JSON.toJSONString(result));
System.out.println("=======execute query unfreezeList end=======");
return result;
}
}

View File

@@ -0,0 +1,37 @@
package com.jsowell.adapay.service;
import com.alibaba.fastjson2.JSON;
import com.google.common.collect.Maps;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Payment;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public class AdapayService {
/**
* 创建交易对象
* createTransactionObject
*/
public void createTransactionObject() {
// 请求参数
Map<String, Object> paymentParams = Maps.newHashMap();
paymentParams.put("app_id", "app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa");
paymentParams.put("order_no", "2023050911410199622174123");
paymentParams.put("pay_channel", "wx_lite");
paymentParams.put("pay_amt", "0.01");
paymentParams.put("currency", "cny");
paymentParams.put("goods_title", "测试商品");
paymentParams.put("goods_desc", "用于支付流程测试的商品");
// paymentParams.put("div_members", [{"amount":"0.05", "fee_flag":"Y", "member_id":"member_id_test"}]);
// 调用创建方法,获取 Payment对象_
try {
Map<String, Object> response = Payment.create(paymentParams);
System.out.println("response:" + JSON.toJSONString(response));
} catch (BaseAdaPayException e) {
e.printStackTrace();
}
}
}