Skip to content

Commit

Permalink
🎨 #1671 优化微信支付回调通知验证签名的代码
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Jul 16, 2020
1 parent 7c0a38e commit 56a271c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ enum Device implements WxMpApiUrl {
*/
DEVICE_TRANSMSG(API_DEFAULT_HOST_URL, "/device/transmsg");

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -131,8 +131,8 @@ enum Other implements WxMpApiUrl {
*/
CLEAR_QUOTA_URL(API_DEFAULT_HOST_URL, "/cgi-bin/clear_quota");

private String prefix;
private String path;
private final String prefix;
private final String path;

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

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -308,8 +308,8 @@ enum TemplateMsg implements WxMpApiUrl {
*/
TEMPLATE_DEL_PRIVATE_TEMPLATE(API_DEFAULT_HOST_URL, "/cgi-bin/template/del_private_template");

private String prefix;
private String path;
private final String prefix;
private final String path;

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

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -402,8 +402,8 @@ enum Wifi implements WxMpApiUrl {
*/
BIZWIFI_SHOP_UPDATE(API_DEFAULT_HOST_URL, "/bizwifi/shop/update");

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -493,8 +493,8 @@ enum Ocr implements WxMpApiUrl {
*/
FILE_COMM(API_DEFAULT_HOST_URL, "/cv/ocr/comm");

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -603,8 +603,8 @@ enum Card implements WxMpApiUrl {
CARD_USER_CARD_LIST(API_DEFAULT_HOST_URL, "/card/user/getcardlist"),
;

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -683,8 +683,8 @@ enum DataCube implements WxMpApiUrl {
*/
GET_INTERFACE_SUMMARY_HOUR(API_DEFAULT_HOST_URL, "/datacube/getinterfacesummaryhour");

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -755,8 +755,8 @@ enum Kefu implements WxMpApiUrl {
*/
CUSTOM_TYPING(API_DEFAULT_HOST_URL, "/cgi-bin/message/custom/typing");

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -809,8 +809,8 @@ enum MassMessage implements WxMpApiUrl {
*/
MESSAGE_MASS_GET_URL(API_DEFAULT_HOST_URL, "/cgi-bin/message/mass/get");

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -865,8 +865,8 @@ enum Material implements WxMpApiUrl {
*/
MATERIAL_BATCHGET_URL(API_DEFAULT_HOST_URL, "/cgi-bin/material/batchget_material");

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -910,8 +910,8 @@ enum MemberCard implements WxMpApiUrl {
*/
MEMBER_CARD_ACTIVATE_TEMP_INFO(API_DEFAULT_HOST_URL, "/card/membercard/activatetempinfo/get");

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -946,8 +946,8 @@ enum Store implements WxMpApiUrl {
*/
POI_ADD_URL(API_DEFAULT_HOST_URL, "/cgi-bin/poi/addpoi");

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -978,8 +978,8 @@ enum User implements WxMpApiUrl {
*/
USER_CHANGE_OPENID_URL(API_DEFAULT_HOST_URL, "/cgi-bin/changeopenid");

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -1029,8 +1029,8 @@ enum Comment implements WxMpApiUrl {
*/
REPLY_DELETE(API_DEFAULT_HOST_URL, "/cgi-bin/comment/reply/delete");

private String prefix;
private String path;
private final String prefix;
private final String path;

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

private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down Expand Up @@ -1145,8 +1145,8 @@ enum Invoice implements WxMpApiUrl {
*/
GET_PAY_MCH_SET_BIZ_ATTR(API_DEFAULT_HOST_URL, "/card/invoice/setbizattr?action=get_pay_mch"),
;
private String prefix;
private String path;
private final String prefix;
private final String path;

@Override
public String getUrl(WxMpConfigStorage config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,16 @@ public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData, String sign
try {
log.debug("微信支付异步通知请求参数:{}", xmlData);
WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData);
if (result.getSignType() != null) {
// 如果解析的通知对象中signType有值,则使用它进行验签
signType = result.getSignType();
if (signType == null) {
if (result.getSignType() != null) {
// 如果解析的通知对象中signType有值,则使用它进行验签
signType = result.getSignType();
} else if (this.getConfig().getSignType() != null) {
// 如果配置中signType有值,则使用它进行验签
signType = this.getConfig().getSignType();
}
}

log.debug("微信支付异步通知请求解析后的对象:{}", result);
result.checkResult(this, signType, false);
return result;
Expand Down

0 comments on commit 56a271c

Please sign in to comment.