切分weixin.properties
This commit is contained in:
+12
-6
@@ -6,7 +6,7 @@ tencent weixin platform java sdk 微信公众平台开发工具包 http://mp.wei
|
||||
功能列表
|
||||
-------
|
||||
|
||||
* TokenApi token实现API
|
||||
* TokenHolder token的实现
|
||||
|
||||
* MediaApi 上传/下载媒体文件API
|
||||
|
||||
@@ -34,16 +34,16 @@ tencent weixin platform java sdk 微信公众平台开发工具包 http://mp.wei
|
||||
|
||||
1.编辑weixin.properties文件,填入appid/appsecret信息,当然也可通过构造函数传入.
|
||||
|
||||
2.实例化一个WeixinProxy对象,如无特别指明appid/appsecret则使用weixin.properties中的值.
|
||||
2.实例化一个WeixinProxy对象,调用API.
|
||||
|
||||
WeixinProxy weixinProxy = new WeixinProxy();
|
||||
// weixinProxy = new WeixinProxy(appid,appsecret);
|
||||
weixinProxy.getUser(openId);
|
||||
|
||||
3.针对token存储有两种方案,File存储/Redis存储,当然也可自己实现TokenApi,如无特别指明默认使用文件(xml)的方式保存token,如果环境中支持redis,建议使用RedisTokenApi.
|
||||
3.针对token存储有两种方案,File存储/Redis存储,当然也可自己实现TokenHolder(继承AbstractTokenHolder类并重写getToken方法),默认使用文件(xml)的方式保存token,如果环境中支持redis,建议使用RedisTokenHolder.
|
||||
|
||||
WeixinProxy weixinProxy = new WeixinProxy(new RedisTokenApi());
|
||||
// weixinProxy = new WeixinProxy(new RedisTokenApi(appid,appsecret));
|
||||
WeixinProxy weixinProxy = new WeixinProxy(new RedisTokenHolder());
|
||||
// weixinProxy = new WeixinProxy(new RedisTokenHolder(appid,appsecret));
|
||||
|
||||
4.mvn package,得到一个zip的压缩包,解压到启动目录(见src/main/startup.sh/APP_HOME)
|
||||
|
||||
@@ -60,4 +60,10 @@ tencent weixin platform java sdk 微信公众平台开发工具包 http://mp.wei
|
||||
|
||||
* 2014-10-28
|
||||
|
||||
1).调整ActionMapping抽象化
|
||||
1).调整ActionMapping抽象化
|
||||
|
||||
* 2014-10-31
|
||||
|
||||
1).weixin.properties切分为API调用地址/公众号信息两部分
|
||||
|
||||
2).TokenApi重命名为TokenHolder
|
||||
@@ -1 +0,0 @@
|
||||
所有的API调用入口类
|
||||
@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.BaseResult;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccountV2;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccountV3;
|
||||
import com.foxinmy.weixin4j.mp.api.GroupApi;
|
||||
import com.foxinmy.weixin4j.mp.api.HelperApi;
|
||||
import com.foxinmy.weixin4j.mp.api.MassApi;
|
||||
@@ -29,10 +30,10 @@ import com.foxinmy.weixin4j.mp.model.UserToken;
|
||||
import com.foxinmy.weixin4j.mp.msg.model.Article;
|
||||
import com.foxinmy.weixin4j.mp.msg.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.mp.msg.notify.BaseNotify;
|
||||
import com.foxinmy.weixin4j.mp.payment.Order;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.Order;
|
||||
import com.foxinmy.weixin4j.mp.response.TemplateMessage;
|
||||
import com.foxinmy.weixin4j.token.FileTokenApi;
|
||||
import com.foxinmy.weixin4j.token.TokenApi;
|
||||
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
|
||||
/**
|
||||
@@ -60,7 +61,7 @@ public class WeixinProxy {
|
||||
* 默认采用文件存放Token跟配置文件中的appi信息
|
||||
*/
|
||||
public WeixinProxy() {
|
||||
this(new FileTokenApi());
|
||||
this(new FileTokenHolder());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,10 +71,10 @@ public class WeixinProxy {
|
||||
* @param appsecret
|
||||
*/
|
||||
public WeixinProxy(String appid, String appsecret) {
|
||||
this(new FileTokenApi(appid, appsecret));
|
||||
this(new FileTokenHolder(appid, appsecret));
|
||||
}
|
||||
|
||||
public WeixinProxy(TokenApi tokenApi) {
|
||||
public WeixinProxy(TokenHolder tokenApi) {
|
||||
this.mediaApi = new MediaApi(tokenApi);
|
||||
this.notifyApi = new NotifyApi(tokenApi);
|
||||
this.massApi = new MassApi(tokenApi);
|
||||
@@ -749,4 +750,36 @@ public class WeixinProxy {
|
||||
public Order orderQuery(WeixinAccountV2 weixinConfig, String orderNo)
|
||||
throws WeixinException {
|
||||
return payApi.orderQuery(weixinConfig, orderNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 维权处理
|
||||
*
|
||||
* @param openId
|
||||
* 用户ID
|
||||
* @param feedbackId
|
||||
* 维权单号
|
||||
* @return
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public BaseResult updateFeedback(String openId, String feedbackId)
|
||||
throws WeixinException {
|
||||
return payApi.updateFeedback(openId, feedbackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* native支付URL转短链接
|
||||
*
|
||||
* @param weixinConfig
|
||||
* 商户配置
|
||||
* @param url
|
||||
* native支付URL
|
||||
* @return 转换后的短链接
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String getShorturl(WeixinAccountV3 weixinConfig, String url)
|
||||
throws WeixinException {
|
||||
return payApi.getShorturl(weixinConfig, url);
|
||||
}
|
||||
|
||||
@@ -30,9 +30,7 @@ public abstract class AbstractAction<M extends BaseMessage> implements
|
||||
BaseMessage message = MessageUtil.xml2msg(msg);
|
||||
if (message == null) {
|
||||
Class<M> messageClass = getGenericType();
|
||||
XStream xstream = new XStream();
|
||||
xstream.ignoreUnknownElements();
|
||||
xstream.autodetectAnnotations(true);
|
||||
XStream xstream = XStream.get();
|
||||
xstream.processAnnotations(messageClass);
|
||||
xstream.alias("xml", messageClass);
|
||||
return execute(xstream.fromXML(msg, messageClass)).toXml();
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
package com.foxinmy.weixin4j.mp.api;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.foxinmy.weixin4j.http.HttpRequest;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -12,4 +19,26 @@ import com.foxinmy.weixin4j.http.HttpRequest;
|
||||
*/
|
||||
public class BaseApi {
|
||||
protected final HttpRequest request = new HttpRequest();
|
||||
protected final XStream xStream = XStream.get();
|
||||
protected final Charset utf8 = StandardCharsets.UTF_8;
|
||||
private final static ResourceBundle weixinBundle;
|
||||
static {
|
||||
weixinBundle = ResourceBundle
|
||||
.getBundle("com/foxinmy/weixin4j/mp/api/weixin");
|
||||
}
|
||||
|
||||
protected String getRequestUri(String key) {
|
||||
String url = weixinBundle.getString(key);
|
||||
Pattern p = Pattern.compile("(\\{[^\\}]*\\})");
|
||||
Matcher m = p.matcher(url);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String sub = null;
|
||||
while (m.find()) {
|
||||
sub = m.group();
|
||||
m.appendReplacement(sb,
|
||||
getRequestUri(sub.substring(1, sub.length() - 1)));
|
||||
}
|
||||
m.appendTail(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@ import com.foxinmy.weixin4j.http.BaseResult;
|
||||
import com.foxinmy.weixin4j.http.Response;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.model.Group;
|
||||
import com.foxinmy.weixin4j.token.TokenApi;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
|
||||
/**
|
||||
* 分组相关API
|
||||
@@ -24,8 +23,8 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
*/
|
||||
public class GroupApi extends BaseApi {
|
||||
|
||||
private final TokenApi tokenApi;
|
||||
public GroupApi(TokenApi tokenApi) {
|
||||
private final TokenHolder tokenApi;
|
||||
public GroupApi(TokenHolder tokenApi) {
|
||||
this.tokenApi = tokenApi;
|
||||
}
|
||||
|
||||
@@ -42,7 +41,7 @@ public class GroupApi extends BaseApi {
|
||||
* @see com.foxinmy.weixin4j.mp.model.Group#toCreateJson()
|
||||
*/
|
||||
public Group createGroup(String name) throws WeixinException {
|
||||
String group_create_uri = ConfigUtil.getValue("group_create_uri");
|
||||
String group_create_uri = getRequestUri("group_create_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Group group = new Group(name);
|
||||
Response response = request.post(
|
||||
@@ -62,7 +61,7 @@ public class GroupApi extends BaseApi {
|
||||
* @see com.foxinmy.weixin4j.mp.model.Group
|
||||
*/
|
||||
public List<Group> getGroups() throws WeixinException {
|
||||
String group_get_uri = ConfigUtil.getValue("group_get_uri");
|
||||
String group_get_uri = getRequestUri("group_get_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Response response = request.get(String.format(group_get_uri,
|
||||
token.getAccessToken()));
|
||||
@@ -83,7 +82,7 @@ public class GroupApi extends BaseApi {
|
||||
* @see com.foxinmy.weixin4j.mp.model.Group
|
||||
*/
|
||||
public int getGroupByOpenId(String openId) throws WeixinException {
|
||||
String group_getid_uri = ConfigUtil.getValue("group_getid_uri");
|
||||
String group_getid_uri = getRequestUri("group_getid_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Response response = request.post(
|
||||
String.format(group_getid_uri, token.getAccessToken()),
|
||||
@@ -107,7 +106,7 @@ public class GroupApi extends BaseApi {
|
||||
*/
|
||||
public BaseResult modifyGroup(int groupId, String name)
|
||||
throws WeixinException {
|
||||
String group_modify_uri = ConfigUtil.getValue("group_modify_uri");
|
||||
String group_modify_uri = getRequestUri("group_modify_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Group group = new Group(groupId, name);
|
||||
|
||||
@@ -131,7 +130,7 @@ public class GroupApi extends BaseApi {
|
||||
*/
|
||||
public BaseResult moveGroup(String openId, int groupId)
|
||||
throws WeixinException {
|
||||
String group_move_uri = ConfigUtil.getValue("group_move_uri");
|
||||
String group_move_uri = getRequestUri("group_move_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Response response = request.post(String.format(group_move_uri,
|
||||
token.getAccessToken()), String.format(
|
||||
|
||||
@@ -4,8 +4,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.Response;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.token.TokenApi;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
|
||||
/**
|
||||
* 辅助相关API
|
||||
@@ -17,12 +16,13 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
* @see
|
||||
*/
|
||||
public class HelperApi extends BaseApi {
|
||||
|
||||
private final TokenApi tokenApi;
|
||||
public HelperApi(TokenApi tokenApi){
|
||||
|
||||
private final TokenHolder tokenApi;
|
||||
|
||||
public HelperApi(TokenHolder tokenApi) {
|
||||
this.tokenApi = tokenApi;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 长链接转短链接
|
||||
*
|
||||
@@ -33,13 +33,15 @@ public class HelperApi extends BaseApi {
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E9%95%BF%E9%93%BE%E6%8E%A5%E8%BD%AC%E7%9F%AD%E9%93%BE%E6%8E%A5%E6%8E%A5%E5%8F%A3">长链接转短链接</a>
|
||||
*/
|
||||
public String getShorturl(String url) throws WeixinException {
|
||||
String shorturl_uri = ConfigUtil.getValue("shorturl_uri");
|
||||
String shorturl_uri = getRequestUri("shorturl_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("action", "long2short");
|
||||
obj.put("long_url", url);
|
||||
Response response = request.post(String.format(shorturl_uri, token.getAccessToken()), obj.toJSONString());
|
||||
|
||||
Response response = request.post(
|
||||
String.format(shorturl_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
|
||||
return response.getAsJson().getString("short_url");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,8 @@ import com.foxinmy.weixin4j.http.BaseResult;
|
||||
import com.foxinmy.weixin4j.http.Response;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.model.MpArticle;
|
||||
import com.foxinmy.weixin4j.token.TokenApi;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
|
||||
/**
|
||||
* 群发相关API
|
||||
@@ -26,9 +25,9 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
*/
|
||||
public class MassApi extends BaseApi {
|
||||
|
||||
private final TokenApi tokenApi;
|
||||
private final TokenHolder tokenApi;
|
||||
|
||||
public MassApi(TokenApi tokenApi) {
|
||||
public MassApi(TokenHolder tokenApi) {
|
||||
this.tokenApi = tokenApi;
|
||||
}
|
||||
|
||||
@@ -47,7 +46,7 @@ public class MassApi extends BaseApi {
|
||||
*/
|
||||
public String uploadArticle(List<MpArticle> articles)
|
||||
throws WeixinException {
|
||||
String article_upload_uri = ConfigUtil.getValue("article_upload_uri");
|
||||
String article_upload_uri = getRequestUri("article_upload_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("articles", articles);
|
||||
@@ -75,7 +74,7 @@ public class MassApi extends BaseApi {
|
||||
*/
|
||||
public String uploadVideo(String mediaId, String title, String desc)
|
||||
throws WeixinException {
|
||||
String video_upload_uri = ConfigUtil.getValue("video_upload_uri");
|
||||
String video_upload_uri = getRequestUri("video_upload_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("media_id", mediaId);
|
||||
@@ -109,7 +108,7 @@ public class MassApi extends BaseApi {
|
||||
*/
|
||||
private String massByGroup(JSONObject jsonPara, String groupId)
|
||||
throws WeixinException {
|
||||
String mass_group_uri = ConfigUtil.getValue("mass_group_uri");
|
||||
String mass_group_uri = getRequestUri("mass_group_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Response response = request.post(
|
||||
String.format(mass_group_uri, token.getAccessToken()),
|
||||
@@ -133,7 +132,7 @@ public class MassApi extends BaseApi {
|
||||
*/
|
||||
private String massByOpenIds(JSONObject jsonPara, String... openIds)
|
||||
throws WeixinException {
|
||||
String mass_openid_uri = ConfigUtil.getValue("mass_openid_uri");
|
||||
String mass_openid_uri = getRequestUri("mass_openid_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Response response = request.post(
|
||||
String.format(mass_openid_uri, token.getAccessToken()),
|
||||
@@ -259,7 +258,7 @@ public class MassApi extends BaseApi {
|
||||
*/
|
||||
public BaseResult deleteMassNews(String msgid) throws WeixinException {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("msgid", msgid);
|
||||
obj.put("msgid", msgid);
|
||||
String mass_delete_uri = getRequestUri("mass_delete_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Response response = request.post(
|
||||
|
||||
@@ -11,9 +11,8 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.PartParameter;
|
||||
import com.foxinmy.weixin4j.http.Response;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.token.TokenApi;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.IOUtil;
|
||||
|
||||
/**
|
||||
@@ -29,9 +28,9 @@ import com.foxinmy.weixin4j.util.IOUtil;
|
||||
*/
|
||||
public class MediaApi extends BaseApi {
|
||||
|
||||
private final TokenApi tokenApi;
|
||||
private final TokenHolder tokenApi;
|
||||
|
||||
public MediaApi(TokenApi tokenApi) {
|
||||
public MediaApi(TokenHolder tokenApi) {
|
||||
this.tokenApi = tokenApi;
|
||||
}
|
||||
|
||||
@@ -74,7 +73,7 @@ public class MediaApi extends BaseApi {
|
||||
public String uploadMedia(String fileName, byte[] bytes, MediaType mediaType)
|
||||
throws WeixinException {
|
||||
Token token = tokenApi.getToken();
|
||||
String file_upload_uri = ConfigUtil.getValue("file_upload_uri");
|
||||
String file_upload_uri = getRequestUri("file_upload_uri");
|
||||
Response response = request.post(String.format(file_upload_uri,
|
||||
token.getAccessToken(), mediaType.name()), new PartParameter(
|
||||
"media", new ByteArrayBody(bytes, fileName)));
|
||||
@@ -101,7 +100,7 @@ public class MediaApi extends BaseApi {
|
||||
*/
|
||||
public File downloadMedia(String mediaId, MediaType mediaType)
|
||||
throws WeixinException, IOException {
|
||||
String media_path = ConfigUtil.getValue("media_path");
|
||||
String media_path = getRequestUri("media_path");
|
||||
byte[] datas = downloadMediaData(mediaId, mediaType);
|
||||
String filename = mediaId + "." + mediaType.getFormatType();
|
||||
File file = new File(media_path + File.separator + filename);
|
||||
@@ -133,7 +132,7 @@ public class MediaApi extends BaseApi {
|
||||
public byte[] downloadMediaData(String mediaId, MediaType mediaType)
|
||||
throws WeixinException {
|
||||
Token token = tokenApi.getToken();
|
||||
String file_download_uri = ConfigUtil.getValue("file_download_uri");
|
||||
String file_download_uri = getRequestUri("file_download_uri");
|
||||
Response response = request.get(String.format(file_download_uri,
|
||||
token.getAccessToken(), mediaId));
|
||||
|
||||
|
||||
@@ -9,8 +9,7 @@ import com.foxinmy.weixin4j.http.BaseResult;
|
||||
import com.foxinmy.weixin4j.http.Response;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.model.Button;
|
||||
import com.foxinmy.weixin4j.token.TokenApi;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
|
||||
/**
|
||||
* 菜单相关API
|
||||
@@ -23,9 +22,9 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
*/
|
||||
public class MenuApi extends BaseApi {
|
||||
|
||||
private final TokenApi tokenApi;
|
||||
private final TokenHolder tokenApi;
|
||||
|
||||
public MenuApi(TokenApi tokenApi) {
|
||||
public MenuApi(TokenHolder tokenApi) {
|
||||
this.tokenApi = tokenApi;
|
||||
}
|
||||
|
||||
@@ -39,7 +38,7 @@ public class MenuApi extends BaseApi {
|
||||
* @see com.foxinmy.weixin4j.mp.model.Button
|
||||
*/
|
||||
public BaseResult createMenu(List<Button> btnList) throws WeixinException {
|
||||
String menu_create_uri = ConfigUtil.getValue("menu_create_uri");
|
||||
String menu_create_uri = getRequestUri("menu_create_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("button", btnList);
|
||||
@@ -60,7 +59,7 @@ public class MenuApi extends BaseApi {
|
||||
* @see com.foxinmy.weixin4j.mp.model.Button
|
||||
*/
|
||||
public List<Button> getMenu() throws WeixinException {
|
||||
String menu_get_uri = ConfigUtil.getValue("menu_get_uri");
|
||||
String menu_get_uri = getRequestUri("menu_get_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Response response = request.get(String.format(menu_get_uri,
|
||||
token.getAccessToken()));
|
||||
@@ -79,7 +78,7 @@ public class MenuApi extends BaseApi {
|
||||
* @see com.foxinmy.weixin4j.mp.model.Button
|
||||
*/
|
||||
public BaseResult deleteMenu() throws WeixinException {
|
||||
String menu_delete_uri = ConfigUtil.getValue("menu_delete_uri");
|
||||
String menu_delete_uri = getRequestUri("menu_delete_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Response response = request.get(String.format(menu_delete_uri,
|
||||
token.getAccessToken()));
|
||||
|
||||
@@ -13,8 +13,7 @@ import com.foxinmy.weixin4j.mp.msg.model.Article;
|
||||
import com.foxinmy.weixin4j.mp.msg.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.mp.msg.notify.ArticleNotify;
|
||||
import com.foxinmy.weixin4j.mp.msg.notify.BaseNotify;
|
||||
import com.foxinmy.weixin4j.token.TokenApi;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
|
||||
/**
|
||||
* 客服相关API
|
||||
@@ -34,9 +33,9 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
*/
|
||||
public class NotifyApi extends BaseApi {
|
||||
|
||||
private final TokenApi tokenApi;
|
||||
private final TokenHolder tokenApi;
|
||||
|
||||
public NotifyApi(TokenApi tokenApi) {
|
||||
public NotifyApi(TokenHolder tokenApi) {
|
||||
this.tokenApi = tokenApi;
|
||||
}
|
||||
|
||||
@@ -50,7 +49,7 @@ public class NotifyApi extends BaseApi {
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF#.E5.8F.91.E9.80.81.E9.9F.B3.E4.B9.90.E6.B6.88.E6.81.AF">发送客服消息</a>
|
||||
*/
|
||||
private BaseResult sendNotify(String jsonPara) throws WeixinException {
|
||||
String custom_notify_uri = ConfigUtil.getValue("custom_notify_uri");
|
||||
String custom_notify_uri = getRequestUri("custom_notify_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Response response = request.post(
|
||||
String.format(custom_notify_uri, token.getAccessToken()),
|
||||
@@ -154,7 +153,7 @@ public class NotifyApi extends BaseApi {
|
||||
obj.put("endtime", endtime);
|
||||
obj.put("pagesize", pagesize > 1000 ? 1000 : pagesize);
|
||||
obj.put("pageindex", pageindex);
|
||||
String custom_record_uri = ConfigUtil.getValue("custom_record_uri");
|
||||
String custom_record_uri = getRequestUri("custom_record_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Response response = request.post(
|
||||
String.format(custom_record_uri, token.getAccessToken()),
|
||||
|
||||
@@ -10,8 +10,7 @@ import com.foxinmy.weixin4j.http.Response;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.model.QRParameter;
|
||||
import com.foxinmy.weixin4j.mp.model.QRParameter.QRType;
|
||||
import com.foxinmy.weixin4j.token.TokenApi;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
|
||||
/**
|
||||
* 二维码相关API
|
||||
@@ -25,9 +24,9 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
*/
|
||||
public class QrApi extends BaseApi {
|
||||
|
||||
private final TokenApi tokenApi;
|
||||
private final TokenHolder tokenApi;
|
||||
|
||||
public QrApi(TokenApi tokenApi) {
|
||||
public QrApi(TokenHolder tokenApi) {
|
||||
this.tokenApi = tokenApi;
|
||||
}
|
||||
|
||||
@@ -41,12 +40,12 @@ public class QrApi extends BaseApi {
|
||||
*/
|
||||
public byte[] getQRData(QRParameter parameter) throws WeixinException {
|
||||
Token token = tokenApi.getToken();
|
||||
String qr_uri = ConfigUtil.getValue("qr_ticket_uri");
|
||||
String qr_uri = getRequestUri("qr_ticket_uri");
|
||||
Response response = request.post(
|
||||
String.format(qr_uri, token.getAccessToken()),
|
||||
parameter.toJson());
|
||||
String ticket = response.getAsJson().getString("ticket");
|
||||
qr_uri = ConfigUtil.getValue("qr_image_uri");
|
||||
qr_uri = getRequestUri("qr_image_uri");
|
||||
response = request.get(String.format(qr_uri, ticket));
|
||||
|
||||
return response.getBody();
|
||||
@@ -90,7 +89,7 @@ public class QrApi extends BaseApi {
|
||||
*/
|
||||
public File getQR(QRParameter parameter) throws WeixinException,
|
||||
IOException {
|
||||
String qr_path = ConfigUtil.getValue("qr_path");
|
||||
String qr_path = getRequestUri("qr_path");
|
||||
String filename = String.format("%s_%d_%d.jpg", parameter.getQrType()
|
||||
.name(), parameter.getSceneId(), parameter.getExpireSeconds());
|
||||
File file = new File(qr_path + File.separator + filename);
|
||||
|
||||
@@ -5,8 +5,7 @@ import com.foxinmy.weixin4j.http.BaseResult;
|
||||
import com.foxinmy.weixin4j.http.Response;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.response.TemplateMessage;
|
||||
import com.foxinmy.weixin4j.token.TokenApi;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
|
||||
/**
|
||||
* 模板消息相关API
|
||||
@@ -19,9 +18,9 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
*/
|
||||
public class TmplApi extends BaseApi {
|
||||
|
||||
private final TokenApi tokenApi;
|
||||
private final TokenHolder tokenApi;
|
||||
|
||||
public TmplApi(TokenApi tokenApi) {
|
||||
public TmplApi(TokenHolder tokenApi) {
|
||||
this.tokenApi = tokenApi;
|
||||
}
|
||||
|
||||
@@ -39,7 +38,7 @@ public class TmplApi extends BaseApi {
|
||||
public BaseResult sendTmplMessage(TemplateMessage tplMessage)
|
||||
throws WeixinException {
|
||||
Token token = tokenApi.getToken();
|
||||
String template_send_uri = ConfigUtil.getValue("template_send_uri");
|
||||
String template_send_uri = getRequestUri("template_send_uri");
|
||||
Response response = request.post(
|
||||
String.format(template_send_uri, token.getAccessToken()),
|
||||
tplMessage.toJson());
|
||||
|
||||
@@ -12,8 +12,7 @@ import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.model.Following;
|
||||
import com.foxinmy.weixin4j.mp.model.User;
|
||||
import com.foxinmy.weixin4j.mp.model.UserToken;
|
||||
import com.foxinmy.weixin4j.token.TokenApi;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
|
||||
/**
|
||||
* 用户相关API
|
||||
@@ -26,9 +25,9 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
*/
|
||||
public class UserApi extends BaseApi {
|
||||
|
||||
private final TokenApi tokenApi;
|
||||
private final TokenHolder tokenApi;
|
||||
|
||||
public UserApi(TokenApi tokenApi) {
|
||||
public UserApi(TokenHolder tokenApi) {
|
||||
this.tokenApi = tokenApi;
|
||||
}
|
||||
|
||||
@@ -44,7 +43,7 @@ public class UserApi extends BaseApi {
|
||||
* @see com.foxinmy.weixin4j.mp.model.UserToken
|
||||
*/
|
||||
public UserToken getAccessToken(String code) throws WeixinException {
|
||||
String user_token_uri = ConfigUtil.getValue("sns_user_token_uri");
|
||||
String user_token_uri = getRequestUri("sns_user_token_uri");
|
||||
Response response = request.get(String.format(user_token_uri, code));
|
||||
|
||||
return response.getAsObject(UserToken.class);
|
||||
@@ -64,7 +63,7 @@ public class UserApi extends BaseApi {
|
||||
* {@link com.foxinmy.weixin4j.mp.api.UserApi#getAccessToken(String)}
|
||||
*/
|
||||
public User getUser(UserToken token) throws WeixinException {
|
||||
String user_info_uri = ConfigUtil.getValue("sns_user_info_uri");
|
||||
String user_info_uri = getRequestUri("sns_user_info_uri");
|
||||
Response response = request.get(String.format(user_info_uri,
|
||||
token.getAccessToken(), token.getOpenid()));
|
||||
|
||||
@@ -87,7 +86,7 @@ public class UserApi extends BaseApi {
|
||||
* @see com.foxinmy.weixin4j.mp.model.User
|
||||
*/
|
||||
public User getUser(String openId) throws WeixinException {
|
||||
String user_info_uri = ConfigUtil.getValue("api_user_info_uri");
|
||||
String user_info_uri = getRequestUri("api_user_info_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Response response = request.get(String.format(user_info_uri,
|
||||
token.getAccessToken(), openId));
|
||||
@@ -107,7 +106,7 @@ public class UserApi extends BaseApi {
|
||||
* @see com.foxinmy.weixin4j.mp.model.Following
|
||||
*/
|
||||
public Following getFollowing(String nextOpenId) throws WeixinException {
|
||||
String fllowing_uri = ConfigUtil.getValue("following_uri");
|
||||
String fllowing_uri = getRequestUri("following_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
Response response = request.get(String.format(fllowing_uri,
|
||||
token.getAccessToken(), nextOpenId == null ? "" : nextOpenId));
|
||||
@@ -168,7 +167,7 @@ public class UserApi extends BaseApi {
|
||||
*/
|
||||
public BaseResult remarkUserName(String openId, String remark)
|
||||
throws WeixinException {
|
||||
String updateremark_uri = ConfigUtil.getValue("updateremark_uri");
|
||||
String updateremark_uri = getRequestUri("updateremark_uri");
|
||||
Token token = tokenApi.getToken();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("openid", openId);
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
# api\u9996\u9875
|
||||
# http://mp.weixin.qq.com/wiki/index.php
|
||||
# \u63a5\u53e3\u8c03\u7528\u8bf4\u660e
|
||||
# http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E5%8F%A3%E9%A2%91%E7%8E%87%E9%99%90%E5%88%B6%E8%AF%B4%E6%98%8E
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
api_base_url=https://api.weixin.qq.com/cgi-bin
|
||||
mp_base_url=https://mp.weixin.qq.com/cgi-bin
|
||||
file_base_url=http://file.api.weixin.qq.com/cgi-bin
|
||||
mch_base_url=https://api.mch.weixin.qq.com
|
||||
|
||||
# \u7f51\u9875\u6388\u6743\u83b7\u53d6\u7528\u6237\u4fe1\u606f
|
||||
user_auth_uri=https://open.weixin.qq.com/connect/oauth2/authorize?appid={app_id}&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect
|
||||
sns_user_token_uri=https://api.weixin.qq.com/sns/oauth2/access_token?appid={app_id}&secret={app_secret}&code=%s&grant_type=authorization_code
|
||||
sns_user_info_uri=https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN
|
||||
|
||||
# \u76f4\u63a5\u83b7\u53d6\u7528\u6237\u4fe1\u606f
|
||||
api_user_info_uri={api_base_url}/user/info?access_token=%s&openid=%s&lang=zh_CN
|
||||
# \u83b7\u53d6token
|
||||
api_token_uri={api_base_url}/token?grant_type=client_credential&appid=%s&secret=%s
|
||||
# \u83b7\u53d6\u4e8c\u7ef4\u7801
|
||||
qr_ticket_uri={api_base_url}/qrcode/create?access_token=%s
|
||||
qr_image_uri={mp_base_url}/showqrcode?ticket=%s
|
||||
# \u4e0a\u4f20\u5a92\u4f53\u6587\u4ef6
|
||||
file_upload_uri={file_base_url}/media/upload?access_token=%s&type=%s
|
||||
# \u4e0b\u8f7d\u5a92\u4f53\u6587\u4ef6
|
||||
file_download_uri={file_base_url}/media/get?access_token=%s&media_id=%s
|
||||
# \u53d1\u9001\u5ba2\u670d\u6d88\u606f
|
||||
custom_notify_uri={api_base_url}/message/custom/send?access_token=%s
|
||||
# \u521b\u5efa\u5206\u7ec4
|
||||
group_create_uri={api_base_url}/groups/create?access_token=%s
|
||||
# \u67e5\u8be2\u5206\u7ec4
|
||||
group_get_uri={api_base_url}/groups/get?access_token=%s
|
||||
# \u67e5\u8be2\u7528\u6237\u6240\u5728\u5206\u7ec4
|
||||
group_getid_uri={api_base_url}/groups/getid?access_token=%s
|
||||
# \u4fee\u6539\u5206\u7ec4\u540d
|
||||
group_modify_uri={api_base_url}/groups/update?access_token=%s
|
||||
# \u79fb\u52a8\u7528\u6237\u5206\u7ec4
|
||||
group_move_uri={api_base_url}/groups/members/update?access_token=%s
|
||||
# \u83b7\u53d6\u5173\u6ce8\u7740
|
||||
following_uri={api_base_url}/user/get?access_token=%s&next_openid=%s
|
||||
# \u81ea\u5b9a\u4e49\u83dc\u5355
|
||||
menu_create_uri={api_base_url}/menu/create?access_token=%s
|
||||
# \u67e5\u8be2\u83dc\u5355
|
||||
menu_get_uri={api_base_url}/menu/get?access_token=%s
|
||||
# \u5220\u9664\u83dc\u5355
|
||||
menu_delete_uri={api_base_url}/menu/delete?access_token=%s
|
||||
# \u4e0a\u4f20\u56fe\u6587
|
||||
article_upload_uri={api_base_url}/media/uploadnews?access_token=%s
|
||||
# \u4e0a\u4f20\u89c6\u9891
|
||||
video_upload_uri={file_base_url}/media/uploadvideo?access_token=%s
|
||||
# \u5206\u7ec4\u7fa4\u53d1
|
||||
mass_group_uri={api_base_url}/message/mass/sendall?access_token=%s
|
||||
# openId\u7fa4\u53d1
|
||||
mass_openid_uri={api_base_url}/message/mass/send?access_token=%s
|
||||
# \u5220\u9664\u7fa4\u53d1
|
||||
mass_delete_uri={api_base_url}/message/mass/delete?access_token=%s
|
||||
# \u5ba2\u670d\u804a\u5929\u8bb0\u5f55
|
||||
custom_record_uri={api_base_url}/customservice/getrecord?access_token=%s
|
||||
# \u957f\u94fe\u63a5\u8f6c\u77ed\u94fe\u63a5
|
||||
shorturl_uri={api_base_url}/shorturl?access_token=%s
|
||||
p_shorturl_uri={mch_base_url}/tools/shorturl
|
||||
# \u8bbe\u7f6e\u5907\u6ce8\u540d
|
||||
updateremark_uri={api_base_url}/user/info/updateremark?access_token=%s
|
||||
# \u6a21\u677f\u6d88\u606f
|
||||
template_send_uri={api_base_url}/message/template/send?access_token=%s
|
||||
# \u67e5\u8be2\u8ba2\u5355
|
||||
orderquery_uri={api_base_url}/pay/orderquery?access_token=%s
|
||||
# \u53d1\u8d27\u901a\u77e5
|
||||
delivernotify_uri={api_base_url}/pay/delivernotify?access_token=%s
|
||||
# \u7ef4\u6743\u5904\u7406
|
||||
payfeedback_update_uri={api_base_url}/payfeedback/update?access_token=%s&openid=%s&feedbackid=%s
|
||||
@@ -2,11 +2,9 @@ package com.foxinmy.weixin4j.mp.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
|
||||
|
||||
/**
|
||||
* 分组
|
||||
*
|
||||
* @author jy.hu
|
||||
* @date 2014年4月4日
|
||||
* @since JDK 1.7
|
||||
@@ -56,29 +54,22 @@ public class Group implements Serializable {
|
||||
|
||||
/**
|
||||
* 返回创建分组所需的json格式字符串
|
||||
*
|
||||
* @return {"group": {"id": 107, "name": "test"}}
|
||||
*/
|
||||
public String toCreateJson() {
|
||||
XStream xstream = new XStream(new JsonHierarchicalStreamDriver());
|
||||
xstream.omitField(this.getClass(), "id");
|
||||
xstream.omitField(this.getClass(), "count");
|
||||
xstream.alias("group", this.getClass());
|
||||
xstream.autodetectAnnotations(true);
|
||||
xstream.processAnnotations(this.getClass());
|
||||
return xstream.toXML(this);
|
||||
return String.format("{\"group\":{\"id\":%s,\"name\":\"%s\"}}", id,
|
||||
name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回修改分组所需的json格式字符串
|
||||
* @return
|
||||
*
|
||||
* @return {"group": {"id": 107, "name": "test"}}
|
||||
*/
|
||||
public String toModifyJson() {
|
||||
XStream xstream = new XStream(new JsonHierarchicalStreamDriver());
|
||||
xstream.omitField(this.getClass(), "count");
|
||||
xstream.alias("group", this.getClass());
|
||||
xstream.autodetectAnnotations(true);
|
||||
xstream.processAnnotations(this.getClass());
|
||||
return xstream.toXML(this);
|
||||
return String.format("{\"group\":{\"id\":%s,\"name\":\"%s\"}}", id,
|
||||
name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,6 +82,7 @@ public class Group implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[Group id=%d ,name=%s ,count=%d]", id, name, count);
|
||||
return String.format("[Group id=%d ,name=%s ,count=%d]", id, name,
|
||||
count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.LinkedList;
|
||||
import com.foxinmy.weixin4j.mp.msg.model.Article;
|
||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
@@ -21,6 +20,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
||||
*/
|
||||
@XStreamAlias("xml")
|
||||
public class ArticleResponse extends BaseResponse {
|
||||
private static final int MAX_ARTICLE_COUNT = 10;
|
||||
private static final long serialVersionUID = -7331603018352309317L;
|
||||
@@ -82,13 +82,12 @@ public class ArticleResponse extends BaseResponse {
|
||||
@Override
|
||||
public String toXml() {
|
||||
this.count = articles.size();
|
||||
XStream xstream = getXStream();
|
||||
xstream.alias("item", Article.class);
|
||||
xstream.aliasField("Title", Article.class, "title");
|
||||
xstream.aliasField("Description", Article.class, "desc");
|
||||
xstream.aliasField("PicUrl", Article.class, "picUrl");
|
||||
xstream.aliasField("Url", Article.class, "url");
|
||||
return xstream.toXML(this);
|
||||
xmlStream.alias("item", Article.class);
|
||||
xmlStream.aliasField("Title", Article.class, "title");
|
||||
xmlStream.aliasField("Description", Article.class, "desc");
|
||||
xmlStream.aliasField("PicUrl", Article.class, "picUrl");
|
||||
xmlStream.aliasField("Url", Article.class, "url");
|
||||
return xmlStream.toXML(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.thoughtworks.xstream.io.json.JsonWriter;
|
||||
public class BaseResponse implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7761192742840031607L;
|
||||
private final static XStream xmlStream = new XStream();
|
||||
protected final static XStream xmlStream = XStream.get();
|
||||
private final static XStream jsonStream = new XStream(
|
||||
new JsonHierarchicalStreamDriver() {
|
||||
public HierarchicalStreamWriter createWriter(Writer writer) {
|
||||
@@ -48,8 +48,6 @@ public class BaseResponse implements Serializable {
|
||||
Class<?>[] classes = ClassUtil.getClasses(
|
||||
BaseResponse.class.getPackage()).toArray(new Class[0]);
|
||||
|
||||
xmlStream.ignoreUnknownElements();
|
||||
xmlStream.autodetectAnnotations(true);
|
||||
xmlStream.processAnnotations(classes);
|
||||
|
||||
jsonStream.setMode(XStream.NO_REFERENCES);
|
||||
@@ -104,20 +102,13 @@ public class BaseResponse implements Serializable {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
protected XStream getXStream() {
|
||||
Class<? extends BaseResponse> targetClass = this.msgType
|
||||
.getMessageClass();
|
||||
xmlStream.alias("xml", targetClass);
|
||||
return xmlStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息对象转换为微信服务器接受的xml格式消息
|
||||
*
|
||||
* @return xml字符串
|
||||
*/
|
||||
public String toXml() {
|
||||
return getXStream().toXML(this);
|
||||
return xmlStream.toXML(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.foxinmy.weixin4j.mp.response;
|
||||
import com.foxinmy.weixin4j.mp.msg.model.Image;
|
||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
@@ -20,6 +19,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
||||
*/
|
||||
@XStreamAlias("xml")
|
||||
public class ImageResponse extends BaseResponse {
|
||||
private static final long serialVersionUID = 6998255203997554731L;
|
||||
|
||||
@@ -42,9 +42,8 @@ public class ImageResponse extends BaseResponse {
|
||||
|
||||
@Override
|
||||
public String toXml() {
|
||||
XStream xstream = getXStream();
|
||||
xstream.aliasField("MediaId", Image.class, "mediaId");
|
||||
return xstream.toXML(this);
|
||||
xmlStream.aliasField("MediaId", Image.class, "mediaId");
|
||||
return xmlStream.toXML(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.foxinmy.weixin4j.mp.response;
|
||||
import com.foxinmy.weixin4j.mp.msg.model.Music;
|
||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
@@ -19,6 +18,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
||||
*/
|
||||
@XStreamAlias("xml")
|
||||
public class MusicResponse extends BaseResponse {
|
||||
|
||||
private static final long serialVersionUID = 4384403772658796395L;
|
||||
@@ -40,13 +40,12 @@ public class MusicResponse extends BaseResponse {
|
||||
|
||||
@Override
|
||||
public String toXml() {
|
||||
XStream xstream = getXStream();
|
||||
xstream.aliasField("MediaId", Music.class, "musicUrl");
|
||||
xstream.aliasField("Title", Music.class, "title");
|
||||
xstream.aliasField("Description", Music.class, "desc");
|
||||
xstream.aliasField("HQMusicUrl", Music.class, "hqMusicUrl");
|
||||
xstream.aliasField("ThumbMediaId", Music.class, "thumbMediaId");
|
||||
return xstream.toXML(this);
|
||||
xmlStream.aliasField("MediaId", Music.class, "musicUrl");
|
||||
xmlStream.aliasField("Title", Music.class, "title");
|
||||
xmlStream.aliasField("Description", Music.class, "desc");
|
||||
xmlStream.aliasField("HQMusicUrl", Music.class, "hqMusicUrl");
|
||||
xmlStream.aliasField("ThumbMediaId", Music.class, "thumbMediaId");
|
||||
return xmlStream.toXML(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,7 +14,8 @@ import com.alibaba.fastjson.annotation.JSONField;
|
||||
* @author jy
|
||||
* @date 2014年9月29日
|
||||
* @since JDK 1.7
|
||||
* @see <a href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%A8%A1%E6%9D%BF%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3">模板消息</a>
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%A8%A1%E6%9D%BF%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3">模板消息</a>
|
||||
*/
|
||||
public class TemplateMessage implements Serializable {
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
||||
*/
|
||||
@XStreamAlias("xml")
|
||||
public class TextResponse extends BaseResponse {
|
||||
|
||||
private static final long serialVersionUID = -7018053906644190260L;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.foxinmy.weixin4j.mp.response;
|
||||
|
||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
* 转移消息到多客服端消息
|
||||
@@ -15,6 +16,7 @@ import com.foxinmy.weixin4j.msg.BaseMessage;
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
||||
*/
|
||||
@XStreamAlias("xml")
|
||||
public class TransferResponse extends BaseResponse {
|
||||
|
||||
private static final long serialVersionUID = -5479496746108594940L;
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.foxinmy.weixin4j.mp.response;
|
||||
import com.foxinmy.weixin4j.mp.msg.model.Video;
|
||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
@@ -19,6 +18,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
||||
*/
|
||||
@XStreamAlias("xml")
|
||||
public class VideoResponse extends BaseResponse {
|
||||
|
||||
private static final long serialVersionUID = -1013075358679078381L;
|
||||
@@ -41,12 +41,11 @@ public class VideoResponse extends BaseResponse {
|
||||
|
||||
@Override
|
||||
public String toXml() {
|
||||
XStream xstream = getXStream();
|
||||
xstream.aliasField("MediaId", Video.class, "mediaId");
|
||||
xstream.aliasField("Title", Video.class, "title");
|
||||
xstream.aliasField("Description", Video.class, "desc");
|
||||
xstream.omitField(Video.class, "thumbMediaId");
|
||||
return xstream.toXML(this);
|
||||
xmlStream.aliasField("MediaId", Video.class, "mediaId");
|
||||
xmlStream.aliasField("Title", Video.class, "title");
|
||||
xmlStream.aliasField("Description", Video.class, "desc");
|
||||
xmlStream.omitField(Video.class, "thumbMediaId");
|
||||
return xmlStream.toXML(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.foxinmy.weixin4j.mp.response;
|
||||
import com.foxinmy.weixin4j.mp.msg.model.Voice;
|
||||
import com.foxinmy.weixin4j.mp.type.ResponseType;
|
||||
import com.foxinmy.weixin4j.msg.BaseMessage;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
@@ -19,6 +18,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse
|
||||
* @see com.foxinmy.weixin4j.mp.response.BaseResponse#toXml()
|
||||
*/
|
||||
@XStreamAlias("xml")
|
||||
public class VoiceResponse extends BaseResponse {
|
||||
|
||||
private static final long serialVersionUID = -7944926238652243793L;
|
||||
@@ -42,9 +42,8 @@ public class VoiceResponse extends BaseResponse {
|
||||
|
||||
@Override
|
||||
public String toXml() {
|
||||
XStream xstream = getXStream();
|
||||
xstream.aliasField("MediaId", Voice.class, "mediaId");
|
||||
return xstream.toXML(this);
|
||||
xmlStream.aliasField("MediaId", Voice.class, "mediaId");
|
||||
return xmlStream.toXML(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.foxinmy.weixin4j.mp.spider;
|
||||
|
||||
public final class MpWeixin {
|
||||
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- http://mp.weixin.qq.com/wiki/index.php?title=%E5%85%A8%E5%B1%80%E8%BF%94%E5%9B%9E%E7%A0%81%E8%AF%B4%E6%98%8E -->
|
||||
<errors>
|
||||
<error code="-1">系统繁忙</error>
|
||||
<error code="40001">获取access_token时AppSecret错误,或者access_token无效</error>
|
||||
<error code="40002">不合法的凭证类型</error>
|
||||
<error code="40003">不合法的OpenID</error>
|
||||
<error code="40004">不合法的媒体文件类型</error>
|
||||
<error code="40005">不合法的文件类型</error>
|
||||
<error code="40006">不合法的文件大小</error>
|
||||
<error code="40007">不合法的媒体文件id</error>
|
||||
<error code="40008">不合法的消息类型</error>
|
||||
<error code="40009">不合法的图片文件大小</error>
|
||||
<error code="40010">不合法的语音文件大小</error>
|
||||
<error code="40011">不合法的视频文件大小</error>
|
||||
<error code="40012">不合法的缩略图文件大小</error>
|
||||
<error code="40013">不合法的APPID</error>
|
||||
<error code="40014">不合法的access_token</error>
|
||||
<error code="40015">不合法的菜单类型</error>
|
||||
<error code="40016">不合法的按钮个数</error>
|
||||
<error code="40017">不合法的按钮个数</error>
|
||||
<error code="40018">不合法的按钮名字长度</error>
|
||||
<error code="40019">不合法的按钮KEY长度</error>
|
||||
<error code="40020">不合法的按钮URL长度</error>
|
||||
<error code="40021">不合法的菜单版本号</error>
|
||||
<error code="40022">不合法的子菜单级数</error>
|
||||
<error code="40023">不合法的子菜单按钮个数</error>
|
||||
<error code="40024">不合法的子菜单按钮类型</error>
|
||||
<error code="40025">不合法的子菜单按钮名字长度</error>
|
||||
<error code="40026">不合法的子菜单按钮KEY长度</error>
|
||||
<error code="40027">不合法的子菜单按钮URL长度</error>
|
||||
<error code="40028">不合法的自定义菜单使用用户</error>
|
||||
<error code="40029">不合法的oauth_code</error>
|
||||
<error code="40030">不合法的refresh_token</error>
|
||||
<error code="40031">不合法的openid列表</error>
|
||||
<error code="40032">不合法的openid列表长度</error>
|
||||
<error code="40033">不合法的请求字符,不能包含\uxxxx格式的字符</error>
|
||||
<error code="40035">不合法的参数</error>
|
||||
<error code="40038">不合法的请求格式</error>
|
||||
<error code="40039">不合法的URL长度</error>
|
||||
<error code="40050">不合法的分组id</error>
|
||||
<error code="40051">分组名字不合法</error>
|
||||
<error code="41001">缺少access_token参数</error>
|
||||
<error code="41002">缺少appid参数</error>
|
||||
<error code="41003">缺少refresh_token参数</error>
|
||||
<error code="41004">缺少secret参数</error>
|
||||
<error code="41005">缺少多媒体文件数据</error>
|
||||
<error code="41006">缺少media_id参数</error>
|
||||
<error code="41007">缺少子菜单数据</error>
|
||||
<error code="41008">缺少oauth code</error>
|
||||
<error code="41009">缺少openid</error>
|
||||
<error code="42001">access_token超时</error>
|
||||
<error code="42002">refresh_token超时</error>
|
||||
<error code="42003">oauth_code超时</error>
|
||||
<error code="43001">需要GET请求</error>
|
||||
<error code="43002">需要POST请求</error>
|
||||
<error code="43003">需要HTTPS请求</error>
|
||||
<error code="43004">需要接收者关注</error>
|
||||
<error code="43005">需要好友关系</error>
|
||||
<error code="44001">多媒体文件为空</error>
|
||||
<error code="44002">POST的数据包为空</error>
|
||||
<error code="44003">图文消息内容为空</error>
|
||||
<error code="44004">文本消息内容为空</error>
|
||||
<error code="45001">多媒体文件大小超过限制</error>
|
||||
<error code="45002">消息内容超过限制</error>
|
||||
<error code="45003">标题字段超过限制</error>
|
||||
<error code="45004">描述字段超过限制</error>
|
||||
<error code="45005">链接字段超过限制</error>
|
||||
<error code="45006">图片链接字段超过限制</error>
|
||||
<error code="45007">语音播放时间超过限制</error>
|
||||
<error code="45008">图文消息超过限制</error>
|
||||
<error code="45009">接口调用超过限制</error>
|
||||
<error code="45010">创建菜单个数超过限制</error>
|
||||
<error code="45015">回复时间超过限制</error>
|
||||
<error code="45016">系统分组,不允许修改</error>
|
||||
<error code="45017">分组名字过长</error>
|
||||
<error code="45018">分组数量超过上限</error>
|
||||
<error code="46001">不存在媒体数据</error>
|
||||
<error code="46002">不存在的菜单版本</error>
|
||||
<error code="46003">不存在的菜单数据</error>
|
||||
<error code="46004">不存在的用户</error>
|
||||
<error code="47001">解析JSON/XML内容错误</error>
|
||||
<error code="48001">api功能未授权</error>
|
||||
<error code="50001">用户未授权该api</error>
|
||||
</errors>
|
||||
@@ -1,80 +1,10 @@
|
||||
# app\u4fe1\u606f
|
||||
app_id=wx4ab8f8de58159a57
|
||||
app_secret=1d4eb0f4bf556aaed539f30ed05ca795
|
||||
app_openId=gh_22b350df957b
|
||||
app_token=wexintoken
|
||||
# \u516c\u4f17\u53f7\u4fe1\u606f
|
||||
account={"appId":"wx4ab8f8de58159a57","appSecret":"1d4eb0f4bf556aaed539f30ed05ca795",\
|
||||
"token":"\u5f00\u653e\u8005\u7684token \u975e\u5fc5\u987b","openId":"\u516c\u4f17\u53f7\u7684openid \u975e\u5fc5\u987b",\
|
||||
"mchId":"V3.x\u7248\u672c\u4e0b\u7684\u5fae\u4fe1\u5546\u6237\u53f7",\
|
||||
"partnerId":"\u8d22\u4ed8\u901a\u7684\u5546\u6237\u53f7","partnerKey":"\u5fae\u4fe1\u652f\u4ed8\u4e2d\u8c03\u7528API\u7684\u5bc6\u94a5"}
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# api\u9996\u9875
|
||||
# http://mp.weixin.qq.com/wiki/index.php
|
||||
# \u63a5\u53e3\u8c03\u7528\u8bf4\u660e
|
||||
# http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E5%8F%A3%E9%A2%91%E7%8E%87%E9%99%90%E5%88%B6%E8%AF%B4%E6%98%8E
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
api_base_url=https://api.weixin.qq.com/cgi-bin
|
||||
mp_base_url=https://mp.weixin.qq.com/cgi-bin
|
||||
file_base_url=http://file.api.weixin.qq.com/cgi-bin
|
||||
|
||||
# \u7f51\u9875\u6388\u6743\u83b7\u53d6\u7528\u6237\u4fe1\u606f
|
||||
user_auth_uri=https://open.weixin.qq.com/connect/oauth2/authorize?appid={app_id}&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect
|
||||
sns_user_token_uri=https://api.weixin.qq.com/sns/oauth2/access_token?appid={app_id}&secret={app_secret}&code=%s&grant_type=authorization_code
|
||||
sns_user_info_uri=https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN
|
||||
|
||||
# \u76f4\u63a5\u83b7\u53d6\u7528\u6237\u4fe1\u606f
|
||||
api_user_info_uri={api_base_url}/user/info?access_token=%s&openid=%s&lang=zh_CN
|
||||
# \u83b7\u53d6\u6211\u7684token
|
||||
api_token_uri={api_base_url}/token?grant_type=client_credential&appid=%s&secret=%s
|
||||
# \u83b7\u53d6\u4e8c\u7ef4\u7801
|
||||
qr_ticket_uri={api_base_url}/qrcode/create?access_token=%s
|
||||
qr_image_uri={mp_base_url}/showqrcode?ticket=%s
|
||||
# \u4e0a\u4f20\u5a92\u4f53\u6587\u4ef6
|
||||
file_upload_uri={file_base_url}/media/upload?access_token=%s&type=%s
|
||||
# \u4e0b\u8f7d\u5a92\u4f53\u6587\u4ef6
|
||||
file_download_uri={file_base_url}/media/get?access_token=%s&media_id=%s
|
||||
# \u53d1\u9001\u5ba2\u670d\u6d88\u606f
|
||||
custom_notify_uri={api_base_url}/message/custom/send?access_token=%s
|
||||
# \u521b\u5efa\u5206\u7ec4
|
||||
group_create_uri={api_base_url}/groups/create?access_token=%s
|
||||
# \u67e5\u8be2\u5206\u7ec4
|
||||
group_get_uri={api_base_url}/groups/get?access_token=%s
|
||||
# \u67e5\u8be2\u7528\u6237\u6240\u5728\u5206\u7ec4
|
||||
group_getid_uri={api_base_url}/groups/getid?access_token=%s
|
||||
# \u4fee\u6539\u5206\u7ec4\u540d
|
||||
group_modify_uri={api_base_url}/groups/update?access_token=%s
|
||||
# \u79fb\u52a8\u7528\u6237\u5206\u7ec4
|
||||
group_move_uri={api_base_url}/groups/members/update?access_token=%s
|
||||
# \u83b7\u53d6\u5173\u6ce8\u7740
|
||||
following_uri={api_base_url}/user/get?access_token=%s&next_openid=%s
|
||||
# \u81ea\u5b9a\u4e49\u83dc\u5355
|
||||
menu_create_uri={api_base_url}/menu/create?access_token=%s
|
||||
# \u67e5\u8be2\u83dc\u5355
|
||||
menu_get_uri={api_base_url}/menu/get?access_token=%s
|
||||
# \u5220\u9664\u83dc\u5355
|
||||
menu_delete_uri={api_base_url}/menu/delete?access_token=%s
|
||||
# \u4e0a\u4f20\u56fe\u6587
|
||||
article_upload_uri={api_base_url}/media/uploadnews?access_token=%s
|
||||
# \u4e0a\u4f20\u89c6\u9891
|
||||
video_upload_uri={file_base_url}/media/uploadvideo?access_token=%s
|
||||
# \u5206\u7ec4\u7fa4\u53d1
|
||||
mass_group_uri={api_base_url}/message/mass/sendall?access_token=%s
|
||||
# openId\u7fa4\u53d1
|
||||
mass_openid_uri={api_base_url}/message/mass/send?access_token=%s
|
||||
# \u5220\u9664\u7fa4\u53d1
|
||||
mass_delete_uri={api_base_url}/message/mass/delete?access_token=%s
|
||||
# \u5ba2\u670d\u804a\u5929\u8bb0\u5f55
|
||||
custom_record_uri={api_base_url}/customservice/getrecord?access_token=%s
|
||||
# \u957f\u94fe\u63a5\u8f6c\u77ed\u94fe\u63a5
|
||||
shorturl_uri={api_base_url}/shorturl?access_token=%s
|
||||
# \u8bbe\u7f6e\u5907\u6ce8\u540d
|
||||
updateremark_uri={api_base_url}/user/info/updateremark?access_token=%s
|
||||
# \u6a21\u677f\u6d88\u606f
|
||||
template_send_uri={api_base_url}/message/template/send?access_token=%s
|
||||
# \u67e5\u8be2\u8ba2\u5355
|
||||
orderquery_uri={api_base_url}/pay/orderquery?access_token=%s
|
||||
# \u53d1\u8d27\u901a\u77e5
|
||||
delivernotify_uri={api_base_url}/pay/delivernotify?access_token=%s
|
||||
|
||||
# token\u5b58\u653e\u8def\u5f84
|
||||
# \u4f7f\u7528FileTokenHolder\u65f6token\u7684\u5b58\u653e\u8def\u5f84
|
||||
token_path=/tmp/weixin/token
|
||||
# \u4e8c\u7ef4\u7801\u4fdd\u5b58\u8def\u5f84
|
||||
qr_path=/tmp/weixin/qr
|
||||
|
||||
@@ -37,7 +37,7 @@ public class GroupTest extends TokenTest {
|
||||
public void get() throws WeixinException {
|
||||
List<Group> groups = groupApi.getGroups();
|
||||
for (Group group : groups) {
|
||||
System.out.println(group);
|
||||
System.out.println(group.toModifyJson());
|
||||
}
|
||||
Assert.assertEquals(1, groups.size());
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.token.FileTokenApi;
|
||||
import com.foxinmy.weixin4j.token.TokenApi;
|
||||
import com.foxinmy.weixin4j.token.FileTokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
|
||||
/**
|
||||
* token测试
|
||||
@@ -18,11 +18,11 @@ import com.foxinmy.weixin4j.token.TokenApi;
|
||||
*/
|
||||
public class TokenTest {
|
||||
|
||||
protected TokenApi tokenApi;
|
||||
protected TokenHolder tokenApi;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
tokenApi = new FileTokenApi();
|
||||
tokenApi = new FileTokenHolder();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,8 +23,7 @@ public class MessagePush {
|
||||
|
||||
public MessagePush() {
|
||||
this.httpClient = new DefaultHttpClient();
|
||||
ResourceBundle config = ResourceBundle
|
||||
.getBundle("netty");
|
||||
ResourceBundle config = ResourceBundle.getBundle("netty");
|
||||
httpPost = new HttpPost();
|
||||
httpPost.setURI(URI.create(String.format("http://localhost:%s",
|
||||
Integer.parseInt(config.getString("port")))));
|
||||
@@ -37,11 +36,11 @@ public class MessagePush {
|
||||
|
||||
int status = statusLine.getStatusCode();
|
||||
if (status != HttpStatus.SC_OK) {
|
||||
throw new WeixinException(status, "request fail");
|
||||
throw new WeixinException(status + "", "request fail");
|
||||
}
|
||||
if (status == HttpStatus.SC_MOVED_PERMANENTLY
|
||||
|| status == HttpStatus.SC_MOVED_TEMPORARILY) {
|
||||
throw new WeixinException(status, "uri moved");
|
||||
throw new WeixinException(status + "", "uri moved");
|
||||
}
|
||||
return EntityUtils.toString(httpResponse.getEntity(),
|
||||
StandardCharsets.UTF_8);
|
||||
|
||||
Reference in New Issue
Block a user