Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加部分企业微信朋友圈API #2361

Merged
merged 5 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
import lombok.NonNull;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.external.WxCpAddMomentResult;
import me.chanjar.weixin.cp.bean.external.WxCpAddMomentTask;
import me.chanjar.weixin.cp.bean.external.WxCpContactWayInfo;
import me.chanjar.weixin.cp.bean.external.WxCpContactWayResult;
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentComments;
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentCustomerList;
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentList;
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentSendResult;
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTask;
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTaskResult;
import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplate;
import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplateAddResult;
import me.chanjar.weixin.cp.bean.external.WxCpUpdateRemarkRequest;
Expand Down Expand Up @@ -181,7 +189,7 @@ public interface WxCpExternalContactService {
* @return 该企业的外部联系人ID
* @throws WxErrorException .
*/
String unionidToExternalUserid(String unionid) throws WxErrorException;
String unionidToExternalUserid(@NotNull String unionid,String openid) throws WxErrorException;

/**
* 批量获取客户详情.
Expand Down Expand Up @@ -586,6 +594,104 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String[] userIdList, String c
*/
WxCpBaseResp markTag(String userid, String externalUserid, String[] addTag, String[] removeTag) throws WxErrorException;

/**
* <pre>
* 企业和第三方应用可通过该接口创建客户朋友圈的发表任务。
* https://open.work.weixin.qq.com/api/doc/90000/90135/95094
* </pre>
* @param task
* @return wx cp add moment result
* @throws WxErrorException the wx error exception
*/
WxCpAddMomentResult addMomentTask(WxCpAddMomentTask task) throws WxErrorException;

/**
* <pre>
* 由于发表任务的创建是异步执行的,应用需要再调用该接口以获取创建的结果。
* https://open.work.weixin.qq.com/api/doc/90000/90135/95094
* </pre>
* @param jobId 异步任务id,最大长度为64字节,由创建发表内容到客户朋友圈任务接口获取
* @return
* @throws WxErrorException
*/
WxCpGetMomentTaskResult getMomentTaskResult(String jobId) throws WxErrorException;

/**
* <pre>
* 获取客户朋友圈全部的发表记录 获取企业全部的发表列表
* https://open.work.weixin.qq.com/api/doc/90000/90135/93333
* </pre>
* @param startTime 朋友圈记录开始时间。Unix时间戳
* @param endTime 朋友圈记录结束时间。Unix时间戳
* @param creator 朋友圈创建人的userid
* @param filterType 朋友圈类型。0:企业发表 1:个人发表 2:所有,包括个人创建以及企业创建,默认情况下为所有类型
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
* @param limit 返回的最大记录数,整型,最大值100,默认值100,超过最大值时取默认值
* @return
* @throws WxErrorException
*/
WxCpGetMomentList getMomentList(Long startTime, Long endTime, String creator, Integer filterType,
String cursor, Integer limit) throws WxErrorException;

/**
* <pre>
* 获取客户朋友圈全部的发表记录 获取客户朋友圈企业发表的列表
* https://open.work.weixin.qq.com/api/doc/90000/90135/93333
* </pre>
* @param momentId 朋友圈id,仅支持企业发表的朋友圈id
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
* @param limit 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
* @return
* @throws WxErrorException
*/
WxCpGetMomentTask getMomentTask(String momentId, String cursor, Integer limit)
throws WxErrorException;

/**
* <pre>
* 获取客户朋友圈全部的发表记录 获取客户朋友圈发表时选择的可见范围
* https://open.work.weixin.qq.com/api/doc/90000/90135/93333
* </pre>
* @param momentId 朋友圈id
* @param userId 企业发表成员userid,如果是企业创建的朋友圈,可以通过获取客户朋友圈企业发表的
* 列表获取已发表成员userid,如果是个人创建的朋友圈,创建人userid就是企业发表成员userid
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
* @param limit 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
* @return
* @throws WxErrorException
*/
WxCpGetMomentCustomerList getMomentCustomerList(String momentId, String userId,
String cursor, Integer limit) throws WxErrorException;

/**
* <pre>
* 获取客户朋友圈全部的发表记录 获取客户朋友圈发表后的可见客户列表
* https://open.work.weixin.qq.com/api/doc/90000/90135/93333
* </pre>
* @param momentId 朋友圈id
* @param userId 企业发表成员userid,如果是企业创建的朋友圈,可以通过获取客户朋友圈企业发表的列表获取已发表成员userid,
* 如果是个人创建的朋友圈,创建人userid就是企业发表成员userid
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
* @param limit 返回的最大记录数,整型,最大值5000,默认值3000,超过最大值时取默认值
* @return
* @throws WxErrorException
*/
WxCpGetMomentSendResult getMomentSendResult(String momentId, String userId,
String cursor, Integer limit) throws WxErrorException;

/**
* <pre>
* 获取客户朋友圈全部的发表记录 获取客户朋友圈的互动数据
* https://open.work.weixin.qq.com/api/doc/90000/90135/93333
* </pre>
* @param momentId 朋友圈id
* @param userId 企业发表成员userid,如果是企业创建的朋友圈,可以通过获取客户朋友圈企业发表的列表获取已发表成员userid,
* 如果是个人创建的朋友圈,创建人userid就是企业发表成员userid
* @return
* @throws WxErrorException
*/
WxCpGetMomentComments getMomentComments(String momentId, String userId)
throws WxErrorException;

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@
import me.chanjar.weixin.cp.api.WxCpExternalContactService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.external.WxCpAddMomentResult;
import me.chanjar.weixin.cp.bean.external.WxCpAddMomentTask;
import me.chanjar.weixin.cp.bean.external.WxCpContactWayInfo;
import me.chanjar.weixin.cp.bean.external.WxCpContactWayResult;
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentComments;
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentCustomerList;
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentList;
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentSendResult;
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTask;
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTaskResult;
import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplate;
import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplateAddResult;
import me.chanjar.weixin.cp.bean.external.WxCpUpdateRemarkRequest;
Expand Down Expand Up @@ -137,9 +145,12 @@ public String convertToOpenid(@NotNull String externalUserId) throws WxErrorExce
}

