mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
🎨 #2985【企业微信】增加会话存档常量类型支持
This commit is contained in:
parent
e2e4d345b0
commit
9e190fef36
@ -175,6 +175,61 @@ public class WxCpConsts {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话存档媒体类型
|
||||||
|
* https://developer.work.weixin.qq.com/document/path/91774
|
||||||
|
*/
|
||||||
|
@UtilityClass
|
||||||
|
public static class MsgAuditMediaType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片
|
||||||
|
*/
|
||||||
|
public static final String IMAGE = "image";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 语音
|
||||||
|
*/
|
||||||
|
public static final String VOICE = "voice";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频
|
||||||
|
*/
|
||||||
|
public static final String VIDEO = "video";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表情
|
||||||
|
*/
|
||||||
|
public static final String EMOTION = "emotion";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件
|
||||||
|
*/
|
||||||
|
public static final String FILE = "file";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音频存档消息
|
||||||
|
*/
|
||||||
|
public static final String MEETING_VOICE_CALL = "meeting_voice_call";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音频共享文档消息
|
||||||
|
*/
|
||||||
|
public static final String VOIP_DOC_SHARE = "voip_doc_share";
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public static class MsgAuditSuffix {
|
||||||
|
|
||||||
|
public static final String JPG = ".jpg";
|
||||||
|
public static final String PNG = ".png";
|
||||||
|
public static final String GIF = ".gif";
|
||||||
|
public static final String MP4 = ".mp4";
|
||||||
|
public static final String AMR = ".amr";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 家校通讯录变更事件CHANGE_TYPE
|
* 家校通讯录变更事件CHANGE_TYPE
|
||||||
*/
|
*/
|
||||||
|
@ -165,8 +165,10 @@ public class WxCpMsgAuditTest {
|
|||||||
/*
|
/*
|
||||||
* 图片,语音,视频,表情,文件,音频存档消息,音频共享文档消息调用 获取媒体消息
|
* 图片,语音,视频,表情,文件,音频存档消息,音频共享文档消息调用 获取媒体消息
|
||||||
*/
|
*/
|
||||||
List<String> mediaType = Arrays.asList("image", "voice", "video", "emotion", "file",
|
List<String> mediaType = Arrays.asList(WxCpConsts.MsgAuditMediaType.IMAGE,
|
||||||
"meeting_voice_call", "voip_doc_share");
|
WxCpConsts.MsgAuditMediaType.VOICE, WxCpConsts.MsgAuditMediaType.VIDEO,
|
||||||
|
WxCpConsts.MsgAuditMediaType.EMOTION, WxCpConsts.MsgAuditMediaType.FILE,
|
||||||
|
WxCpConsts.MsgAuditMediaType.MEETING_VOICE_CALL, WxCpConsts.MsgAuditMediaType.VOIP_DOC_SHARE);
|
||||||
|
|
||||||
// 模拟多次拉取数据,根据seq拉取
|
// 模拟多次拉取数据,根据seq拉取
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
@ -214,43 +216,43 @@ public class WxCpMsgAuditTest {
|
|||||||
// sdkFileId
|
// sdkFileId
|
||||||
String sdkFileId = "";
|
String sdkFileId = "";
|
||||||
switch (msgType) {
|
switch (msgType) {
|
||||||
case "image":
|
case WxCpConsts.MsgAuditMediaType.IMAGE:
|
||||||
suffix = ".jpg";
|
suffix = WxCpConsts.MsgAuditMediaType.MsgAuditSuffix.JPG;
|
||||||
md5Sum = decryptData.getImage().getMd5Sum();
|
md5Sum = decryptData.getImage().getMd5Sum();
|
||||||
sdkFileId = decryptData.getImage().getSdkFileId();
|
sdkFileId = decryptData.getImage().getSdkFileId();
|
||||||
break;
|
break;
|
||||||
case "voice":
|
case WxCpConsts.MsgAuditMediaType.VOICE:
|
||||||
suffix = ".amr";
|
suffix = WxCpConsts.MsgAuditMediaType.MsgAuditSuffix.AMR;
|
||||||
md5Sum = decryptData.getVoice().getMd5Sum();
|
md5Sum = decryptData.getVoice().getMd5Sum();
|
||||||
sdkFileId = decryptData.getVoice().getSdkFileId();
|
sdkFileId = decryptData.getVoice().getSdkFileId();
|
||||||
break;
|
break;
|
||||||
case "video":
|
case WxCpConsts.MsgAuditMediaType.VIDEO:
|
||||||
suffix = ".mp4";
|
suffix = WxCpConsts.MsgAuditMediaType.MsgAuditSuffix.MP4;
|
||||||
md5Sum = decryptData.getVideo().getMd5Sum();
|
md5Sum = decryptData.getVideo().getMd5Sum();
|
||||||
sdkFileId = decryptData.getVideo().getSdkFileId();
|
sdkFileId = decryptData.getVideo().getSdkFileId();
|
||||||
break;
|
break;
|
||||||
case "emotion":
|
case WxCpConsts.MsgAuditMediaType.EMOTION:
|
||||||
md5Sum = decryptData.getEmotion().getMd5Sum();
|
md5Sum = decryptData.getEmotion().getMd5Sum();
|
||||||
sdkFileId = decryptData.getEmotion().getSdkFileId();
|
sdkFileId = decryptData.getEmotion().getSdkFileId();
|
||||||
int type = decryptData.getEmotion().getType();
|
int type = decryptData.getEmotion().getType();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 1:
|
case 1:
|
||||||
suffix = ".gif";
|
suffix = WxCpConsts.MsgAuditMediaType.MsgAuditSuffix.GIF;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
suffix = ".png";
|
suffix = WxCpConsts.MsgAuditMediaType.MsgAuditSuffix.PNG;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "file":
|
case WxCpConsts.MsgAuditMediaType.FILE:
|
||||||
md5Sum = decryptData.getFile().getMd5Sum();
|
md5Sum = decryptData.getFile().getMd5Sum();
|
||||||
suffix = "." + decryptData.getFile().getFileExt();
|
suffix = "." + decryptData.getFile().getFileExt();
|
||||||
sdkFileId = decryptData.getFile().getSdkFileId();
|
sdkFileId = decryptData.getFile().getSdkFileId();
|
||||||
break;
|
break;
|
||||||
// 音频存档消息
|
// 音频存档消息
|
||||||
case "meeting_voice_call":
|
case WxCpConsts.MsgAuditMediaType.MEETING_VOICE_CALL:
|
||||||
|
|
||||||
md5Sum = decryptData.getVoiceId();
|
md5Sum = decryptData.getVoiceId();
|
||||||
sdkFileId = decryptData.getMeetingVoiceCall().getSdkFileId();
|
sdkFileId = decryptData.getMeetingVoiceCall().getSdkFileId();
|
||||||
@ -262,7 +264,7 @@ public class WxCpMsgAuditTest {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
// 音频共享文档消息
|
// 音频共享文档消息
|
||||||
case "voip_doc_share":
|
case WxCpConsts.MsgAuditMediaType.VOIP_DOC_SHARE:
|
||||||
|
|
||||||
md5Sum = decryptData.getVoipId();
|
md5Sum = decryptData.getVoipId();
|
||||||
WxCpFileItem docShare = decryptData.getVoipDocShare();
|
WxCpFileItem docShare = decryptData.getVoipDocShare();
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.github.binarywang.wxpay.bean.notify;
|
package com.github.binarywang.wxpay.bean.notify;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信支付订单和退款的异步通知,V3版本共用的响应类.
|
* 微信支付订单和退款的异步通知,V3版本共用的响应类.
|
||||||
@ -33,7 +33,7 @@ public class WxPayNotifyV3Response {
|
|||||||
*/
|
*/
|
||||||
public static String success(String msg) {
|
public static String success(String msg) {
|
||||||
WxPayNotifyV3Response response = new WxPayNotifyV3Response(SUCCESS, msg);
|
WxPayNotifyV3Response response = new WxPayNotifyV3Response(SUCCESS, msg);
|
||||||
return new Gson().toJson(response);
|
return WxGsonBuilder.create().toJson(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,7 +44,7 @@ public class WxPayNotifyV3Response {
|
|||||||
*/
|
*/
|
||||||
public static String fail(String msg) {
|
public static String fail(String msg) {
|
||||||
WxPayNotifyV3Response response = new WxPayNotifyV3Response(FAIL, msg);
|
WxPayNotifyV3Response response = new WxPayNotifyV3Response(FAIL, msg);
|
||||||
return new Gson().toJson(response);
|
return WxGsonBuilder.create().toJson(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -157,6 +157,13 @@ public abstract class BaseWxPayRequest implements Serializable {
|
|||||||
return yuan.multiply(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_HALF_UP).intValue();
|
return yuan.multiply(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_HALF_UP).intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分转元
|
||||||
|
*/
|
||||||
|
public static BigDecimal fen2Yuan(BigDecimal fen) {
|
||||||
|
return fen.divide(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查请求参数内容,包括必填参数以及特殊约束.
|
* 检查请求参数内容,包括必填参数以及特殊约束.
|
||||||
*/
|
*/
|
||||||
|
@ -779,7 +779,7 @@ public class BaseWxPayServiceImplTest {
|
|||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testParseOrderNotifyV3Result(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
public String testParseOrderNotifyV3Result(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
|
||||||
String timestamp = request.getHeader("Wechatpay-Timestamp");
|
String timestamp = request.getHeader("Wechatpay-Timestamp");
|
||||||
Optional.ofNullable(timestamp).orElseThrow(() -> new RuntimeException("时间戳不能为空"));
|
Optional.ofNullable(timestamp).orElseThrow(() -> new RuntimeException("时间戳不能为空"));
|
||||||
@ -799,6 +799,8 @@ public class BaseWxPayServiceImplTest {
|
|||||||
final WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = this.payService.parseOrderNotifyV3Result(RequestUtils.readData(request),
|
final WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = this.payService.parseOrderNotifyV3Result(RequestUtils.readData(request),
|
||||||
new SignatureHeader(timestamp, nonce, signature, serialNo));
|
new SignatureHeader(timestamp, nonce, signature, serialNo));
|
||||||
log.info(GSON.toJson(wxPayOrderNotifyV3Result));
|
log.info(GSON.toJson(wxPayOrderNotifyV3Result));
|
||||||
|
|
||||||
|
return WxPayNotifyV3Response.success("成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -808,7 +810,7 @@ public class BaseWxPayServiceImplTest {
|
|||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testParseRefundNotifyV3Result(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
public String testParseRefundNotifyV3Result(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
|
||||||
String timestamp = request.getHeader("Wechatpay-Timestamp");
|
String timestamp = request.getHeader("Wechatpay-Timestamp");
|
||||||
Optional.ofNullable(timestamp).orElseThrow(() -> new RuntimeException("时间戳不能为空"));
|
Optional.ofNullable(timestamp).orElseThrow(() -> new RuntimeException("时间戳不能为空"));
|
||||||
@ -827,6 +829,21 @@ public class BaseWxPayServiceImplTest {
|
|||||||
final WxPayRefundNotifyV3Result wxPayRefundNotifyV3Result = this.payService.parseRefundNotifyV3Result(RequestUtils.readData(request),
|
final WxPayRefundNotifyV3Result wxPayRefundNotifyV3Result = this.payService.parseRefundNotifyV3Result(RequestUtils.readData(request),
|
||||||
new SignatureHeader(timestamp, nonce, signature, serialNo));
|
new SignatureHeader(timestamp, nonce, signature, serialNo));
|
||||||
log.info(GSON.toJson(wxPayRefundNotifyV3Result));
|
log.info(GSON.toJson(wxPayRefundNotifyV3Result));
|
||||||
|
|
||||||
|
// 退款金额
|
||||||
|
final WxPayRefundNotifyV3Result.DecryptNotifyResult result = wxPayRefundNotifyV3Result.getResult();
|
||||||
|
final BigDecimal total = BaseWxPayRequest.fen2Yuan(BigDecimal.valueOf(result.getAmount().getTotal()));
|
||||||
|
final BigDecimal payerRefund = BaseWxPayRequest.fen2Yuan(BigDecimal.valueOf(result.getAmount().getPayerRefund()));
|
||||||
|
|
||||||
|
// 处理业务逻辑 ...
|
||||||
|
|
||||||
|
return WxPayNotifyV3Response.success("成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWxPayNotifyV3Response() {
|
||||||
|
System.out.println(WxPayNotifyV3Response.success("success"));
|
||||||
|
System.out.println(WxPayNotifyV3Response.fail("fail"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
<xml>
|
<xml>
|
||||||
<appId>公众号appid</appId>
|
|
||||||
<mchId>微信商户平台ID</mchId>
|
|
||||||
<!---
|
<!---
|
||||||
以下为官网文档所提供样例参数,仅供部分接口测试使用
|
以下为官网文档所提供样例参数,仅供部分接口测试使用
|
||||||
<appId>wxd930ea5d5a258f4f</appId>
|
<appId>wxd930ea5d5a258f4f</appId>
|
||||||
<mchId>10000100</mchId>
|
<mchId>10000100</mchId>
|
||||||
<mchKey>192006250b4c09247ec02edce69f6a2d</mchKey>
|
<mchKey>192006250b4c09247ec02edce69f6a2d</mchKey>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<appId>appid</appId>
|
||||||
|
<mchId>微信商户平台ID</mchId>
|
||||||
|
|
||||||
<!-- v2版本 -->
|
<!-- v2版本 -->
|
||||||
<mchKey>商户平台设置的API密钥</mchKey>
|
<mchKey>商户平台设置的API密钥</mchKey>
|
||||||
<keyPath>商户平台的证书文件地址</keyPath>
|
<keyPath>商户平台的证书文件地址</keyPath>
|
||||||
|
Loading…
Reference in New Issue
Block a user