Browse Source

清理企业号api

master
Daniel Qian 10 years ago
parent
commit
471b4a7a51
50 changed files with 108 additions and 854 deletions
  1. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/AdapterCDATA.java
  2. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/FileUtils.java
  3. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/GsonHelper.java
  4. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/MediaIdMarshaller.java
  5. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/XmlTransformer.java
  6. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxConsts.java
  7. +5
    -5
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpService.java
  8. +10
    -10
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpServiceImpl.java
  9. +2
    -2
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxAccessToken.java
  10. +5
    -5
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpDepart.java
  11. +2
    -2
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpMessage.java
  12. +2
    -2
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlMessage.java
  13. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutImageMessage.java
  14. +2
    -2
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMessage.java
  15. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMewsMessage.java
  16. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMusicMessage.java
  17. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutTextMessage.java
  18. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVideoMessage.java
  19. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVoiceMessage.java
  20. +0
    -70
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxMassGroupMessage.java
  21. +0
    -117
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxMassNews.java
  22. +0
    -79
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxMassOpenIdsMessage.java
  23. +0
    -43
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxMassVideo.java
  24. +4
    -4
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxMenu.java
  25. +2
    -2
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxError.java
  26. +2
    -2
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxMassSendResult.java
  27. +2
    -2
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxMassUploadResult.java
  28. +2
    -2
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxMediaUploadResult.java
  29. +0
    -46
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxQrCodeTicket.java
  30. +2
    -2
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxUser.java
  31. +2
    -2
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxUserList.java
  32. +1
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/MediaDownloadRequestExecutor.java
  33. +0
    -56
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/QrCodeRequestExecutor.java
  34. +2
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpAccessTokenAdapter.java
  35. +6
    -5
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpDepartGsonAdapter.java
  36. +29
    -0
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpGsonBuilder.java
  37. +2
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMediaUploadResultAdapter.java
  38. +2
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMenuGsonAdapter.java
  39. +2
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpUserGsonAdapter.java
  40. +2
    -1
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpUserListGsonAdapter.java
  41. +1
    -0
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxErrorAdapter.java
  42. +0
    -36
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxGsonBuilder.java
  43. +0
    -64
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMassMessageGsonAdapter.java
  44. +0
    -55
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMassNewsGsonAdapter.java
  45. +0
    -68
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMassOpenIdsMessageGsonAdapter.java
  46. +0
    -39
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMassSendResultAdapter.java
  47. +0
    -39
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMassUploadResultAdapter.java
  48. +0
    -31
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMassVideoAdapter.java
  49. +0
    -39
      weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxQrCodeTicketAdapter.java
  50. +5
    -5
      weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxGroupAPITest.java

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/xml/AdapterCDATA.java → weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/AdapterCDATA.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.util.xml;
package me.chanjar.weixin.common;


import javax.xml.bind.annotation.adapters.XmlAdapter; import javax.xml.bind.annotation.adapters.XmlAdapter;



weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/fs/FileUtils.java → weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/FileUtils.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.util.fs;
package me.chanjar.weixin.common;


import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/GsonHelper.java → weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/GsonHelper.java View File

@@ -6,7 +6,7 @@
* arose from modification of the original source, or other redistribution of this source * 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. * 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; import com.google.gson.JsonElement;

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/xml/MediaIdMarshaller.java → weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/MediaIdMarshaller.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.util.xml;
package me.chanjar.weixin.common;


import javax.xml.bind.annotation.adapters.XmlAdapter; import javax.xml.bind.annotation.adapters.XmlAdapter;



weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/xml/XmlTransformer.java → weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/XmlTransformer.java View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.enterprise.util.xml;
package me.chanjar.weixin.common;


import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;

+ 1
- 1
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxConsts.java View File

