mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-03 12:17:46 +08:00
🆕 #2501【微信支付】增加V3版本回调通知应答
This commit is contained in:
parent
c84b46a55b
commit
6472484b32
@ -0,0 +1,50 @@
|
|||||||
|
package com.github.binarywang.wxpay.bean.notify;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信支付订单和退款的异步通知,V3版本共用的响应类.
|
||||||
|
* https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_11.shtml
|
||||||
|
*
|
||||||
|
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
|
||||||
|
* @date 2022-08-15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WxPayNotifyV3Response {
|
||||||
|
|
||||||
|
private static final transient String SUCCESS = "SUCCESS";
|
||||||
|
private static final transient String FAIL = "FAIL";
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回成功
|
||||||
|
*
|
||||||
|
* @param msg
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String success(String msg) {
|
||||||
|
WxPayNotifyV3Response response = new WxPayNotifyV3Response(SUCCESS, msg);
|
||||||
|
return new Gson().toJson(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回失败
|
||||||
|
*
|
||||||
|
* @param msg 返回信息,如非空,为错误原因
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String fail(String msg) {
|
||||||
|
WxPayNotifyV3Response response = new WxPayNotifyV3Response(FAIL, msg);
|
||||||
|
return new Gson().toJson(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -311,6 +311,7 @@ public class WxPayConstants {
|
|||||||
public static final String SUCCESS = "SUCCESS";
|
public static final String SUCCESS = "SUCCESS";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* v2
|
||||||
* 退款关闭.
|
* 退款关闭.
|
||||||
*/
|
*/
|
||||||
public static final String REFUND_CLOSE = "REFUNDCLOSE";
|
public static final String REFUND_CLOSE = "REFUNDCLOSE";
|
||||||
@ -321,10 +322,23 @@ public class WxPayConstants {
|
|||||||
public static final String PROCESSING = "PROCESSING";
|
public static final String PROCESSING = "PROCESSING";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* v2
|
||||||
* 退款异常.
|
* 退款异常.
|
||||||
* 退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往商户平台(pay.weixin.qq.com)-交易中心,手动处理此笔退款。
|
* 退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往商户平台(pay.weixin.qq.com)-交易中心,手动处理此笔退款。
|
||||||
*/
|
*/
|
||||||
public static final String CHANGE = "CHANGE";
|
public static final String CHANGE = "CHANGE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* v3
|
||||||
|
* 退款关闭
|
||||||
|
*/
|
||||||
|
public static final String CLOSED = "CLOSED";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* v3
|
||||||
|
* 退款异常
|
||||||
|
*/
|
||||||
|
public static final String ABNORMAL = "ABNORMAL";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ReceiverType {
|
public static class ReceiverType {
|
||||||
@ -345,4 +359,5 @@ public class WxPayConstants {
|
|||||||
*/
|
*/
|
||||||
public static final String PERSONAL_SUB_OPENID = "PERSONAL_SUB_OPENID";
|
public static final String PERSONAL_SUB_OPENID = "PERSONAL_SUB_OPENID";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.github.binarywang.wxpay.bean.notify;
|
package com.github.binarywang.wxpay.bean.notify;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@ -10,8 +11,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||||
* @date 2019-06-30
|
* @date 2019-06-30
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class WxPayNotifyResponseTest {
|
public class WxPayNotifyResponseTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* V2版本
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess() {
|
public void testSuccess() {
|
||||||
final String result = WxPayNotifyResponse.success("OK");
|
final String result = WxPayNotifyResponse.success("OK");
|
||||||
@ -38,4 +43,23 @@ public class WxPayNotifyResponseTest {
|
|||||||
"<return_msg><![CDATA[500]]></return_msg>" +
|
"<return_msg><![CDATA[500]]></return_msg>" +
|
||||||
"</xml>");
|
"</xml>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* V3版本
|
||||||
|
* https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testV3Fail() {
|
||||||
|
final String result = WxPayNotifyV3Response.fail("失败");
|
||||||
|
log.info(result);
|
||||||
|
assertThat(result).isNotEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testV3Success() {
|
||||||
|
final String result = WxPayNotifyV3Response.success("成功");
|
||||||
|
log.info(result);
|
||||||
|
assertThat(result).isNotEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user