Skip to content

Commit 8b7ca9b

Browse files
committed
🆕 #1710 企业微信增加发送新客户欢迎语接口
1 parent 928ba17 commit 8b7ca9b

29 files changed

+363
-144
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/redis/JedisWxRedisOps.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
@RequiredArgsConstructor
1212
public class JedisWxRedisOps implements WxRedisOps {
13-
1413
private final Pool<Jedis> jedisPool;
1514

1615
@Override

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java

Lines changed: 117 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import lombok.NonNull;
44
import me.chanjar.weixin.common.error.WxErrorException;
5-
import me.chanjar.weixin.cp.bean.*;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.bean.external.*;
67

78
import java.util.Date;
89
import java.util.List;
@@ -32,8 +33,8 @@ public interface WxCpExternalContactService {
3233
* </pre>
3334
*
3435
* @param info 客户联系「联系我」方式
35-
* @return
36-
* @throws WxErrorException
36+
* @return wx cp contact way result
37+
* @throws WxErrorException the wx error exception
3738
*/
3839
WxCpContactWayResult addContactWay(@NonNull WxCpContactWayInfo info) throws WxErrorException;
3940

@@ -45,8 +46,8 @@ public interface WxCpExternalContactService {
4546
* </pre>
4647
*
4748
* @param configId 联系方式的配置id,必填
48-
* @return
49-
* @throws WxErrorException
49+
* @return contact way
50+
* @throws WxErrorException the wx error exception
5051
*/
5152
WxCpContactWayInfo getContactWay(@NonNull String configId) throws WxErrorException;
5253

@@ -58,8 +59,8 @@ public interface WxCpExternalContactService {
5859
* </pre>
5960
*
6061
* @param info 客户联系「联系我」方式
61-
* @return
62-
* @throws WxErrorException
62+
* @return wx cp base resp
63+
* @throws WxErrorException the wx error exception
6364
*/
6465
WxCpBaseResp updateContactWay(@NonNull WxCpContactWayInfo info) throws WxErrorException;
6566

@@ -71,8 +72,8 @@ public interface WxCpExternalContactService {
7172
* </pre>
7273
*
7374
* @param configId 企业联系方式的配置id,必填
74-
* @return
75-
* @throws WxErrorException
75+
* @return wx cp base resp
76+
* @throws WxErrorException the wx error exception
7677
*/
7778
WxCpBaseResp deleteContactWay(@NonNull String configId) throws WxErrorException;
7879

@@ -85,10 +86,10 @@ public interface WxCpExternalContactService {
8586
* 注意:请保证传入的企业成员和客户之间有仍然有效的临时会话, 通过<b>其他方式的添加外部联系人无法通过此接口关闭会话</b>。
8687
* </pre>
8788
*
88-
* @param userId
89-
* @param externalUserId
90-
* @return
91-
* @throws WxErrorException
89+
* @param userId the user id
90+
* @param externalUserId the external user id
91+
* @return wx cp base resp
92+
* @throws WxErrorException the wx error exception
9293
*/
9394
WxCpBaseResp closeTempChat(@NonNull String userId, @NonNull String externalUserId) throws WxErrorException;
9495

@@ -103,7 +104,8 @@ public interface WxCpExternalContactService {
103104
* </pre>
104105
*
105106
* @param userId 外部联系人的userid
106-
* @return .
107+
* @return . external contact
108+
* @throws WxErrorException the wx error exception
107109
* @deprecated 建议使用 {@link #getContactDetail(String)}
108110
*/
109111
@Deprecated
@@ -125,7 +127,7 @@ public interface WxCpExternalContactService {
125127
* </pre>
126128
*
127129
* @param userId 外部联系人的userid,注意不是企业成员的帐号
128-
* @return .
130+
* @return . contact detail
129131
* @throws WxErrorException .
130132
*/
131133
WxCpUserExternalContactInfo getContactDetail(String userId) throws WxErrorException;
@@ -167,21 +169,21 @@ public interface WxCpExternalContactService {
167169
/**
168170
* 企业和第三方可通过此接口,获取所有离职成员的客户列表,并可进一步调用离职成员的外部联系人再分配接口将这些客户重新分配给其他企业成员。
169171
*
170-
* @param page
171-
* @param pageSize
172-
* @return
173-
* @throws WxErrorException
172+
* @param page the page
173+
* @param pageSize the page size
174+
* @return wx cp user external unassign list
175+
* @throws WxErrorException the wx error exception
174176
*/
175177
WxCpUserExternalUnassignList listUnassignedList(Integer page, Integer pageSize) throws WxErrorException;
176178

177179
/**
178180
* 企业可通过此接口,将已离职成员的外部联系人分配给另一个成员接替联系。
179181
*
180-
* @param externalUserid
181-
* @param handOverUserid
182-
* @param takeOverUserid
183-
* @return
184-
* @throws WxErrorException
182+
* @param externalUserid the external userid
183+
* @param handOverUserid the hand over userid
184+
* @param takeOverUserid the take over userid
185+
* @return wx cp base resp
186+
* @throws WxErrorException the wx error exception
185187
*/
186188
WxCpBaseResp transferExternalContact(String externalUserid, String handOverUserid, String takeOverUserid) throws WxErrorException;
187189

@@ -192,6 +194,14 @@ public interface WxCpExternalContactService {
192194
* 暂不支持第三方调用。
193195
* 微信文档:https://work.weixin.qq.com/api/doc/90000/90135/92119
194196
* </pre>
197+
*
198+
* @param pageIndex the page index
199+
* @param pageSize the page size
200+
* @param status the status
201+
* @param userIds the user ids
202+
* @param partyIds the party ids
203+
* @return the wx cp user external group chat list
204+
* @throws WxErrorException the wx error exception
195205
*/
196206
WxCpUserExternalGroupChatList listGroupChat(Integer pageIndex, Integer pageSize, int status, String[] userIds, String[] partyIds) throws WxErrorException;
197207

@@ -203,9 +213,9 @@ public interface WxCpExternalContactService {
203213
* 微信文档:https://work.weixin.qq.com/api/doc/90000/90135/92122
204214
* </pre>
205215
*
206-
* @param chatId
207-
* @return
208-
* @throws WxErrorException
216+
* @param chatId the chat id
217+
* @return group chat
218+
* @throws WxErrorException the wx error exception
209219
*/
210220
WxCpUserExternalGroupChatInfo getGroupChat(String chatId) throws WxErrorException;
211221

@@ -217,12 +227,12 @@ public interface WxCpExternalContactService {
217227
* 第三方/自建应用调用时传入的userid和partyid要在应用的可见范围内;
218228
* </pre>
219229
*
220-
* @param startTime
221-
* @param endTime
222-
* @param userIds
223-
* @param partyIds
224-
* @return
225-
* @throws WxErrorException
230+
* @param startTime the start time
231+
* @param endTime the end time
232+
* @param userIds the user ids
233+
* @param partyIds the party ids
234+
* @return user behavior statistic
235+
* @throws WxErrorException the wx error exception
226236
*/
227237
WxCpUserExternalUserBehaviorStatistic getUserBehaviorStatistic(Date startTime, Date endTime, String[] userIds, String[] partyIds) throws WxErrorException;
228238

@@ -233,74 +243,117 @@ public interface WxCpExternalContactService {
233243
* 暂不支持第三方调用。
234244
* </pre>
235245
*
236-
* @param startTime
237-
* @param orderBy
238-
* @param orderAsc
239-
* @param pageIndex
240-
* @param pageSize
241-
* @param userIds
242-
* @param partyIds
243-
* @return
244-
* @throws WxErrorException
246+
* @param startTime the start time
247+
* @param orderBy the order by
248+
* @param orderAsc the order asc
249+
* @param pageIndex the page index
250+
* @param pageSize the page size
251+
* @param userIds the user ids
252+
* @param partyIds the party ids
253+
* @return group chat statistic
254+
* @throws WxErrorException the wx error exception
245255
*/
246256
WxCpUserExternalGroupChatStatistic getGroupChatStatistic(Date startTime, Integer orderBy, Integer orderAsc, Integer pageIndex, Integer pageSize, String[] userIds, String[] partyIds) throws WxErrorException;
247257

258+
/**
259+
* 添加企业群发消息任务
260+
* 企业可通过此接口添加企业群发消息的任务并通知客服人员发送给相关客户或客户群。(注:企业微信终端需升级到2.7.5版本及以上)
261+
* 注意:调用该接口并不会直接发送消息给客户/客户群,需要相关的客服人员操作以后才会实际发送(客服人员的企业微信需要升级到2.7.5及以上版本)
262+
* 同一个企业每个自然月内仅可针对一个客户/客户群发送4条消息,超过限制的用户将会被忽略。
263+
* <p>
264+
* 请求方式: POST(HTTP)
265+
* <p>
266+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_msg_template?access_token=ACCESS_TOKEN
267+
* <p>
268+
* 文档地址:https://work.weixin.qq.com/api/doc/90000/90135/92135
269+
*
270+
* @param wxCpMsgTemplate the wx cp msg template
271+
* @return the wx cp msg template add result
272+
* @throws WxErrorException the wx error exception
273+
*/
248274
WxCpMsgTemplateAddResult addMsgTemplate(WxCpMsgTemplate wxCpMsgTemplate) throws WxErrorException;
249275

276+
/**
277+
* 发送新客户欢迎语
278+
* <pre>
279+
* 企业微信在向企业推送添加外部联系人事件时,会额外返回一个welcome_code,企业以此为凭据调用接口,即可通过成员向新添加的客户发送个性化的欢迎语。
280+
* 为了保证用户体验以及避免滥用,企业仅可在收到相关事件后20秒内调用,且只可调用一次。
281+
* 如果企业已经在管理端为相关成员配置了可用的欢迎语,则推送添加外部联系人事件时不会返回welcome_code。
282+
* 每次添加新客户时可能有多个企业自建应用/第三方应用收到带有welcome_code的回调事件,但仅有最先调用的可以发送成功。后续调用将返回41051(externaluser has started chatting)错误,请用户根据实际使用需求,合理设置应用可见范围,避免冲突。
283+
* 请求方式: POST(HTTP)
284+
*
285+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/send_welcome_msg?access_token=ACCESS_TOKEN
286+
*
287+
* 文档地址:https://work.weixin.qq.com/api/doc/90000/90135/92137
288+
* </pre>
289+
*
290+
* @param msg .
291+
* @throws WxErrorException .
292+
*/
293+
void sendWelcomeMsg(WxCpWelcomeMsg msg) throws WxErrorException;
250294

251295
/**
252296
* <pre>
253297
* 企业可通过此接口获取企业客户标签详情。
254298
* </pre>
255-
* @param tagId
256-
* @return
299+
*
300+
* @param tagId the tag id
301+
* @return corp tag list
302+
* @throws WxErrorException the wx error exception
257303
*/
258-
WxCpUserExternalTagGroupList getCorpTagList(String [] tagId) throws WxErrorException;
259-
304+
WxCpUserExternalTagGroupList getCorpTagList(String[] tagId) throws WxErrorException;
260305

261306
/**
262307
* <pre>
263308
* 企业可通过此接口向客户标签库中添加新的标签组和标签,每个企业最多可配置3000个企业标签。
264309
* 暂不支持第三方调用。
265310
* </pre>
266-
* @param tagGroup
267-
* @return
311+
*
312+
* @param tagGroup the tag group
313+
* @return wx cp user external tag group info
314+
* @throws WxErrorException the wx error exception
268315
*/
269-
WxCpUserExternalTagGroupInfo addCorpTag(WxCpUserExternalTagGroupInfo tagGroup)throws WxErrorException;
316+
WxCpUserExternalTagGroupInfo addCorpTag(WxCpUserExternalTagGroupInfo tagGroup) throws WxErrorException;
270317

271318
/**
272319
* <pre>
273320
* 企业可通过此接口编辑客户标签/标签组的名称或次序值。
274321
* 暂不支持第三方调用。
275322
* </pre>
276-
* @param id
277-
* @param name
278-
* @param order
279-
* @return
323+
*
324+
* @param id the id
325+
* @param name the name
326+
* @param order the order
327+
* @return wx cp base resp
328+
* @throws WxErrorException the wx error exception
280329
*/
281-
WxCpBaseResp editCorpTag(String id,String name,Integer order)throws WxErrorException;
330+
WxCpBaseResp editCorpTag(String id, String name, Integer order) throws WxErrorException;
282331

283332
/**
284333
* <pre>
285334
* 企业可通过此接口删除客户标签库中的标签,或删除整个标签组。
286335
* 暂不支持第三方调用。
287336
* </pre>
288-
* @param tagId
289-
* @param groupId
290-
* @return
337+
*
338+
* @param tagId the tag id
339+
* @param groupId the group id
340+
* @return wx cp base resp
341+
* @throws WxErrorException the wx error exception
291342
*/
292-
WxCpBaseResp delCorpTag(String [] tagId,String[] groupId)throws WxErrorException;
343+
WxCpBaseResp delCorpTag(String[] tagId, String[] groupId) throws WxErrorException;
293344

294345
/**
295346
* <pre>
296347
* 企业可通过此接口为指定成员的客户添加上由企业统一配置的标签。
297348
* https://work.weixin.qq.com/api/doc/90000/90135/92117
298349
* </pre>
299-
* @param userid
300-
* @param externalUserid
301-
* @param addTag
302-
* @param removeTag
303-
* @return
350+
*
351+
* @param userid the userid
352+
* @param externalUserid the external userid
353+
* @param addTag the add tag
354+
* @param removeTag the remove tag
355+
* @return wx cp base resp
356+
* @throws WxErrorException the wx error exception
304357
*/
305-
WxCpBaseResp markTag(String userid,String externalUserid,String[] addTag,String [] removeTag)throws WxErrorException;
358+
WxCpBaseResp markTag(String userid, String externalUserid, String[] addTag, String[] removeTag) throws WxErrorException;
306359
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import me.chanjar.weixin.common.error.WxErrorException;
44
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
55
import me.chanjar.weixin.cp.bean.WxCpUser;
6-
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
6+
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalContactInfo;
77

88
import java.util.List;
99
import java.util.Map;

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import me.chanjar.weixin.cp.api.WxCpExternalContactService;
1010
import me.chanjar.weixin.cp.api.WxCpService;
1111
import me.chanjar.weixin.cp.bean.*;
12+
import me.chanjar.weixin.cp.bean.external.*;
1213
import org.apache.commons.lang3.ArrayUtils;
1314
import org.apache.commons.lang3.StringUtils;
1415

@@ -223,6 +224,12 @@ public WxCpMsgTemplateAddResult addMsgTemplate(WxCpMsgTemplate wxCpMsgTemplate)
223224
return WxCpMsgTemplateAddResult.fromJson(result);
224225
}
225226

227+
@Override
228+
public void sendWelcomeMsg(WxCpWelcomeMsg msg) throws WxErrorException {
229+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(SEND_WELCOME_MSG);
230+
this.mainService.post(url, msg.toJson());
231+
}
232+
226233
@Override
227234
public WxCpUserExternalTagGroupList getCorpTagList(String[] tagId) throws WxErrorException {
228235
JsonObject json = new JsonObject();

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import me.chanjar.weixin.cp.api.WxCpUserService;
1111
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
1212
import me.chanjar.weixin.cp.bean.WxCpUser;
13-
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
13+
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalContactInfo;
1414
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
1515

1616
import java.util.List;

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpContactWayInfo.java renamed to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpContactWayInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.chanjar.weixin.cp.bean;
1+
package me.chanjar.weixin.cp.bean.external;
22

33
import com.google.gson.annotations.JsonAdapter;
44
import com.google.gson.annotations.SerializedName;

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpContactWayResult.java renamed to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpContactWayResult.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package me.chanjar.weixin.cp.bean;
1+
package me.chanjar.weixin.cp.bean.external;
22

33
import com.google.gson.annotations.SerializedName;
44
import lombok.Data;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
56
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
67

78
/**

0 commit comments

Comments
 (0)