Skip to content

Commit

Permalink
1. paypal V2
Browse files Browse the repository at this point in the history
2.账单类型定义与实现
3.微信小程序领红包实现
4.代码优化
  • Loading branch information
egzosn committed Feb 22, 2021
1 parent abe13c8 commit 7de62e4
Show file tree
Hide file tree
Showing 31 changed files with 1,618 additions and 628 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.egzosn.pay.ali.api;

import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
Expand All @@ -19,6 +20,7 @@

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.egzosn.pay.ali.bean.AliPayBillType;
import com.egzosn.pay.ali.bean.AliPayConst;
import com.egzosn.pay.ali.bean.AliPayMessage;
import com.egzosn.pay.ali.bean.AliRefundResult;
Expand All @@ -27,6 +29,7 @@
import com.egzosn.pay.ali.bean.CertEnvironment;
import com.egzosn.pay.ali.bean.OrderSettle;
import com.egzosn.pay.common.api.BasePayService;
import com.egzosn.pay.common.bean.BillType;
import com.egzosn.pay.common.bean.MethodType;
import com.egzosn.pay.common.bean.Order;
import com.egzosn.pay.common.bean.PayMessage;
Expand Down Expand Up @@ -560,26 +563,42 @@ public Map<String, Object> refundquery(RefundOrder refundOrder) {
/**
* 目前只支持日账单
*
* @param billDate 账单类型,商户通过接口或商户经开放平台授权后其所属服务商通过接口可以获取以下账单类型:trade、signcustomer;trade指商户基于支付宝交易收单的业务账单;signcustomer是指基于商户支付宝余额收入及支出等资金变动的帐务账单;
* @param billType 账单时间:日账单格式为yyyy-MM-dd,月账单格式为yyyy-MM。
* @param billDate 账单时间:日账单格式为yyyy-MM-dd,月账单格式为yyyy-MM。
* @param billType 账单类型,商户通过接口或商户经开放平台授权后其所属服务商通过接口可以获取以下账单类型:trade、signcustomer;trade指商户基于支付宝交易收单的业务账单;signcustomer是指基于商户支付宝余额收入及支出等资金变动的帐务账单;
* @return 返回支付方下载对账单的结果
*/
@Deprecated
@Override
public Map<String, Object> downloadbill(Date billDate, String billType) {

return this.downloadBill(billDate, "trade".equals(billType) ? AliPayBillType.TRADE_DAY : AliPayBillType.SIGNCUSTOMER_DAY);
}

/**
* 下载对账单
*
* @param billDate 账单时间:日账单格式为yyyy-MM-dd,月账单格式为yyyy-MM。
* @param billType 账单类型,商户通过接口或商户经开放平台授权后其所属服务商通过接口可以获取以下账单类型:trade、signcustomer;trade指商户基于支付宝交易收单的业务账单;signcustomer是指基于商户支付宝余额收入及支出等资金变动的帐务账单;
* @return 返回支付方下载对账单的结果
*/
public Map<String, Object> downloadBill(Date billDate, BillType billType) {
//获取公共参数
Map<String, Object> parameters = getPublicParameters(AliTransactionType.DOWNLOADBILL);

Map<String, Object> bizContent = new TreeMap<>();
bizContent.put("bill_type", billType);
bizContent.put("bill_type", billType.getType());
//目前只支持日账单
bizContent.put("bill_date", DateUtils.formatDay(billDate));
bizContent.put("bill_date", DateUtils.formatDate(billDate, billType.getDatePattern()));
//设置请求参数的集合
parameters.put(BIZ_CONTENT, JSON.toJSONString(bizContent));
final String bizContentStr = JSON.toJSONString(bizContent);
parameters.put(BIZ_CONTENT, bizContentStr);
//设置签名
setSign(parameters);
return requestTemplate.getForObject(getReqUrl() + "?" + UriVariables.getMapToParameters(parameters), JSONObject.class);
}
Map<String, String> bizContentMap = new HashMap<String, String>(1);
parameters.put(BIZ_CONTENT, bizContentStr);
return requestTemplate.postForObject(getReqUrl() + "?" + UriVariables.getMapToParameters(parameters), bizContentMap, JSONObject.class);

}