@Override
public String unionidToExternalUserid(@NotNull String unionid) throws WxErrorException {
public String unionidToExternalUserid(@NotNull String unionid,String openid) throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("unionid", unionid);
if(StringUtils.isNotEmpty(openid)){
json.addProperty("openid",openid);
}
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UNIONID_TO_EXTERNAL_USERID);
String responseContent = this.mainService.post(url, json.toString());
JsonObject tmpJson = GsonParser.parse(responseContent);
Expand Down Expand Up @@ -449,6 +460,105 @@ public WxCpBaseResp markTag(String userid, String externalUserid, String[] addTa
return WxCpBaseResp.fromJson(result);
}

@Override
public WxCpAddMomentResult addMomentTask(WxCpAddMomentTask task) throws WxErrorException {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_MOMENT_TASK);
final String result = this.mainService.post(url, task.toJson());
return WxCpAddMomentResult.fromJson(result);
}

@Override
public WxCpGetMomentTaskResult getMomentTaskResult(String jobId) throws WxErrorException {
String params = "&jobid=" + jobId;
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_TASK_RESULT);
final String result = this.mainService.get(url, params);
return WxCpGetMomentTaskResult.fromJson(result);
}

@Override
public WxCpGetMomentList getMomentList(Long startTime, Long endTime, String creator, Integer filterType,
String cursor, Integer limit) throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("start_time", startTime);
json.addProperty("end_time", endTime);
if (!StringUtils.isEmpty(creator)) {
json.addProperty("creator", creator);
}
if (filterType!=null) {
json.addProperty("filter_type", filterType);
}
if (!StringUtils.isEmpty(cursor)) {
json.addProperty("cursor", cursor);
}
if (limit!=null) {
json.addProperty("limit", limit);
}
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_LIST);
final String result = this.mainService.post(url, json.toString());
return WxCpGetMomentList.fromJson(result);
}

@Override
public WxCpGetMomentTask getMomentTask(String momentId, String cursor, Integer limit)
throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("moment_id", momentId);
if (!StringUtils.isEmpty(cursor)) {
json.addProperty("cursor", cursor);
}
if (limit!=null) {
json.addProperty("limit", limit);
}
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_TASK);
final String result = this.mainService.post(url, json.toString());
return WxCpGetMomentTask.fromJson(result);
}

@Override
public WxCpGetMomentCustomerList getMomentCustomerList(String momentId, String userId,
String cursor, Integer limit) throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("moment_id", momentId);
json.addProperty("userid", userId);
if (!StringUtils.isEmpty(cursor)) {
json.addProperty("cursor", cursor);
}
if (limit!=null) {
json.addProperty("limit", limit);
}
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_CUSTOMER_LIST);
final String result = this.mainService.post(url, json.toString());
return WxCpGetMomentCustomerList.fromJson(result);
}

@Override
public WxCpGetMomentSendResult getMomentSendResult(String momentId, String userId,
String cursor, Integer limit) throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("moment_id", momentId);
json.addProperty("userid", userId);
if (!StringUtils.isEmpty(cursor)) {
json.addProperty("cursor", cursor);
}
if (limit!=null) {
json.addProperty("limit", limit);
}
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_SEND_RESULT);
final String result = this.mainService.post(url, json.toString());
return WxCpGetMomentSendResult.fromJson(result);
}

@Override
public WxCpGetMomentComments getMomentComments(String momentId, String userId)
throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("moment_id", momentId);
json.addProperty("userid", userId);
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_COMMENTS);
final String result = this.mainService.post(url, json.toString());
return WxCpGetMomentComments.fromJson(result);
}

/**
* <pre>
* 企业和第三方应用可通过此接口获取企业与成员的群发记录。
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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;

/**
* 企业发表内容到客户的朋友圈 创建发表任务结果
*
* @author leiin
* @date 2021-10-29
*/
@Data
public class WxCpAddMomentResult extends WxCpBaseResp {

@SerializedName("jobid")
private String jobId;

public static WxCpAddMomentResult fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpAddMomentResult.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.chanjar.weixin.cp.bean.external;

import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.cp.bean.external.msg.Attachment;
import me.chanjar.weixin.cp.bean.external.msg.Text;
import me.chanjar.weixin.cp.bean.external.moment.VisibleRange;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

/**
* 企业发表内容到客户的朋友圈 创建发表任务
*
* @author leiin
* @date 2021-10-29
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxCpAddMomentTask implements Serializable {
@SerializedName("visible_range")
private VisibleRange visibleRange;

private Text text;

private List<Attachment> attachments;

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package me.chanjar.weixin.cp.bean.external;

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

/**
* 企业发表内容到客户的朋友圈 获取客户朋友圈的互动数据
*
* @author leiin
* @date 2021-10-29
*/
@Data
public class WxCpGetMomentComments extends WxCpBaseResp {
@SerializedName("comment_list")
private List<CommentLikeItem> commentList;
@SerializedName("like_list")
private List<CommentLikeItem> likeList;

@Getter
@Setter
public static class CommentLikeItem {
@SerializedName("external_userid")
private String externalUserId;
@SerializedName("create_time")
private Long createTime;
}

public static WxCpGetMomentComments fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpGetMomentComments.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
Loading