weixin4j-qy:新增客服消息
This commit is contained in:
@@ -120,4 +120,8 @@
|
||||
|
||||
* 2015-11-09
|
||||
|
||||
+ version upgrade to 1.6.3
|
||||
+ version upgrade to 1.6.3
|
||||
|
||||
* 2015-11-20
|
||||
|
||||
+ 新增客服消息
|
||||
@@ -26,6 +26,7 @@ import com.foxinmy.weixin4j.qy.api.QyApi;
|
||||
import com.foxinmy.weixin4j.qy.api.TagApi;
|
||||
import com.foxinmy.weixin4j.qy.api.UserApi;
|
||||
import com.foxinmy.weixin4j.qy.message.ChatMessage;
|
||||
import com.foxinmy.weixin4j.qy.message.CustomeMessage;
|
||||
import com.foxinmy.weixin4j.qy.message.NotifyMessage;
|
||||
import com.foxinmy.weixin4j.qy.model.AgentInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.AgentOverview;
|
||||
@@ -173,6 +174,28 @@ public class WeixinProxy {
|
||||
return notifyApi.sendNotifyMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送客服消息
|
||||
*
|
||||
* @param message
|
||||
* 客服消息对象
|
||||
* @return 发送结果
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%AE%A2%E6%9C%8D%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E">客服接口说明</a>
|
||||
* @see com.foxinmy.weixin4j.qy.api.NotifyApi
|
||||
* @see com.foxinmy.weixin4j.tuple.Text
|
||||
* @see com.foxinmy.weixin4j.tuple.Image
|
||||
* @see com.foxinmy.weixin4j.tuple.Voice
|
||||
* @see com.foxinmy.weixin4j.tuple.Video
|
||||
* @see com.foxinmy.weixin4j.tuple.File
|
||||
* @see com.foxinmy.weixin4j.qy.message.CustomeMessage
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult sendCustomeMessage(CustomeMessage message)
|
||||
throws WeixinException {
|
||||
return notifyApi.sendCustomeMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义菜单(管理员须拥有应用的管理权限 并且应用必须设置在回调模式)
|
||||
*
|
||||
|
||||
@@ -5,8 +5,10 @@ import java.util.Map;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.qy.message.CustomeMessage;
|
||||
import com.foxinmy.weixin4j.qy.message.NotifyMessage;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.tuple.NotifyTuple;
|
||||
@@ -47,7 +49,7 @@ public class NotifyApi extends QyApi {
|
||||
* </p>
|
||||
*
|
||||
* @param message
|
||||
* 客服消息对象
|
||||
* 普通消息对象
|
||||
* @return 如果无权限,则本次发送失败;如果收件人不存在或未关注,发送仍然执行。两种情况下均返回无效的部分</br> { "errcode":
|
||||
* 0, "errmsg": "ok", "invaliduser": "UserID1",
|
||||
* "invalidparty":"PartyID1", "invalidtag":"TagID1" }
|
||||
@@ -86,4 +88,35 @@ public class NotifyApi extends QyApi {
|
||||
|
||||
return response.getAsJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送客服消息
|
||||
*
|
||||
* @param message
|
||||
* 客服消息对象
|
||||
* @return 发送结果
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%AE%A2%E6%9C%8D%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E">客服接口说明</a>
|
||||
* @see com.foxinmy.weixin4j.tuple.Text
|
||||
* @see com.foxinmy.weixin4j.tuple.Image
|
||||
* @see com.foxinmy.weixin4j.tuple.Voice
|
||||
* @see com.foxinmy.weixin4j.tuple.Video
|
||||
* @see com.foxinmy.weixin4j.tuple.File
|
||||
* @see com.foxinmy.weixin4j.qy.message.CustomeMessage
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult sendCustomeMessage(CustomeMessage message)
|
||||
throws WeixinException {
|
||||
NotifyTuple tuple = message.getTuple();
|
||||
String msgtype = tuple.getMessageType();
|
||||
JSONObject obj = (JSONObject) JSON.toJSON(message);
|
||||
obj.put("msgtype", msgtype);
|
||||
obj.put(msgtype, tuple);
|
||||
String message_kf_send_uri = getRequestUri("message_kf_send_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(message_kf_send_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,8 +57,10 @@ menu_create_uri={api_base_url}/menu/create?access_token=%s&agentid=%d
|
||||
menu_delete_uri={api_base_url}/menu/delete?access_token=%s&agentid=%d
|
||||
# \u67e5\u8be2\u83dc\u5355
|
||||
menu_get_uri={api_base_url}/menu/get?access_token=%s&agentid=%d
|
||||
# \u53d1\u9001\u6d88\u606f
|
||||
# \u53d1\u9001\u666e\u901a\u6d88\u606f
|
||||
message_send_uri={api_base_url}/message/send?access_token=%s
|
||||
# \u53d1\u9001\u5ba2\u670d\u6d88\u606f
|
||||
message_kf_send_uri={api_base_url}/kf/send?access_token=%s
|
||||
# \u83b7\u53d6\u5fae\u4fe1IP\u5730\u5740
|
||||
getcallbackip_uri={api_base_url}/getcallbackip?access_token=%s
|
||||
# \u83b7\u53d6\u4f01\u4e1a\u53f7\u5e94\u7528\u4fe1\u606f
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.foxinmy.weixin4j.qy.message;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.tuple.NotifyTuple;
|
||||
|
||||
/**
|
||||
* 客服消息对象
|
||||
*
|
||||
* @className CustomeMessage
|
||||
* @author jy
|
||||
* @date 2015年11月20日
|
||||
* @since JDK 1.7
|
||||
* @see com.foxinmy.weixin4j.tuple.Text
|
||||
* @see com.foxinmy.weixin4j.tuple.Image
|
||||
* @see com.foxinmy.weixin4j.tuple.Voice
|
||||
* @see com.foxinmy.weixin4j.tuple.Video
|
||||
* @see com.foxinmy.weixin4j.tuple.File
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%AE%A2%E6%9C%8D%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E">客服消息</a>
|
||||
*/
|
||||
public class CustomeMessage implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3620361273175868681L;
|
||||
|
||||
private CustomeTarget sender;
|
||||
private CustomeTarget receiver;
|
||||
/**
|
||||
* 消息对象
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
private NotifyTuple tuple;
|
||||
|
||||
public CustomeMessage(CustomeTarget sender, CustomeTarget receiver,
|
||||
NotifyTuple tuple) {
|
||||
this.sender = sender;
|
||||
this.receiver = receiver;
|
||||
this.tuple = tuple;
|
||||
}
|
||||
|
||||
public CustomeTarget getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public CustomeTarget getReceiver() {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public NotifyTuple getTuple() {
|
||||
return tuple;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户类型
|
||||
*
|
||||
* @className CustomeIdType
|
||||
* @author jy
|
||||
* @date 2015年11月20日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public enum CustomeIdType {
|
||||
/**
|
||||
* 客服
|
||||
*/
|
||||
kf,
|
||||
/**
|
||||
* 企业员工userid
|
||||
*/
|
||||
userid,
|
||||
/**
|
||||
* 公众号openid
|
||||
*/
|
||||
openid
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息对象
|
||||
*
|
||||
* @className CustomeTarget
|
||||
* @author jy
|
||||
* @date 2015年11月20日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public static class CustomeTarget implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private CustomeIdType type;
|
||||
private String id;
|
||||
|
||||
public CustomeTarget(CustomeIdType type, String id) {
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public CustomeIdType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CustomeMessage [sender=" + sender + ", receiver=" + receiver
|
||||
+ ", tuple=" + tuple + "]";
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import com.foxinmy.weixin4j.qy.model.IdParameter;
|
||||
import com.foxinmy.weixin4j.tuple.NotifyTuple;
|
||||
|
||||
/**
|
||||
* 客服消息对象
|
||||
* 消息提醒对象
|
||||
*
|
||||
* @className NotifyMessage
|
||||
* @author jy
|
||||
|
||||
Reference in New Issue
Block a user