@@ -17,7 +17,7 @@ public class WxConsts {
public static final String XML_MSG_LOCATION = "location"; public static final String XML_MSG_LOCATION = "location";
public static final String XML_MSG_LINK = "link"; public static final String XML_MSG_LINK = "link";
public static final String XML_MSG_EVENT = "event"; public static final String XML_MSG_EVENT = "event";
/////////////////////// ///////////////////////
// 客服消息的消息类型 // 客服消息的消息类型
/////////////////////// ///////////////////////


+ 5
- 5
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpService.java View File

@@ -6,7 +6,7 @@ import java.io.InputStream;
import java.util.List; import java.util.List;


import me.chanjar.weixin.enterprise.bean.*; 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.WxMediaUploadResult;
import me.chanjar.weixin.enterprise.bean.result.WxUser; import me.chanjar.weixin.enterprise.bean.result.WxUser;
import me.chanjar.weixin.enterprise.exception.WxErrorException; import me.chanjar.weixin.enterprise.exception.WxErrorException;
@@ -131,7 +131,7 @@ public interface WxCpService {
* @param name 分组名字(30个字符以内) * @param name 分组名字(30个字符以内)
* @throws WxErrorException * @throws WxErrorException
*/ */
public WxCpDepartment departmentCreate(String name) throws WxErrorException;
public WxCpDepart departmentCreate(String name) throws WxErrorException;
/** /**
* <pre> * <pre>
@@ -141,7 +141,7 @@ public interface WxCpService {
* @return * @return
* @throws WxErrorException * @throws WxErrorException
*/ */
public List<WxCpDepartment> departmentGet() throws WxErrorException;
public List<WxCpDepart> departmentGet() throws WxErrorException;
/** /**
* <pre> * <pre>
@@ -153,7 +153,7 @@ public interface WxCpService {
* @param group 要更新的group,group的id,name必须设置 * @param group 要更新的group,group的id,name必须设置
* @throws WxErrorException * @throws WxErrorException
*/ */
public void departmentUpdate(WxCpDepartment group) throws WxErrorException;
public void departmentUpdate(WxCpDepart group) throws WxErrorException;


/** /**
* <pre> * <pre>
@@ -163,7 +163,7 @@ public interface WxCpService {
* @param department * @param department
* @throws WxErrorException * @throws WxErrorException
*/ */
public void departmentDelete(WxCpDepartment department) throws WxErrorException;
public void departmentDelete(WxCpDepart department) throws WxErrorException;


public void userCreate(WxUser user) throws WxErrorException; public void userCreate(WxUser user) throws WxErrorException;




+ 10
- 10
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpServiceImpl.java View File

@@ -11,6 +11,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import me.chanjar.weixin.enterprise.bean.*; import me.chanjar.weixin.enterprise.bean.*;
import me.chanjar.weixin.enterprise.util.http.SimpleGetRequestExecutor; import me.chanjar.weixin.enterprise.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.enterprise.util.crypto.SHA1; 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.commons.lang3.StringUtils;
import org.apache.http.client.ClientProtocolException; import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse; 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.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; 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.WxError;
import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult; import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.enterprise.bean.result.WxUser; import me.chanjar.weixin.enterprise.bean.result.WxUser;
import me.chanjar.weixin.enterprise.exception.WxErrorException; 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.MediaDownloadRequestExecutor;
import me.chanjar.weixin.enterprise.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.enterprise.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.enterprise.util.http.RequestExecutor; import me.chanjar.weixin.enterprise.util.http.RequestExecutor;
import me.chanjar.weixin.enterprise.util.http.SimplePostRequestExecutor; 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.JsonElement;
import com.google.gson.JsonObject; 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 // TODO
String url = "https://api.weixin.qq.com/cgi-bin/groups/create"; String url = "https://api.weixin.qq.com/cgi-bin/groups/create";
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
@@ -154,16 +154,16 @@ public class WxCpServiceImpl implements WxCpService {
new SimplePostRequestExecutor(), new SimplePostRequestExecutor(),
url, url,
json.toString()); 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 // TODO
String url = "https://api.weixin.qq.com/cgi-bin/groups/update"; String url = "https://api.weixin.qq.com/cgi-bin/groups/update";
execute(new SimplePostRequestExecutor(), url, group.toJson()); execute(new SimplePostRequestExecutor(), url, group.toJson());
} }


