mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-06-20 06:22:27 +08:00
移除已废弃的字段与方法
This commit is contained in:
@@ -4,7 +4,8 @@ import com.egzosn.pay.common.api.BasePayConfigStorage;
|
||||
|
||||
/**
|
||||
* 微信配置存储
|
||||
* @author egan
|
||||
*
|
||||
* @author egan
|
||||
*
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
@@ -17,34 +18,32 @@ public class WxPayConfigStorage extends BasePayConfigStorage {
|
||||
/**
|
||||
* 微信分配的公众账号ID
|
||||
*/
|
||||
private String appid ;
|
||||
private String appId;
|
||||
/**
|
||||
* 微信分配的子商户公众账号ID
|
||||
*/
|
||||
private String subAppid ;
|
||||
private String subAppId;
|
||||
/**
|
||||
* 微信支付分配的商户号 合作者id
|
||||
* 微信支付分配的商户号 合作者id
|
||||
*/
|
||||
private String mchId;
|
||||
/**
|
||||
* 微信支付分配的子商户号,开发者模式下必填 合作者id
|
||||
* 微信支付分配的子商户号,开发者模式下必填 合作者id
|
||||
*/
|
||||
private String subMchId;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public String getAppid() {
|
||||
return appid;
|
||||
}
|
||||
|
||||
public void setAppid(String appid) {
|
||||
this.appid = appid;
|
||||
return appId;
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public void setAppid(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -56,8 +55,6 @@ public class WxPayConfigStorage extends BasePayConfigStorage {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getSeller() {
|
||||
return null;
|
||||
@@ -73,7 +70,8 @@ public class WxPayConfigStorage extends BasePayConfigStorage {
|
||||
}
|
||||
|
||||
/**
|
||||
* 为商户平台设置的密钥key
|
||||
* 为商户平台设置的密钥key
|
||||
*
|
||||
* @return 微信密钥
|
||||
*/
|
||||
public String getSecretKey() {
|
||||
@@ -81,17 +79,50 @@ public class WxPayConfigStorage extends BasePayConfigStorage {
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
setKeyPrivate(secretKey);
|
||||
setKeyPrivate(secretKey);
|
||||
}
|
||||
|
||||
public void setAppId(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用id
|
||||
* 纠正名称
|
||||
*
|
||||
* @return 应用id
|
||||
*/
|
||||
@Override
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public String getSubAppId() {
|
||||
return subAppId;
|
||||
}
|
||||
|
||||
public void setSubAppId(String subAppId) {
|
||||
this.subAppId = subAppId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用id
|
||||
* 纠正名称
|
||||
*
|
||||
* @return 应用id
|
||||
* @see #getSubAppId()
|
||||
*/
|
||||
@Deprecated
|
||||
public String getSubAppid() {
|
||||
return subAppid;
|
||||
return subAppId;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setSubAppid(String subAppid) {
|
||||
this.subAppid = subAppid;
|
||||
this.subAppId = subAppid;
|
||||
}
|
||||
|
||||
|
||||
public String getSubMchId() {
|
||||
return subMchId;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ import com.egzosn.pay.wx.bean.WxTransferType;
|
||||
* date 2016-5-18 14:09:01
|
||||
* </pre>
|
||||
*/
|
||||
public class WxPayService extends BasePayService<WxPayConfigStorage> implements WxRedPackService,WxBillService {
|
||||
public class WxPayService extends BasePayService<WxPayConfigStorage> implements WxRedPackService, WxBillService {
|
||||
|
||||
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
@Override
|
||||
public boolean verify(Map<String, Object> params) {
|
||||
|
||||
if (null == params.get(SIGN) || !(SUCCESS.equals(params.get(RETURN_CODE)) && SUCCESS.equals(params.get(RESULT_CODE))) ) {
|
||||
if (null == params.get(SIGN) || !(SUCCESS.equals(params.get(RETURN_CODE)) && SUCCESS.equals(params.get(RESULT_CODE)))) {
|
||||
if (LOG.isErrorEnabled()) {
|
||||
LOG.error(String.format("微信支付异常:return_code=%s,参数集=%s", params.get(RETURN_CODE), params));
|
||||
}
|
||||
@@ -140,26 +140,15 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
}
|
||||
|
||||
try {
|
||||
return signVerify(params, (String) params.get(SIGN)) && verifySource((String) params.get(OUT_TRADE_NO));
|
||||
} catch (PayErrorException e) {
|
||||
return signVerify(params, (String) params.get(SIGN));
|
||||
}
|
||||
catch (PayErrorException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 微信是否也需要再次校验来源,进行订单查询
|
||||
*
|
||||
* @param id 商户单号
|
||||
* @return true通过
|
||||
*/
|
||||
@Override
|
||||
public boolean verifySource(String id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据反馈回来的信息,生成签名结果
|
||||
*
|
||||
@@ -167,7 +156,6 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
* @param sign 比对的签名结果
|
||||
* @return 生成的签名结果
|
||||
*/
|
||||
@Override
|
||||
public boolean signVerify(Map<String, Object> params, String sign) {
|
||||
return signVerify(params, sign, payConfigStorage.isTest());
|
||||
}
|
||||
@@ -190,11 +178,11 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
private Map<String, Object> getPublicParameters() {
|
||||
|
||||
Map<String, Object> parameters = new TreeMap<String, Object>();
|
||||
parameters.put(APPID, payConfigStorage.getAppid());
|
||||
parameters.put(APPID, payConfigStorage.getAppId());
|
||||
parameters.put(MCH_ID, payConfigStorage.getMchId());
|
||||
//判断如果是服务商模式信息则加入
|
||||
setParameters(parameters, "sub_mch_id", payConfigStorage.getSubMchId());
|
||||
setParameters(parameters, "sub_appid", payConfigStorage.getSubAppid());
|
||||
setParameters(parameters, "sub_appid", payConfigStorage.getSubAppId());
|
||||
parameters.put(NONCE_STR, SignUtils.randomStr());
|
||||
return parameters;
|
||||
|
||||
@@ -289,7 +277,8 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
params.put("timeStamp", System.currentTimeMillis() / 1000);
|
||||
params.put("nonceStr", result.get(NONCE_STR));
|
||||
params.put("package", "prepay_id=" + result.get("prepay_id"));
|
||||
} else if (WxTransactionType.APP == order.getTransactionType()) {
|
||||
}
|
||||
else if (WxTransactionType.APP == order.getTransactionType()) {
|
||||
params.put("partnerid", payConfigStorage.getPid());
|
||||
params.put(APPID, payConfigStorage.getAppid());
|
||||
params.put("prepayid", result.get("prepay_id"));
|
||||
@@ -391,7 +380,8 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
TreeMap<String, Object> map = new TreeMap<String, Object>();
|
||||
try {
|
||||
return XML.inputStream2Map(is, map);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new PayErrorException(new PayException("IOException", e.getMessage()));
|
||||
}
|
||||
|
||||
@@ -419,7 +409,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
*/
|
||||
@Override
|
||||
public PayOutMessage successPayOutMessage(PayMessage payMessage) {
|
||||
return PayOutMessage.XML().code("Success").content("成功").build();
|
||||
return PayOutMessage.XML().code("SUCCESS").content("成功").build();
|
||||
}
|
||||
|
||||
|
||||
@@ -471,7 +461,8 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
if (null == order.getTransactionType()) {
|
||||
order.setTransactionType(WxTransactionType.MICROPAY);
|
||||
|
||||
} else if (WxTransactionType.MICROPAY != order.getTransactionType() && WxTransactionType.FACEPAY != order.getTransactionType()) {
|
||||
}
|
||||
else if (WxTransactionType.MICROPAY != order.getTransactionType() && WxTransactionType.FACEPAY != order.getTransactionType()) {
|
||||
throw new PayErrorException(new PayException("-1", "错误的交易类型:" + order.getTransactionType()));
|
||||
}
|
||||
return orderInfo(order);
|
||||
@@ -575,7 +566,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> downloadbill(Date billDate, String billType) {
|
||||
Map<String, Object> parameters = getDownloadBillParam(billDate, billType,false);
|
||||
Map<String, Object> parameters = getDownloadBillParam(billDate, billType, false);
|
||||
//设置签名
|
||||
setSign(parameters);
|
||||
String respStr = requestTemplate.postForObject(getReqUrl(WxTransactionType.DOWNLOADBILL), XML.getMap2Xml(parameters), String.class);
|
||||
@@ -595,25 +586,26 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
*
|
||||
* @param billDate 账单类型,商户通过接口或商户经开放平台授权后其所属服务商通过接口可以获取以下账单类型:trade、signcustomer;trade指商户基于支付宝交易收单的业务账单;signcustomer是指基于商户支付宝余额收入及支出等资金变动的帐务账单;
|
||||
* @param billType 账单时间:日账单格式为yyyy-MM-dd,月账单格式为yyyy-MM。
|
||||
* @param path 账单返回格式 账单存储的基础路径,按月切割
|
||||
* @param path 账单返回格式 账单存储的基础路径,按月切割
|
||||
* @return 返回支付方下载对账单的结果
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> downloadbill(Date billDate, String billType, String path) {
|
||||
Map<String, Object> parameters = getDownloadBillParam(billDate, billType,true);
|
||||
//设置签名
|
||||
Map<String, Object> parameters = getDownloadBillParam(billDate, billType, true);
|
||||
//设置签名
|
||||
setSign(parameters);
|
||||
InputStream inputStream = requestTemplate.postForObject(getReqUrl(WxTransactionType.DOWNLOADBILL), XML.getMap2Xml(parameters), InputStream.class);
|
||||
try {
|
||||
//解压流
|
||||
inputStream = uncompress(inputStream);
|
||||
writeToLocal(path+DateUtils.formatDate(new Date(), DateUtils.YYYYMM)+"/"+DateUtils.formatDate(new Date(), DateUtils.YYYYMMDDHHMMSS)+".txt", inputStream);
|
||||
writeToLocal(path + DateUtils.formatDate(new Date(), DateUtils.YYYYMM) + "/" + DateUtils.formatDate(new Date(), DateUtils.YYYYMMDDHHMMSS) + ".txt", inputStream);
|
||||
Map<String, Object> ret = new HashMap<String, Object>(3);
|
||||
ret.put(RETURN_CODE, SUCCESS);
|
||||
ret.put(RETURN_MSG_CODE, "ok");
|
||||
ret.put("data", path);
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Map<String, Object> ret = new HashMap<String, Object>(3);
|
||||
ret.put(RETURN_CODE, FAIL);
|
||||
@@ -627,8 +619,8 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
* GZIP解压缩
|
||||
*
|
||||
* @param input 输入流账单
|
||||
* @return 解压后输入流
|
||||
* @throws IOException IOException
|
||||
* @return 解压后输入流
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
public static InputStream uncompress(InputStream input) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
@@ -644,6 +636,7 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
|
||||
/**
|
||||
* 将InputStream写入本地文件
|
||||
*
|
||||
* @param destination 写入本地目录
|
||||
* @param inputStream 输入流
|
||||
* @throws IOException IOException
|
||||
@@ -651,45 +644,46 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
private void writeToLocal(String destination, InputStream inputStream)
|
||||
throws IOException {
|
||||
|
||||
// 判断字节大小
|
||||
if (inputStream.available() != 0) {
|
||||
System.out.println("结果大小:" + inputStream.available());
|
||||
File file = new File(destination);
|
||||
if (!file.getParentFile().exists()) {
|
||||
boolean result = file.getParentFile().mkdirs();
|
||||
if (!result) {
|
||||
System.out.println("创建失败");
|
||||
}
|
||||
// 判断字节大小
|
||||
if (inputStream.available() != 0) {
|
||||
System.out.println("结果大小:" + inputStream.available());
|
||||
File file = new File(destination);
|
||||
if (!file.getParentFile().exists()) {
|
||||
boolean result = file.getParentFile().mkdirs();
|
||||
if (!result) {
|
||||
System.out.println("创建失败");
|
||||
}
|
||||
OutputStream out = new FileOutputStream(file);
|
||||
int size = 0;
|
||||
int len = 0;
|
||||
byte[] buf = new byte[1024];
|
||||
while ((size = inputStream.read(buf)) != -1) {
|
||||
len += size;
|
||||
out.write(buf, 0, size);
|
||||
}
|
||||
System.out.println("最终写入字节数大小:" + len);
|
||||
inputStream.close();
|
||||
out.close();
|
||||
}
|
||||
OutputStream out = new FileOutputStream(file);
|
||||
int size = 0;
|
||||
int len = 0;
|
||||
byte[] buf = new byte[1024];
|
||||
while ((size = inputStream.read(buf)) != -1) {
|
||||
len += size;
|
||||
out.write(buf, 0, size);
|
||||
}
|
||||
System.out.println("最终写入字节数大小:" + len);
|
||||
inputStream.close();
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 下载账单公共参数
|
||||
*
|
||||
* @param billDate 账单类型,商户通过接口或商户经开放平台授权后其所属服务商通过接口可以获取以下账单类型:trade、signcustomer;trade指商户基于支付宝交易收单的业务账单;signcustomer是指基于商户支付宝余额收入及支出等资金变动的帐务账单;
|
||||
* @param billType 账单时间:日账单格式为yyyy-MM-dd,月账单格式为yyyy-MM。
|
||||
* @param tarType 账单返回格式 默认返回流false ,gzip 时候true
|
||||
* @param tarType 账单返回格式 默认返回流false ,gzip 时候true
|
||||
* @return
|
||||
*/
|
||||
private Map<String, Object> getDownloadBillParam(Date billDate, String billType,boolean tarType) {
|
||||
private Map<String, Object> getDownloadBillParam(Date billDate, String billType, boolean tarType) {
|
||||
//获取公共参数
|
||||
Map<String, Object> parameters = getPublicParameters();
|
||||
parameters.put("bill_type", billType);
|
||||
//目前只支持日账单
|
||||
parameters.put("bill_date", DateUtils.formatDate(billDate, DateUtils.YYYYMMDD));
|
||||
if(tarType){
|
||||
if (tarType) {
|
||||
parameters.put("tar_type", "GZIP");
|
||||
}
|
||||
return parameters;
|
||||
@@ -702,7 +696,6 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
* @param transactionType 交易类型
|
||||
* @return 返回支付方对应接口的结果
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> secondaryInterface(Object transactionIdOrBillDate, String outTradeNoBillType, TransactionType transactionType) {
|
||||
|
||||
if (transactionType == WxTransactionType.REFUND) {
|
||||
@@ -735,12 +728,12 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
* @param order 转账订单
|
||||
* <pre>
|
||||
*
|
||||
* 注意事项:
|
||||
* ◆ 当返回错误码为“SYSTEMERROR”时,请不要更换商户订单号,一定要使用原商户订单号重试,否则可能造成重复支付等资金风险。
|
||||
* ◆ XML具有可扩展性,因此返回参数可能会有新增,而且顺序可能不完全遵循此文档规范,如果在解析回包的时候发生错误,请商户务必不要换单重试,请商户联系客服确认付款情况。如果有新回包字段,会更新到此API文档中。
|
||||
* ◆ 因为错误代码字段err_code的值后续可能会增加,所以商户如果遇到回包返回新的错误码,请商户务必不要换单重试,请商户联系客服确认付款情况。如果有新的错误码,会更新到此API文档中。
|
||||
* ◆ 错误代码描述字段err_code_des只供人工定位问题时做参考,系统实现时请不要依赖这个字段来做自动化处理。
|
||||
* </pre>
|
||||
* 注意事项:
|
||||
* ◆ 当返回错误码为“SYSTEMERROR”时,请不要更换商户订单号,一定要使用原商户订单号重试,否则可能造成重复支付等资金风险。
|
||||
* ◆ XML具有可扩展性,因此返回参数可能会有新增,而且顺序可能不完全遵循此文档规范,如果在解析回包的时候发生错误,请商户务必不要换单重试,请商户联系客服确认付款情况。如果有新回包字段,会更新到此API文档中。
|
||||
* ◆ 因为错误代码字段err_code的值后续可能会增加,所以商户如果遇到回包返回新的错误码,请商户务必不要换单重试,请商户联系客服确认付款情况。如果有新的错误码,会更新到此API文档中。
|
||||
* ◆ 错误代码描述字段err_code_des只供人工定位问题时做参考,系统实现时请不要依赖这个字段来做自动化处理。
|
||||
* </pre>
|
||||
* @return 对应的转账结果
|
||||
*/
|
||||
@Override
|
||||
@@ -757,7 +750,8 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
if (null != order.getTransferType() && TRANSFERS == order.getTransferType()) {
|
||||
transfers(parameters, order);
|
||||
parameters.put("mchid", payConfigStorage.getPid());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
parameters.put(MCH_ID, payConfigStorage.getPid());
|
||||
order.setTransferType(WxTransferType.PAY_BANK);
|
||||
payBank(parameters, order);
|
||||
@@ -842,7 +836,8 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
public String keyPublic(String content) {
|
||||
try {
|
||||
return RSA2.encrypt(content, payConfigStorage.getKeyPublic(), CIPHER_ALGORITHM, payConfigStorage.getInputCharset());
|
||||
} catch (GeneralSecurityException | IOException e) {
|
||||
}
|
||||
catch (GeneralSecurityException | IOException e) {
|
||||
throw new PayErrorException(new WxPayError(FAILURE, e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
@@ -873,7 +868,8 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> implements
|
||||
//现金红包,小程序红包默认传1.裂变红包取传入值,且需要大于3
|
||||
parameters.put("total_num", Math.max(redpackOrder.getTotalNum(), 3));
|
||||
parameters.put("amt_type", "ALL_RAND");
|
||||
} else if (WxSendredpackType.SENDMINIPROGRAMHB == redpackOrder.getTransferType()) {
|
||||
}
|
||||
else if (WxSendredpackType.SENDMINIPROGRAMHB == redpackOrder.getTransferType()) {
|
||||
parameters.put("notify_way", "MINI_PROGRAM_JSAPI");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user