🎨 优化部分代码

This commit is contained in:
Binary Wang 2023-07-08 19:23:26 +08:00
parent 736fbd3ed8
commit e621bb1828
6 changed files with 23 additions and 23 deletions

View File

@ -5,7 +5,7 @@ import lombok.Data;
/**
* @author momorans
* @create 2019-03-12
* @since 2019-03-12
**/
@Data
@Builder

View File

@ -12,13 +12,11 @@ import java.io.Serializable;
* 通用通知实体
*
* @author yuanbo
* @create 2022-04-26-21:33 PM
* @since 2022-04-26-21:33 PM
*/
@Data
@NoArgsConstructor
public class ProfitSharingNotifyData implements Serializable{
private static final long serialVersionUID = 4242383310854692441L;
/**

View File

@ -12,13 +12,11 @@ import java.io.Serializable;
* 分账动账通知解密后数据实体
*
* @author yuanbo
* @create 2022-04-26-21:08 PM
* @since 2022-04-26-21:08 PM
*/
@Data
@NoArgsConstructor
public class ProfitSharingNotifyResult implements Serializable {
private static final long serialVersionUID = -2875006651351414624L;
/**

View File

@ -238,7 +238,7 @@ public interface ProfitSharingV3Service {
* @throws WxPayException the wx pay exception
* @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_10.shtml">微信文档</a>
*/
ProfitSharingNotifyData getProfitSharingNotifyData(String notifyData, SignatureHeader header) throws WxPayException;
ProfitSharingNotifyResult getProfitSharingNotifyData(String notifyData, SignatureHeader header) throws WxPayException;
/**
* <pre>

View File

@ -48,14 +48,17 @@ public class ProfitSharingV3ServiceImpl implements ProfitSharingV3Service {
@Override
public ProfitSharingResult getProfitSharingResult(String outOrderNo, String transactionId) throws WxPayException {
String url = String.format("%s/v3/profitsharing/orders/%s?transaction_id=%s", this.payService.getPayBaseUrl(), outOrderNo, transactionId);
String url = String.format("%s/v3/profitsharing/orders/%s?transaction_id=%s", this.payService.getPayBaseUrl(),
outOrderNo, transactionId);
String result = this.payService.getV3(url);
return GSON.fromJson(result, ProfitSharingResult.class);
}
@Override
public ProfitSharingResult getProfitSharingResult(String outOrderNo, String transactionId, String subMchId) throws WxPayException {
String url = String.format("%s/v3/profitsharing/orders/%s?sub_mchid=%s&transaction_id=%s", this.payService.getPayBaseUrl(), outOrderNo, subMchId, transactionId);
public ProfitSharingResult getProfitSharingResult(String outOrderNo, String transactionId, String subMchId)
throws WxPayException {
String url = String.format("%s/v3/profitsharing/orders/%s?sub_mchid=%s&transaction_id=%s",
this.payService.getPayBaseUrl(), outOrderNo, subMchId, transactionId);
String result = this.payService.getV3(url);
return GSON.fromJson(result, ProfitSharingResult.class);
}
@ -70,14 +73,17 @@ public class ProfitSharingV3ServiceImpl implements ProfitSharingV3Service {
@Override
public ProfitSharingReturnResult getProfitSharingReturnResult(String outOrderNo, String outReturnNo) throws WxPayException {
String url = String.format("%s/v3/profitsharing/return-orders/%s?out_order_no=%s", this.payService.getPayBaseUrl(), outReturnNo, outOrderNo);
String url = String.format("%s/v3/profitsharing/return-orders/%s?out_order_no=%s", this.payService.getPayBaseUrl(),
outReturnNo, outOrderNo);
String result = this.payService.getV3(url);
return GSON.fromJson(result, ProfitSharingReturnResult.class);
}
@Override
public ProfitSharingReturnResult getProfitSharingReturnResult(String outOrderNo, String outReturnNo, String subMchId) throws WxPayException {
String url = String.format("%s/v3/profitsharing/return-orders/%s?sub_mchid=%s&out_order_no=%s", this.payService.getPayBaseUrl(), outReturnNo, subMchId, outOrderNo);
public ProfitSharingReturnResult getProfitSharingReturnResult(String outOrderNo, String outReturnNo, String subMchId)
throws WxPayException {
String url = String.format("%s/v3/profitsharing/return-orders/%s?sub_mchid=%s&out_order_no=%s",
this.payService.getPayBaseUrl(), outReturnNo, subMchId, outOrderNo);
String result = this.payService.getV3(url);
return GSON.fromJson(result, ProfitSharingReturnResult.class);
}
@ -114,7 +120,7 @@ public class ProfitSharingV3ServiceImpl implements ProfitSharingV3Service {
}
@Override
public ProfitSharingNotifyData getProfitSharingNotifyData(String notifyData, SignatureHeader header) throws WxPayException {
public ProfitSharingNotifyResult getProfitSharingNotifyData(String notifyData, SignatureHeader header) throws WxPayException {
ProfitSharingNotifyData response = parseNotifyData(notifyData, header);
ProfitSharingNotifyData.Resource resource = response.getResource();
String cipherText = resource.getCipherText();
@ -123,8 +129,7 @@ public class ProfitSharingV3ServiceImpl implements ProfitSharingV3Service {
String apiV3Key = this.payService.getConfig().getApiV3Key();
try {
String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key);
ProfitSharingNotifyData notifyResult = GSON.fromJson(result, ProfitSharingNotifyData.class);
return notifyResult;
return GSON.fromJson(result, ProfitSharingNotifyResult.class);
} catch (GeneralSecurityException | IOException e) {
throw new WxPayException("解析报文异常!", e);
}
@ -132,7 +137,9 @@ public class ProfitSharingV3ServiceImpl implements ProfitSharingV3Service {
@Override
public ProfitSharingBillResult getProfitSharingBill(ProfitSharingBillRequest request) throws WxPayException {
String url = String.format("%s/v3/profitsharing/bills?bill_date=%s", this.payService.getPayBaseUrl(), request.getBillDate());
String url = String.format("%s/v3/profitsharing/bills?bill_date=%s", this.payService.getPayBaseUrl(),
request.getBillDate());
if (StringUtils.isNotBlank(request.getSubMchId())) {
url = String.format("%s&sub_mchid=%s", url, request.getSubMchId());
}
@ -158,10 +165,7 @@ public class ProfitSharingV3ServiceImpl implements ProfitSharingV3Service {
* @return true:校验通过 false:校验不通过
*/
private boolean verifyNotifySign(SignatureHeader header, String data) throws WxPayException {
String beforeSign = String.format("%s\n%s\n%s\n",
header.getTimeStamp(),
header.getNonce(),
data);
String beforeSign = String.format("%s%n%s%n%s%n", header.getTimeStamp(), header.getNonce(), data);
Verifier verifier = this.payService.getConfig().getVerifier();
if (verifier == null) {
throw new WxPayException("证书检验对象为空");

View File

@ -15,7 +15,7 @@ import org.testng.annotations.Test;
* 测试类
*
* @author yuanbo
* @create 2022-04-26-22:33 PM
* @since 2022-04-26-22:33 PM
*/
@Test
@Slf4j