Skip to content

Commit

Permalink
Merge commit '505cdafe98c036428c4bb4aec70c3b717bde0faa' into local
Browse files Browse the repository at this point in the history
* commit '505cdafe98c036428c4bb4aec70c3b717bde0faa':
  binarywang#705 企业微信增加获取外部联系人详情接口
  binarywang#705 企业微信用户相关接口增加成员对外信息external_profile
  binarywang#727 小程序模块增加内容安全接口
  binarywang#730 公众号模块增加客服输入状态接口
  优化代码
  • Loading branch information
袁启勋 committed Sep 18, 2018
2 parents df7a902 + 505cdaf commit eebf8f9
Show file tree
Hide file tree
Showing 16 changed files with 750 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package me.chanjar.weixin.cp.api;

import java.util.List;
import java.util.Map;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
import me.chanjar.weixin.cp.bean.WxCpUser;

import java.util.List;
import java.util.Map;
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;

/**
* <pre>
Expand All @@ -18,7 +19,7 @@
public interface WxCpUserService {
/**
* <pre>
* 用在二次验证的时候
* 用在二次验证的时候.
* 企业在员工验证成功后,调用本方法告诉企业号平台该员工关注成功。
* </pre>
*
Expand All @@ -28,7 +29,7 @@ public interface WxCpUserService {

/**
* <pre>
* 获取部门成员(详情)
* 获取部门成员(详情).
*
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98.28.E8.AF.A6.E6.83.85.29
* </pre>
Expand All @@ -41,7 +42,7 @@ public interface WxCpUserService {

/**
* <pre>
* 获取部门成员
* 获取部门成员.
*
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98
* </pre>
Expand All @@ -53,22 +54,22 @@ public interface WxCpUserService {
List<WxCpUser> listSimpleByDepartment(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException;

/**
* 新建用户
* 新建用户.
*
* @param user 用户对象
*/
void create(WxCpUser user) throws WxErrorException;

/**
* 更新用户
* 更新用户.
*
* @param user 用户对象
*/
void update(WxCpUser user) throws WxErrorException;

/**
* <pre>
* 删除用户/批量删除成员
* 删除用户/批量删除成员.
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E6.89.B9.E9.87.8F.E5.88.A0.E9.99.A4.E6.88.90.E5.91.98
* </pre>
*
Expand All @@ -77,15 +78,15 @@ public interface WxCpUserService {
void delete(String... userIds) throws WxErrorException;

/**
* 获取用户
* 获取用户.
*
* @param userid 用户id
*/
WxCpUser getById(String userid) throws WxErrorException;

/**
* <pre>
* 邀请成员
* 邀请成员.
* 企业可通过接口批量邀请成员使用企业微信,邀请后将通过短信或邮件下发通知。
* 请求方式:POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/batch/invite?access_token=ACCESS_TOKEN
Expand Down Expand Up @@ -113,14 +114,14 @@ public interface WxCpUserService {
* @param userId 企业内的成员id
* @param agentId 非必填,整型,仅用于发红包。其它场景该参数不要填,如微信支付、企业转账、电子发票
* @return map对象,可能包含以下值:
* - openid 企业微信成员userid对应的openid,若有传参agentid,则是针对该agentid的openid。否则是针对企业微信corpid的openid
* - appid 应用的appid,若请求包中不包含agentid则不返回appid。该appid在使用微信红包时会用到
* - openid 企业微信成员userid对应的openid,若有传参agentid,则是针对该agentid的openid。否则是针对企业微信corpid的openid
* - appid 应用的appid,若请求包中不包含agentid则不返回appid。该appid在使用微信红包时会用到
*/
Map<String, String> userId2Openid(String userId, Integer agentId) throws WxErrorException;

/**
* <pre>
* openid转userid
* openid转userid.
*
* 该接口主要应用于使用微信支付、微信红包和企业转账之后的结果查询。
* 开发者需要知道某个结果事件的openid对应企业微信内成员的信息时,可以通过调用该接口进行转换查询。
Expand All @@ -134,4 +135,17 @@ public interface WxCpUserService {
* @return userid 该openid在企业微信对应的成员userid
*/
String openid2UserId(String openid) throws WxErrorException;