public List<WxCpDepartment> departmentGet() throws WxErrorException {
public List<WxCpDepart> departmentGet() throws WxErrorException {
// TODO // TODO
String url = "https://api.weixin.qq.com/cgi-bin/groups/get"; String url = "https://api.weixin.qq.com/cgi-bin/groups/get";
String responseContent = execute(new SimpleGetRequestExecutor(), url, null); String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
@@ -172,12 +172,12 @@ public class WxCpServiceImpl implements WxCpService {
* 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] } * 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
*/ */
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); 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()); }.getType());
} }


public void departmentDelete(WxCpDepartment department) throws WxErrorException {
public void departmentDelete(WxCpDepart department) throws WxErrorException {
// TODO // TODO


} }


+ 2
- 2
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxAccessToken.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean; 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 { public class WxAccessToken {


@@ -25,7 +25,7 @@ public class WxAccessToken {
} }


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

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpDepartment.java → weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpDepart.java View File

@@ -1,13 +1,13 @@
package me.chanjar.weixin.enterprise.bean; 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 * @author Daniel Qian
* *
*/ */
public class WxCpDepartment {
public class WxCpDepart {


private long id = -1; private long id = -1;
private String name; private String name;
@@ -31,12 +31,12 @@ public class WxCpDepartment {
this.count = count; 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() { public String toJson() {
return WxGsonBuilder.create().toJson(this);
return WxCpGsonBuilder.create().toJson(this);
} }
@Override @Override
public String toString() { public String toString() {

+ 2
- 2
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpMessage.java View File

@@ -5,7 +5,7 @@ import java.util.List;


import me.chanjar.weixin.enterprise.api.WxConsts; import me.chanjar.weixin.enterprise.api.WxConsts;
import me.chanjar.weixin.enterprise.bean.messagebuilder.*; 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() { public String toJson() {
return WxGsonBuilder.INSTANCE.create().toJson(this);
return WxCpGsonBuilder.INSTANCE.create().toJson(this);
} }
public static class WxArticle { public static class WxArticle {


+ 2
- 2
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlMessage.java View File

@@ -2,8 +2,8 @@ package me.chanjar.weixin.enterprise.bean;


import me.chanjar.weixin.enterprise.api.WxCpConfigStorage; import me.chanjar.weixin.enterprise.api.WxCpConfigStorage;
import me.chanjar.weixin.enterprise.api.WxConsts; 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 me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;




+ 1
- 1
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutImageMessage.java View File

@@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;


import me.chanjar.weixin.enterprise.api.WxConsts; import me.chanjar.weixin.enterprise.api.WxConsts;
import me.chanjar.weixin.enterprise.util.xml.MediaIdMarshaller;
import me.chanjar.weixin.common.MediaIdMarshaller;


@XmlRootElement(name = "xml") @XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)


+ 2
- 2
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMessage.java View File

@@ -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.VideoBuilder;
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.VoiceBuilder; import me.chanjar.weixin.enterprise.bean.outxmlbuilder.VoiceBuilder;
import me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil; 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") @XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)


+ 1
- 1
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMewsMessage.java View File

@@ -11,7 +11,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;


import me.chanjar.weixin.enterprise.api.WxConsts; import me.chanjar.weixin.enterprise.api.WxConsts;
import me.chanjar.weixin.enterprise.util.xml.AdapterCDATA;
import me.chanjar.weixin.common.AdapterCDATA;


@XmlRootElement(name = "xml") @XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)


+ 1
- 1
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMusicMessage.java View File

@@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;


import me.chanjar.weixin.enterprise.api.WxConsts; import me.chanjar.weixin.enterprise.api.WxConsts;
import me.chanjar.weixin.enterprise.util.xml.AdapterCDATA;
import me.chanjar.weixin.common.AdapterCDATA;


@XmlRootElement(name = "xml") @XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)


+ 1
- 1
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutTextMessage.java View File

@@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;


import me.chanjar.weixin.enterprise.api.WxConsts; import me.chanjar.weixin.enterprise.api.WxConsts;
import me.chanjar.weixin.enterprise.util.xml.AdapterCDATA;
import me.chanjar.weixin.common.AdapterCDATA;


@XmlRootElement(name = "xml") @XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)


+ 1
- 1
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVideoMessage.java View File

@@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;


import me.chanjar.weixin.enterprise.api.WxConsts; import me.chanjar.weixin.enterprise.api.WxConsts;
import me.chanjar.weixin.enterprise.util.xml.AdapterCDATA;
import me.chanjar.weixin.common.AdapterCDATA;


@XmlRootElement(name = "xml") @XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)


+ 1
- 1
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVoiceMessage.java View File

@@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;


import me.chanjar.weixin.enterprise.api.WxConsts; import me.chanjar.weixin.enterprise.api.WxConsts;
import me.chanjar.weixin.enterprise.util.xml.MediaIdMarshaller;
import me.chanjar.weixin.common.MediaIdMarshaller;


@XmlRootElement(name = "xml") @XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)


+ 0
- 70
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxMassGroupMessage.java View File

@@ -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;
}

}

