From eb56efd7963d1a29952779d8db2a421a5a50849d Mon Sep 17 00:00:00 2001 From: Hugo-Ho <52446959+Hugo-Ho@users.noreply.github.com> Date: Wed, 13 Dec 2023 19:43:19 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20=20#3184=E3=80=90=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E3=80=91=E6=96=B0=E5=A2=9E=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E5=BA=94=E7=94=A8=E5=8F=AF=E6=9F=A5=E8=AF=A2=E8=8E=B7?= =?UTF-8?q?=E5=AE=A2=E9=93=BE=E6=8E=A5=E7=9A=84=E4=BD=BF=E7=94=A8=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cp/api/WxCpExternalContactService.java | 18 ++++++++++ .../impl/WxCpExternalContactServiceImpl.java | 17 +++++++++ .../WxCpCustomerAcquisitionStatistic.java | 36 +++++++++++++++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 4 +++ 4 files changed, 75 insertions(+) create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/acquisition/WxCpCustomerAcquisitionStatistic.java diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java index 09d23db830..dee5b3e317 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java @@ -1291,4 +1291,22 @@ WxMediaUploadResult uploadAttachment(String mediaType, Integer attachmentType, F * @throws WxErrorException the wx error exception */ WxCpCustomerAcquisitionQuota customerAcquisitionQuota() throws WxErrorException; + + + /** + * 查询链接使用详情 + * 服务商可通过此接口查询指定组件授权的获客链接在指定时间范围内的访问情况。 + * + * 请求方式:POST(HTTPS) + * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/statistic?access_token=ACCESS_TOKEN + * + * @author Hugo + * @date 2023/12/5 14:34 + * @param linkId 获客链接的id + * @param startTime 统计起始时间 + * @param endTime 统计结束时间 + * @return 点击链接客户数和新增客户数 + * @throws WxErrorException the wx error exception + */ + WxCpCustomerAcquisitionStatistic customerAcquisitionStatistic(String linkId, Date startTime, Date endTime) throws WxErrorException; } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java index bef01ca777..06847c2739 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java @@ -2,6 +2,7 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; +import lombok.NonNull; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.error.WxCpErrorMsgEnum; @@ -817,6 +818,22 @@ public WxCpCustomerAcquisitionQuota customerAcquisitionQuota() throws WxErrorExc return WxCpCustomerAcquisitionQuota.fromJson(this.mainService.get(url, null)); } + @Override + public WxCpCustomerAcquisitionStatistic customerAcquisitionStatistic(String linkId, @NonNull Date startTime, + @NonNull Date endTime) throws WxErrorException { + long endTimestamp = endTime.getTime() / 1000L; + long startTimestamp = startTime.getTime() / 1000L; + + JsonObject o = new JsonObject(); + o.addProperty("link_id", linkId); + o.addProperty("start_time", startTimestamp); + o.addProperty("end_time", endTimestamp); + + String url = this.mainService.getWxCpConfigStorage().getApiUrl(CUSTOMER_ACQUISITION_STATISTIC); + return WxCpCustomerAcquisitionStatistic.fromJson(this.mainService.post(url, o)); + } + + @Override public WxCpGroupJoinWayResult addJoinWay(WxCpGroupJoinWayInfo wxCpGroupJoinWayInfo) throws WxErrorException { if (wxCpGroupJoinWayInfo.getJoinWay().getChatIdList() != null && wxCpGroupJoinWayInfo.getJoinWay().getChatIdList().size() > 5) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/acquisition/WxCpCustomerAcquisitionStatistic.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/acquisition/WxCpCustomerAcquisitionStatistic.java new file mode 100644 index 0000000000..bb02b039bd --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/acquisition/WxCpCustomerAcquisitionStatistic.java @@ -0,0 +1,36 @@ +package me.chanjar.weixin.cp.bean.external.acquisition; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +/** + * 获客链接的使用详情 + * + * @author Hugo + * @date 2023/12/11 10:31 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxCpCustomerAcquisitionStatistic extends WxCpBaseResp { + private static final long serialVersionUID = -3816540677590841079L; + + /** + * 点击链接客户数 + */ + @SerializedName("click_link_customer_cnt") + private Integer clickLinkCustomerCnt; + + /** + * 新增客户数 + */ + @SerializedName("new_customer_cnt") + private Integer newCustomerCnt; + + public static WxCpCustomerAcquisitionStatistic fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpCustomerAcquisitionStatistic.class); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index 0f67a2051e..18c3ac6d28 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -1330,6 +1330,10 @@ interface ExternalContact { */ String CUSTOMER_ACQUISITION_QUOTA = "/cgi-bin/externalcontact/customer_acquisition_quota"; + /** + * 查询链接使用详情 + */ + String CUSTOMER_ACQUISITION_STATISTIC = "/cgi-bin/externalcontact/customer_acquisition/statistic"; } /**