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

改修获取企业已配置的「联系我」方式详情对象数据映射BUG,添加联系二维码的URL #1713

Merged
merged 18 commits into from
Aug 16, 2020
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 @@ -28,12 +28,12 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic
@Override
public WxCpContactWayResult addContactWay(@NonNull WxCpContactWayInfo info) throws WxErrorException {

if (info.getUsers() != null && info.getUsers().size() > 100) {
if (info.getContactWay().getUsers() != null && info.getContactWay().getUsers().size() > 100) {
throw new RuntimeException("「联系我」使用人数默认限制不超过100人(包括部门展开后的人数)");
}

final String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_CONTACT_WAY);
String responseContent = this.mainService.post(url, info.toJson());
String responseContent = this.mainService.post(url, info.getContactWay().toJson());

return WxCpContactWayResult.fromJson(responseContent);
}
Expand All @@ -45,21 +45,20 @@ public WxCpContactWayInfo getContactWay(@NonNull String configId) throws WxError

final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CONTACT_WAY);
String responseContent = this.mainService.post(url, json.toString());

return WxCpContactWayInfo.fromJson(responseContent);
}

@Override
public WxCpBaseResp updateContactWay(@NonNull WxCpContactWayInfo info) throws WxErrorException {
if (StringUtils.isBlank(info.getConfigId())) {
if (StringUtils.isBlank(info.getContactWay().getConfigId())) {
throw new RuntimeException("更新「联系我」方式需要指定configId");
}
if (info.getUsers() != null && info.getUsers().size() > 100) {
if (info.getContactWay().getUsers() != null && info.getContactWay().getUsers().size() > 100) {
throw new RuntimeException("「联系我」使用人数默认限制不超过100人(包括部门展开后的人数)");
}

final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_CONTACT_WAY);
String responseContent = this.mainService.post(url, info.toJson());
String responseContent = this.mainService.post(url, info.getContactWay().toJson());

return WxCpBaseResp.fromJson(responseContent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import me.chanjar.weixin.cp.util.json.WxCpConclusionAdapter;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

Expand All @@ -18,124 +20,168 @@
@NoArgsConstructor
public class WxCpContactWayInfo {

/**
* 联系方式的配置id
*/
@SerializedName("config_id")
private String configId;

/**
* <pre>
* 必填
* 联系方式类型,1-单人, 2-多人
* </pre>
*/
private TYPE type;

/**
* <pre>
* 必填
* 场景,1-在小程序中联系,2-通过二维码联系
* </pre>
*/
private SCENE scene;

/**
* <pre>
* 非必填
* 在小程序中联系时使用的控件样式
* <b>单人样式(type=1)时可选1,2,3</b>
* <b>多人样式(type=2)时可选1,2</b>
* </pre>
*/
private Integer style;

/**
* <pre>
* 非必填
* 联系方式的备注信息,用于助记,不超过30个字符
* </pre>
*/
private String remark;

/**
* <pre>
* 非必填
* 外部客户添加时是否无需验证,默认为true
* </pre>
*/
@SerializedName("skip_verify")
private Boolean skipVerify = Boolean.TRUE;

/**
* <pre>
* 非必填
* 企业自定义的state参数,用于区分不同的添加渠道,在调用“获取外部联系人详情(WxCpExternalContactService.getContactDetail)” 时会返回该参数值,不超过30个字符
* </pre>
*/
private String state;

/**
* <pre>
* 使用该联系方式的用户userID列表,在type为1时为必填,且只能有一个
* </pre>
*/
@SerializedName("user")
private List<String> users;


/**
* <pre>
* 非必填
* 使用该联系方式的部门id列表,只在type为2时有效
* </pre>
*/
@SerializedName("party")
private List<String> partys;

/**
* <pre>
* 非必填
* 是否临时会话模式,true表示使用临时会话模式,默认为false
* </pre>
*/
@SerializedName("is_temp")
private Boolean isTemp = Boolean.FALSE;

/**
* <pre>
* 非必填
* 临时会话二维码有效期,以秒为单位。该参数仅在is_temp为true时有效,默认7天
* </pre>
*/
@SerializedName("expires_in")
private Integer expiresIn;

/**
* <pre>
* 非必填
* 临时会话有效期,以秒为单位。该参数仅在is_temp为true时有效,默认为添加好友后24小时
* </pre>
*/
@SerializedName("chat_expires_in")
private Integer chatExpiresIn;

/**
* <pre>
* 非必填
* 可进行临时会话的客户unionid,该参数仅在is_temp为true时有效,如不指定则不进行限制
* </pre>
*/
@SerializedName("unionid")
private String unionId;

/**
* <pre>
* 非必填
* 结束语,会话结束时自动发送给客户,可参考“结束语定义”,仅在is_temp为true时有效
* </pre>
*/
private Conclusion conclusions;
@SerializedName("contact_way")
private ContactWay contactWay;

@Getter
@Setter
public static class ContactWay {
/**
* 联系方式的配置id
*/
@SerializedName("config_id")
private String configId;

/**
* <pre>
* 必填
* 联系方式类型,1-单人, 2-多人
* </pre>
*/
private TYPE type;

/**
* <pre>
* 必填
* 场景,1-在小程序中联系,2-通过二维码联系
* </pre>
*/
private SCENE scene;

/**
* <pre>
* 非必填
* 在小程序中联系时使用的控件样式
* <b>单人样式(type=1)时可选1,2,3</b>
* <b>多人样式(type=2)时可选1,2</b>
* </pre>
*/
private Integer style;

/**
* <pre>
* 非必填
* 联系方式的备注信息,用于助记,不超过30个字符
* </pre>
*/
private String remark;

/**
* <pre>
* 非必填
* 外部客户添加时是否无需验证,默认为true
* </pre>
*/
@SerializedName("skip_verify")
private Boolean skipVerify = Boolean.TRUE;

/**
* <pre>
* 非必填
* 企业自定义的state参数,用于区分不同的添加渠道,在调用“获取外部联系人详情(WxCpExternalContactService.getContactDetail)” 时会返回该参数值,不超过30个字符
* </pre>
*/
private String state;

/**
* <pre>
* 联系二维码的URL,仅在scene为2时返回
* </pre>
*/
@SerializedName("qr_code")
private String qrCode;

/**
* <pre>
* 使用该联系方式的用户userID列表,在type为1时为必填,且只能有一个
* </pre>
*/
@SerializedName("user")
private List<String> users;


/**
* <pre>
* 非必填
* 使用该联系方式的部门id列表,只在type为2时有效
* </pre>
*/
@SerializedName("party")
private List<String> partys;
binarywang marked this conversation as resolved.
Show resolved Hide resolved

/**
* <pre>
* 非必填
* 是否临时会话模式,true表示使用临时会话模式,默认为false
* </pre>
*/
@SerializedName("is_temp")
private Boolean isTemp = Boolean.FALSE;

/**
* <pre>
* 非必填
* 临时会话二维码有效期,以秒为单位。该参数仅在is_temp为true时有效,默认7天
* </pre>
*/
@SerializedName("expires_in")
private Integer expiresIn;

/**
* <pre>
* 非必填
* 临时会话有效期,以秒为单位。该参数仅在is_temp为true时有效,默认为添加好友后24小时
* </pre>
*/
@SerializedName("chat_expires_in")
private Integer chatExpiresIn;

/**
* <pre>
* 非必填
* 可进行临时会话的客户unionid,该参数仅在is_temp为true时有效,如不指定则不进行限制
* </pre>
*/
@SerializedName("unionid")
private String unionId;

/**
* <pre>
* 非必填
* 结束语,会话结束时自动发送给客户,可参考“结束语定义”,仅在is_temp为true时有效
* </pre>
*/
private Conclusion conclusions;

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

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

/**
* 结束语定义
*/
@Data
@JsonAdapter(WxCpConclusionAdapter.class)
public static class Conclusion {
private String textContent;
private String imgMediaId;
private String imgPicUrl;
private String linkTitle;
private String linkPicUrl;
private String linkDesc;
private String linkUrl;
private String miniProgramTitle;
private String miniProgramPicMediaId;
private String miniProgramAppId;
private String miniProgramPage;
}

}


public static WxCpContactWayInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpContactWayInfo.class);
Expand All @@ -145,25 +191,6 @@ public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

/**
* 结束语定义
*/
@Data
@JsonAdapter(WxCpConclusionAdapter.class)
public static class Conclusion {
private String textContent;
private String imgMediaId;
private String imgPicUrl;
private String linkTitle;
private String linkPicUrl;
private String linkDesc;
private String linkUrl;
private String miniProgramTitle;
private String miniProgramPicMediaId;
private String miniProgramAppId;
private String miniProgramPage;
}

public enum TYPE {
/**
* 单人
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
*
* @author element
*/
public class WxCpConclusionAdapter implements JsonSerializer<WxCpContactWayInfo.Conclusion>, JsonDeserializer<WxCpContactWayInfo.Conclusion> {
public class WxCpConclusionAdapter implements JsonSerializer<WxCpContactWayInfo.ContactWay.Conclusion>, JsonDeserializer<WxCpContactWayInfo.ContactWay.Conclusion> {
@Override
public WxCpContactWayInfo.Conclusion deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
public WxCpContactWayInfo.ContactWay.Conclusion deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();

WxCpContactWayInfo.Conclusion conclusion = new WxCpContactWayInfo.Conclusion();
WxCpContactWayInfo.ContactWay.Conclusion conclusion = new WxCpContactWayInfo.ContactWay.Conclusion();

if (jsonObject.get("text") != null) {
JsonObject jsonText = jsonObject.get("text").getAsJsonObject();
Expand Down Expand Up @@ -77,7 +77,7 @@ public WxCpContactWayInfo.Conclusion deserialize(JsonElement json, Type typeOfT,
}

@Override
public JsonElement serialize(WxCpContactWayInfo.Conclusion src, Type typeOfSrc, JsonSerializationContext context) {
public JsonElement serialize(WxCpContactWayInfo.ContactWay.Conclusion src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject();
if (StringUtils.isNotBlank(src.getTextContent())) {
JsonObject jsonText = new JsonObject();
Expand Down
Loading