@@ -17,7 +17,7 @@ weixin-java-tools | |||
<dependency> | |||
<groupId>me.chanjar</groupId> | |||
<artifactId>weixin-java-mp</artifactId> | |||
<version>1.2.0</version> | |||
<version>1.3.0</version> | |||
</dependency> | |||
``` | |||
@@ -27,7 +27,7 @@ weixin-java-tools | |||
<dependency> | |||
<groupId>me.chanjar</groupId> | |||
<artifactId>weixin-java-cp</artifactId> | |||
<version>1.2.0</version> | |||
<version>1.3.0</version> | |||
</dependency> | |||
``` | |||
@@ -54,3 +54,5 @@ weixin-java-tools | |||
## 关于Pull Request | |||
非常欢迎和感谢对本项目发起Pull Request的同学,不过本项目基于[git flow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)开发流程,因此在发起Pull Request的时候请选择develop分支。 | |||
且本项目代码风格是用2个空格代表一个tab,因此在发起PR时注意一下,否则很容易发生在IDE格式化代码后与原代码产生大量diff,这样我在阅读PR的时候就很困难。 |
@@ -5,7 +5,7 @@ | |||
<modelVersion>4.0.0</modelVersion> | |||
<groupId>me.chanjar</groupId> | |||
<artifactId>weixin-java-parent</artifactId> | |||
<version>1.2.0</version> | |||
<version>1.3.0</version> | |||
<packaging>pom</packaging> | |||
<name>WeiXin Java Tools - Parent</name> | |||
<description>微信公众号、企业号上级POM</description> | |||
@@ -41,7 +41,7 @@ | |||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |||
<downloadJavadocs>true</downloadJavadocs> | |||
<downloadSources>true</downloadSources> | |||
<httpclient.version>4.3.5</httpclient.version> | |||
<httpclient.version>4.5</httpclient.version> | |||
<slf4j.version>1.7.10</slf4j.version> | |||
<logback.version>1.1.2</logback.version> | |||
</properties> | |||
@@ -6,7 +6,7 @@ | |||
<parent> | |||
<groupId>me.chanjar</groupId> | |||
<artifactId>weixin-java-parent</artifactId> | |||
<version>1.2.0</version> | |||
<version>1.3.0</version> | |||
</parent> | |||
<artifactId>weixin-java-common</artifactId> | |||
@@ -29,6 +29,7 @@ public class WxConsts { | |||
public static final String CUSTOM_MSG_MUSIC = "music"; | |||
public static final String CUSTOM_MSG_NEWS = "news"; | |||
public static final String CUSTOM_MSG_FILE = "file"; | |||
public static final String CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service"; | |||
/////////////////////// | |||
// 群发消息的消息类型 | |||
@@ -6,11 +6,10 @@ import java.io.Serializable; | |||
* jspai signature | |||
*/ | |||
public class WxJsapiSignature implements Serializable { | |||
private String appid; | |||
private String noncestr; | |||
private String jsapiTicket; | |||
private long timestamp; | |||
private String url; | |||
@@ -33,14 +32,6 @@ public class WxJsapiSignature implements Serializable { | |||
this.noncestr = noncestr; | |||
} | |||
public String getJsapiTicket() { | |||
return jsapiTicket; | |||
} | |||
public void setJsapiTicket(String jsapiTicket) { | |||
this.jsapiTicket = jsapiTicket; | |||
} | |||
public long getTimestamp() { | |||
return timestamp; | |||
} | |||
@@ -57,4 +48,12 @@ public class WxJsapiSignature implements Serializable { | |||
this.url = url; | |||
} | |||
public String getAppid() { | |||
return appid; | |||
} | |||
public void setAppid(String appid) { | |||
this.appid = appid; | |||
} | |||
} |
@@ -49,7 +49,7 @@ public class WxError implements Serializable { | |||
@Override | |||
public String toString() { | |||
return "微信错误 errcode=" + errorCode + ", errmsg=" + errorMsg + "\njson:" + json; | |||
return "微信错误: errcode=" + errorCode + ", errmsg=" + errorMsg + "\njson:" + json; | |||
} | |||
} |
@@ -6,7 +6,7 @@ | |||
<parent> | |||
<groupId>me.chanjar</groupId> | |||
<artifactId>weixin-java-parent</artifactId> | |||
<version>1.2.0</version> | |||
<version>1.3.0</version> | |||
</parent> | |||
<artifactId>weixin-java-cp</artifactId> | |||
@@ -408,7 +408,7 @@ public interface WxCpService { | |||
* </pre> | |||
* @param redirectUri | |||
* @param state | |||
* @return code | |||
* @return url | |||
*/ | |||
String oauth2buildAuthorizationUrl(String redirectUri, String state); | |||
@@ -556,4 +556,26 @@ public interface WxCpService { | |||
* @param sessionManager | |||
*/ | |||
void setSessionManager(WxSessionManager sessionManager); | |||
/** | |||
* 上传部门列表覆盖企业号上的部门信息 | |||
* @param mediaId | |||
* @throws WxErrorException | |||
*/ | |||
String replaceParty(String mediaId) throws WxErrorException; | |||
/** | |||
* 上传用户列表覆盖企业号上的用户信息 | |||
* @param mediaId | |||
* @throws WxErrorException | |||
*/ | |||
String replaceUser(String mediaId) throws WxErrorException; | |||
/** | |||
* 获取异步任务结果 | |||
* @param joinId | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
String getTaskResult(String joinId) throws WxErrorException; | |||
} |
@@ -1,13 +1,14 @@ | |||
package me.chanjar.weixin.cp.api; | |||
import com.google.gson.JsonArray; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonPrimitive; | |||
import com.google.gson.internal.Streams; | |||
import com.google.gson.reflect.TypeToken; | |||
import com.google.gson.stream.JsonReader; | |||
import com.sun.media.sound.SoftTuning; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.StringReader; | |||
import java.math.BigDecimal; | |||
import java.security.NoSuchAlgorithmException; | |||
import java.util.List; | |||
import java.util.UUID; | |||
import me.chanjar.weixin.common.bean.WxAccessToken; | |||
import me.chanjar.weixin.common.bean.WxJsapiSignature; | |||
import me.chanjar.weixin.common.bean.WxMenu; | |||
@@ -21,13 +22,19 @@ import me.chanjar.weixin.common.util.RandomUtils; | |||
import me.chanjar.weixin.common.util.StringUtils; | |||
import me.chanjar.weixin.common.util.crypto.SHA1; | |||
import me.chanjar.weixin.common.util.fs.FileUtils; | |||
import me.chanjar.weixin.common.util.http.*; | |||
import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor; | |||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; | |||
import me.chanjar.weixin.common.util.http.RequestExecutor; | |||
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | |||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; | |||
import me.chanjar.weixin.common.util.http.URIUtil; | |||
import me.chanjar.weixin.common.util.json.GsonHelper; | |||
import me.chanjar.weixin.cp.bean.WxCpDepart; | |||
import me.chanjar.weixin.cp.bean.WxCpMessage; | |||
import me.chanjar.weixin.cp.bean.WxCpTag; | |||
import me.chanjar.weixin.cp.bean.WxCpUser; | |||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; | |||
import org.apache.http.HttpHost; | |||
import org.apache.http.auth.AuthScope; | |||
import org.apache.http.auth.UsernamePasswordCredentials; | |||
@@ -43,14 +50,13 @@ import org.apache.http.impl.client.HttpClients; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.StringReader; | |||
import java.math.BigDecimal; | |||
import java.security.NoSuchAlgorithmException; | |||
import java.util.List; | |||
import java.util.UUID; | |||
import com.google.gson.JsonArray; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonPrimitive; | |||
import com.google.gson.internal.Streams; | |||
import com.google.gson.reflect.TypeToken; | |||
import com.google.gson.stream.JsonReader; | |||
public class WxCpServiceImpl implements WxCpService { | |||
@@ -243,7 +249,6 @@ public class WxCpServiceImpl implements WxCpService { | |||
public File mediaDownload(String media_id) throws WxErrorException { | |||
String url = "https://qyapi.weixin.qq.com/cgi-bin/media/get"; | |||
return execute(new MediaDownloadRequestExecutor(wxCpConfigStorage.getTmpDirFile()), url, "media_id=" + media_id); | |||
} | |||
@@ -551,6 +556,9 @@ public class WxCpServiceImpl implements WxCpService { | |||
} | |||
protected <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException { | |||
if (uri.indexOf("access_token=") != -1) { | |||
throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); | |||
} | |||
String accessToken = getAccessToken(false); | |||
String uriWithAccessToken = uri; | |||
@@ -647,6 +655,28 @@ public class WxCpServiceImpl implements WxCpService { | |||
this.sessionManager = sessionManager; | |||
} | |||
@Override | |||
public String replaceParty(String mediaId) throws WxErrorException { | |||
String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty"; | |||
JsonObject jsonObject = new JsonObject(); | |||
jsonObject.addProperty("media_id", mediaId); | |||
return post(url, jsonObject.toString()); | |||
} | |||
@Override | |||
public String replaceUser(String mediaId) throws WxErrorException { | |||
String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceuser"; | |||
JsonObject jsonObject = new JsonObject(); | |||
jsonObject.addProperty("media_id", mediaId); | |||
return post(url, jsonObject.toString()); | |||
} | |||
@Override | |||
public String getTaskResult(String joinId) throws WxErrorException { | |||
String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/getresult?jobid="+joinId; | |||
return get(url, null); | |||
} | |||
public File getTmpDirFile() { | |||
return tmpDirFile; | |||
} | |||
@@ -24,6 +24,7 @@ public class WxCpUser implements Serializable { | |||
private String weiXinId; | |||
private String avatar; | |||
private Integer status; | |||
private Integer enable; | |||
private final List<Attr> extAttrs = new ArrayList<Attr>(); | |||
public String getUserId() { | |||
@@ -114,6 +115,14 @@ public class WxCpUser implements Serializable { | |||
this.status = status; | |||
} | |||
public Integer getEnable() { | |||
return enable; | |||
} | |||
public void setEnable(Integer enable) { | |||
this.enable = enable; | |||
} | |||
public void addExtAttr(String name, String value) { | |||
this.extAttrs.add(new Attr(name, value)); | |||
} | |||
@@ -38,14 +38,7 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri | |||
user.setPosition(GsonHelper.getString(o, "position")); | |||
user.setMobile(GsonHelper.getString(o, "mobile")); | |||
Integer gender = GsonHelper.getInteger(o, "gender"); | |||
if (new Integer(1).equals(gender)) { | |||
user.setGender("男"); | |||
} else if (new Integer(2).equals(gender)) { | |||
user.setGender("女"); | |||
} else { | |||
user.setGender("未知"); | |||
} | |||
user.setGender(GsonHelper.getString(o, "gender")); | |||
user.setTel(GsonHelper.getString(o, "tel")); | |||
user.setEmail(GsonHelper.getString(o, "email")); | |||
user.setWeiXinId(GsonHelper.getString(o, "weixinid")); | |||
@@ -88,7 +81,7 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri | |||
o.addProperty("mobile", user.getMobile()); | |||
} | |||
if (user.getGender() != null) { | |||
o.addProperty("gender", user.getGender().equals("男") ? 0 : 1); | |||
o.addProperty("gender", user.getGender()); | |||
} | |||
if (user.getTel() != null) { | |||
o.addProperty("tel", user.getTel()); | |||
@@ -105,6 +98,9 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri | |||
if (user.getStatus() != null) { | |||
o.addProperty("status", user.getStatus()); | |||
} | |||
if (user.getEnable() != null) { | |||
o.addProperty("enable", user.getEnable()); | |||
} | |||
if (user.getExtAttrs().size() > 0) { | |||
JsonArray attrsJsonArray = new JsonArray(); | |||
for (WxCpUser.Attr attr : user.getExtAttrs()) { | |||
@@ -6,7 +6,7 @@ | |||
<parent> | |||
<groupId>me.chanjar</groupId> | |||
<artifactId>weixin-java-parent</artifactId> | |||
<version>1.2.0</version> | |||
<version>1.3.0</version> | |||
</parent> | |||
<artifactId>weixin-java-mp</artifactId> | |||
<name>WeiXin Java Tools - MP</name> | |||
@@ -47,9 +47,9 @@ public interface WxMpService { | |||
* <pre> | |||
* 获取access_token,本方法线程安全 | |||
* 且在多线程同时刷新时只刷新一次,避免超出2000次/日的调用次数上限 | |||
* | |||
* | |||
* 另:本service的所有方法都会在access_token过期是调用此方法 | |||
* | |||
* | |||
* 程序员在非必要情况下尽量不要主动调用此方法 | |||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token | |||
@@ -111,6 +111,135 @@ public interface WxMpService { | |||
*/ | |||
public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException, IOException; | |||
/** | |||
* <pre> | |||
* 上传非图文永久素材 | |||
* | |||
* 上传的多媒体文件有格式和大小限制,如下: | |||
* 图片(image): 图片大小不超过2M,支持bmp/png/jpeg/jpg/gif格式 | |||
* 语音(voice):语音大小不超过5M,长度不超过60秒,支持mp3/wma/wav/amr格式 | |||
* 视频(video):在上传视频素材时需要POST另一个表单,id为description,包含素材的描述信息,内容格式为JSON | |||
* 缩略图(thumb):文档未说明 | |||
* | |||
* 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html | |||
* </pre> | |||
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts} | |||
* @param material 上传的素材, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterial} | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
public WxMpMaterialUploadResult materialFileUpload(String mediaType, WxMpMaterial material) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 上传永久图文素材 | |||
* | |||
* 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html | |||
* </pre> | |||
* @param news 上传的图文消息, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialNews} | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
public WxMpMaterialUploadResult materialNewsUpload(WxMpMaterialNews news) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 下载声音或者图片永久素材 | |||
* | |||
* 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html | |||
* </pre> | |||
* @param media_id 永久素材的id | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
public InputStream materialImageOrVoiceDownload(String media_id) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 获取视频永久素材的信息和下载地址 | |||
* | |||
* 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html | |||
* </pre> | |||
* @param media_id 永久素材的id | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
public WxMpMaterialVideoInfoResult materialVideoInfo(String media_id) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 获取图文永久素材的信息 | |||
* | |||
* 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html | |||
* </pre> | |||
* @param media_id 永久素材的id | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
public WxMpMaterialNews materialNewsInfo(String media_id) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 更新图文永久素材 | |||
* | |||
* 详情请见: http://mp.weixin.qq.com/wiki/4/19a59cba020d506e767360ca1be29450.html | |||
* </pre> | |||
* @param wxMpMaterialArticleUpdate 用来更新图文素材的bean, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate} | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 删除永久素材 | |||
* | |||
* 详情请见: http://mp.weixin.qq.com/wiki/5/e66f61c303db51a6c0f90f46b15af5f5.html | |||
* </pre> | |||
* @param media_id 永久素材的id | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
public boolean materialDelete(String media_id) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 获取各类素材总数 | |||
* | |||
* 详情请见: http://mp.weixin.qq.com/wiki/16/8cc64f8c189674b421bee3ed403993b8.html | |||
* </pre> | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
public WxMpMaterialCountResult materialCount() throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 分页获取图文素材列表 | |||
* | |||
* 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html | |||
* </pre> | |||
* @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回 | |||
* @param count 返回素材的数量,取值在1到20之间 | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 分页获取其他媒体素材列表 | |||
* | |||
* 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html | |||
* </pre> | |||
* @param type 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts} | |||
* @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回 | |||
* @param count 返回素材的数量,取值在1到20之间 | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offset, int count) throws WxErrorException; | |||
/** | |||
* @see #mediaUpload(String, String, InputStream) | |||
* @param mediaType | |||
@@ -118,7 +247,7 @@ public interface WxMpService { | |||
* @throws WxErrorException | |||
*/ | |||
public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 下载多媒体文件 | |||
@@ -130,7 +259,7 @@ public interface WxMpService { | |||
* @throws WxErrorException | |||
*/ | |||
public File mediaDownload(String media_id) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 发送客服消息 | |||
@@ -140,11 +269,11 @@ public interface WxMpService { | |||
* @throws WxErrorException | |||
*/ | |||
public void customMessageSend(WxMpCustomMessage message) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 上传群发用的图文消息,上传后才能群发图文消息 | |||
* | |||
* 上传群发用的图文消息,上传后才能群发图文消息 | |||
* | |||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口 | |||
* </pre> | |||
* @param news | |||
@@ -153,7 +282,7 @@ public interface WxMpService { | |||
* @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage) | |||
*/ | |||
public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 上传群发用的视频,上传后才能群发视频消息 | |||
@@ -175,10 +304,10 @@ public interface WxMpService { | |||
* </pre> | |||
* @param message | |||
* @throws WxErrorException | |||
* @return | |||
* @return | |||
*/ | |||
public WxMpMassSendResult massGroupMessageSend(WxMpMassGroupMessage message) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 按openId列表群发消息 | |||
@@ -201,7 +330,7 @@ public interface WxMpService { | |||
* @throws WxErrorException | |||
*/ | |||
public void menuCreate(WxMenu menu) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 自定义菜单删除接口 | |||
@@ -210,7 +339,7 @@ public interface WxMpService { | |||
* @throws WxErrorException | |||
*/ | |||
public void menuDelete() throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 自定义菜单查询接口 | |||
@@ -227,11 +356,11 @@ public interface WxMpService { | |||
* 最多支持创建500个分组 | |||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 | |||
* </pre> | |||
* @param name 分组名字(30个字符以内) | |||
* @param name 分组名字(30个字符以内) | |||
* @throws WxErrorException | |||
*/ | |||
public WxMpGroup groupCreate(String name) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 分组管理接口 - 查询所有分组 | |||
@@ -241,34 +370,34 @@ public interface WxMpService { | |||
* @throws WxErrorException | |||
*/ | |||
public List<WxMpGroup> groupGet() throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 分组管理接口 - 查询用户所在分组 | |||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 | |||
* </pre> | |||
* @param openid 微信用户的openid | |||
* @param openid 微信用户的openid | |||
* @throws WxErrorException | |||
*/ | |||
public long userGetGroup(String openid) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 分组管理接口 - 修改分组名 | |||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 | |||
* | |||
* | |||
* 如果id为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误 | |||
* </pre> | |||
* @param group 要更新的group,group的id,name必须设置 | |||
* @param group 要更新的group,group的id,name必须设置 | |||
* @throws WxErrorException | |||
*/ | |||
public void groupUpdate(WxMpGroup group) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 分组管理接口 - 移动用户分组 | |||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 | |||
* | |||
* | |||
* 如果to_groupid为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误 | |||
* </pre> | |||
* @param openid 用户openid | |||
@@ -294,7 +423,7 @@ public interface WxMpService { | |||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取用户基本信息 | |||
* </pre> | |||
* @param openid 用户openid | |||
* @param lang 语言,zh_CN 简体(默认),zh_TW 繁体,en 英语 | |||
* @param lang 语言,zh_CN 简体(默认),zh_TW 繁体,en 英语 | |||
* @return | |||
* @throws WxErrorException | |||
*/ | |||
@@ -397,7 +526,7 @@ public interface WxMpService { | |||
* </pre> | |||
* @param scope | |||
* @param state | |||
* @return code | |||
* @return url | |||
*/ | |||
public String oauth2buildAuthorizationUrl(String scope, String state); | |||
@@ -410,7 +539,7 @@ public interface WxMpService { | |||
* 用户授权完成后的重定向链接,无需urlencode, 方法内会进行encode | |||
* @param scope | |||
* @param state | |||
* @return code | |||
* @return url | |||
*/ | |||
public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state); | |||
/** | |||
@@ -543,7 +672,7 @@ public interface WxMpService { | |||
void setMaxRetryTimes(int maxRetryTimes); | |||
/** | |||
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_1) | |||
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1) | |||
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识" | |||
* @param openId 支付人openId | |||
* @param outTradeNo 商户端对应订单号 | |||
@@ -570,4 +699,19 @@ public interface WxMpService { | |||
*/ | |||
Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl); | |||
/** | |||
* 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。 | |||
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2 | |||
* @param transactionId | |||
* @param outTradeNo | |||
*/ | |||
WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo); | |||
/** | |||
* 读取支付结果通知 | |||
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 | |||
* @param xmlData | |||
* @return | |||
*/ | |||
WxMpPayCallback getJSSDKCallbackData(String xmlData); | |||
} |
@@ -1,13 +1,21 @@ | |||
package me.chanjar.weixin.mp.api; | |||
import com.google.gson.Gson; | |||
import com.google.gson.JsonArray; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.internal.Streams; | |||
import com.google.gson.reflect.TypeToken; | |||
import com.google.gson.stream.JsonReader; | |||
import com.thoughtworks.xstream.XStream; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.StringReader; | |||
import java.security.NoSuchAlgorithmException; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.Date; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.SortedMap; | |||
import java.util.TreeMap; | |||
import java.util.UUID; | |||
import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.common.bean.WxAccessToken; | |||
import me.chanjar.weixin.common.bean.WxJsapiSignature; | |||
import me.chanjar.weixin.common.bean.WxMenu; | |||
@@ -21,13 +29,53 @@ import me.chanjar.weixin.common.util.StringUtils; | |||
import me.chanjar.weixin.common.util.crypto.SHA1; | |||
import me.chanjar.weixin.common.util.crypto.WxCryptUtil; | |||
import me.chanjar.weixin.common.util.fs.FileUtils; | |||
import me.chanjar.weixin.common.util.http.*; | |||
import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor; | |||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; | |||
import me.chanjar.weixin.common.util.http.RequestExecutor; | |||
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | |||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; | |||
import me.chanjar.weixin.common.util.http.URIUtil; | |||
import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; | |||
import me.chanjar.weixin.common.util.json.GsonHelper; | |||
import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.common.util.xml.XStreamInitializer; | |||
import me.chanjar.weixin.mp.bean.*; | |||
import me.chanjar.weixin.mp.bean.result.*; | |||
import me.chanjar.weixin.mp.util.http.*; | |||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpGroup; | |||
import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpMassNews; | |||
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpMassVideo; | |||
import me.chanjar.weixin.mp.bean.WxMpMaterial; | |||
import me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate; | |||
import me.chanjar.weixin.mp.bean.WxMpMaterialNews; | |||
import me.chanjar.weixin.mp.bean.WxMpSemanticQuery; | |||
import me.chanjar.weixin.mp.bean.WxMpTemplateMessage; | |||
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpMaterialCountResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpMaterialFileBatchGetResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpMaterialNewsBatchGetResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpMaterialUploadResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpMaterialVideoInfoResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||
import me.chanjar.weixin.mp.bean.result.WxMpPayCallback; | |||
import me.chanjar.weixin.mp.bean.result.WxMpPayResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpPrepayIdResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; | |||
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate; | |||
import me.chanjar.weixin.mp.bean.result.WxMpUserList; | |||
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary; | |||
import me.chanjar.weixin.mp.util.http.MaterialDeleteRequestExecutor; | |||
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor; | |||
import me.chanjar.weixin.mp.util.http.MaterialUploadRequestExecutor; | |||
import me.chanjar.weixin.mp.util.http.MaterialVideoInfoRequestExecutor; | |||
import me.chanjar.weixin.mp.util.http.MaterialVoiceAndImageDownloadRequestExecutor; | |||
import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor; | |||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
import org.apache.commons.codec.digest.DigestUtils; | |||
import org.apache.http.Consts; | |||
import org.apache.http.HttpHost; | |||
import org.apache.http.auth.AuthScope; | |||
@@ -46,12 +94,13 @@ import org.apache.http.impl.client.HttpClients; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.StringReader; | |||
import java.security.NoSuchAlgorithmException; | |||
import java.util.*; | |||
import com.google.gson.JsonArray; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.internal.Streams; | |||
import com.google.gson.reflect.TypeToken; | |||
import com.google.gson.stream.JsonReader; | |||
import com.thoughtworks.xstream.XStream; | |||
public class WxMpServiceImpl implements WxMpService { | |||
@@ -162,6 +211,7 @@ public class WxMpServiceImpl implements WxMpService { | |||
"url=" + url | |||
); | |||
WxJsapiSignature jsapiSignature = new WxJsapiSignature(); | |||
jsapiSignature.setAppid(wxMpConfigStorage.getAppId()); | |||
jsapiSignature.setTimestamp(timestamp); | |||
jsapiSignature.setNoncestr(noncestr); | |||
jsapiSignature.setUrl(url); | |||
@@ -271,13 +321,13 @@ public class WxMpServiceImpl implements WxMpService { | |||
} | |||
} | |||
public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(String type, int offset, int count) throws WxErrorException { | |||
public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException { | |||
String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material"; | |||
Map<String, Object> params = new HashMap<String, Object>(); | |||
params.put("type", type); | |||
Map<String, Object> params = new HashMap<>(); | |||
params.put("type", WxConsts.MATERIAL_NEWS); | |||
params.put("offset", offset); | |||
params.put("count", count); | |||
String responseText = post(url, new Gson().toJson(params)); | |||
String responseText = post(url, WxGsonBuilder.create().toJson(params)); | |||
WxError wxError = WxError.fromJson(responseText); | |||
if (wxError.getErrorCode() == 0) { | |||
return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialNewsBatchGetResult.class); | |||
@@ -288,11 +338,11 @@ public class WxMpServiceImpl implements WxMpService { | |||
public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offset, int count) throws WxErrorException { | |||
String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material"; | |||
Map<String, Object> params = new HashMap<String, Object>(); | |||
Map<String, Object> params = new HashMap<>(); | |||
params.put("type", type); | |||
params.put("offset", offset); | |||
params.put("count", count); | |||
String responseText = post(url, new Gson().toJson(params)); | |||
String responseText = post(url, WxGsonBuilder.create().toJson(params)); | |||
WxError wxError = WxError.fromJson(responseText); | |||
if (wxError.getErrorCode() == 0) { | |||
return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialFileBatchGetResult.class); | |||
@@ -347,8 +397,9 @@ public class WxMpServiceImpl implements WxMpService { | |||
* 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] } | |||
*/ | |||
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); | |||
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), new TypeToken<List<WxMpGroup>>() { | |||
}.getType()); | |||
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), | |||
new TypeToken<List<WxMpGroup>>() { | |||
}.getType()); | |||
} | |||
public long userGetGroup(String openid) throws WxErrorException { | |||
@@ -595,8 +646,9 @@ public class WxMpServiceImpl implements WxMpService { | |||
param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate)); | |||
String responseContent = post(url, param.toString()); | |||
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); | |||
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), new TypeToken<List<WxMpUserCumulate>>() { | |||
}.getType()); | |||
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), | |||
new TypeToken<List<WxMpUserCumulate>>() { | |||
}.getType()); | |||
} | |||
public String get(String url, String queryParam) throws WxErrorException { | |||
@@ -644,6 +696,9 @@ public class WxMpServiceImpl implements WxMpService { | |||
} | |||
protected <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException { | |||
if (uri.indexOf("access_token=") != -1) { | |||
throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); | |||
} | |||
String accessToken = getAccessToken(false); | |||
String uriWithAccessToken = uri; | |||
@@ -789,7 +844,64 @@ public class WxMpServiceImpl implements WxMpService { | |||
payInfo.put("signType", "MD5"); | |||
String finalSign = WxCryptUtil.createSign(payInfo, wxMpConfigStorage.getPartnerKey()); | |||
payInfo.put("sign", finalSign); | |||
payInfo.put("paySign", finalSign); | |||
return payInfo; | |||
} | |||
@Override | |||
public WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo) { | |||
String nonce_str = System.currentTimeMillis() + ""; | |||
SortedMap<String, String> packageParams = new TreeMap<String, String>(); | |||
packageParams.put("appid", wxMpConfigStorage.getAppId()); | |||
packageParams.put("mch_id", wxMpConfigStorage.getPartnerId()); | |||
packageParams.put("transaction_id", transactionId); | |||
packageParams.put("out_trade_no", outTradeNo); | |||
packageParams.put("nonce_str", nonce_str); | |||
String sign = WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey()); | |||
String xml = "<xml>" + | |||
"<appid>" + wxMpConfigStorage.getAppId() + "</appid>" + | |||
"<mch_id>" + wxMpConfigStorage.getPartnerId() + "</mch_id>" + | |||
"<transaction_id>" + transactionId + "</transaction_id>" + | |||
"<out_trade_no>" + outTradeNo + "</out_trade_no>" + | |||
"<nonce_str>" + nonce_str + "</nonce_str>" + | |||
"<sign>" + sign + "</sign>" + | |||
"</xml>"; | |||
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/pay/orderquery"); | |||
if (httpProxy != null) { | |||
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build(); | |||
httpPost.setConfig(config); | |||
} | |||
StringEntity entity = new StringEntity(xml, Consts.UTF_8); | |||
httpPost.setEntity(entity); | |||
try { | |||
CloseableHttpResponse response = httpClient.execute(httpPost); | |||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); | |||
XStream xstream = XStreamInitializer.getInstance(); | |||
xstream.alias("xml", WxMpPayResult.class); | |||
WxMpPayResult wxMpPayResult = (WxMpPayResult) xstream.fromXML(responseContent); | |||
return wxMpPayResult; | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
return new WxMpPayResult(); | |||
} | |||
@Override | |||
public WxMpPayCallback getJSSDKCallbackData(String xmlData) { | |||
try { | |||
XStream xstream = XStreamInitializer.getInstance(); | |||
xstream.alias("xml", WxMpPayCallback.class); | |||
WxMpPayCallback wxMpCallback = (WxMpPayCallback) xstream.fromXML(xmlData); | |||
return wxMpCallback; | |||
} catch (Exception e){ | |||
e.printStackTrace(); | |||
} | |||
return new WxMpPayCallback(); | |||
} | |||
} |
@@ -35,7 +35,8 @@ public class WxMpMaterialNews implements Serializable { | |||
* 4. contentSourceUrl 在图文消息页面点击“阅读原文”后的页面链接 | |||
* 5. content (必填) 图文消息页面的内容,支持HTML标签 | |||
* 6. digest 图文消息的描述 | |||
* 7, showCoverPic 是否显示封面,true为显示,false为不显示 | |||
* 7. showCoverPic 是否显示封面,true为显示,false为不显示 | |||
* 8. url 点击图文消息跳转链接 | |||
* </pre> | |||
* | |||
* @author chanjarster | |||
@@ -70,6 +71,12 @@ public class WxMpMaterialNews implements Serializable { | |||
*/ | |||
private boolean showCoverPic; | |||
/** | |||
* 点击图文消息跳转链接 | |||
* @return | |||
*/ | |||
private String url; | |||
public String getThumbMediaId() { | |||
return thumbMediaId; | |||
} | |||
@@ -126,11 +133,19 @@ public class WxMpMaterialNews implements Serializable { | |||
this.showCoverPic = showCoverPic; | |||
} | |||
public String getUrl() { | |||
return url; | |||
} | |||
public void setUrl(String url) { | |||
this.url = url; | |||
} | |||
@Override | |||
public String toString() { | |||
return "WxMpMassNewsArticle [" + "thumbMediaId=" + thumbMediaId + ", author=" + author + ", title=" + title + | |||
", contentSourceUrl=" + contentSourceUrl + ", content=" + content + ", digest=" + digest + | |||
", showCoverPic=" + showCoverPic + "]"; | |||
", showCoverPic=" + showCoverPic +", url=" + url + "]"; | |||
} | |||
} | |||
@@ -121,4 +121,12 @@ public abstract class WxMpXmlOutMessage implements Serializable { | |||
public static NewsBuilder NEWS() { | |||
return new NewsBuilder(); | |||
} | |||
/** | |||
* 获得客服消息builder | |||
* | |||
* @return | |||
*/ | |||
public static TransferCustomerServiceBuilder TRANSFER_CUSTOMER_SERVICE() { | |||
return new TransferCustomerServiceBuilder(); | |||
} | |||
} |
@@ -0,0 +1,41 @@ | |||
package me.chanjar.weixin.mp.bean; | |||
import com.thoughtworks.xstream.annotations.XStreamAlias; | |||
import com.thoughtworks.xstream.annotations.XStreamConverter; | |||
import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter; | |||
import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter; | |||
@XStreamAlias("xml") | |||
public class WxMpXmlOutTransferCustomerServiceMessage extends WxMpXmlOutMessage { | |||
@XStreamAlias("TransInfo") | |||
protected final TransInfo transInfo = new TransInfo(); | |||
public WxMpXmlOutTransferCustomerServiceMessage() { | |||
this.msgType = WxConsts.CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE; | |||
} | |||
public String getKfAccount() { | |||
return transInfo.getKfAccount(); | |||
} | |||
public void setKfAccount(String kfAccount) { | |||
transInfo.setKfAccount(kfAccount); | |||
} | |||
@XStreamAlias("TransInfo") | |||
public static class TransInfo { | |||
@XStreamAlias("KfAccount") | |||
@XStreamConverter(value=XStreamCDataConverter.class) | |||
private String kfAccount; | |||
public String getKfAccount() { | |||
return kfAccount; | |||
} | |||
public void setKfAccount(String kfAccount) { | |||
this.kfAccount = kfAccount; | |||
} | |||
} | |||
} |
@@ -0,0 +1,28 @@ | |||
package me.chanjar.weixin.mp.bean.outxmlbuilder; | |||
import me.chanjar.weixin.mp.bean.WxMpXmlOutTransferCustomerServiceMessage; | |||
/** | |||
* 客服消息builder | |||
* <pre> | |||
* 用法: WxMpCustomMessage m = WxMpCustomMessage.TRANSFER_CUSTOMER_SERVICE().content(...).toUser(...).build(); | |||
* </pre> | |||
* | |||
* @author chanjarster | |||
*/ | |||
public final class TransferCustomerServiceBuilder extends BaseBuilder<TransferCustomerServiceBuilder, WxMpXmlOutTransferCustomerServiceMessage> { | |||
private String kfAccount; | |||
public TransferCustomerServiceBuilder kfAccount(String kfAccount) { | |||
this.kfAccount = kfAccount; | |||
return this; | |||
} | |||
public WxMpXmlOutTransferCustomerServiceMessage build() { | |||
WxMpXmlOutTransferCustomerServiceMessage m = new WxMpXmlOutTransferCustomerServiceMessage(); | |||
setCommon(m); | |||
m.setKfAccount(kfAccount); | |||
return m; | |||
} | |||
} |
@@ -0,0 +1,279 @@ | |||
package me.chanjar.weixin.mp.bean.result; | |||
import java.io.Serializable; | |||
/** | |||
* pre> 订单支付状态回调 | |||
* | |||
* 支付结果通知(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7) | |||
* | |||
* /pre> | |||
* | |||
* @author ukid | |||
*/ | |||
public class WxMpPayCallback implements Serializable { | |||
private String return_code; | |||
private String return_msg; | |||
private String appid; | |||
private String mch_id; | |||
private String device_info; | |||
private String nonce_str; | |||
private String sign; | |||
private String result_code; | |||
private String err_code; | |||
private String err_code_des; | |||
private String openid; | |||
private String is_subscribe; | |||
private String trade_type; | |||
private String bank_type; | |||
private String total_fee; | |||
private String fee_type; | |||
private String cash_fee; | |||
private String cash_fee_type; | |||
private String coupon_fee; | |||
private String coupon_count; | |||
private String coupon_batch_id_$n; | |||
private String coupon_id_$n; | |||
private String coupon_fee_$n; | |||
private String transaction_id; | |||
private String out_trade_no; | |||
private String attach; | |||
private String time_end; | |||
public String getReturn_code() { | |||
return return_code; | |||
} | |||
public String getReturn_msg() { | |||
return return_msg; | |||
} | |||
public String getAppid() { | |||
return appid; | |||
} | |||
public String getMch_id() { | |||
return mch_id; | |||
} | |||
public String getDevice_info() { | |||
return device_info; | |||
} | |||
public String getNonce_str() { | |||
return nonce_str; | |||
} | |||
public String getSign() { | |||
return sign; | |||
} | |||
public String getResult_code() { | |||
return result_code; | |||
} | |||
public String getErr_code() { | |||
return err_code; | |||
} | |||
public String getErr_code_des() { | |||
return err_code_des; | |||
} | |||
public String getOpenid() { | |||
return openid; | |||
} | |||
public String getIs_subscribe() { | |||
return is_subscribe; | |||
} | |||
public String getTrade_type() { | |||
return trade_type; | |||
} | |||
public String getBank_type() { | |||
return bank_type; | |||
} | |||
public String getTotal_fee() { | |||
return total_fee; | |||
} | |||
public String getFee_type() { | |||
return fee_type; | |||
} | |||
public String getCash_fee() { | |||
return cash_fee; | |||
} | |||
public String getCash_fee_type() { | |||
return cash_fee_type; | |||
} | |||
public String getCoupon_fee() { | |||
return coupon_fee; | |||
} | |||
public String getCoupon_count() { | |||
return coupon_count; | |||
} | |||
public String getCoupon_batch_id_$n() { | |||
return coupon_batch_id_$n; | |||
} | |||
public String getCoupon_id_$n() { | |||
return coupon_id_$n; | |||
} | |||
public String getCoupon_fee_$n() { | |||
return coupon_fee_$n; | |||
} | |||
public String getTransaction_id() { | |||
return transaction_id; | |||
} | |||
public String getOut_trade_no() { | |||
return out_trade_no; | |||
} | |||
public String getAttach() { | |||
return attach; | |||
} | |||
public String getTime_end() { | |||
return time_end; | |||
} | |||
public void setReturn_code(String return_code) { | |||
this.return_code = return_code; | |||
} | |||
public void setReturn_msg(String return_msg) { | |||
this.return_msg = return_msg; | |||
} | |||
public void setAppid(String appid) { | |||
this.appid = appid; | |||
} | |||
public void setMch_id(String mch_id) { | |||
this.mch_id = mch_id; | |||
} | |||
public void setDevice_info(String device_info) { | |||
this.device_info = device_info; | |||
} | |||
public void setNonce_str(String nonce_str) { | |||
this.nonce_str = nonce_str; | |||
} | |||
public void setSign(String sign) { | |||
this.sign = sign; | |||
} | |||
public void setResult_code(String result_code) { | |||
this.result_code = result_code; | |||
} | |||
public void setErr_code(String err_code) { | |||
this.err_code = err_code; | |||
} | |||
public void setErr_code_des(String err_code_des) { | |||
this.err_code_des = err_code_des; | |||
} | |||
public void setOpenid(String openid) { | |||
this.openid = openid; | |||
} | |||
public void setIs_subscribe(String is_subscribe) { | |||
this.is_subscribe = is_subscribe; | |||
} | |||
public void setTrade_type(String trade_type) { | |||
this.trade_type = trade_type; | |||
} | |||
public void setBank_type(String bank_type) { | |||
this.bank_type = bank_type; | |||
} | |||
public void setTotal_fee(String total_fee) { | |||
this.total_fee = total_fee; | |||
} | |||
public void setFee_type(String fee_type) { | |||
this.fee_type = fee_type; | |||
} | |||
public void setCash_fee(String cash_fee) { | |||
this.cash_fee = cash_fee; | |||
} | |||
public void setCash_fee_type(String cash_fee_type) { | |||
this.cash_fee_type = cash_fee_type; | |||
} | |||
public void setCoupon_fee(String coupon_fee) { | |||
this.coupon_fee = coupon_fee; | |||
} | |||
public void setCoupon_count(String coupon_count) { | |||
this.coupon_count = coupon_count; | |||
} | |||
public void setCoupon_batch_id_$n(String coupon_batch_id_$n) { | |||
this.coupon_batch_id_$n = coupon_batch_id_$n; | |||
} | |||
public void setCoupon_id_$n(String coupon_id_$n) { | |||
this.coupon_id_$n = coupon_id_$n; | |||
} | |||
public void setCoupon_fee_$n(String coupon_fee_$n) { | |||
this.coupon_fee_$n = coupon_fee_$n; | |||
} | |||
public void setTransaction_id(String transaction_id) { | |||
this.transaction_id = transaction_id; | |||
} | |||
public void setOut_trade_no(String out_trade_no) { | |||
this.out_trade_no = out_trade_no; | |||
} | |||
public void setAttach(String attach) { | |||
this.attach = attach; | |||
} | |||
public void setTime_end(String time_end) { | |||
this.time_end = time_end; | |||
} | |||
@Override | |||
public String toString() { | |||
return "WxMpPayCallback [return_code=" + return_code + ", return_msg=" | |||
+ return_msg + ", appid=" + appid + ", mch_id=" + mch_id | |||
+ ", device_info=" + device_info + ", nonce_str=" + nonce_str | |||
+ ", sign=" + sign + ", result_code=" + result_code | |||
+ ", err_code=" + err_code + ", err_code_des=" + err_code_des | |||
+ ", openid=" + openid + ", is_subscribe=" + is_subscribe | |||
+ ", trade_type=" + trade_type + ", bank_type=" + bank_type | |||
+ ", total_fee=" + total_fee + ", fee_type=" + fee_type | |||
+ ", cash_fee=" + cash_fee + ", cash_fee_type=" + cash_fee_type | |||
+ ", coupon_fee=" + coupon_fee + ", coupon_count=" | |||
+ coupon_count + ", coupon_batch_id_$n=" + coupon_batch_id_$n | |||
+ ", coupon_id_$n=" + coupon_id_$n + ", coupon_fee_$n=" | |||
+ coupon_fee_$n + ", transaction_id=" + transaction_id | |||
+ ", out_trade_no=" + out_trade_no + ", attach=" + attach | |||
+ ", time_end=" + time_end + "]"; | |||
} | |||
} |
@@ -0,0 +1,215 @@ | |||
package me.chanjar.weixin.mp.bean.result; | |||
import java.io.Serializable; | |||
/** | |||
* <pre> | |||
* 查询订单支付状态返回的结果 | |||
* | |||
* 查询订单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2) | |||
* | |||
* </pre> | |||
* | |||
* @author ukid | |||
*/ | |||
public class WxMpPayResult implements Serializable { | |||
private String return_code; | |||
private String return_msg; | |||
private String appid; | |||
private String mch_id; | |||
private String nonce_str; | |||
private String sign; | |||
private String result_code; | |||
private String err_code; | |||
private String err_code_des; | |||
private String trade_state; | |||
private String device_info; | |||
private String openid; | |||
private String is_subscribe; | |||
private String trade_type; | |||
private String bank_type; | |||
private String total_fee; | |||
private String coupon_fee; | |||
private String fee_type; | |||
private String transaction_id; | |||
private String out_trade_no; | |||
private String attach; | |||
private String time_end; | |||
public String getReturn_code() { | |||
return return_code; | |||
} | |||
public String getReturn_msg() { | |||
return return_msg; | |||
} | |||
public String getAppid() { | |||
return appid; | |||
} | |||
public String getMch_id() { | |||
return mch_id; | |||
} | |||
public String getNonce_str() { | |||
return nonce_str; | |||
} | |||
public String getSign() { | |||
return sign; | |||
} | |||
public String getResult_code() { | |||
return result_code; | |||
} | |||
public String getErr_code() { | |||
return err_code; | |||
} | |||
public String getErr_code_des() { | |||
return err_code_des; | |||
} | |||
public String getTrade_state() { | |||
return trade_state; | |||
} | |||
public String getDevice_info() { | |||
return device_info; | |||
} | |||
public String getOpenid() { | |||
return openid; | |||
} | |||
public String getIs_subscribe() { | |||
return is_subscribe; | |||
} | |||
public String getTrade_type() { | |||
return trade_type; | |||
} | |||
public String getBank_type() { | |||
return bank_type; | |||
} | |||
public String getTotal_fee() { | |||
return total_fee; | |||
} | |||
public String getCoupon_fee() { | |||
return coupon_fee; | |||
} | |||
public String getFee_type() { | |||
return fee_type; | |||
} | |||
public String getTransaction_id() { | |||
return transaction_id; | |||
} | |||
public String getOut_trade_no() { | |||
return out_trade_no; | |||
} | |||
public String getAttach() { | |||
return attach; | |||
} | |||
public String getTime_end() { | |||
return time_end; | |||
} | |||
public void setReturn_code(String return_code) { | |||
this.return_code = return_code; | |||
} | |||
public void setReturn_msg(String return_msg) { | |||
this.return_msg = return_msg; | |||
} | |||
public void setAppid(String appid) { | |||
this.appid = appid; | |||
} | |||
public void setMch_id(String mch_id) { | |||
this.mch_id = mch_id; | |||
} | |||
public void setNonce_str(String nonce_str) { | |||
this.nonce_str = nonce_str; | |||
} | |||
public void setSign(String sign) { | |||
this.sign = sign; | |||
} | |||
public void setResult_code(String result_code) { | |||
this.result_code = result_code; | |||
} | |||
public void setErr_code(String err_code) { | |||
this.err_code = err_code; | |||
} | |||
public void setErr_code_des(String err_code_des) { | |||
this.err_code_des = err_code_des; | |||
} | |||
public void setTrade_state(String trade_state) { | |||
this.trade_state = trade_state; | |||
} | |||
public void setDevice_info(String device_info) { | |||
this.device_info = device_info; | |||
} | |||
public void setOpenid(String openid) { | |||
this.openid = openid; | |||
} | |||
public void setIs_subscribe(String is_subscribe) { | |||
this.is_subscribe = is_subscribe; | |||
} | |||
public void setTrade_type(String trade_type) { | |||
this.trade_type = trade_type; | |||
} | |||
public void setBank_type(String bank_type) { | |||
this.bank_type = bank_type; | |||
} | |||
public void setTotal_fee(String total_fee) { | |||
this.total_fee = total_fee; | |||
} | |||
public void setCoupon_fee(String coupon_fee) { | |||
this.coupon_fee = coupon_fee; | |||
} | |||
public void setFee_type(String fee_type) { | |||
this.fee_type = fee_type; | |||
} | |||
public void setTransaction_id(String transaction_id) { | |||
this.transaction_id = transaction_id; | |||
} | |||
public void setOut_trade_no(String out_trade_no) { | |||
this.out_trade_no = out_trade_no; | |||
} | |||
public void setAttach(String attach) { | |||
this.attach = attach; | |||
} | |||
public void setTime_end(String time_end) { | |||
this.time_end = time_end; | |||
} | |||
} |
@@ -4,10 +4,9 @@ import java.io.Serializable; | |||
/** | |||
* <pre> | |||
* 群发消息一发送就返回的结果 | |||
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"返回的结果 | |||
* | |||
* 真正的群发消息是否发送成功要看 | |||
* http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口#.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81.E7.BE.A4.E5.8F.91.E7.BB.93.E6.9E.9C | |||
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1) | |||
* | |||
* </pre> | |||
* | |||
@@ -1,10 +1,10 @@ | |||
package me.chanjar.weixin.mp.util.http; | |||
import com.google.gson.Gson; | |||
import me.chanjar.weixin.common.bean.result.WxError; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
import me.chanjar.weixin.common.util.http.RequestExecutor; | |||
import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; | |||
import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||
import org.apache.http.HttpHost; | |||
import org.apache.http.client.ClientProtocolException; | |||
import org.apache.http.client.config.RequestConfig; | |||
@@ -31,9 +31,9 @@ public class MaterialDeleteRequestExecutor implements RequestExecutor<Boolean, S | |||
httpPost.setConfig(config); | |||
} | |||
Map<String, String> params = new HashMap<String, String>(); | |||
Map<String, String> params = new HashMap<>(); | |||
params.put("media_id", materialId); | |||
httpPost.setEntity(new StringEntity(new Gson().toJson(params))); | |||
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params))); | |||
CloseableHttpResponse response = httpclient.execute(httpPost); | |||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); | |||
WxError error = WxError.fromJson(responseContent); | |||
@@ -1,10 +1,10 @@ | |||
package me.chanjar.weixin.mp.util.http; | |||
import com.google.gson.Gson; | |||
import me.chanjar.weixin.common.bean.result.WxError; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
import me.chanjar.weixin.common.util.http.RequestExecutor; | |||
import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; | |||
import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.mp.bean.WxMpMaterialNews; | |||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
import org.apache.http.HttpHost; | |||
@@ -32,9 +32,9 @@ public class MaterialNewsInfoRequestExecutor implements RequestExecutor<WxMpMate | |||
httpPost.setConfig(config); | |||
} | |||
Map<String, String> params = new HashMap<String, String>(); | |||
Map<String, String> params = new HashMap<>(); | |||
params.put("media_id", materialId); | |||
httpPost.setEntity(new StringEntity(new Gson().toJson(params))); | |||
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params))); | |||
CloseableHttpResponse response = httpclient.execute(httpPost); | |||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); | |||
WxError error = WxError.fromJson(responseContent); | |||
@@ -1,10 +1,10 @@ | |||
package me.chanjar.weixin.mp.util.http; | |||
import com.google.gson.Gson; | |||
import me.chanjar.weixin.common.bean.result.WxError; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
import me.chanjar.weixin.common.util.http.RequestExecutor; | |||
import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; | |||
import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.mp.bean.WxMpMaterial; | |||
import me.chanjar.weixin.mp.bean.result.WxMpMaterialUploadResult; | |||
import org.apache.http.HttpHost; | |||
@@ -39,7 +39,7 @@ public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMateri | |||
multipartEntityBuilder.addPart("media", new InputStreamBody(bufferedInputStream, material.getName())); | |||
Map<String, String> form = material.getForm(); | |||
if (material.getForm() != null) { | |||
multipartEntityBuilder.addTextBody("description", new Gson().toJson(form)); | |||
multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form)); | |||
} | |||
httpPost.setEntity(multipartEntityBuilder.build()); | |||
httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString()); | |||
@@ -1,10 +1,10 @@ | |||
package me.chanjar.weixin.mp.util.http; | |||
import com.google.gson.Gson; | |||
import me.chanjar.weixin.common.bean.result.WxError; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
import me.chanjar.weixin.common.util.http.RequestExecutor; | |||
import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; | |||
import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.mp.bean.result.WxMpMaterialVideoInfoResult; | |||
import org.apache.http.HttpHost; | |||
import org.apache.http.client.ClientProtocolException; | |||
@@ -31,9 +31,9 @@ public class MaterialVideoInfoRequestExecutor implements RequestExecutor<WxMpMat | |||
httpPost.setConfig(config); | |||
} | |||
Map<String, String> params = new HashMap<String, String>(); | |||
Map<String, String> params = new HashMap<>(); | |||
params.put("media_id", materialId); | |||
httpPost.setEntity(new StringEntity(new Gson().toJson(params))); | |||
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params))); | |||
CloseableHttpResponse response = httpclient.execute(httpPost); | |||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); | |||
WxError error = WxError.fromJson(responseContent); | |||
@@ -1,10 +1,10 @@ | |||
package me.chanjar.weixin.mp.util.http; | |||
import com.google.gson.Gson; | |||
import me.chanjar.weixin.common.bean.result.WxError; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
import me.chanjar.weixin.common.util.http.InputStreamResponseHandler; | |||
import me.chanjar.weixin.common.util.http.RequestExecutor; | |||
import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||
import org.apache.commons.io.IOUtils; | |||
import org.apache.http.HttpHost; | |||
import org.apache.http.client.ClientProtocolException; | |||
@@ -41,9 +41,9 @@ public class MaterialVoiceAndImageDownloadRequestExecutor implements RequestExec | |||
httpPost.setConfig(config); | |||
} | |||
Map<String, String> params = new HashMap<String, String>(); | |||
Map<String, String> params = new HashMap<>(); | |||
params.put("media_id", materialId); | |||
httpPost.setEntity(new StringEntity(new Gson().toJson(params))); | |||
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params))); | |||
CloseableHttpResponse response = httpclient.execute(httpPost); | |||
// 下载媒体文件出错 | |||
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response); | |||
@@ -51,7 +51,7 @@ public class MaterialVoiceAndImageDownloadRequestExecutor implements RequestExec | |||
String responseContentString = new String(responseContent, "UTF-8"); | |||
if (responseContentString.length() < 100) { | |||
try { | |||
WxError wxError = new Gson().fromJson(responseContentString, WxError.class); | |||
WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class); | |||
if (wxError.getErrorCode() != 0) { | |||
throw new WxErrorException(wxError); | |||
} | |||
@@ -29,7 +29,7 @@ public class WxMpMaterialFileBatchGetGsonAdapter implements JsonDeserializer<WxM | |||
} | |||
if (json.get("item") != null && !json.get("item").isJsonNull()) { | |||
JsonArray item = json.getAsJsonArray("item"); | |||
List<WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem> items = new ArrayList<WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem>(); | |||
List<WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem> items = new ArrayList<>(); | |||
for (JsonElement anItem : item) { | |||
JsonObject articleInfo = anItem.getAsJsonObject(); | |||
items.add(WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem.class)); | |||
@@ -32,6 +32,9 @@ public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer<WxMpMa | |||
articleJson.addProperty("digest", article.getDigest()); | |||
} | |||
articleJson.addProperty("show_cover_pic", article.isShowCoverPic() ? "1" : "0"); | |||
if (null != article.getUrl()) { | |||
articleJson.addProperty("url", article.getUrl()); | |||
} | |||
return articleJson; | |||
} | |||
@@ -67,6 +70,10 @@ public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer<WxMpMa | |||
if (showCoverPic != null && !showCoverPic.isJsonNull()) { | |||
article.setShowCoverPic(GsonHelper.getAsBoolean(showCoverPic)); | |||
} | |||
JsonElement url = articleInfo.get("url"); | |||
if (url != null && !url.isJsonNull()) { | |||
article.setUrl(GsonHelper.getAsString(url)); | |||
} | |||
return article; | |||
} | |||
} |
@@ -29,7 +29,7 @@ public class WxMpMaterialNewsBatchGetGsonAdapter implements JsonDeserializer<WxM | |||
} | |||
if (json.get("item") != null && !json.get("item").isJsonNull()) { | |||
JsonArray item = json.getAsJsonArray("item"); | |||
List<WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem> items = new ArrayList<WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem>(); | |||
List<WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem> items = new ArrayList<>(); | |||
for (JsonElement anItem : item) { | |||
JsonObject articleInfo = anItem.getAsJsonObject(); | |||
items.add(WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem.class)); | |||
@@ -31,7 +31,7 @@ public class WxMpMaterialAPITest { | |||
@Inject | |||
protected WxMpServiceImpl wxService; | |||
private Map<String, Map<String, Object>> media_ids = new LinkedHashMap<String, Map<String, Object>>(); | |||
private Map<String, Map<String, Object>> media_ids = new LinkedHashMap<>(); | |||
// 缩略图的id,测试上传图文使用 | |||
private String thumbMediaId = ""; | |||
// 单图文消息media_id | |||
@@ -64,7 +64,7 @@ public class WxMpMaterialAPITest { | |||
thumbMediaId = res.getMediaId(); | |||
} | |||
Map<String, Object> materialInfo = new HashMap<String, Object>(); | |||
Map<String, Object> materialInfo = new HashMap<>(); | |||
materialInfo.put("media_id", res.getMediaId()); | |||
materialInfo.put("length", tempFile.length()); | |||
materialInfo.put("filename", tempFile.getName()); | |||
@@ -195,7 +195,7 @@ public class WxMpMaterialAPITest { | |||
@Test(dependsOnMethods = {"testUpdateNewsInfo"}) | |||
public void testMaterialNewsList() throws WxErrorException { | |||
WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = wxService.materialNewsBatchGet(WxConsts.MATERIAL_NEWS, 0, 20); | |||
WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = wxService.materialNewsBatchGet(0, 20); | |||
return; | |||
} | |||
@@ -217,8 +217,8 @@ public class WxMpMaterialAPITest { | |||
public Object[][] downloadMaterial() { | |||
Object[][] params = new Object[this.media_ids.size()][]; | |||
int index = 0; | |||
for (Iterator<String> iterator = this.media_ids.keySet().iterator(); iterator.hasNext(); ) { | |||
params[index] = new Object[]{iterator.next()}; | |||
for (String mediaId : this.media_ids.keySet()) { | |||
params[index] = new Object[]{mediaId}; | |||
index++; | |||
} | |||
return params; | |||
@@ -226,9 +226,9 @@ public class WxMpMaterialAPITest { | |||
@DataProvider | |||
public Iterator<Object[]> allTestMaterial() { | |||
List<Object[]> params = new ArrayList<Object[]>(); | |||
for (Iterator<String> iterator = this.media_ids.keySet().iterator(); iterator.hasNext(); ) { | |||
params.add(new Object[]{iterator.next()}); | |||
List<Object[]> params = new ArrayList<>(); | |||
for (String mediaId : this.media_ids.keySet()) { | |||
params.add(new Object[]{mediaId}); | |||
} | |||
params.add(new Object[]{this.singleNewsMediaId}); | |||
params.add(new Object[]{this.multiNewsMediaId}); | |||