Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ public class WxMaLiveGoodInfo implements Serializable {
* https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/liveplayer/pendant.html
*/
private List<String> goodsKey;


/**
* 当商品为第三方小程序的商品则填写为对应第三方小程序的appid,自身小程序商品则为''
*/
private String thirdPartyAppid;
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public static class Goods implements Serializable {
*/
@SerializedName("third_party_tag")
private String thirdPartyTag;

/**
* 当商品为第三方小程序的商品则填写为对应第三方小程序的appid,自身小程序商品则为''
*/
private String thirdPartyAppid;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class RefundsResult implements Serializable {
* </pre>
*/
@SerializedName(value = "create_time")
private Date createTime;
private String createTime;

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,6 @@ public class ReturnOrdersResult implements Serializable {
* </pre>
*/
@SerializedName(value = "finish_time")
private Date finishTime;
private String finishTime;

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
import com.google.common.base.CaseFormat;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.lang3.StringUtils;
import lombok.RequiredArgsConstructor;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.text.DateFormat;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
Expand All @@ -30,6 +30,11 @@
public class EcommerceServiceImpl implements EcommerceService {

private static final Gson GSON = new GsonBuilder().create();

// https://stackoverflow.com/questions/6873020/gson-date-format
// gson default date format not match, so custom DateFormat
// detail DateFormat: FULL,LONG,SHORT,MEDIUM
private static final Gson GSON_CUSTOM = new GsonBuilder().setDateFormat(DateFormat.FULL, DateFormat.FULL).create();
private final WxPayService payService;

@Override
Expand Down Expand Up @@ -71,7 +76,7 @@ public <T> T combineTransactions(TradeTypeEnum tradeType, CombineTransactionsReq

@Override
public CombineTransactionsNotifyResult parseCombineNotifyResult(String notifyData, SignatureHeader header) throws WxPayException {
if(Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)){
if (Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)) {
throw new WxPayException("非法请求,头部信息验证失败");
}
NotifyResponse response = GSON.fromJson(notifyData, NotifyResponse.class);
Expand All @@ -81,7 +86,7 @@ public CombineTransactionsNotifyResult parseCombineNotifyResult(String notifyDat
String nonce = resource.getNonce();
String apiV3Key = this.payService.getConfig().getApiV3Key();
try {
String result = AesUtils.decryptToString(associatedData, nonce,cipherText, apiV3Key);
String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key);
CombineTransactionsResult transactionsResult = GSON.fromJson(result, CombineTransactionsResult.class);

CombineTransactionsNotifyResult notifyResult = new CombineTransactionsNotifyResult();
Expand Down Expand Up @@ -117,7 +122,7 @@ public <T> T partnerTransactions(TradeTypeEnum tradeType, PartnerTransactionsReq

@Override
public PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException {
if(Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)){
if (Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)) {
throw new WxPayException("非法请求,头部信息验证失败");
}
NotifyResponse response = GSON.fromJson(notifyData, NotifyResponse.class);
Expand All @@ -127,7 +132,7 @@ public PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyDat
String nonce = resource.getNonce();
String apiV3Key = this.payService.getConfig().getApiV3Key();
try {
String result = AesUtils.decryptToString(associatedData, nonce,cipherText, apiV3Key);
String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key);
PartnerTransactionsResult transactionsResult = GSON.fromJson(result, PartnerTransactionsResult.class);

PartnerTransactionsNotifyResult notifyResult = new PartnerTransactionsNotifyResult();
Expand Down Expand Up @@ -277,7 +282,7 @@ public RefundQueryResult queryRefundByOutRefundNo(String subMchid, String outRef

@Override
public RefundNotifyResult parseRefundNotifyResult(String notifyData, SignatureHeader header) throws WxPayException {
if(Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)){
if (Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)) {
throw new WxPayException("非法请求,头部信息验证失败");
}
NotifyResponse response = GSON.fromJson(notifyData, NotifyResponse.class);
Expand All @@ -287,7 +292,7 @@ public RefundNotifyResult parseRefundNotifyResult(String notifyData, SignatureHe
String nonce = resource.getNonce();
String apiV3Key = this.payService.getConfig().getApiV3Key();
try {
String result = AesUtils.decryptToString(associatedData, nonce,cipherText, apiV3Key);
String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key);
RefundNotifyResult notifyResult = GSON.fromJson(result, RefundNotifyResult.class);
notifyResult.setRawData(response);
return notifyResult;
Expand Down Expand Up @@ -359,8 +364,9 @@ public InputStream downloadBill(String url) throws WxPayException {

/**
* 校验通知签名
*
* @param header 通知头信息
* @param data 通知数据
* @param data 通知数据
* @return true:校验通过 false:校验不通过
*/
private boolean verifyNotifySign(SignatureHeader header, String data) {
Expand All @@ -374,8 +380,9 @@ private boolean verifyNotifySign(SignatureHeader header, String data) {

/**
* 对象拼接到url
*
* @param o 转换对象
* @return 拼接好的string
* @return 拼接好的string
*/
private String parseURLPair(Object o) {
Map<Object, Object> map = new BeanMap(o);
Expand All @@ -384,13 +391,12 @@ private String parseURLPair(Object o) {
StringBuilder sb = new StringBuilder();
while (it.hasNext()) {
Map.Entry<Object, Object> e = it.next();
if ( !"class".equals(e.getKey()) && e.getValue() != null) {
if (!"class".equals(e.getKey()) && e.getValue() != null) {
sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, String.valueOf(e.getKey())))
.append("=").append(e.getValue()).append("&");
}
}
return sb.deleteCharAt(sb.length() - 1).toString();
}


}
}