Skip to content

Commit 537a933

Browse files
authored
🆕 #2361 【企业微信】增加客户朋友圈相关的部分接口
1 parent dde4451 commit 537a933

22 files changed

+651
-6
lines changed

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

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
import lombok.NonNull;
44
import me.chanjar.weixin.common.error.WxErrorException;
55
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.bean.external.WxCpAddMomentResult;
7+
import me.chanjar.weixin.cp.bean.external.WxCpAddMomentTask;
68
import me.chanjar.weixin.cp.bean.external.WxCpContactWayInfo;
79
import me.chanjar.weixin.cp.bean.external.WxCpContactWayResult;
10+
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentComments;
11+
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentCustomerList;
12+
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentList;
13+
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentSendResult;
14+
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTask;
15+
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTaskResult;
816
import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplate;
917
import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplateAddResult;
1018
import me.chanjar.weixin.cp.bean.external.WxCpUpdateRemarkRequest;
@@ -181,7 +189,7 @@ public interface WxCpExternalContactService {
181189
* @return 该企业的外部联系人ID
182190
* @throws WxErrorException .
183191
*/
184-
String unionidToExternalUserid(String unionid) throws WxErrorException;
192+
String unionidToExternalUserid(@NotNull String unionid,String openid) throws WxErrorException;
185193

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

597+
/**
598+
* <pre>
599+
* 企业和第三方应用可通过该接口创建客户朋友圈的发表任务。
600+
* https://open.work.weixin.qq.com/api/doc/90000/90135/95094
601+
* </pre>
602+
* @param task
603+
* @return wx cp add moment result
604+
* @throws WxErrorException the wx error exception
605+
*/
606+
WxCpAddMomentResult addMomentTask(WxCpAddMomentTask task) throws WxErrorException;
607+
608+
/**
609+
* <pre>
610+
* 由于发表任务的创建是异步执行的,应用需要再调用该接口以获取创建的结果。
611+
* https://open.work.weixin.qq.com/api/doc/90000/90135/95094
612+
* </pre>
613+
* @param jobId 异步任务id,最大长度为64字节,由创建发表内容到客户朋友圈任务接口获取
614+
* @return
615+
* @throws WxErrorException
616+
*/
617+
WxCpGetMomentTaskResult getMomentTaskResult(String jobId) throws WxErrorException;
618+
619+
/**
620+
* <pre>
621+
* 获取客户朋友圈全部的发表记录 获取企业全部的发表列表
622+
* https://open.work.weixin.qq.com/api/doc/90000/90135/93333
623+
* </pre>
624+
* @param startTime 朋友圈记录开始时间。Unix时间戳
625+
* @param endTime 朋友圈记录结束时间。Unix时间戳
626+
* @param creator 朋友圈创建人的userid
627+
* @param filterType 朋友圈类型。0:企业发表 1:个人发表 2:所有,包括个人创建以及企业创建,默认情况下为所有类型
628+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
629+
* @param limit 返回的最大记录数,整型,最大值100,默认值100,超过最大值时取默认值
630+
* @return
631+
* @throws WxErrorException
632+
*/
633+
WxCpGetMomentList getMomentList(Long startTime, Long endTime, String creator, Integer filterType,
634+
String cursor, Integer limit) throws WxErrorException;
635+
636+
/**
637+
* <pre>
638+
* 获取客户朋友圈全部的发表记录 获取客户朋友圈企业发表的列表
639+
* https://open.work.weixin.qq.com/api/doc/90000/90135/93333
640+
* </pre>
641+
* @param momentId 朋友圈id,仅支持企业发表的朋友圈id
642+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
643+
* @param limit 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
644+
* @return
645+
* @throws WxErrorException
646+
*/
647+
WxCpGetMomentTask getMomentTask(String momentId, String cursor, Integer limit)
648+
throws WxErrorException;
649+
650+
/**
651+
* <pre>
652+
* 获取客户朋友圈全部的发表记录 获取客户朋友圈发表时选择的可见范围
653+
* https://open.work.weixin.qq.com/api/doc/90000/90135/93333
654+
* </pre>
655+
* @param momentId 朋友圈id
656+
* @param userId 企业发表成员userid,如果是企业创建的朋友圈,可以通过获取客户朋友圈企业发表的
657+
* 列表获取已发表成员userid,如果是个人创建的朋友圈,创建人userid就是企业发表成员userid
658+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
659+
* @param limit 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
660+
* @return
661+
* @throws WxErrorException
662+
*/
663+
WxCpGetMomentCustomerList getMomentCustomerList(String momentId, String userId,
664+
String cursor, Integer limit) throws WxErrorException;
665+
666+
/**
667+
* <pre>
668+
* 获取客户朋友圈全部的发表记录 获取客户朋友圈发表后的可见客户列表
669+
* https://open.work.weixin.qq.com/api/doc/90000/90135/93333
670+
* </pre>
671+
* @param momentId 朋友圈id
672+
* @param userId 企业发表成员userid,如果是企业创建的朋友圈,可以通过获取客户朋友圈企业发表的列表获取已发表成员userid,
673+
* 如果是个人创建的朋友圈,创建人userid就是企业发表成员userid
674+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
675+
* @param limit 返回的最大记录数,整型,最大值5000,默认值3000,超过最大值时取默认值
676+
* @return
677+
* @throws WxErrorException
678+
*/
679+
WxCpGetMomentSendResult getMomentSendResult(String momentId, String userId,
680+
String cursor, Integer limit) throws WxErrorException;
681+
682+
/**
683+
* <pre>
684+
* 获取客户朋友圈全部的发表记录 获取客户朋友圈的互动数据
685+
* https://open.work.weixin.qq.com/api/doc/90000/90135/93333
686+
* </pre>
687+
* @param momentId 朋友圈id
688+
* @param userId 企业发表成员userid,如果是企业创建的朋友圈,可以通过获取客户朋友圈企业发表的列表获取已发表成员userid,
689+
* 如果是个人创建的朋友圈,创建人userid就是企业发表成员userid
690+
* @return
691+
* @throws WxErrorException
692+
*/
693+
WxCpGetMomentComments getMomentComments(String momentId, String userId)
694+
throws WxErrorException;
589695

590696
/**
591697
* <pre>

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

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@
1212
import me.chanjar.weixin.cp.api.WxCpExternalContactService;
1313
import me.chanjar.weixin.cp.api.WxCpService;
1414
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
15+
import me.chanjar.weixin.cp.bean.external.WxCpAddMomentResult;
16+
import me.chanjar.weixin.cp.bean.external.WxCpAddMomentTask;
1517
import me.chanjar.weixin.cp.bean.external.WxCpContactWayInfo;
1618
import me.chanjar.weixin.cp.bean.external.WxCpContactWayResult;
19+
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentComments;
20+
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentCustomerList;
21+
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentList;
22+
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentSendResult;
23+
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTask;
24+
import me.chanjar.weixin.cp.bean.external.WxCpGetMomentTaskResult;
1725
import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplate;
1826
import me.chanjar.weixin.cp.bean.external.WxCpMsgTemplateAddResult;
1927
import me.chanjar.weixin.cp.bean.external.WxCpUpdateRemarkRequest;
@@ -137,9 +145,12 @@ public String convertToOpenid(@NotNull String externalUserId) throws WxErrorExce
137145
}
138146

139147
@Override
140-
public String unionidToExternalUserid(@NotNull String unionid) throws WxErrorException {
148+
public String unionidToExternalUserid(@NotNull String unionid,String openid) throws WxErrorException {
141149
JsonObject json = new JsonObject();
142150
json.addProperty("unionid", unionid);
151+
if(StringUtils.isNotEmpty(openid)){
152+
json.addProperty("openid",openid);
153+
}
143154
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UNIONID_TO_EXTERNAL_USERID);
144155
String responseContent = this.mainService.post(url, json.toString());
145156
JsonObject tmpJson = GsonParser.parse(responseContent);
@@ -449,6 +460,105 @@ public WxCpBaseResp markTag(String userid, String externalUserid, String[] addTa
449460
return WxCpBaseResp.fromJson(result);
450461
}
451462

463+
@Override
464+
public WxCpAddMomentResult addMomentTask(WxCpAddMomentTask task) throws WxErrorException {
465+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_MOMENT_TASK);
466+
final String result = this.mainService.post(url, task.toJson());
467+
return WxCpAddMomentResult.fromJson(result);
468+
}
469+
470+
@Override
471+
public WxCpGetMomentTaskResult getMomentTaskResult(String jobId) throws WxErrorException {
472+
String params = "&jobid=" + jobId;
473+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_TASK_RESULT);
474+
final String result = this.mainService.get(url, params);
475+
return WxCpGetMomentTaskResult.fromJson(result);
476+
}
477+
478+
@Override
479+
public WxCpGetMomentList getMomentList(Long startTime, Long endTime, String creator, Integer filterType,
480+
String cursor, Integer limit) throws WxErrorException {
481+
JsonObject json = new JsonObject();
482+
json.addProperty("start_time", startTime);
483+
json.addProperty("end_time", endTime);
484+
if (!StringUtils.isEmpty(creator)) {
485+
json.addProperty("creator", creator);
486+
}
487+
if (filterType!=null) {
488+
json.addProperty("filter_type", filterType);
489+
}
490+
if (!StringUtils.isEmpty(cursor)) {
491+
json.addProperty("cursor", cursor);
492+
}
493+
if (limit!=null) {
494+
json.addProperty("limit", limit);
495+
}
496+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_LIST);
497+
final String result = this.mainService.post(url, json.toString());
498+
return WxCpGetMomentList.fromJson(result);
499+
}
500+
501+
@Override
502+
public WxCpGetMomentTask getMomentTask(String momentId, String cursor, Integer limit)
503+
throws WxErrorException {
504+
JsonObject json = new JsonObject();
505+
json.addProperty("moment_id", momentId);
506+
if (!StringUtils.isEmpty(cursor)) {
507+
json.addProperty("cursor", cursor);
508+
}
509+
if (limit!=null) {
510+
json.addProperty("limit", limit);
511+
}
512+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_TASK);
513+
final String result = this.mainService.post(url, json.toString());
514+
return WxCpGetMomentTask.fromJson(result);
515+
}
516+
517+
@Override
518+
public WxCpGetMomentCustomerList getMomentCustomerList(String momentId, String userId,
519+
String cursor, Integer limit) throws WxErrorException {
520+
JsonObject json = new JsonObject();
521+
json.addProperty("moment_id", momentId);
522+
json.addProperty("userid", userId);
523+
if (!StringUtils.isEmpty(cursor)) {
524+
json.addProperty("cursor", cursor);
525+
}
526+
if (limit!=null) {
527+
json.addProperty("limit", limit);
528+
}
529+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_CUSTOMER_LIST);
530+
final String result = this.mainService.post(url, json.toString());
531+
return WxCpGetMomentCustomerList.fromJson(result);
532+
}
533+
534+
@Override
535+
public WxCpGetMomentSendResult getMomentSendResult(String momentId, String userId,
536+
String cursor, Integer limit) throws WxErrorException {
537+
JsonObject json = new JsonObject();
538+
json.addProperty("moment_id", momentId);
539+
json.addProperty("userid", userId);
540+
if (!StringUtils.isEmpty(cursor)) {
541+
json.addProperty("cursor", cursor);
542+
}
543+
if (limit!=null) {
544+
json.addProperty("limit", limit);
545+
}
546+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_SEND_RESULT);
547+
final String result = this.mainService.post(url, json.toString());
548+
return WxCpGetMomentSendResult.fromJson(result);
549+
}
550+
551+
@Override
552+
public WxCpGetMomentComments getMomentComments(String momentId, String userId)
553+
throws WxErrorException {
554+
JsonObject json = new JsonObject();
555+
json.addProperty("moment_id", momentId);
556+
json.addProperty("userid", userId);
557+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_MOMENT_COMMENTS);
558+
final String result = this.mainService.post(url, json.toString());
559+
return WxCpGetMomentComments.fromJson(result);
560+
}
561+
452562
/**
453563
* <pre>
454564
* 企业和第三方应用可通过此接口获取企业与成员的群发记录。
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package me.chanjar.weixin.cp.bean.external;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
/**
9+
* 企业发表内容到客户的朋友圈 创建发表任务结果
10+
*
11+
* @author leiin
12+
* @date 2021-10-29
13+
*/
14+
@Data
15+
public class WxCpAddMomentResult extends WxCpBaseResp {
16+
17+
@SerializedName("jobid")
18+
private String jobId;
19+
20+
public static WxCpAddMomentResult fromJson(String json) {
21+
return WxCpGsonBuilder.create().fromJson(json, WxCpAddMomentResult.class);
22+
}
23+
24+
public String toJson() {
25+
return WxCpGsonBuilder.create().toJson(this);
26+
}
27+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package me.chanjar.weixin.cp.bean.external;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import java.io.Serializable;
5+
import java.util.List;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Builder;
8+
import lombok.Data;
9+
import lombok.NoArgsConstructor;
10+
import me.chanjar.weixin.cp.bean.external.msg.Attachment;
11+
import me.chanjar.weixin.cp.bean.external.msg.Text;
12+
import me.chanjar.weixin.cp.bean.external.moment.VisibleRange;
13+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
14+
15+
/**
16+
* 企业发表内容到客户的朋友圈 创建发表任务
17+
*
18+
* @author leiin
19+
* @date 2021-10-29
20+
*/
21+
@Data
22+
@Builder
23+
@NoArgsConstructor
24+
@AllArgsConstructor
25+
public class WxCpAddMomentTask implements Serializable {
26+
@SerializedName("visible_range")
27+
private VisibleRange visibleRange;
28+
29+
private Text text;
30+
31+
private List<Attachment> attachments;
32+
33+
public String toJson() {
34+
return WxCpGsonBuilder.create().toJson(this);
35+
}
36+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package me.chanjar.weixin.cp.bean.external;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import java.util.List;
5+
import lombok.Data;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
9+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
10+
11+
/**
12+
* 企业发表内容到客户的朋友圈 获取客户朋友圈的互动数据
13+
*
14+
* @author leiin
15+
* @date 2021-10-29
16+
*/
17+
@Data
18+
public class WxCpGetMomentComments extends WxCpBaseResp {
19+
@SerializedName("comment_list")
20+
private List<CommentLikeItem> commentList;
21+
@SerializedName("like_list")
22+
private List<CommentLikeItem> likeList;
23+
24+
@Getter
25+
@Setter
26+
public static class CommentLikeItem {
27+
@SerializedName("external_userid")
28+
private String externalUserId;
29+
@SerializedName("create_time")
30+
private Long createTime;
31+
}
32+
33+
public static WxCpGetMomentComments fromJson(String json) {
34+
return WxCpGsonBuilder.create().fromJson(json, WxCpGetMomentComments.class);
35+
}
36+
37+
public String toJson() {
38+
return WxCpGsonBuilder.create().toJson(this);
39+
}
40+
}

0 commit comments

Comments
 (0)