@@ -1,4 +1,4 @@ | |||
package me.chanjar.weixin.enterprise.util.xml; | |||
package me.chanjar.weixin.common; | |||
import javax.xml.bind.annotation.adapters.XmlAdapter; | |||
@@ -1,4 +1,4 @@ | |||
package me.chanjar.weixin.enterprise.util.fs; | |||
package me.chanjar.weixin.common; | |||
import java.io.File; | |||
import java.io.FileOutputStream; |
@@ -6,7 +6,7 @@ | |||
* arose from modification of the original source, or other redistribution of this source | |||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. | |||
*/ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
package me.chanjar.weixin.common; | |||
import com.google.gson.JsonElement; |
@@ -1,4 +1,4 @@ | |||
package me.chanjar.weixin.enterprise.util.xml; | |||
package me.chanjar.weixin.common; | |||
import javax.xml.bind.annotation.adapters.XmlAdapter; | |||
@@ -1,4 +1,4 @@ | |||
package me.chanjar.weixin.enterprise.util.xml; | |||
package me.chanjar.weixin.common; | |||
import java.io.IOException; | |||
import java.io.InputStream; |
@@ -17,7 +17,7 @@ public class WxConsts { | |||
public static final String XML_MSG_LOCATION = "location"; | |||
public static final String XML_MSG_LINK = "link"; | |||
public static final String XML_MSG_EVENT = "event"; | |||
/////////////////////// | |||
// 客服消息的消息类型 | |||
/////////////////////// | |||
@@ -6,7 +6,7 @@ import java.io.InputStream; | |||
import java.util.List; | |||
import me.chanjar.weixin.enterprise.bean.*; | |||
import me.chanjar.weixin.enterprise.bean.WxCpDepartment; | |||
import me.chanjar.weixin.enterprise.bean.WxCpDepart; | |||
import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult; | |||
import me.chanjar.weixin.enterprise.bean.result.WxUser; | |||
import me.chanjar.weixin.enterprise.exception.WxErrorException; | |||
@@ -131,7 +131,7 @@ public interface WxCpService { | |||
* @param name 分组名字(30个字符以内) | |||
* @throws WxErrorException | |||
*/ | |||
public WxCpDepartment departmentCreate(String name) throws WxErrorException; | |||
public WxCpDepart departmentCreate(String name) throws WxErrorException; | |||
/** | |||
* <pre> | |||
@@ -141,7 +141,7 @@ public interface WxCpService { | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
public List<WxCpDepartment> departmentGet() throws WxErrorException; | |||
public List<WxCpDepart> departmentGet() throws WxErrorException; | |||
/** | |||
* <pre> | |||
@@ -153,7 +153,7 @@ public interface WxCpService { | |||
* @param group 要更新的group,group的id,name必须设置 | |||
* @throws WxErrorException | |||
*/ | |||
public void departmentUpdate(WxCpDepartment group) throws WxErrorException; | |||
public void departmentUpdate(WxCpDepart group) throws WxErrorException; | |||
/** | |||
* <pre> | |||
@@ -163,7 +163,7 @@ public interface WxCpService { | |||
* @param department | |||
* @throws WxErrorException | |||
*/ | |||
public void departmentDelete(WxCpDepartment department) throws WxErrorException; | |||
public void departmentDelete(WxCpDepart department) throws WxErrorException; | |||
public void userCreate(WxUser user) throws WxErrorException; | |||
@@ -11,6 +11,7 @@ import java.util.concurrent.atomic.AtomicBoolean; | |||
import me.chanjar.weixin.enterprise.bean.*; | |||
import me.chanjar.weixin.enterprise.util.http.SimpleGetRequestExecutor; | |||
import me.chanjar.weixin.enterprise.util.crypto.SHA1; | |||
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.apache.http.client.ClientProtocolException; | |||
import org.apache.http.client.methods.CloseableHttpResponse; | |||
@@ -19,17 +20,16 @@ import org.apache.http.impl.client.BasicResponseHandler; | |||
import org.apache.http.impl.client.CloseableHttpClient; | |||
import org.apache.http.impl.client.HttpClients; | |||
import me.chanjar.weixin.enterprise.bean.WxCpDepartment; | |||
import me.chanjar.weixin.enterprise.bean.WxCpDepart; | |||
import me.chanjar.weixin.enterprise.bean.result.WxError; | |||
import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult; | |||
import me.chanjar.weixin.enterprise.bean.result.WxUser; | |||
import me.chanjar.weixin.enterprise.exception.WxErrorException; | |||
import me.chanjar.weixin.enterprise.util.fs.FileUtils; | |||
import me.chanjar.weixin.common.FileUtils; | |||
import me.chanjar.weixin.enterprise.util.http.MediaDownloadRequestExecutor; | |||
import me.chanjar.weixin.enterprise.util.http.MediaUploadRequestExecutor; | |||
import me.chanjar.weixin.enterprise.util.http.RequestExecutor; | |||
import me.chanjar.weixin.enterprise.util.http.SimplePostRequestExecutor; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
@@ -142,7 +142,7 @@ public class WxCpServiceImpl implements WxCpService { | |||
} | |||
public WxCpDepartment departmentCreate(String name) throws WxErrorException { | |||
public WxCpDepart departmentCreate(String name) throws WxErrorException { | |||
// TODO | |||
String url = "https://api.weixin.qq.com/cgi-bin/groups/create"; | |||
JsonObject json = new JsonObject(); | |||
@@ -154,16 +154,16 @@ public class WxCpServiceImpl implements WxCpService { | |||
new SimplePostRequestExecutor(), | |||
url, | |||
json.toString()); | |||
return WxCpDepartment.fromJson(responseContent); | |||
return WxCpDepart.fromJson(responseContent); | |||
} | |||
public void departmentUpdate(WxCpDepartment group) throws WxErrorException { | |||
public void departmentUpdate(WxCpDepart group) throws WxErrorException { | |||
// TODO | |||
String url = "https://api.weixin.qq.com/cgi-bin/groups/update"; | |||
execute(new SimplePostRequestExecutor(), url, group.toJson()); | |||
} | |||
public List<WxCpDepartment> departmentGet() throws WxErrorException { | |||
public List<WxCpDepart> departmentGet() throws WxErrorException { | |||
// TODO | |||
String url = "https://api.weixin.qq.com/cgi-bin/groups/get"; | |||
String responseContent = execute(new SimpleGetRequestExecutor(), url, null); | |||
@@ -172,12 +172,12 @@ public class WxCpServiceImpl implements WxCpService { | |||
* 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] } | |||
*/ | |||
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); | |||
return WxGsonBuilder.INSTANCE.create() | |||
.fromJson(tmpJsonElement.getAsJsonObject().get("groups"), new TypeToken<List<WxCpDepartment>>() { | |||
return WxCpGsonBuilder.INSTANCE.create() | |||
.fromJson(tmpJsonElement.getAsJsonObject().get("groups"), new TypeToken<List<WxCpDepart>>() { | |||
}.getType()); | |||
} | |||
public void departmentDelete(WxCpDepartment department) throws WxErrorException { | |||
public void departmentDelete(WxCpDepart department) throws WxErrorException { | |||
// TODO | |||
} | |||
@@ -1,6 +1,6 @@ | |||
package me.chanjar.weixin.enterprise.bean; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; | |||
public class WxAccessToken { | |||
@@ -25,7 +25,7 @@ public class WxAccessToken { | |||
} | |||
public static WxAccessToken fromJson(String json) { | |||
return WxGsonBuilder.create().fromJson(json, WxAccessToken.class); | |||
return WxCpGsonBuilder.create().fromJson(json, WxAccessToken.class); | |||
} | |||
} |
@@ -1,13 +1,13 @@ | |||
package me.chanjar.weixin.enterprise.bean; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; | |||
/** | |||
* 微信用户分组 | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxCpDepartment { | |||
public class WxCpDepart { | |||
private long id = -1; | |||
private String name; | |||
@@ -31,12 +31,12 @@ public class WxCpDepartment { | |||
this.count = count; | |||
} | |||
public static WxCpDepartment fromJson(String json) { | |||
return WxGsonBuilder.create().fromJson(json, WxCpDepartment.class); | |||
public static WxCpDepart fromJson(String json) { | |||
return WxCpGsonBuilder.create().fromJson(json, WxCpDepart.class); | |||
} | |||
public String toJson() { | |||
return WxGsonBuilder.create().toJson(this); | |||
return WxCpGsonBuilder.create().toJson(this); | |||
} | |||
@Override | |||
public String toString() { |
@@ -5,7 +5,7 @@ import java.util.List; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.bean.messagebuilder.*; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; | |||
/** | |||
* 客服消息 | |||
@@ -128,7 +128,7 @@ public class WxCpMessage { | |||
} | |||
public String toJson() { | |||
return WxGsonBuilder.INSTANCE.create().toJson(this); | |||
return WxCpGsonBuilder.INSTANCE.create().toJson(this); | |||
} | |||
public static class WxArticle { | |||
@@ -2,8 +2,8 @@ package me.chanjar.weixin.enterprise.bean; | |||
import me.chanjar.weixin.enterprise.api.WxCpConfigStorage; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.util.xml.AdapterCDATA; | |||
import me.chanjar.weixin.enterprise.util.xml.XmlTransformer; | |||
import me.chanjar.weixin.common.AdapterCDATA; | |||
import me.chanjar.weixin.common.XmlTransformer; | |||
import me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil; | |||
import org.apache.commons.io.IOUtils; | |||
@@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement; | |||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.util.xml.MediaIdMarshaller; | |||
import me.chanjar.weixin.common.MediaIdMarshaller; | |||
@XmlRootElement(name = "xml") | |||
@XmlAccessorType(XmlAccessType.FIELD) | |||
@@ -15,8 +15,8 @@ import me.chanjar.weixin.enterprise.bean.outxmlbuilder.TextBuilder; | |||
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.VideoBuilder; | |||
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.VoiceBuilder; | |||
import me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil; | |||
import me.chanjar.weixin.enterprise.util.xml.AdapterCDATA; | |||
import me.chanjar.weixin.enterprise.util.xml.XmlTransformer; | |||
import me.chanjar.weixin.common.AdapterCDATA; | |||
import me.chanjar.weixin.common.XmlTransformer; | |||
@XmlRootElement(name = "xml") | |||
@XmlAccessorType(XmlAccessType.FIELD) | |||
@@ -11,7 +11,7 @@ import javax.xml.bind.annotation.XmlRootElement; | |||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.util.xml.AdapterCDATA; | |||
import me.chanjar.weixin.common.AdapterCDATA; | |||
@XmlRootElement(name = "xml") | |||
@XmlAccessorType(XmlAccessType.FIELD) | |||
@@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement; | |||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.util.xml.AdapterCDATA; | |||
import me.chanjar.weixin.common.AdapterCDATA; | |||
@XmlRootElement(name = "xml") | |||
@XmlAccessorType(XmlAccessType.FIELD) | |||
@@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement; | |||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.util.xml.AdapterCDATA; | |||
import me.chanjar.weixin.common.AdapterCDATA; | |||
@XmlRootElement(name = "xml") | |||
@XmlAccessorType(XmlAccessType.FIELD) | |||
@@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement; | |||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.util.xml.AdapterCDATA; | |||
import me.chanjar.weixin.common.AdapterCDATA; | |||
@XmlRootElement(name = "xml") | |||
@XmlAccessorType(XmlAccessType.FIELD) | |||
@@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement; | |||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.util.xml.MediaIdMarshaller; | |||
import me.chanjar.weixin.common.MediaIdMarshaller; | |||
@XmlRootElement(name = "xml") | |||
@XmlAccessorType(XmlAccessType.FIELD) | |||
@@ -1,70 +0,0 @@ | |||
package me.chanjar.weixin.enterprise.bean; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
/** | |||
* 分组群发的消息 | |||
* | |||
* @author Daniel Qian | |||
*/ | |||
public class WxMassGroupMessage { | |||
private long groupId; | |||
private String msgtype; | |||
private String content; | |||
private String mediaId; | |||
public WxMassGroupMessage() { | |||
super(); | |||
} | |||
public String getMsgtype() { | |||
return msgtype; | |||
} | |||
/** | |||
* <pre> | |||
* 请使用 | |||
* {@link WxConsts#MASS_MSG_IMAGE} | |||
* {@link WxConsts#MASS_MSG_NEWS} | |||
* {@link WxConsts#MASS_MSG_TEXT} | |||
* {@link WxConsts#MASS_MSG_VIDEO} | |||
* {@link WxConsts#MASS_MSG_VOICE} | |||
* 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误 | |||
* </pre> | |||
* @param msgtype | |||
*/ | |||
public void setMsgtype(String msgtype) { | |||
this.msgtype = msgtype; | |||
} | |||
public String getContent() { | |||
return content; | |||
} | |||
public void setContent(String content) { | |||
this.content = content; | |||
} | |||
public String getMediaId() { | |||
return mediaId; | |||
} | |||
public void setMediaId(String mediaId) { | |||
this.mediaId = mediaId; | |||
} | |||
public String toJson() { | |||
return WxGsonBuilder.INSTANCE.create().toJson(this); | |||
} | |||
public long getGroupId() { | |||
return groupId; | |||
} | |||
public void setGroupId(long groupId) { | |||
this.groupId = groupId; | |||
} | |||
} |
@@ -1,117 +0,0 @@ | |||
package me.chanjar.weixin.enterprise.bean; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
/** | |||
* 群发时用到的图文消息素材 | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMassNews { | |||
private List<WxMassNewsArticle> articles = new ArrayList<WxMassNewsArticle>(); | |||
public List<WxMassNewsArticle> getArticles() { | |||
return articles; | |||
} | |||
public void addArticle(WxMassNewsArticle article) { | |||
this.articles.add(article); | |||
} | |||
public String toJson() { | |||
return WxGsonBuilder.INSTANCE.create().toJson(this); | |||
} | |||
/** | |||
* <pre> | |||
* 群发图文消息article | |||
* 1. thumbMediaId (必填) 图文消息缩略图的media_id,可以在基础支持-上传多媒体文件接口中获得 | |||
* 2. author 图文消息的作者 | |||
* 3. title (必填) 图文消息的标题 | |||
* 4. contentSourceUrl 在图文消息页面点击“阅读原文”后的页面链接 | |||
* 5. content (必填) 图文消息页面的内容,支持HTML标签 | |||
* 6. digest 图文消息的描述 | |||
* 7, showCoverPic 是否显示封面,true为显示,false为不显示 | |||
* </pre> | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public static class WxMassNewsArticle { | |||
/** | |||
* (必填) 图文消息缩略图的media_id,可以在基础支持-上传多媒体文件接口中获得 | |||
*/ | |||
private String thumbMediaId; | |||
/** | |||
* 图文消息的作者 | |||
*/ | |||
private String author; | |||
/** | |||
* (必填) 图文消息的标题 | |||
*/ | |||
private String title; | |||
/** | |||
* 在图文消息页面点击“阅读原文”后的页面链接 | |||
*/ | |||
private String contentSourceUrl; | |||
/** | |||
* (必填) 图文消息页面的内容,支持HTML标签 | |||
*/ | |||
private String content; | |||
/** | |||
* 图文消息的描述 | |||
*/ | |||
private String digest; | |||
/** | |||
* 是否显示封面,true为显示,false为不显示 | |||
*/ | |||
private boolean showCoverPic; | |||
public String getThumbMediaId() { | |||
return thumbMediaId; | |||
} | |||
public void setThumbMediaId(String thumbMediaId) { | |||
this.thumbMediaId = thumbMediaId; | |||
} | |||
public String getAuthor() { | |||
return author; | |||
} | |||
public void setAuthor(String author) { | |||
this.author = author; | |||
} | |||
public String getTitle() { | |||
return title; | |||
} | |||
public void setTitle(String title) { | |||
this.title = title; | |||
} | |||
public String getContentSourceUrl() { | |||
return contentSourceUrl; | |||
} | |||
public void setContentSourceUrl(String contentSourceUrl) { | |||
this.contentSourceUrl = contentSourceUrl; | |||
} | |||
public String getContent() { | |||
return content; | |||
} | |||
public void setContent(String content) { | |||
this.content = content; | |||
} | |||
public String getDigest() { | |||
return digest; | |||
} | |||
public void setDigest(String digest) { | |||
this.digest = digest; | |||
} | |||
public boolean isShowCoverPic() { | |||
return showCoverPic; | |||
} | |||
public void setShowCoverPic(boolean showCoverPic) { | |||
this.showCoverPic = showCoverPic; | |||
} | |||
} | |||
} |
@@ -1,79 +0,0 @@ | |||
package me.chanjar.weixin.enterprise.bean; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
/** | |||
* OpenId列表群发的消息 | |||
* | |||
* @author Daniel Qian | |||
*/ | |||
public class WxMassOpenIdsMessage { | |||
private List<String> toUsers = new ArrayList<String>(); | |||
private String msgType; | |||
private String content; | |||
private String mediaId; | |||
public WxMassOpenIdsMessage() { | |||
super(); | |||
} | |||
public String getMsgType() { | |||
return msgType; | |||
} | |||
/** | |||
* <pre> | |||
* 请使用 | |||
* {@link me.chanjar.weixin.enterprise.api.WxConsts#MASS_MSG_IMAGE} | |||
* {@link me.chanjar.weixin.enterprise.api.WxConsts#MASS_MSG_NEWS} | |||
* {@link me.chanjar.weixin.enterprise.api.WxConsts#MASS_MSG_TEXT} | |||
* {@link me.chanjar.weixin.enterprise.api.WxConsts#MASS_MSG_VIDEO} | |||
* {@link me.chanjar.weixin.enterprise.api.WxConsts#MASS_MSG_VOICE} | |||
* 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误 | |||
* </pre> | |||
* @param msgType | |||
*/ | |||
public void setMsgType(String msgType) { | |||
this.msgType = msgType; | |||
} | |||
public String getContent() { | |||
return content; | |||
} | |||
public void setContent(String content) { | |||
this.content = content; | |||
} | |||
public String getMediaId() { | |||
return mediaId; | |||
} | |||
public void setMediaId(String mediaId) { | |||
this.mediaId = mediaId; | |||
} | |||
public String toJson() { | |||
return WxGsonBuilder.INSTANCE.create().toJson(this); | |||
} | |||
/** | |||
* OpenId列表,最多支持10,000个 | |||
* @return | |||
*/ | |||
public List<String> getToUsers() { | |||
return toUsers; | |||
} | |||
/** | |||
* 添加OpenId,最多支持10,000个 | |||
* @param openId | |||
*/ | |||
public void addUser(String openId) { | |||
this.toUsers.add(openId); | |||
} | |||
} |
@@ -1,43 +0,0 @@ | |||
package me.chanjar.weixin.enterprise.bean; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
/** | |||
* 群发时用到的视频素材 | |||
* | |||
* @author Daniel Qian | |||
*/ | |||
public class WxMassVideo { | |||
private String mediaId; | |||
private String title; | |||
private String description; | |||
public String getTitle() { | |||
return title; | |||
} | |||
public void setTitle(String title) { | |||
this.title = title; | |||
} | |||
public String getDescription() { | |||
return description; | |||
} | |||
public void setDescription(String description) { | |||
this.description = description; | |||
} | |||
public String getMediaId() { | |||
return mediaId; | |||
} | |||
public void setMediaId(String mediaId) { | |||
this.mediaId = mediaId; | |||
} | |||
public String toJson() { | |||
return WxGsonBuilder.INSTANCE.create().toJson(this); | |||
} | |||
} |
@@ -5,7 +5,7 @@ import java.io.InputStreamReader; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; | |||
/** | |||
* 公众号菜单 | |||
@@ -25,15 +25,15 @@ public class WxMenu { | |||
} | |||
public String toJson() { | |||
return WxGsonBuilder.create().toJson(this); | |||
return WxCpGsonBuilder.create().toJson(this); | |||
} | |||
public static WxMenu fromJson(String json) { | |||
return WxGsonBuilder.create().fromJson(json, WxMenu.class); | |||
return WxCpGsonBuilder.create().fromJson(json, WxMenu.class); | |||
} | |||
public static WxMenu fromJson(InputStream is) { | |||
return WxGsonBuilder.create().fromJson(new InputStreamReader(is), WxMenu.class); | |||
return WxCpGsonBuilder.create().fromJson(new InputStreamReader(is), WxMenu.class); | |||
} | |||
public static class WxMenuButton { | |||
@@ -3,7 +3,7 @@ package me.chanjar.weixin.enterprise.bean.result; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; | |||
/** | |||
* 微信错误码说明 | |||
@@ -125,7 +125,7 @@ public class WxError { | |||
} | |||
public static WxError fromJson(String json) { | |||
return WxGsonBuilder.create().fromJson(json, WxError.class); | |||
return WxCpGsonBuilder.create().fromJson(json, WxError.class); | |||
} | |||
@Override | |||
@@ -1,6 +1,6 @@ | |||
package me.chanjar.weixin.enterprise.bean.result; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; | |||
/** | |||
* <pre> | |||
@@ -44,7 +44,7 @@ public class WxMassSendResult { | |||
} | |||
public static WxMassSendResult fromJson(String json) { | |||
return WxGsonBuilder.create().fromJson(json, WxMassSendResult.class); | |||
return WxCpGsonBuilder.create().fromJson(json, WxMassSendResult.class); | |||
} | |||
@Override | |||
@@ -1,6 +1,6 @@ | |||
package me.chanjar.weixin.enterprise.bean.result; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; | |||
/** | |||
* <pre> | |||
@@ -41,7 +41,7 @@ public class WxMassUploadResult { | |||
} | |||
public static WxMassUploadResult fromJson(String json) { | |||
return WxGsonBuilder.create().fromJson(json, WxMassUploadResult.class); | |||
return WxCpGsonBuilder.create().fromJson(json, WxMassUploadResult.class); | |||
} | |||
@Override | |||
@@ -1,6 +1,6 @@ | |||
package me.chanjar.weixin.enterprise.bean.result; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; | |||
public class WxMediaUploadResult { | |||
@@ -34,7 +34,7 @@ public class WxMediaUploadResult { | |||
} | |||
public static WxMediaUploadResult fromJson(String json) { | |||
return WxGsonBuilder.create().fromJson(json, WxMediaUploadResult.class); | |||
return WxCpGsonBuilder.create().fromJson(json, WxMediaUploadResult.class); | |||
} | |||
public String getThumbMediaId() { | |||
@@ -1,46 +0,0 @@ | |||
package me.chanjar.weixin.enterprise.bean.result; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
/** | |||
* 换取二维码的Ticket | |||
* | |||
* @author Daniel Qian | |||
*/ | |||
public class WxQrCodeTicket { | |||
protected String ticket; | |||
protected int expire_seconds = -1; | |||
protected String url; | |||
public String getTicket() { | |||
return ticket; | |||
} | |||
public void setTicket(String ticket) { | |||
this.ticket = ticket; | |||
} | |||
/** | |||
* 如果返回-1说明是永久 | |||
*/ | |||
public int getExpire_seconds() { | |||
return expire_seconds; | |||
} | |||
public void setExpire_seconds(int expire_seconds) { | |||
this.expire_seconds = expire_seconds; | |||
} | |||
public String getUrl() { | |||
return url; | |||
} | |||
public void setUrl(String url) { | |||
this.url = url; | |||
} | |||
public static WxQrCodeTicket fromJson(String json) { | |||
return WxGsonBuilder.INSTANCE.create().fromJson(json, WxQrCodeTicket.class); | |||
} | |||
} |
@@ -1,6 +1,6 @@ | |||
package me.chanjar.weixin.enterprise.bean.result; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; | |||
/** | |||
* 微信用户信息 | |||
@@ -89,7 +89,7 @@ public class WxUser { | |||
} | |||
public static WxUser fromJson(String json) { | |||
return WxGsonBuilder.INSTANCE.create().fromJson(json, WxUser.class); | |||
return WxCpGsonBuilder.INSTANCE.create().fromJson(json, WxUser.class); | |||
} | |||
} |
@@ -3,7 +3,7 @@ package me.chanjar.weixin.enterprise.bean.result; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; | |||
/** | |||
* 关注者列表 | |||
@@ -42,6 +42,6 @@ public class WxUserList { | |||
} | |||
public static WxUserList fromJson(String json) { | |||
return WxGsonBuilder.INSTANCE.create().fromJson(json, WxUserList.class); | |||
return WxCpGsonBuilder.INSTANCE.create().fromJson(json, WxUserList.class); | |||
} | |||
} |
@@ -15,7 +15,7 @@ import org.apache.http.entity.ContentType; | |||
import me.chanjar.weixin.enterprise.bean.result.WxError; | |||
import me.chanjar.weixin.enterprise.exception.WxErrorException; | |||
import me.chanjar.weixin.enterprise.util.fs.FileUtils; | |||
import me.chanjar.weixin.common.FileUtils; | |||
/** | |||
* 下载媒体文件请求执行器,请求的参数是String, 返回的结果是File | |||
@@ -1,56 +0,0 @@ | |||
package me.chanjar.weixin.enterprise.util.http; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.net.URLEncoder; | |||
import java.util.UUID; | |||
import me.chanjar.weixin.enterprise.bean.result.WxQrCodeTicket; | |||
import me.chanjar.weixin.enterprise.exception.WxErrorException; | |||
import me.chanjar.weixin.enterprise.util.fs.FileUtils; | |||
import org.apache.http.Header; | |||
import org.apache.http.client.ClientProtocolException; | |||
import org.apache.http.client.methods.CloseableHttpResponse; | |||
import org.apache.http.client.methods.HttpGet; | |||
import org.apache.http.entity.ContentType; | |||
import me.chanjar.weixin.enterprise.bean.result.WxError; | |||
/** | |||
* 获得QrCode图片 请求执行器 | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class QrCodeRequestExecutor implements RequestExecutor<File, WxQrCodeTicket> { | |||
@Override | |||
public File execute(String uri, WxQrCodeTicket ticket) throws WxErrorException, ClientProtocolException, IOException { | |||
if (ticket != null) { | |||
if (uri.indexOf('?') == -1) { | |||
uri += '?'; | |||
} | |||
uri += uri.endsWith("?") ? | |||
"ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8") | |||
: | |||
"&ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8"); | |||
} | |||
HttpGet httpGet = new HttpGet(uri); | |||
CloseableHttpResponse response = httpclient.execute(httpGet); | |||
Header[] contentTypeHeader = response.getHeaders("Content-Type"); | |||
if (contentTypeHeader != null && contentTypeHeader.length > 0) { | |||
// 出错 | |||
if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) { | |||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); | |||
throw new WxErrorException(WxError.fromJson(responseContent)); | |||
} | |||
} | |||
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response); | |||
File localFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg"); | |||
return localFile; | |||
} | |||
} |
@@ -9,6 +9,7 @@ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.common.GsonHelper; | |||
import me.chanjar.weixin.enterprise.bean.WxAccessToken; | |||
import java.lang.reflect.Type; | |||
@@ -18,7 +19,7 @@ import java.lang.reflect.Type; | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxAccessTokenAdapter implements JsonDeserializer<WxAccessToken> { | |||
public class WxCpAccessTokenAdapter implements JsonDeserializer<WxAccessToken> { | |||
public WxAccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |||
WxAccessToken accessToken = new WxAccessToken(); |
@@ -10,7 +10,8 @@ package me.chanjar.weixin.enterprise.util.json; | |||
import java.lang.reflect.Type; | |||
import me.chanjar.weixin.enterprise.bean.WxCpDepartment; | |||
import me.chanjar.weixin.common.GsonHelper; | |||
import me.chanjar.weixin.enterprise.bean.WxCpDepart; | |||
import com.google.gson.JsonDeserializationContext; | |||
import com.google.gson.JsonDeserializer; | |||
@@ -25,9 +26,9 @@ import com.google.gson.JsonSerializer; | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxGroupGsonAdapter implements JsonSerializer<WxCpDepartment>, JsonDeserializer<WxCpDepartment> { | |||
public class WxCpDepartGsonAdapter implements JsonSerializer<WxCpDepart>, JsonDeserializer<WxCpDepart> { | |||
public JsonElement serialize(WxCpDepartment group, Type typeOfSrc, JsonSerializationContext context) { | |||
public JsonElement serialize(WxCpDepart group, Type typeOfSrc, JsonSerializationContext context) { | |||
JsonObject json = new JsonObject(); | |||
JsonObject groupJson = new JsonObject(); | |||
groupJson.addProperty("name", group.getName()); | |||
@@ -37,8 +38,8 @@ public class WxGroupGsonAdapter implements JsonSerializer<WxCpDepartment>, JsonD | |||
return json; | |||
} | |||
public WxCpDepartment deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |||
WxCpDepartment group = new WxCpDepartment(); | |||
public WxCpDepart deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |||
WxCpDepart group = new WxCpDepart(); | |||
JsonObject groupJson = json.getAsJsonObject(); | |||
if (json.getAsJsonObject().get("group") != null) { | |||
groupJson = json.getAsJsonObject().get("group").getAsJsonObject(); |
@@ -0,0 +1,29 @@ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
import com.google.gson.Gson; | |||
import com.google.gson.GsonBuilder; | |||
import me.chanjar.weixin.enterprise.bean.*; | |||
import me.chanjar.weixin.enterprise.bean.result.*; | |||
public class WxCpGsonBuilder { | |||
public static final GsonBuilder INSTANCE = new GsonBuilder(); | |||
static { | |||
INSTANCE.disableHtmlEscaping(); | |||
INSTANCE.registerTypeAdapter(WxCpMessage.class, new WxCpMessageGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMenu.class, new WxCpMenuGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxCpDepart.class, new WxCpDepartGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxUser.class, new WxCpUserGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxUserList.class, new WxCpUserListGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxAccessToken.class, new WxCpAccessTokenAdapter()); | |||
INSTANCE.registerTypeAdapter(WxError.class, new WxErrorAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMediaUploadResult.class, new WxCpMediaUploadResultAdapter()); | |||
} | |||
public static Gson create() { | |||
return INSTANCE.create(); | |||
} | |||
} |
@@ -9,6 +9,7 @@ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.common.GsonHelper; | |||
import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult; | |||
import java.lang.reflect.Type; | |||
@@ -18,7 +19,7 @@ import java.lang.reflect.Type; | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMediaUploadResultAdapter implements JsonDeserializer<WxMediaUploadResult> { | |||
public class WxCpMediaUploadResultAdapter implements JsonDeserializer<WxMediaUploadResult> { | |||
public WxMediaUploadResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |||
WxMediaUploadResult uploadResult = new WxMediaUploadResult(); |
@@ -10,6 +10,7 @@ package me.chanjar.weixin.enterprise.util.json; | |||
import java.lang.reflect.Type; | |||
import me.chanjar.weixin.common.GsonHelper; | |||
import me.chanjar.weixin.enterprise.bean.WxMenu; | |||
import com.google.gson.JsonArray; | |||
@@ -26,7 +27,7 @@ import com.google.gson.JsonSerializer; | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializer<WxMenu> { | |||
public class WxCpMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializer<WxMenu> { | |||
public JsonElement serialize(WxMenu menu, Type typeOfSrc, JsonSerializationContext context) { | |||
JsonObject json = new JsonObject(); |
@@ -10,6 +10,7 @@ package me.chanjar.weixin.enterprise.util.json; | |||
import java.lang.reflect.Type; | |||
import me.chanjar.weixin.common.GsonHelper; | |||
import me.chanjar.weixin.enterprise.bean.result.WxUser; | |||
import com.google.gson.JsonDeserializationContext; | |||
@@ -23,7 +24,7 @@ import com.google.gson.JsonParseException; | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxUserGsonAdapter implements JsonDeserializer<WxUser> { | |||
public class WxCpUserGsonAdapter implements JsonDeserializer<WxUser> { | |||
public WxUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |||
JsonObject o = json.getAsJsonObject(); |
@@ -10,6 +10,7 @@ package me.chanjar.weixin.enterprise.util.json; | |||
import java.lang.reflect.Type; | |||
import me.chanjar.weixin.common.GsonHelper; | |||
import me.chanjar.weixin.enterprise.bean.result.WxUserList; | |||
import com.google.gson.JsonArray; | |||
@@ -24,7 +25,7 @@ import com.google.gson.JsonParseException; | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxUserListGsonAdapter implements JsonDeserializer<WxUserList> { | |||
public class WxCpUserListGsonAdapter implements JsonDeserializer<WxUserList> { | |||
public WxUserList deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |||
JsonObject o = json.getAsJsonObject(); |
@@ -9,6 +9,7 @@ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.common.GsonHelper; | |||
import me.chanjar.weixin.enterprise.bean.result.WxError; | |||
import java.lang.reflect.Type; | |||
@@ -1,36 +0,0 @@ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
import com.google.gson.Gson; | |||
import com.google.gson.GsonBuilder; | |||
import me.chanjar.weixin.enterprise.bean.*; | |||
import me.chanjar.weixin.enterprise.bean.result.*; | |||
public class WxGsonBuilder { | |||
public static final GsonBuilder INSTANCE = new GsonBuilder(); | |||
static { | |||
INSTANCE.disableHtmlEscaping(); | |||
INSTANCE.registerTypeAdapter(WxCpMessage.class, new WxCpMessageGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMenu.class, new WxMenuGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMassNews.class, new WxMassNewsGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMassGroupMessage.class, new WxMassMessageGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMassOpenIdsMessage.class, new WxMassOpenIdsMessageGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxCpDepartment.class, new WxGroupGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxUser.class, new WxUserGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxUserList.class, new WxUserListGsonAdapter()); | |||
INSTANCE.registerTypeAdapter(WxAccessToken.class, new WxAccessTokenAdapter()); | |||
INSTANCE.registerTypeAdapter(WxError.class, new WxErrorAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMassVideo.class, new WxMassVideoAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMediaUploadResult.class, new WxMediaUploadResultAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMassSendResult.class, new WxMassSendResultAdapter()); | |||
INSTANCE.registerTypeAdapter(WxMassUploadResult.class, new WxMassUploadResultAdapter()); | |||
INSTANCE.registerTypeAdapter(WxQrCodeTicket.class, new WxQrCodeTicketAdapter()); | |||
} | |||
public static Gson create() { | |||
return INSTANCE.create(); | |||
} | |||
} |
@@ -1,64 +0,0 @@ | |||
/* | |||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved. | |||
* | |||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended | |||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction | |||
* arose from modification of the original source, or other redistribution of this source | |||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. | |||
*/ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
import java.lang.reflect.Type; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.bean.WxMassGroupMessage; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonSerializationContext; | |||
import com.google.gson.JsonSerializer; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMassMessageGsonAdapter implements JsonSerializer<WxMassGroupMessage> { | |||
public JsonElement serialize(WxMassGroupMessage message, Type typeOfSrc, JsonSerializationContext context) { | |||
JsonObject messageJson = new JsonObject(); | |||
JsonObject filter = new JsonObject(); | |||
filter.addProperty("group_id", message.getGroupId()); | |||
messageJson.add("filter", filter); | |||
if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgtype())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
messageJson.add(WxConsts.MASS_MSG_NEWS, sub); | |||
} | |||
if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgtype())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("content", message.getContent()); | |||
messageJson.add(WxConsts.MASS_MSG_TEXT, sub); | |||
} | |||
if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgtype())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
messageJson.add(WxConsts.MASS_MSG_VOICE, sub); | |||
} | |||
if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgtype())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
messageJson.add(WxConsts.MASS_MSG_IMAGE, sub); | |||
} | |||
if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgtype())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
messageJson.add(WxConsts.MASS_MSG_VIDEO, sub); | |||
} | |||
messageJson.addProperty("msgtype", message.getMsgtype()); | |||
return messageJson; | |||
} | |||
} |
@@ -1,55 +0,0 @@ | |||
/* | |||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved. | |||
* | |||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended | |||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction | |||
* arose from modification of the original source, or other redistribution of this source | |||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. | |||
*/ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
import java.lang.reflect.Type; | |||
import me.chanjar.weixin.enterprise.bean.WxMassNews; | |||
import com.google.gson.JsonArray; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonSerializationContext; | |||
import com.google.gson.JsonSerializer; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMassNewsGsonAdapter implements JsonSerializer<WxMassNews> { | |||
public JsonElement serialize(WxMassNews message, Type typeOfSrc, JsonSerializationContext context) { | |||
JsonObject newsJson = new JsonObject(); | |||
JsonArray articleJsonArray = new JsonArray(); | |||
for (WxMassNews.WxMassNewsArticle article : message.getArticles()) { | |||
JsonObject articleJson = new JsonObject(); | |||
articleJson.addProperty("thumb_media_id", article.getThumbMediaId()); | |||
articleJson.addProperty("title", article.getTitle()); | |||
articleJson.addProperty("content", article.getContent()); | |||
if (null != article.getAuthor()) { | |||
articleJson.addProperty("author", article.getAuthor()); | |||
} | |||
if (null != article.getContentSourceUrl()) { | |||
articleJson.addProperty("content_source_url", article.getContentSourceUrl()); | |||
} | |||
if (null != article.getDigest()) { | |||
articleJson.addProperty("digest", article.getDigest()); | |||
} | |||
articleJson.addProperty("show_cover_pic", article.isShowCoverPic() ? "1" : "0"); | |||
articleJsonArray.add(articleJson); | |||
} | |||
newsJson.add("articles", articleJsonArray); | |||
return newsJson; | |||
} | |||
} |
@@ -1,68 +0,0 @@ | |||
/* | |||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved. | |||
* | |||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended | |||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction | |||
* arose from modification of the original source, or other redistribution of this source | |||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. | |||
*/ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
import java.lang.reflect.Type; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.bean.WxMassOpenIdsMessage; | |||
import com.google.gson.JsonArray; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonPrimitive; | |||
import com.google.gson.JsonSerializationContext; | |||
import com.google.gson.JsonSerializer; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMassOpenIdsMessageGsonAdapter implements JsonSerializer<WxMassOpenIdsMessage> { | |||
public JsonElement serialize(WxMassOpenIdsMessage message, Type typeOfSrc, JsonSerializationContext context) { | |||
JsonObject messageJson = new JsonObject(); | |||
JsonArray toUsers = new JsonArray(); | |||
for (String openId : message.getToUsers()) { | |||
toUsers.add(new JsonPrimitive(openId)); | |||
} | |||
messageJson.add("touser", toUsers); | |||
if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgType())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
messageJson.add(WxConsts.MASS_MSG_NEWS, sub); | |||
} | |||
if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgType())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("content", message.getContent()); | |||
messageJson.add(WxConsts.MASS_MSG_TEXT, sub); | |||
} | |||
if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgType())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
messageJson.add(WxConsts.MASS_MSG_VOICE, sub); | |||
} | |||
if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgType())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
messageJson.add(WxConsts.MASS_MSG_IMAGE, sub); | |||
} | |||
if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgType())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
messageJson.add(WxConsts.MASS_MSG_VIDEO, sub); | |||
} | |||
messageJson.addProperty("msgtype", message.getMsgType()); | |||
return messageJson; | |||
} | |||
} |
@@ -1,39 +0,0 @@ | |||
/* | |||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved. | |||
* | |||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended | |||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction | |||
* arose from modification of the original source, or other redistribution of this source | |||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. | |||
*/ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.enterprise.bean.result.WxMassSendResult; | |||
import java.lang.reflect.Type; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMassSendResultAdapter implements JsonDeserializer<WxMassSendResult> { | |||
public WxMassSendResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |||
WxMassSendResult sendResult = new WxMassSendResult(); | |||
JsonObject sendResultJsonObject = json.getAsJsonObject(); | |||
if (sendResultJsonObject.get("errcode") != null && !sendResultJsonObject.get("errcode").isJsonNull()) { | |||
sendResult.setErrorCode(GsonHelper.getAsString(sendResultJsonObject.get("errcode"))); | |||
} | |||
if (sendResultJsonObject.get("errmsg") != null && !sendResultJsonObject.get("errmsg").isJsonNull()) { | |||
sendResult.setErrorMsg(GsonHelper.getAsString(sendResultJsonObject.get("errmsg"))); | |||
} | |||
if (sendResultJsonObject.get("msg_id") != null && !sendResultJsonObject.get("msg_id").isJsonNull()) { | |||
sendResult.setMsgId(GsonHelper.getAsString(sendResultJsonObject.get("msg_id"))); | |||
} | |||
return sendResult; | |||
} | |||
} |
@@ -1,39 +0,0 @@ | |||
/* | |||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved. | |||
* | |||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended | |||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction | |||
* arose from modification of the original source, or other redistribution of this source | |||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. | |||
*/ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.enterprise.bean.result.WxMassUploadResult; | |||
import java.lang.reflect.Type; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMassUploadResultAdapter implements JsonDeserializer<WxMassUploadResult> { | |||
public WxMassUploadResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |||
WxMassUploadResult uploadResult = new WxMassUploadResult(); | |||
JsonObject uploadResultJsonObject = json.getAsJsonObject(); | |||
if (uploadResultJsonObject.get("type") != null && !uploadResultJsonObject.get("type").isJsonNull()) { | |||
uploadResult.setType(GsonHelper.getAsString(uploadResultJsonObject.get("type"))); | |||
} | |||
if (uploadResultJsonObject.get("media_id") != null && !uploadResultJsonObject.get("media_id").isJsonNull()) { | |||
uploadResult.setMediaId(GsonHelper.getAsString(uploadResultJsonObject.get("media_id"))); | |||
} | |||
if (uploadResultJsonObject.get("created_at") != null && !uploadResultJsonObject.get("created_at").isJsonNull()) { | |||
uploadResult.setCreatedAt(GsonHelper.getAsPrimitiveLong(uploadResultJsonObject.get("created_at"))); | |||
} | |||
return uploadResult; | |||
} | |||
} |
@@ -1,31 +0,0 @@ | |||
/* | |||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved. | |||
* | |||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended | |||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction | |||
* arose from modification of the original source, or other redistribution of this source | |||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. | |||
*/ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.enterprise.bean.WxMassVideo; | |||
import java.lang.reflect.Type; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMassVideoAdapter implements JsonSerializer<WxMassVideo> { | |||
public JsonElement serialize(WxMassVideo message, Type typeOfSrc, JsonSerializationContext context) { | |||
JsonObject messageJson = new JsonObject(); | |||
messageJson.addProperty("media_id", message.getMediaId()); | |||
messageJson.addProperty("description", message.getDescription()); | |||
messageJson.addProperty("title", message.getTitle()); | |||
return messageJson; | |||
} | |||
} |
@@ -1,39 +0,0 @@ | |||
/* | |||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved. | |||
* | |||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended | |||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction | |||
* arose from modification of the original source, or other redistribution of this source | |||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. | |||
*/ | |||
package me.chanjar.weixin.enterprise.util.json; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.enterprise.bean.result.WxQrCodeTicket; | |||
import java.lang.reflect.Type; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxQrCodeTicketAdapter implements JsonDeserializer<WxQrCodeTicket> { | |||
public WxQrCodeTicket deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |||
WxQrCodeTicket ticket = new WxQrCodeTicket(); | |||
JsonObject ticketJsonObject = json.getAsJsonObject(); | |||
if (ticketJsonObject.get("ticket") != null && !ticketJsonObject.get("ticket").isJsonNull()) { | |||
ticket.setTicket(GsonHelper.getAsString(ticketJsonObject.get("ticket"))); | |||
} | |||
if (ticketJsonObject.get("expire_seconds") != null && !ticketJsonObject.get("expire_seconds").isJsonNull()) { | |||
ticket.setExpire_seconds(GsonHelper.getAsPrimitiveInt(ticketJsonObject.get("expire_seconds"))); | |||
} | |||
if (ticketJsonObject.get("url") != null && !ticketJsonObject.get("url").isJsonNull()) { | |||
ticket.setUrl(GsonHelper.getAsString(ticketJsonObject.get("url"))); | |||
} | |||
return ticket; | |||
} | |||
} |
@@ -2,7 +2,7 @@ package me.chanjar.weixin.enterprise.api; | |||
import java.util.List; | |||
import me.chanjar.weixin.enterprise.bean.WxCpDepartment; | |||
import me.chanjar.weixin.enterprise.bean.WxCpDepart; | |||
import org.testng.Assert; | |||
import org.testng.annotations.Guice; | |||
import org.testng.annotations.Test; | |||
@@ -23,19 +23,19 @@ public class WxGroupAPITest { | |||
@Inject | |||
protected WxCpServiceImpl wxService; | |||
protected WxCpDepartment group; | |||
protected WxCpDepart group; | |||
public void testGroupCreate() throws WxErrorException { | |||
WxCpDepartment res = wxService.departmentCreate("测试分组1"); | |||
WxCpDepart res = wxService.departmentCreate("测试分组1"); | |||
Assert.assertEquals(res.getName(), "测试分组1"); | |||
} | |||
@Test(dependsOnMethods="testGroupCreate") | |||
public void testGroupGet() throws WxErrorException { | |||
List<WxCpDepartment> groupList = wxService.departmentGet(); | |||
List<WxCpDepart> groupList = wxService.departmentGet(); | |||
Assert.assertNotNull(groupList); | |||
Assert.assertTrue(groupList.size() > 0); | |||
for (WxCpDepartment g : groupList) { | |||
for (WxCpDepart g : groupList) { | |||
group = g; | |||
Assert.assertNotNull(g.getName()); | |||
} | |||