Skip to content

Commit 15d6b79

Browse files
author
Liu Kai
committed
企业号的发送消息接口的数据格式中加入safe字段
根据微信企业号官方文档( http://qydev.weixin.qq.com/wiki/index.php?title=%E6%B6%88%E6%81%AF%E7%B1%BB%E5%9E%8B%E5%8F%8A%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F ),发送消息接口的数据格式中需要加入safe字段。并且经过实际验证,官方文档上“safe为非必须项”的表述有误,safe应为必须项,即如果参数中没有写safe字段而调用发送消息接口的话,微信服务器会正常返回,但touser却收不到任何消息。 Change-Id: Ifc894e6f6b03147f000b42f346d2bdccb11b0c64 Signed-off-by: Liu Kai <[email protected]>
1 parent 0388c8d commit 15d6b79

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class WxConsts {
3030
public static final String CUSTOM_MSG_NEWS = "news";
3131
public static final String CUSTOM_MSG_FILE = "file";
3232
public static final String CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service";
33+
public static final String CUSTOM_MSG_SAFE_NO = "0";
34+
public static final String CUSTOM_MSG_SAFE_YES = "1";
3335

3436
///////////////////////
3537
// 群发消息的消息类型

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class WxCpMessage implements Serializable {
2626
private String description;
2727
private String musicUrl;
2828
private String hqMusicUrl;
29+
private String safe;
2930
private List<WxArticle> articles = new ArrayList<WxArticle>();
3031

3132
public String getToUser() {
@@ -63,6 +64,14 @@ public String getMsgType() {
6364
return msgType;
6465
}
6566

67+
public String getSafe() {
68+
return safe;
69+
}
70+
71+
public void setSafe(String safe) {
72+
this.safe = safe;
73+
}
74+
6675
/**
6776
* <pre>
6877
* 请使用

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/BaseBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.chanjar.weixin.cp.bean.messagebuilder;
22

3+
import me.chanjar.weixin.common.api.WxConsts;
34
import me.chanjar.weixin.cp.bean.WxCpMessage;
45

56
public class BaseBuilder<T> {
@@ -8,6 +9,7 @@ public class BaseBuilder<T> {
89
protected String toUser;
910
protected String toParty;
1011
protected String toTag;
12+
protected String safe;
1113

1214
public T agentId(String agentId) {
1315
this.agentId = agentId;
@@ -29,13 +31,20 @@ public T toTag(String toTag) {
2931
return (T) this;
3032
}
3133

34+
public T safe(String safe) {
35+
this.safe = safe;
36+
return (T) this;
37+
}
38+
3239
public WxCpMessage build() {
3340
WxCpMessage m = new WxCpMessage();
3441
m.setAgentId(this.agentId);
3542
m.setMsgType(this.msgType);
3643
m.setToUser(this.toUser);
3744
m.setToParty(this.toParty);
3845
m.setToTag(this.toTag);
46+
m.setSafe(
47+
(this.safe == null || "".equals(this.safe))? WxConsts.CUSTOM_MSG_SAFE_NO: this.safe);
3948
return m;
4049
}
4150

0 commit comments

Comments
 (0)