/**
* 获取外部联系人详情.
* <pre>
* 企业可通过此接口,根据外部联系人的userid,拉取外部联系人详情。权限说明:
* 企业需要使用外部联系人管理secret所获取的accesstoken来调用
* 第三方应用需拥有“企业客户”权限。
* 第三方应用调用时,返回的跟进人follow_user仅包含应用可见范围之内的成员。
* </pre>
*
* @param userId 外部联系人的userid
*/
WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException;
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package me.chanjar.weixin.cp.api.impl;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Maps;
import com.google.gson.*;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
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.util.json.WxCpGsonBuilder;

import java.util.List;
import java.util.Map;

/**
* <pre>
* Created by BinaryWang on 2017/6/24.
Expand Down Expand Up @@ -178,4 +183,11 @@ public String openid2UserId(String openid) throws WxErrorException {
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("userid").getAsString();
}

@Override
public WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/crm/get_external_contact?external_userid=" + userId;
String responseContent = this.mainService.get(url, null);
return WxCpUserExternalContactInfo.fromJson(responseContent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

/**
Expand Down Expand Up @@ -34,6 +36,14 @@ public class WxCpUser implements Serializable {
private String telephone;
private String qrCode;
private Boolean toInvite;
/**
* 成员对外信息.
*/
private List<ExternalAttribute> externalAttrs = new ArrayList<>();

public void addExternalAttr(ExternalAttribute externalAttr) {
this.externalAttrs.add(externalAttr);
}

public void addExtAttr(String name, String value) {
this.extAttrs.add(new Attr(name, value));
Expand All @@ -54,4 +64,39 @@ public static class Attr {
private String value;
}

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class ExternalAttribute {
/**
* 属性类型: 0-本文 1-网页 2-小程序.
*/
private int type;
/**
* 属性名称: 需要先确保在管理端有创建改属性,否则会忽略.
*/
private String name;
/**
* 文本属性内容,长度限制12个UTF8字符.
*/
private String value;
/**
* 网页的url,必须包含http或者https头.
*/
private String url;
/**
* 小程序的展示标题,长度限制12个UTF8字符.
* 或者 网页的展示标题,长度限制12个UTF8字符
*/
private String title;
/**
* 小程序appid,必须是有在本企业安装授权的小程序,否则会被忽略.
*/
private String appid;
/**
* 小程序的页面路径.
*/
private String pagePath;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package me.chanjar.weixin.cp.bean;

import java.util.List;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

/**
* <pre>
* 外部联系人详情
* Created by Binary Wang on 2018/9/16.
* 参考文档:https://work.weixin.qq.com/api/doc#13878
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Getter
@Setter
public class WxCpUserExternalContactInfo {
@SerializedName("external_contact")
private ExternalContact externalContact;

@SerializedName("follow_user")
private List<FollowedUser> followedUsers;

@Getter
@Setter
public static class ExternalContact {
@SerializedName("external_userid")
private String externalUserId;

@SerializedName("position")
private String position;

@SerializedName("name")
private String name;

@SerializedName("avatar")
private String avatar;

@SerializedName("corp_name")
private String corpName;

@SerializedName("corp_full_name")
private String corpFullName;

@SerializedName("type")
private Integer type;

@SerializedName("gender")
private Integer gender;

@SerializedName("unionid")
private String unionId;

@SerializedName("external_profile")
private ExternalProfile externalProfile;
}

@Setter
@Getter
public static class ExternalProfile {
@SerializedName("external_attr")
private List<ExternalAttribute> externalAttrs;
}

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class ExternalAttribute {
@Setter
@Getter
public static class Text {
private String value;
}

@Setter
@Getter
public static class Web {
private String title;
private String url;
}

@Setter
@Getter
public static class MiniProgram {
@SerializedName("pagepath")
private String pagePath;
private String appid;
private String title;
}

private int type;

private String name;

private Text text;

private Web web;

@SerializedName("miniprogram")
private MiniProgram miniProgram;
}

@Setter
@Getter
public static class FollowedUser {
@SerializedName("userid")
private String userId;
private String remark;
private String description;
@SerializedName("createtime")
private Long createTime;
}

public static WxCpUserExternalContactInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpUserExternalContactInfo.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import me.chanjar.weixin.cp.bean.WxCpTag;
import me.chanjar.weixin.cp.bean.WxCpUser;

/**
* @author Daniel Qian
*/
public class WxCpGsonBuilder {

public static final GsonBuilder INSTANCE = new GsonBuilder();
Expand Down
Loading

0 comments on commit eebf8f9

Please sign in to comment.