Skip to content

Commit

Permalink
🆕 #1710 企业微信增加发送新客户欢迎语接口
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Aug 16, 2020
1 parent 928ba17 commit 8b7ca9b
Show file tree
Hide file tree
Showing 29 changed files with 363 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

@RequiredArgsConstructor
public class JedisWxRedisOps implements WxRedisOps {

private final Pool<Jedis> jedisPool;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import lombok.NonNull;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.*;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.external.*;

import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -32,8 +33,8 @@ public interface WxCpExternalContactService {
* </pre>
*
* @param info 客户联系「联系我」方式
* @return
* @throws WxErrorException
* @return wx cp contact way result
* @throws WxErrorException the wx error exception
*/
WxCpContactWayResult addContactWay(@NonNull WxCpContactWayInfo info) throws WxErrorException;

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

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

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

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

Expand All @@ -103,7 +104,8 @@ public interface WxCpExternalContactService {
* </pre>
*
* @param userId 外部联系人的userid
* @return .
* @return . external contact
* @throws WxErrorException the wx error exception
* @deprecated 建议使用 {@link #getContactDetail(String)}
*/
@Deprecated
Expand All @@ -125,7 +127,7 @@ public interface WxCpExternalContactService {
* </pre>
*
* @param userId 外部联系人的userid,注意不是企业成员的帐号
* @return .
* @return . contact detail
* @throws WxErrorException .
*/
WxCpUserExternalContactInfo getContactDetail(String userId) throws WxErrorException;
Expand Down Expand Up @@ -167,21 +169,21 @@ public interface WxCpExternalContactService {
/**
* 企业和第三方可通过此接口,获取所有离职成员的客户列表,并可进一步调用离职成员的外部联系人再分配接口将这些客户重新分配给其他企业成员。
*
* @param page
* @param pageSize
* @return
* @throws WxErrorException
* @param page the page
* @param pageSize the page size
* @return wx cp user external unassign list
* @throws WxErrorException the wx error exception
*/
WxCpUserExternalUnassignList listUnassignedList(Integer page, Integer pageSize) throws WxErrorException;

/**
* 企业可通过此接口,将已离职成员的外部联系人分配给另一个成员接替联系。
*
* @param externalUserid
* @param handOverUserid
* @param takeOverUserid
* @return
* @throws WxErrorException
* @param externalUserid the external userid
* @param handOverUserid the hand over userid
* @param takeOverUserid the take over userid
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
WxCpBaseResp transferExternalContact(String externalUserid, String handOverUserid, String takeOverUserid) throws WxErrorException;

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

Expand All @@ -203,9 +213,9 @@ public interface WxCpExternalContactService {
* 微信文档:https://work.weixin.qq.com/api/doc/90000/90135/92122
* </pre>
*
* @param chatId
* @return
* @throws WxErrorException
* @param chatId the chat id
* @return group chat
* @throws WxErrorException the wx error exception
*/
WxCpUserExternalGroupChatInfo getGroupChat(String chatId) throws WxErrorException;

Expand All @@ -217,12 +227,12 @@ public interface WxCpExternalContactService {
* 第三方/自建应用调用时传入的userid和partyid要在应用的可见范围内;
* </pre>
*
* @param startTime
* @param endTime
* @param userIds
* @param partyIds
* @return
* @throws WxErrorException
* @param startTime the start time
* @param endTime the end time
* @param userIds the user ids
* @param partyIds the party ids
* @return user behavior statistic
* @throws WxErrorException the wx error exception
*/
WxCpUserExternalUserBehaviorStatistic getUserBehaviorStatistic(Date startTime, Date endTime, String[] userIds, String[] partyIds) throws WxErrorException;

Expand All @@ -233,74 +243,117 @@ public interface WxCpExternalContactService {
* 暂不支持第三方调用。
* </pre>
*
* @param startTime
* @param orderBy
* @param orderAsc
* @param pageIndex
* @param pageSize
* @param userIds
* @param partyIds
* @return
* @throws WxErrorException
* @param startTime the start time
* @param orderBy the order by
* @param orderAsc the order asc
* @param pageIndex the page index
* @param pageSize the page size
* @param userIds the user ids
* @param partyIds the party ids
* @return group chat statistic
* @throws WxErrorException the wx error exception
*/
WxCpUserExternalGroupChatStatistic getGroupChatStatistic(Date startTime, Integer orderBy, Integer orderAsc, Integer pageIndex, Integer pageSize, String[] userIds, String[] partyIds) throws WxErrorException;

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

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

/**
* <pre>
* 企业可通过此接口获取企业客户标签详情。
* </pre>
* @param tagId
* @return
*
* @param tagId the tag id
* @return corp tag list
* @throws WxErrorException the wx error exception
*/
WxCpUserExternalTagGroupList getCorpTagList(String [] tagId) throws WxErrorException;

WxCpUserExternalTagGroupList getCorpTagList(String[] tagId) throws WxErrorException;

/**
* <pre>
* 企业可通过此接口向客户标签库中添加新的标签组和标签,每个企业最多可配置3000个企业标签。
* 暂不支持第三方调用。
* </pre>
* @param tagGroup
* @return
*
* @param tagGroup the tag group
* @return wx cp user external tag group info
* @throws WxErrorException the wx error exception
*/
WxCpUserExternalTagGroupInfo addCorpTag(WxCpUserExternalTagGroupInfo tagGroup)throws WxErrorException;
WxCpUserExternalTagGroupInfo addCorpTag(WxCpUserExternalTagGroupInfo tagGroup) throws WxErrorException;

/**
* <pre>
* 企业可通过此接口编辑客户标签/标签组的名称或次序值。
* 暂不支持第三方调用。
* </pre>
* @param id
* @param name
* @param order
* @return
*
* @param id the id
* @param name the name
* @param order the order
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
WxCpBaseResp editCorpTag(String id,String name,Integer order)throws WxErrorException;
WxCpBaseResp editCorpTag(String id, String name, Integer order) throws WxErrorException;

/**
* <pre>
* 企业可通过此接口删除客户标签库中的标签,或删除整个标签组。
* 暂不支持第三方调用。
* </pre>
* @param tagId
* @param groupId
* @return
*
* @param tagId the tag id
* @param groupId the group id
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
WxCpBaseResp delCorpTag(String [] tagId,String[] groupId)throws WxErrorException;
WxCpBaseResp delCorpTag(String[] tagId, String[] groupId) throws WxErrorException;

/**
* <pre>
* 企业可通过此接口为指定成员的客户添加上由企业统一配置的标签。
* https://work.weixin.qq.com/api/doc/90000/90135/92117
* </pre>
* @param userid
* @param externalUserid
* @param addTag
* @param removeTag
* @return
*
* @param userid the userid
* @param externalUserid the external userid
* @param addTag the add tag
* @param removeTag the remove tag
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
WxCpBaseResp markTag(String userid,String externalUserid,String[] addTag,String [] removeTag)throws WxErrorException;
WxCpBaseResp markTag(String userid, String externalUserid, String[] addTag, String[] removeTag) throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalContactInfo;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import me.chanjar.weixin.cp.api.WxCpExternalContactService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.*;
import me.chanjar.weixin.cp.bean.external.*;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -223,6 +224,12 @@ public WxCpMsgTemplateAddResult addMsgTemplate(WxCpMsgTemplate wxCpMsgTemplate)
return WxCpMsgTemplateAddResult.fromJson(result);
}

@Override
public void sendWelcomeMsg(WxCpWelcomeMsg msg) throws WxErrorException {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(SEND_WELCOME_MSG);
this.mainService.post(url, msg.toJson());
}

@Override
public WxCpUserExternalTagGroupList getCorpTagList(String[] tagId) throws WxErrorException {
JsonObject json = new JsonObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import me.chanjar.weixin.cp.api.WxCpUserService;
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
import me.chanjar.weixin.cp.bean.external.WxCpUserExternalContactInfo;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.chanjar.weixin.cp.bean;
package me.chanjar.weixin.cp.bean.external;

import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package me.chanjar.weixin.cp.bean;
package me.chanjar.weixin.cp.bean.external;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

/**
Expand Down
Loading

0 comments on commit 8b7ca9b

Please sign in to comment.