/**
* @param tradeNoOrBillDate 支付平台订单号或者账单类型, 具体请
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.egzosn.pay.ali.bean;

import com.egzosn.pay.common.bean.BillType;
import com.egzosn.pay.common.util.DateUtils;

/**
* 支付宝账单类型
* @author Egan
* <pre>
* email [email protected]
* date 2021/2/22
* </pre>
*/
public enum AliPayBillType implements BillType {
/**
* 商户基于支付宝交易收单的业务账单;每日账单
*/
TRADE_DAY("trade", DateUtils.YYYY_MM_DD),
/**
* 商户基于支付宝交易收单的业务账单;每月账单
*/
TRADE_MONTH("trade", DateUtils.YYYY_MM),
/**
* 基于商户支付宝余额收入及支出等资金变动的帐务账单;每日账单
*/
SIGNCUSTOMER_DAY("signcustomer", DateUtils.YYYY_MM_DD),
/**
* 基于商户支付宝余额收入及支出等资金变动的帐务账单;每月账单
*/
SIGNCUSTOMER_MONTH("signcustomer", DateUtils.YYYY_MM),

;

/**
* 账单类型
*/
private String type;
/**
* 日期格式化表达式
*/
private String datePattern;

AliPayBillType(String type, String datePattern) {
this.type = type;
this.datePattern = datePattern;
}

/**
* 获取类型名称
*
* @return 类型
*/
@Override
public String getType() {
return type;
}

/**
* 获取类型对应的日期格式化表达式
*
* @return 日期格式化表达式
*/
@Override
public String getDatePattern() {
return datePattern;
}

/**
* 获取文件类型
*
* @return 文件类型
*/
@Override
public String getFileType() {
return null;
}


/**
* 自定义属性
*
* @return 自定义属性
*/
@Override
public String getCustom() {
return null;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.egzosn.pay.baidu.bean.BaiduBillType;
import com.egzosn.pay.baidu.bean.BaiduPayOrder;
import com.egzosn.pay.baidu.bean.BaiduTransactionType;
import com.egzosn.pay.baidu.bean.type.AuditStatus;
import com.egzosn.pay.baidu.util.Asserts;
import com.egzosn.pay.common.api.BasePayService;
import com.egzosn.pay.common.bean.BaseRefundResult;
import com.egzosn.pay.common.bean.BillType;
import com.egzosn.pay.common.bean.CurType;
import com.egzosn.pay.common.bean.MethodType;
import com.egzosn.pay.common.bean.PayMessage;
Expand Down Expand Up @@ -402,34 +404,48 @@ public Map<String, Object> refundquery(RefundOrder refundOrder) {
}

/**
* 下载资金账单
* 下载订单对账单
*
* @param billDate 账单时间:日账单格式为yyyy-MM-dd
* @param accessToken 用户token
* @return 对账单
*/
@Deprecated
@Override
public Map<String, Object> downloadbill(Date billDate, String accessToken) {
return downloadBill(billDate, new BaiduBillType(accessToken, BaiduTransactionType.DOWNLOAD_ORDER_BILL.name()));
}

/**
* 下载对账单
*
* @param billDate 账单时间:日账单格式为yyyy-MM-dd,月账单格式为yyyy-MM。
* @param billType 账单类型 {@link BaiduBillType}
* @return 返回支付方下载对账单的结果
*/
public Map<String, Object> downloadBill(Date billDate, BillType billType) {
Map<String, Object> parameters = new HashMap<>();
parameters.put("access_token", accessToken);
parameters.put("billTime", DateUtils.formatDay(billDate));
return requestTemplate.getForObject(String.format("%s?%s", getReqUrl(BaiduTransactionType.DOWNLOAD_BILL),
parameters.put("access_token", billType.getCustom());
parameters.put("billTime", DateUtils.formatDate(billDate, billType.getDatePattern()));
final String type = billType.getType();
BaiduTransactionType transactionType = BaiduTransactionType.DOWNLOAD_ORDER_BILL;
if (BaiduTransactionType.DOWNLOAD_BILL.name().equals(type)) {
transactionType = BaiduTransactionType.DOWNLOAD_BILL;
}
return requestTemplate.getForObject(String.format("%s?%s", getReqUrl(transactionType),
UriVariables.getMapToParameters(parameters)), JSONObject.class);
}

/**
* 下载订单对账单
* 下载资金账单
*
* @param billDate 账单时间:日账单格式为yyyy-MM-dd
* @param accessToken 用户token
* @return 账单结果
*/
public Map<String, Object> downloadOrderBill(Date billDate, String accessToken) {
Map<String, Object> parameters = new HashMap<>();
parameters.put("access_token", accessToken);
parameters.put("billTime", DateUtils.formatDay(billDate));
return requestTemplate.getForObject(String.format("%s?%s", getReqUrl(BaiduTransactionType.DOWNLOAD_ORDER_BILL),
UriVariables.getMapToParameters(parameters)), JSONObject.class);
@Deprecated
public Map<String, Object> downloadMoneyBill(Date billDate, String accessToken) {
return downloadBill(billDate, new BaiduBillType(accessToken, BaiduTransactionType.DOWNLOAD_BILL.name()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.egzosn.pay.baidu.bean;

import com.egzosn.pay.common.bean.BillType;
import com.egzosn.pay.common.util.DateUtils;
import com.egzosn.pay.common.util.str.StringUtils;

/**
* 百度
* @author Egan
* <pre>
* email [email protected]
* date 2021/2/22
* </pre>
*/
public class BaiduBillType implements BillType {
/**
* 用户accessToken
*/
private String accessToken;
/**
* 值为DOWNLOAD_ORDER_BILL与DOWNLOAD_BILL
* com.egzosn.pay.baidu.bean.BaiduTransactionType#DOWNLOAD_ORDER_BILL
* com.egzosn.pay.baidu.bean.BaiduTransactionType#DOWNLOAD_BILL
*/
private String type;

private String datePattern;

public String getAccessToken() {
return accessToken;
}

public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}

public void setType(String type) {
this.type = type;
}

/**
* 获取类型名称
*
* @return 类型
*/
@Override
public String getType() {
return type;
}

/**
* 获取类型对应的日期格式化表达式
*
* @return 日期格式化表达式
*/
@Override
public String getDatePattern() {
if (StringUtils.isEmpty(datePattern)){
datePattern = DateUtils.YYYY_MM_DD;
}
return datePattern;
}

/**
* 获取文件类型
*
* @return 文件类型
*/
@Override
public String getFileType() {
return null;
}

public void setDatePattern(String datePattern) {
this.datePattern = datePattern;
}



/**
* 自定义属性
*
* @return 自定义属性
*/
@Override
public String getCustom() {
return accessToken;
}

public BaiduBillType() {
}

public BaiduBillType(String accessToken) {
this.accessToken = accessToken;
}

public BaiduBillType(String accessToken, String type) {
this.accessToken = accessToken;
this.type = type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public String createSign(Map<String, Object> content, String characterEncoding)
*/
@Override
public <O extends PayOrder> String toPay(O order) {
Map orderInfo = orderInfo(order);
Map<String, Object> orderInfo = orderInfo(order);
return buildRequest(orderInfo, MethodType.POST);
}

Expand Down Expand Up @@ -423,6 +423,30 @@ public PayOutMessage payBack(Map<String, String[]> parameterMap, InputStream is)
return getPayMessageHandler().handle(payMessage, context, this);
}

/**
* 使用转换过的参数进行回调处理
*
* @param data 转化后的参数Map
* @return 获得回调响应信息
*/
@Override
public PayOutMessage payBack(Map<String, Object> data) {
if (LOG.isDebugEnabled()) {
LOG.debug("回调响应:" + JSON.toJSONString(data));
}
if (!verify(data)) {
return getPayOutMessage("fail", "失败");
}
PayMessage payMessage = this.createMessage(data);
Map<String, Object> context = new HashMap<String, Object>();
for (PayMessageInterceptor interceptor : interceptors) {
if (!interceptor.intercept(payMessage, context, this)) {
return successPayOutMessage(payMessage);
}
}
return getPayMessageHandler().handle(payMessage, context, this);
}

/**
* 创建消息
*
Expand Down
Loading

0 comments on commit 7de62e4

Please sign in to comment.