From 69abc0ce2d8068e4a72cb36c7aaa0fbcdd2581e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=95=E6=B3=BD=E4=BA=91?= <75881401@qq.com> Date: Mon, 27 Mar 2023 13:54:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1=EF=BC=9A?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=95=86=E7=9A=84=E5=B8=90=E5=8F=B7ID=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WxCpTpConvertTmpExternalUserIdResult.java | 41 ++++++++++++++ .../cp/bean/WxCpTpOpenKfIdConvertResult.java | 46 +++++++++++++++ .../cp/bean/WxCpTpTagIdListConvertResult.java | 51 +++++++++++++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 24 ++++++++ .../cp/tp/service/WxCpTpIdConvertService.java | 33 +++++++++++ .../impl/WxCpTpIdConvertServiceImpl.java | 56 ++++++++++++++++++- 6 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpConvertTmpExternalUserIdResult.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpOpenKfIdConvertResult.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpTagIdListConvertResult.java diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpConvertTmpExternalUserIdResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpConvertTmpExternalUserIdResult.java new file mode 100644 index 0000000000..9bca31c2d0 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpConvertTmpExternalUserIdResult.java @@ -0,0 +1,41 @@ +package me.chanjar.weixin.cp.bean; + +import com.google.gson.annotations.SerializedName; +import lombok.Getter; +import lombok.Setter; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.util.List; + +@Setter +@Getter +public class WxCpTpConvertTmpExternalUserIdResult extends WxCpBaseResp { + + + @SerializedName("invalid_tmp_external_userid_list") + private List results; + + @Getter + @Setter + public static class Results { + + @SerializedName("tmp_external_userid") + private String tmpExternalUserId; + + @SerializedName("external_userid") + private String externalUserId; + + @SerializedName("corpid") + private String corpId; + + @SerializedName("userid") + private String userId; + } + + @SerializedName("invalid_tmp_external_userid_list") + private List invalidTmpExternalUserIdList; + + public static WxCpTpConvertTmpExternalUserIdResult fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpConvertTmpExternalUserIdResult.class); + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpOpenKfIdConvertResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpOpenKfIdConvertResult.java new file mode 100644 index 0000000000..b6b0e9ef82 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpOpenKfIdConvertResult.java @@ -0,0 +1,46 @@ +package me.chanjar.weixin.cp.bean; + +import com.google.gson.annotations.SerializedName; +import lombok.Getter; +import lombok.Setter; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.util.List; + +@Setter +@Getter +public class WxCpTpOpenKfIdConvertResult extends WxCpBaseResp { + + /** + * 微信客服ID转换结果 + */ + @SerializedName("items") + private List items; + + /** + * 无法转换的微信客服ID列表 + */ + @SerializedName("invalid_open_kfid_list") + private List invalidOpenKfIdList; + + @Getter + @Setter + public static class Item { + + /*** + * 企业主体下的微信客服ID + */ + @SerializedName("open_kfid") + private String openKfId; + + /** + * 服务商主体下的微信客服ID,如果传入的open_kfid已经是服务商主体下的ID,则new_open_kfid与open_kfid相同。 + */ + @SerializedName("new_open_kfid") + private String newOpenKfId; + } + + public static WxCpTpOpenKfIdConvertResult fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpOpenKfIdConvertResult.class); + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpTagIdListConvertResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpTagIdListConvertResult.java new file mode 100644 index 0000000000..e24d36d4d0 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpTagIdListConvertResult.java @@ -0,0 +1,51 @@ +package me.chanjar.weixin.cp.bean; + + +import com.google.gson.annotations.SerializedName; +import lombok.Getter; +import lombok.Setter; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.util.List; + +@Getter +@Setter +public class WxCpTpTagIdListConvertResult extends WxCpBaseResp { + + private static final long serialVersionUID = -6153589164415497369L; + + + /** + * 客户标签转换结果 + */ + @SerializedName("items") + private List items; + + /** + * 无法转换的客户标签ID列表 + */ + @SerializedName("invalid_external_tagid_list") + private List invalidExternalTagIdList; + + + @Getter + @Setter + public static class Item { + + /** + * 企业主体下的客户标签ID + */ + @SerializedName("external_tagid") + private String externalTagId; + + /** + * 服务商主体下的客户标签ID,如果传入的external_tagid已经是服务商主体下的ID,则open_external_tagid与external_tagid相同。 + */ + @SerializedName("open_external_tagid") + private String openExternalTagId; + } + + public static WxCpTpTagIdListConvertResult fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpTagIdListConvertResult.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 5ffcee7ddb..d03a52f31e 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 @@ -1451,4 +1451,28 @@ interface LinkedCorp { */ String SENG_MESSAGE="/cgi-bin/linkedcorp/message/send"; } + + interface IdConvert { + + /** + * 将企业主体下的客户标签ID转换成服务商主体下的客户标签ID。 + */ + String EXTERNAL_TAG_ID = "/cgi-bin/idconvert/external_tagid"; + + /** + * 将微信客户的unionid转为第三方主体的external_userid + * 该接口有调用频率限制,当subject_type为0时,按企业作如下的限制:10万次/小时、48万次/天、750万次/月 + */ + String UNION_ID_TO_EXTERNAL_USER_ID = "/cgi-bin/idconvert/unionid_to_external_userid"; + + /** + * 将企业主体下的微信客服ID转换成服务商主体下的微信客服ID + */ + String OPEN_KF_ID = "/cgi-bin/idconvert/open_kfid"; + + /** + * 将应用获取的外部用户临时idtmp_external_userid,转换为external_userid。 + */ + String CONVERT_TMP_EXTERNAL_USER_ID = "/cgi-bin/idconvert/convert_tmp_external_userid"; + } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpIdConvertService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpIdConvertService.java index 95979f628c..78c52d5c36 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpIdConvertService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpIdConvertService.java @@ -1,8 +1,13 @@ package me.chanjar.weixin.cp.tp.service; import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.cp.bean.WxCpTpConvertTmpExternalUserIdResult; +import me.chanjar.weixin.cp.bean.WxCpTpOpenKfIdConvertResult; +import me.chanjar.weixin.cp.bean.WxCpTpTagIdListConvertResult; import me.chanjar.weixin.cp.bean.WxCpTpUnionidToExternalUseridResult; +import java.util.List; + /** *
  *  企业微信三方应用ID转换接口
@@ -25,4 +30,32 @@ public interface WxCpTpIdConvertService {
   WxCpTpUnionidToExternalUseridResult unionidToExternalUserid(String cropId, String unionid, String openid,
                                                               Integer subjectType) throws WxErrorException;
 
+
+  /**
+   * 将企业主体下的客户标签ID转换成服务商主体下的客户标签ID
+   * @param corpId             企业微信 ID
+   * @param externalTagIdList  企业主体下的客户标签ID列表,最多不超过1000个
+   * @return                    客户标签转换结果
+   * @throws WxErrorException .
+   */
+  WxCpTpTagIdListConvertResult externalTagId(String corpId, String... externalTagIdList) throws WxErrorException;
+
+  /**
+   * 将企业主体下的微信客服ID转换成服务商主体下的微信客服ID
+   * @param corpId             企业微信 ID
+   * @param openKfIdList       微信客服ID列表,最多不超过1000个
+   * @return                   微信客服ID转换结果
+   * @throws WxErrorException  .
+   */
+  WxCpTpOpenKfIdConvertResult ConvertOpenKfId (String corpId, String... openKfIdList ) throws WxErrorException;
+
+  /**
+   * 将应用获取的外部用户临时idtmp_external_userid,转换为external_userid
+   * @param corpId                 企业微信Id
+   * @param businessType           业务类型。1-会议 2-收集表
+   * @param userType               转换的目标用户类型。1-客户 2-企业互联 3-上下游 4-互联企业(圈子)
+   * @param tmpExternalUserIdList  外部用户临时id,最多不超过100个
+   * @return                       转换成功的结果列表
+   */
+  WxCpTpConvertTmpExternalUserIdResult convertTmpExternalUserId(String corpId, int businessType, int userType, String... tmpExternalUserIdList) throws WxErrorException;
 }
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpIdConvertServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpIdConvertServiceImpl.java
index 7692794a61..7d0d80b452 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpIdConvertServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpIdConvertServiceImpl.java
@@ -1,13 +1,21 @@
 package me.chanjar.weixin.cp.tp.service.impl;
 
