You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
202 lines
5.6 KiB
202 lines
5.6 KiB
2 years ago
|
package com.ynxbd.common.bean.enums;
|
||
|
|
||
|
import lombok.ToString;
|
||
|
import org.apache.commons.lang3.ObjectUtils;
|
||
|
import org.apache.commons.lang3.StringUtils;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Arrays;
|
||
|
import java.util.List;
|
||
|
|
||
|
/**
|
||
|
* 商户类型
|
||
|
*
|
||
|
* @Author wsq
|
||
|
*/
|
||
|
@ToString
|
||
|
public enum MerchantEnum {
|
||
|
|
||
|
// 支付宝
|
||
|
ALI("ali", "【支付宝】", "3",
|
||
|
"25,26,27,28,29,30",
|
||
|
"ali_pay/notify",
|
||
|
"",
|
||
|
"10", "11", "12"),
|
||
|
|
||
|
// 微信
|
||
|
WX("wx", "【微信】", "4",
|
||
|
"10,11,12,13,14,15",
|
||
|
"wx_pay/apiNotify",
|
||
|
"wx_pay/nativeNotify",
|
||
|
"0", "1", "2"),
|
||
|
|
||
|
BCM("bcm", "【交行】", "4",
|
||
|
"",
|
||
|
"bcm_pay/notify",
|
||
|
"",
|
||
|
"20", "21", "22"),
|
||
|
|
||
|
WX_MEDICAL("wx_medical", "【微信医保】", "4",
|
||
|
"10,11,12,13,14,15",
|
||
|
"medical/payNotify",
|
||
|
"",
|
||
|
"0", "1", "2");
|
||
|
|
||
|
|
||
|
|
||
|
public final String CODE;
|
||
|
|
||
|
public final String NAME;
|
||
|
|
||
|
public final String HIS_PAY_WAY;
|
||
|
// 条码规则
|
||
|
public final String BAR_CODE_RULES;
|
||
|
// 支付回调通知地址
|
||
|
public final String NOTIFY_URL;
|
||
|
|
||
|
public final String QR_NOTIFY_URL;
|
||
|
// 程序内支付代码
|
||
|
public final String PAY_WAY_IN;
|
||
|
// 扫码支付代码
|
||
|
public final String PAY_WAY_QR;
|
||
|
// 盒子支付代码
|
||
|
public final String PAY_WAY_MICRO;
|
||
|
|
||
|
MerchantEnum(String CODE, String NAME, String HIS_PAY_WAY, String BAR_CODE_RULES, String NOTIFY_URL, String QR_NOTIFY_URL, String PAY_WAY_IN, String PAY_WAY_QR, String PAY_WAY_MICRO) {
|
||
|
this.CODE = CODE;
|
||
|
this.NAME = NAME;
|
||
|
this.HIS_PAY_WAY = HIS_PAY_WAY;
|
||
|
this.BAR_CODE_RULES = BAR_CODE_RULES;
|
||
|
this.NOTIFY_URL = NOTIFY_URL;
|
||
|
this.QR_NOTIFY_URL = QR_NOTIFY_URL;
|
||
|
this.PAY_WAY_IN = PAY_WAY_IN;
|
||
|
this.PAY_WAY_QR = PAY_WAY_QR;
|
||
|
this.PAY_WAY_MICRO = PAY_WAY_MICRO;
|
||
|
}
|
||
|
|
||
|
public static MerchantEnum getMerchantEnumByCode(String code) {
|
||
|
if (ObjectUtils.isEmpty(code)) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
for (MerchantEnum merchantEnum : MerchantEnum.values()) {
|
||
|
if (merchantEnum.CODE.equals(code)) {
|
||
|
return merchantEnum;
|
||
|
}
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 根据商户订单号获取支付类型
|
||
|
*
|
||
|
* @param outTradeNo 商户订单号
|
||
|
* @return 支付类型
|
||
|
*/
|
||
|
public static MerchantEnum getMerchantEnumByOutTradeNo(String outTradeNo) {
|
||
|
if (outTradeNo == null) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
if (outTradeNo.indexOf(MerchantEnum.WX.CODE.toUpperCase()) == 0) {
|
||
|
return MerchantEnum.WX;
|
||
|
|
||
|
} else if (outTradeNo.indexOf(MerchantEnum.ALI.CODE.toUpperCase()) == 0) {
|
||
|
return MerchantEnum.ALI;
|
||
|
} else {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 根据(数据库中的payWay)判断支付方式
|
||
|
*
|
||
|
* @param payWay 支付代码
|
||
|
* @return 支付方式
|
||
|
*/
|
||
|
public static MerchantEnum getMerchantEnumByPayWay(String payWay) {
|
||
|
if (ObjectUtils.isEmpty(payWay)) {
|
||
|
return MerchantEnum.WX;
|
||
|
}
|
||
|
for (MerchantEnum item : MerchantEnum.values()) {
|
||
|
if (item.PAY_WAY_IN.equals(payWay) || item.PAY_WAY_QR.equals(payWay) || item.PAY_WAY_MICRO.equals(payWay)) {
|
||
|
return item;
|
||
|
}
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 根据扫码的客户端判断支付类型
|
||
|
*
|
||
|
* @param userAgent 用户客户端信息
|
||
|
* @return 支付类型
|
||
|
*/
|
||
|
public static MerchantEnum getMerchantEnumByQr(String userAgent) {
|
||
|
if (userAgent.contains("MicroMessenger")) {
|
||
|
return MerchantEnum.WX;
|
||
|
|
||
|
} else if (userAgent.contains("AlipayClient")) {
|
||
|
return MerchantEnum.ALI;
|
||
|
|
||
|
} else {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 根据支付方式获取支付代码集合
|
||
|
*
|
||
|
* @param merchantEnum 支付方式
|
||
|
* @return 支付代码集合
|
||
|
*/
|
||
|
public static List<String> getPayWayValues(MerchantEnum merchantEnum) {
|
||
|
List<String> resultList = new ArrayList<>();
|
||
|
if (merchantEnum == null) {
|
||
|
return resultList;
|
||
|
}
|
||
|
|
||
|
for (MerchantEnum item : MerchantEnum.values()) {
|
||
|
if (item.CODE.equals(merchantEnum.CODE)) {
|
||
|
resultList.add(item.PAY_WAY_IN);
|
||
|
resultList.add(item.PAY_WAY_QR);
|
||
|
resultList.add(item.PAY_WAY_MICRO);
|
||
|
return resultList;
|
||
|
}
|
||
|
}
|
||
|
return resultList;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 根据扫码的客户端判断支付类型
|
||
|
*
|
||
|
* @param authCode 编码
|
||
|
* @return 支付类型
|
||
|
*/
|
||
|
public static MerchantEnum getMerchantEnumByAuthCode(String authCode) {
|
||
|
if (StringUtils.isEmpty(authCode) || authCode.length() < 16) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
String prefix = authCode.substring(0, 2);
|
||
|
for (MerchantEnum item : MerchantEnum.values()) {
|
||
|
if (Arrays.asList(item.BAR_CODE_RULES.split(",")).contains(prefix)) {
|
||
|
return item;
|
||
|
}
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 拼接回调地址
|
||
|
*/
|
||
|
public String getNotifyUrl(String outTradeNo, String notifyType) {
|
||
|
return this.NOTIFY_URL + "?notifyType=" + notifyType
|
||
|
+ (ObjectUtils.isEmpty(outTradeNo) ? "" : ("&outTradeNo=" + outTradeNo));
|
||
|
}
|
||
|
}
|