+ 0
- 117
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxMassNews.java View File

@@ -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;
}
}
}

+ 0
- 79
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxMassOpenIdsMessage.java View File

@@ -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);
}
}

+ 0
- 43
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxMassVideo.java View File

@@ -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);
}
}

+ 4
- 4
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxMenu.java View File

@@ -5,7 +5,7 @@ import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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() { public String toJson() {
return WxGsonBuilder.create().toJson(this);
return WxCpGsonBuilder.create().toJson(this);
} }
public static WxMenu fromJson(String json) { 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) { 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 { public static class WxMenuButton {


+ 2
- 2
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxError.java View File

@@ -3,7 +3,7 @@ package me.chanjar.weixin.enterprise.bean.result;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; 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) { public static WxError fromJson(String json) {
return WxGsonBuilder.create().fromJson(json, WxError.class);
return WxCpGsonBuilder.create().fromJson(json, WxError.class);
} }


@Override @Override


+ 2
- 2
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxMassSendResult.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean.result; package me.chanjar.weixin.enterprise.bean.result;


import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder;
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder;


/** /**
* <pre> * <pre>
@@ -44,7 +44,7 @@ public class WxMassSendResult {
} }
public static WxMassSendResult fromJson(String json) { public static WxMassSendResult fromJson(String json) {
return WxGsonBuilder.create().fromJson(json, WxMassSendResult.class);
return WxCpGsonBuilder.create().fromJson(json, WxMassSendResult.class);
} }


@Override @Override


+ 2
- 2
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxMassUploadResult.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean.result; package me.chanjar.weixin.enterprise.bean.result;


import me.chanjar.weixin.enterprise.util.json.WxGsonBuilder;
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder;


/** /**
* <pre> * <pre>
@@ -41,7 +41,7 @@ public class WxMassUploadResult {
} }


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


@Override @Override


+ 2
- 2
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxMediaUploadResult.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean.result; 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 { public class WxMediaUploadResult {


@@ -34,7 +34,7 @@ public class WxMediaUploadResult {
} }


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


public String getThumbMediaId() { public String getThumbMediaId() {


+ 0
- 46
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxQrCodeTicket.java View File

@@ -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);
}
}

+ 2
- 2
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxUser.java View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.enterprise.bean.result; 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) { public static WxUser fromJson(String json) {
return WxGsonBuilder.INSTANCE.create().fromJson(json, WxUser.class);
return WxCpGsonBuilder.INSTANCE.create().fromJson(json, WxUser.class);
} }
} }

+ 2
- 2
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxUserList.java View File

@@ -3,7 +3,7 @@ package me.chanjar.weixin.enterprise.bean.result;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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) { public static WxUserList fromJson(String json) {
return WxGsonBuilder.INSTANCE.create().fromJson(json, WxUserList.class);
return WxCpGsonBuilder.INSTANCE.create().fromJson(json, WxUserList.class);
} }
} }

+ 1
- 1
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/MediaDownloadRequestExecutor.java View File

@@ -15,7 +15,7 @@ import org.apache.http.entity.ContentType;


import me.chanjar.weixin.enterprise.bean.result.WxError; import me.chanjar.weixin.enterprise.bean.result.WxError;
import me.chanjar.weixin.enterprise.exception.WxErrorException; import me.chanjar.weixin.enterprise.exception.WxErrorException;
import me.chanjar.weixin.enterprise.util.fs.FileUtils;
import me.chanjar.weixin.common.FileUtils;


/** /**
* 下载媒体文件请求执行器,请求的参数是String, 返回的结果是File * 下载媒体文件请求执行器,请求的参数是String, 返回的结果是File


+ 0
- 56
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/QrCodeRequestExecutor.java View 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;
}

}

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxAccessTokenAdapter.java → weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpAccessTokenAdapter.java View File

@@ -9,6 +9,7 @@
package me.chanjar.weixin.enterprise.util.json; package me.chanjar.weixin.enterprise.util.json;


import com.google.gson.*; import com.google.gson.*;
import me.chanjar.weixin.common.GsonHelper;
import me.chanjar.weixin.enterprise.bean.WxAccessToken; import me.chanjar.weixin.enterprise.bean.WxAccessToken;


import java.lang.reflect.Type; import java.lang.reflect.Type;
@@ -18,7 +19,7 @@ import java.lang.reflect.Type;
* @author Daniel Qian * @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 { public WxAccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
WxAccessToken accessToken = new WxAccessToken(); WxAccessToken accessToken = new WxAccessToken();

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxGroupGsonAdapter.java → weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpDepartGsonAdapter.java View File

@@ -10,7 +10,8 @@ package me.chanjar.weixin.enterprise.util.json;


import java.lang.reflect.Type; 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.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
@@ -25,9 +26,9 @@ import com.google.gson.JsonSerializer;
* @author Daniel Qian * @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 json = new JsonObject();
JsonObject groupJson = new JsonObject(); JsonObject groupJson = new JsonObject();
groupJson.addProperty("name", group.getName()); groupJson.addProperty("name", group.getName());
@@ -37,8 +38,8 @@ public class WxGroupGsonAdapter implements JsonSerializer<WxCpDepartment>, JsonD
return json; 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(); JsonObject groupJson = json.getAsJsonObject();
if (json.getAsJsonObject().get("group") != null) { if (json.getAsJsonObject().get("group") != null) {
groupJson = json.getAsJsonObject().get("group").getAsJsonObject(); groupJson = json.getAsJsonObject().get("group").getAsJsonObject();

+ 29
- 0
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpGsonBuilder.java View File

@@ -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();
}
}

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMediaUploadResultAdapter.java → weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMediaUploadResultAdapter.java View File

@@ -9,6 +9,7 @@
package me.chanjar.weixin.enterprise.util.json; package me.chanjar.weixin.enterprise.util.json;


import com.google.gson.*; import com.google.gson.*;
import me.chanjar.weixin.common.GsonHelper;
import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult; import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult;


import java.lang.reflect.Type; import java.lang.reflect.Type;
@@ -18,7 +19,7 @@ import java.lang.reflect.Type;
* @author Daniel Qian * @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 { public WxMediaUploadResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
WxMediaUploadResult uploadResult = new WxMediaUploadResult(); WxMediaUploadResult uploadResult = new WxMediaUploadResult();

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMenuGsonAdapter.java → weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMenuGsonAdapter.java View File

@@ -10,6 +10,7 @@ package me.chanjar.weixin.enterprise.util.json;


import java.lang.reflect.Type; import java.lang.reflect.Type;


import me.chanjar.weixin.common.GsonHelper;
import me.chanjar.weixin.enterprise.bean.WxMenu; import me.chanjar.weixin.enterprise.bean.WxMenu;


import com.google.gson.JsonArray; import com.google.gson.JsonArray;
@@ -26,7 +27,7 @@ import com.google.gson.JsonSerializer;
* @author Daniel Qian * @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) { public JsonElement serialize(WxMenu menu, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxUserGsonAdapter.java → weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpUserGsonAdapter.java View File

@@ -10,6 +10,7 @@ package me.chanjar.weixin.enterprise.util.json;


import java.lang.reflect.Type; import java.lang.reflect.Type;


import me.chanjar.weixin.common.GsonHelper;
import me.chanjar.weixin.enterprise.bean.result.WxUser; import me.chanjar.weixin.enterprise.bean.result.WxUser;


import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializationContext;
@@ -23,7 +24,7 @@ import com.google.gson.JsonParseException;
* @author Daniel Qian * @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 { public WxUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject o = json.getAsJsonObject(); JsonObject o = json.getAsJsonObject();

weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxUserListGsonAdapter.java → weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpUserListGsonAdapter.java View File

@@ -10,6 +10,7 @@ package me.chanjar.weixin.enterprise.util.json;


import java.lang.reflect.Type; import java.lang.reflect.Type;


import me.chanjar.weixin.common.GsonHelper;
import me.chanjar.weixin.enterprise.bean.result.WxUserList; import me.chanjar.weixin.enterprise.bean.result.WxUserList;


import com.google.gson.JsonArray; import com.google.gson.JsonArray;
@@ -24,7 +25,7 @@ import com.google.gson.JsonParseException;
* @author Daniel Qian * @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 { public WxUserList deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject o = json.getAsJsonObject(); JsonObject o = json.getAsJsonObject();

+ 1
- 0
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxErrorAdapter.java View File

@@ -9,6 +9,7 @@
package me.chanjar.weixin.enterprise.util.json; package me.chanjar.weixin.enterprise.util.json;


import com.google.gson.*; import com.google.gson.*;
import me.chanjar.weixin.common.GsonHelper;
import me.chanjar.weixin.enterprise.bean.result.WxError; import me.chanjar.weixin.enterprise.bean.result.WxError;


import java.lang.reflect.Type; import java.lang.reflect.Type;


+ 0
- 36
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxGsonBuilder.java View File

@@ -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();
}
}

+ 0
- 64
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMassMessageGsonAdapter.java View File

@@ -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;
}

}

+ 0
- 55
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMassNewsGsonAdapter.java View File

@@ -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;
}

}

+ 0
- 68
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMassOpenIdsMessageGsonAdapter.java View File

@@ -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;
}

}

+ 0
- 39
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMassSendResultAdapter.java View File

@@ -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;
}
}

+ 0
- 39
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMassUploadResultAdapter.java View File

@@ -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;
}
}

+ 0
- 31
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxMassVideoAdapter.java View File

@@ -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;
}

}

+ 0
- 39
weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxQrCodeTicketAdapter.java View File

@@ -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;
}
}

+ 5
- 5
weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxGroupAPITest.java View File

@@ -2,7 +2,7 @@ package me.chanjar.weixin.enterprise.api;


import java.util.List; 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.Assert;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@@ -23,19 +23,19 @@ public class WxGroupAPITest {
@Inject @Inject
protected WxCpServiceImpl wxService; protected WxCpServiceImpl wxService;


protected WxCpDepartment group;
protected WxCpDepart group;
public void testGroupCreate() throws WxErrorException { public void testGroupCreate() throws WxErrorException {
WxCpDepartment res = wxService.departmentCreate("测试分组1");
WxCpDepart res = wxService.departmentCreate("测试分组1");
Assert.assertEquals(res.getName(), "测试分组1"); Assert.assertEquals(res.getName(), "测试分组1");
} }


@Test(dependsOnMethods="testGroupCreate") @Test(dependsOnMethods="testGroupCreate")
public void testGroupGet() throws WxErrorException { public void testGroupGet() throws WxErrorException {
List<WxCpDepartment> groupList = wxService.departmentGet();
List<WxCpDepart> groupList = wxService.departmentGet();
Assert.assertNotNull(groupList); Assert.assertNotNull(groupList);
Assert.assertTrue(groupList.size() > 0); Assert.assertTrue(groupList.size() > 0);
for (WxCpDepartment g : groupList) {
for (WxCpDepart g : groupList) {
group = g; group = g;
Assert.assertNotNull(g.getName()); Assert.assertNotNull(g.getName());
} }


Loading…
Cancel
Save