+import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
 import lombok.RequiredArgsConstructor;
 import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.bean.WxCpTpConvertTmpExternalUserIdResult;
+import me.chanjar.weixin.cp.bean.WxCpTpOpenKfIdConvertResult;
+import me.chanjar.weixin.cp.bean.WxCpTpTagIdListConvertResult;
 import me.chanjar.weixin.cp.bean.WxCpTpUnionidToExternalUseridResult;
 import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
+import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
 import me.chanjar.weixin.cp.tp.service.WxCpTpIdConvertService;
 import me.chanjar.weixin.cp.tp.service.WxCpTpService;
 
+import java.util.List;
+
 
 /**
  * @author cocoa
@@ -26,11 +34,57 @@ public WxCpTpUnionidToExternalUseridResult unionidToExternalUserid(String cropId
     }
     WxCpTpConfigStorage wxCpTpConfigStorage = mainService.getWxCpTpConfigStorage();
     String accessToken = wxCpTpConfigStorage.getAccessToken(cropId);
-    String url = wxCpTpConfigStorage.getApiUrl("/cgi-bin/idconvert/unionid_to_external_userid");
+    String url = wxCpTpConfigStorage.getApiUrl(WxCpApiPathConsts.IdConvert.UNION_ID_TO_EXTERNAL_USER_ID);
     url += "?access_token=" + accessToken;
     String responseContent = this.mainService.post(url, json.toString());
     return WxCpTpUnionidToExternalUseridResult.fromJson(responseContent);
   }
 
+  @Override
+  public WxCpTpTagIdListConvertResult externalTagId(String corpId, String... externalTagIdList) throws WxErrorException {
+    WxCpTpConfigStorage wxCpTpConfigStorage = mainService.getWxCpTpConfigStorage();
+    String url = wxCpTpConfigStorage.getApiUrl(WxCpApiPathConsts.IdConvert.EXTERNAL_TAG_ID ) + "?access_token=" + mainService.getWxCpTpConfigStorage().getAccessToken(corpId);
+
+    JsonObject jsonObject = new JsonObject();
+    JsonArray jsonArray = new JsonArray();
+    for (String tagId : externalTagIdList) {
+      jsonArray.add(new JsonPrimitive(tagId));
+    }
+    jsonObject.add("external_tagid_list", jsonArray);
+    String responseContent = this.mainService.post(url, jsonObject.toString());
+
+    return WxCpTpTagIdListConvertResult.fromJson(responseContent);
+  }
+
+  @Override
+  public WxCpTpOpenKfIdConvertResult ConvertOpenKfId(String corpId, String... openKfIdList) throws WxErrorException {
+    WxCpTpConfigStorage wxCpTpConfigStorage = mainService.getWxCpTpConfigStorage();
+    String url = wxCpTpConfigStorage.getApiUrl(WxCpApiPathConsts.IdConvert.OPEN_KF_ID + "?access_token=" + mainService.getWxCpTpConfigStorage().getAccessToken(corpId));
+    JsonObject jsonObject = new JsonObject();
+    JsonArray jsonArray = new JsonArray();
+    for (String kfId : openKfIdList) {
+      jsonArray.add(new JsonPrimitive(kfId));
+    }
+    jsonObject.add("open_kfid_list", jsonArray);
+    String responseContent = this.mainService.post(url, jsonObject.toString());
+    return WxCpTpOpenKfIdConvertResult.fromJson(responseContent);
+  }
+
+  @Override
+  public WxCpTpConvertTmpExternalUserIdResult convertTmpExternalUserId(String corpId, int businessType, int userType, String... tmpExternalUserIdList) throws WxErrorException {
+    WxCpTpConfigStorage wxCpTpConfigStorage = mainService.getWxCpTpConfigStorage();
+    String url = wxCpTpConfigStorage.getApiUrl(WxCpApiPathConsts.IdConvert.CONVERT_TMP_EXTERNAL_USER_ID + "?access_token=" + mainService.getWxCpTpConfigStorage().getAccessToken(corpId));
+    JsonObject jsonObject = new JsonObject();
+    JsonArray jsonArray = new JsonArray();
+    jsonObject.addProperty("business_type", businessType);
+    jsonObject.addProperty("user_type", userType);
+    for (String userId : tmpExternalUserIdList) {
+      jsonArray.add(new JsonPrimitive(userId));
+    }
+    jsonObject.add("tmp_external_userid_list", jsonArray);
+    String responseContent = mainService.post(url, jsonObject.toString());
+    return WxCpTpConvertTmpExternalUserIdResult.fromJson(responseContent);
+  }
+
 
 }