Skip to content

Commit 56a271c

Browse files
committed
🎨 #1671 优化微信支付回调通知验证签名的代码
1 parent 7c0a38e commit 56a271c

2 files changed

Lines changed: 45 additions & 39 deletions

File tree

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ enum Device implements WxMpApiUrl {
6262
*/
6363
DEVICE_TRANSMSG(API_DEFAULT_HOST_URL, "/device/transmsg");
6464

65-
private String prefix;
66-
private String path;
65+
private final String prefix;
66+
private final String path;
6767

6868
@Override
6969
public String getUrl(WxMpConfigStorage config) {
@@ -131,8 +131,8 @@ enum Other implements WxMpApiUrl {
131131
*/
132132
CLEAR_QUOTA_URL(API_DEFAULT_HOST_URL, "/cgi-bin/clear_quota");
133133

134-
private String prefix;
135-
private String path;
134+
private final String prefix;
135+
private final String path;
136136

137137
@Override
138138
public String getUrl(WxMpConfigStorage config) {
@@ -159,8 +159,8 @@ enum Marketing implements WxMpApiUrl {
159159
*/
160160
WECHAT_AD_LEADS_GET(API_DEFAULT_HOST_URL, "/marketing/wechat_ad_leads/get");
161161

162-
private String prefix;
163-
private String path;
162+
private final String prefix;
163+
private final String path;
164164

165165
@Override
166166
public String getUrl(WxMpConfigStorage config) {
@@ -308,8 +308,8 @@ enum TemplateMsg implements WxMpApiUrl {
308308
*/
309309
TEMPLATE_DEL_PRIVATE_TEMPLATE(API_DEFAULT_HOST_URL, "/cgi-bin/template/del_private_template");
310310

311-
private String prefix;
312-
private String path;
311+
private final String prefix;
312+
private final String path;
313313

314314
@Override
315315
public String getUrl(WxMpConfigStorage config) {
@@ -332,8 +332,8 @@ enum UserBlacklist implements WxMpApiUrl {
332332
*/
333333
BATCHUNBLACKLIST(API_DEFAULT_HOST_URL, "/cgi-bin/tags/members/batchunblacklist");
334334

335-
private String prefix;
336-
private String path;
335+
private final String prefix;
336+
private final String path;
337337

338338
@Override
339339
public String getUrl(WxMpConfigStorage config) {
@@ -402,8 +402,8 @@ enum Wifi implements WxMpApiUrl {
402402
*/
403403
BIZWIFI_SHOP_UPDATE(API_DEFAULT_HOST_URL, "/bizwifi/shop/update");
404404

405-
private String prefix;
406-
private String path;
405+
private final String prefix;
406+
private final String path;
407407

408408
@Override
409409
public String getUrl(WxMpConfigStorage config) {
@@ -493,8 +493,8 @@ enum Ocr implements WxMpApiUrl {
493493
*/
494494
FILE_COMM(API_DEFAULT_HOST_URL, "/cv/ocr/comm");
495495

496-
private String prefix;
497-
private String path;
496+
private final String prefix;
497+
private final String path;
498498

499499
@Override
500500
public String getUrl(WxMpConfigStorage config) {
@@ -603,8 +603,8 @@ enum Card implements WxMpApiUrl {
603603
CARD_USER_CARD_LIST(API_DEFAULT_HOST_URL, "/card/user/getcardlist"),
604604
;
605605

606-
private String prefix;
607-
private String path;
606+
private final String prefix;
607+
private final String path;
608608

609609
@Override
610610
public String getUrl(WxMpConfigStorage config) {
@@ -683,8 +683,8 @@ enum DataCube implements WxMpApiUrl {
683683
*/
684684
GET_INTERFACE_SUMMARY_HOUR(API_DEFAULT_HOST_URL, "/datacube/getinterfacesummaryhour");
685685

686-
private String prefix;
687-
private String path;
686+
private final String prefix;
687+
private final String path;
688688

689689
@Override
690690
public String getUrl(WxMpConfigStorage config) {
@@ -755,8 +755,8 @@ enum Kefu implements WxMpApiUrl {
755755
*/
756756
CUSTOM_TYPING(API_DEFAULT_HOST_URL, "/cgi-bin/message/custom/typing");
757757

758-
private String prefix;
759-
private String path;
758+
private final String prefix;
759+
private final String path;
760760

761761
@Override
762762
public String getUrl(WxMpConfigStorage config) {
@@ -809,8 +809,8 @@ enum MassMessage implements WxMpApiUrl {
809809
*/
810810
MESSAGE_MASS_GET_URL(API_DEFAULT_HOST_URL, "/cgi-bin/message/mass/get");
811811

812-
private String prefix;
813-
private String path;
812+
private final String prefix;
813+
private final String path;
814814

815815
@Override
816816
public String getUrl(WxMpConfigStorage config) {
@@ -865,8 +865,8 @@ enum Material implements WxMpApiUrl {
865865
*/
866866
MATERIAL_BATCHGET_URL(API_DEFAULT_HOST_URL, "/cgi-bin/material/batchget_material");
867867

868-
private String prefix;
869-
private String path;
868+
private final String prefix;
869+
private final String path;
870870

871871
@Override
872872
public String getUrl(WxMpConfigStorage config) {
@@ -910,8 +910,8 @@ enum MemberCard implements WxMpApiUrl {
910910
*/
911911
MEMBER_CARD_ACTIVATE_TEMP_INFO(API_DEFAULT_HOST_URL, "/card/membercard/activatetempinfo/get");
912912

913-
private String prefix;
914-
private String path;
913+
private final String prefix;
914+
private final String path;
915915

916916
@Override
917917
public String getUrl(WxMpConfigStorage config) {
@@ -946,8 +946,8 @@ enum Store implements WxMpApiUrl {
946946
*/
947947
POI_ADD_URL(API_DEFAULT_HOST_URL, "/cgi-bin/poi/addpoi");
948948

949-
private String prefix;
950-
private String path;
949+
private final String prefix;
950+
private final String path;
951951

952952
@Override
953953
public String getUrl(WxMpConfigStorage config) {
@@ -978,8 +978,8 @@ enum User implements WxMpApiUrl {
978978
*/
979979
USER_CHANGE_OPENID_URL(API_DEFAULT_HOST_URL, "/cgi-bin/changeopenid");
980980

981-
private String prefix;
982-
private String path;
981+
private final String prefix;
982+
private final String path;
983983

984984
@Override
985985
public String getUrl(WxMpConfigStorage config) {
@@ -1029,8 +1029,8 @@ enum Comment implements WxMpApiUrl {
10291029
*/
10301030
REPLY_DELETE(API_DEFAULT_HOST_URL, "/cgi-bin/comment/reply/delete");
10311031

1032-
private String prefix;
1033-
private String path;
1032+
private final String prefix;
1033+
private final String path;
10341034

10351035
@Override
10361036
public String getUrl(WxMpConfigStorage config) {
@@ -1070,8 +1070,8 @@ enum ImgProc implements WxMpApiUrl {
10701070
*/
10711071
FILE_AI_CROP(API_DEFAULT_HOST_URL, "/cv/img/aicrop?ratios=%s");
10721072

1073-
private String prefix;
1074-
private String path;
1073+
private final String prefix;
1074+
private final String path;
10751075

10761076
@Override
10771077
public String getUrl(WxMpConfigStorage config) {
@@ -1145,8 +1145,8 @@ enum Invoice implements WxMpApiUrl {
11451145
*/
11461146
GET_PAY_MCH_SET_BIZ_ATTR(API_DEFAULT_HOST_URL, "/card/invoice/setbizattr?action=get_pay_mch"),
11471147
;
1148-
private String prefix;
1149-
private String path;
1148+
private final String prefix;
1149+
private final String path;
11501150

11511151
@Override
11521152
public String getUrl(WxMpConfigStorage config) {

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,16 @@ public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData, String sign
190190
try {
191191
log.debug("微信支付异步通知请求参数:{}", xmlData);
192192
WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData);
193-
if (result.getSignType() != null) {
194-
// 如果解析的通知对象中signType有值,则使用它进行验签
195-
signType = result.getSignType();
193+
if (signType == null) {
194+
if (result.getSignType() != null) {
195+
// 如果解析的通知对象中signType有值,则使用它进行验签
196+
signType = result.getSignType();
197+
} else if (this.getConfig().getSignType() != null) {
198+
// 如果配置中signType有值,则使用它进行验签
199+
signType = this.getConfig().getSignType();
200+
}
196201
}
202+
197203
log.debug("微信支付异步通知请求解析后的对象:{}", result);
198204
result.checkResult(this, signType, false);
199205
return result;

0 commit comments

Comments
 (0)