add custom record method
This commit is contained in:
parent
6d3a824990
commit
a891ccab41
@ -29,6 +29,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.HttpRequest;
|
import com.foxinmy.weixin4j.http.HttpRequest;
|
||||||
import com.foxinmy.weixin4j.http.Response;
|
import com.foxinmy.weixin4j.http.Response;
|
||||||
import com.foxinmy.weixin4j.model.Button;
|
import com.foxinmy.weixin4j.model.Button;
|
||||||
|
import com.foxinmy.weixin4j.model.CustomRecord;
|
||||||
import com.foxinmy.weixin4j.model.Following;
|
import com.foxinmy.weixin4j.model.Following;
|
||||||
import com.foxinmy.weixin4j.model.Group;
|
import com.foxinmy.weixin4j.model.Group;
|
||||||
import com.foxinmy.weixin4j.model.MpArticle;
|
import com.foxinmy.weixin4j.model.MpArticle;
|
||||||
@ -71,9 +72,8 @@ public class WeixinProxy {
|
|||||||
* 随机数
|
* 随机数
|
||||||
* @param signature
|
* @param signature
|
||||||
* 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数
|
* 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数
|
||||||
* @return
|
* @return 开发者通过检验signature对请求进行相关校验。若确认此次GET请求来自微信服务器
|
||||||
* 开发者通过检验signature对请求进行相关校验。若确认此次GET请求来自微信服务器,请原样返回echostr参数内容,则接入生效
|
* 请原样返回echostr参数内容,则接入生效 成为开发者成功,否则接入失败
|
||||||
* ,成为开发者成功,否则接入失败
|
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97">接入指南</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97">接入指南</a>
|
||||||
*/
|
*/
|
||||||
@ -91,7 +91,7 @@ public class WeixinProxy {
|
|||||||
}
|
}
|
||||||
String _signature = null;
|
String _signature = null;
|
||||||
try {
|
try {
|
||||||
String[] a = { app_token, timestamp, nonce };
|
String[] a = {app_token, timestamp, nonce};
|
||||||
Arrays.sort(a);
|
Arrays.sort(a);
|
||||||
StringBuilder sb = new StringBuilder(3);
|
StringBuilder sb = new StringBuilder(3);
|
||||||
for (String str : a) {
|
for (String str : a) {
|
||||||
@ -203,7 +203,7 @@ public class WeixinProxy {
|
|||||||
long now_time = ca.getTimeInMillis();
|
long now_time = ca.getTimeInMillis();
|
||||||
try {
|
try {
|
||||||
token_path = WeixinConfig.getValue("api_token_uri");
|
token_path = WeixinConfig.getValue("api_token_uri");
|
||||||
Response response = null;
|
Response response = request.get(token_path);
|
||||||
if (token_file.exists()) {
|
if (token_file.exists()) {
|
||||||
token = (Token) xstream.fromXML(token_file);
|
token = (Token) xstream.fromXML(token_file);
|
||||||
|
|
||||||
@ -221,7 +221,6 @@ public class WeixinProxy {
|
|||||||
token_file.getParentFile().mkdirs();
|
token_file.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
token = response.getAsObject(Token.class);
|
token = response.getAsObject(Token.class);
|
||||||
token.setTime(now_time);
|
token.setTime(now_time);
|
||||||
token.setOpenid(appOpenId);
|
token.setOpenid(appOpenId);
|
||||||
@ -557,8 +556,7 @@ public class WeixinProxy {
|
|||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
JSONObject obj = response.getAsJson();
|
return response.getAsJson().getObject("group", Group.class);
|
||||||
return JSON.parseObject(obj.getString("group"), Group.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -575,8 +573,9 @@ public class WeixinProxy {
|
|||||||
Token token = getToken();
|
Token token = getToken();
|
||||||
Response response = request.get(String.format(group_get_uri,
|
Response response = request.get(String.format(group_get_uri,
|
||||||
token.getAccess_token()));
|
token.getAccess_token()));
|
||||||
JSONObject obj = response.getAsJson();
|
|
||||||
return JSON.parseArray(obj.getString("groups"), Group.class);
|
return JSON.parseArray(response.getAsJson().getString("groups"),
|
||||||
|
Group.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -887,7 +886,7 @@ public class WeixinProxy {
|
|||||||
/**
|
/**
|
||||||
* 删除群发消息
|
* 删除群发消息
|
||||||
* <p>
|
* <p>
|
||||||
* 请注意,只有已经发送成功的消息才能删除删除消息只是将消息的图文详情页失效,已经收到的用户,还是能在其本地看到消息卡片
|
* 请注意,只有已经发送成功的消息才能删除删除消息只是将消息的图文详情页失效,已经收到的用户,还是能在其本地看到消息卡片
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param msgid
|
* @param msgid
|
||||||
@ -896,8 +895,7 @@ public class WeixinProxy {
|
|||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E9%AB%98%E7%BA%A7%E7%BE%A4%E5%8F%91%E6%8E%A5%E5%8F%A3#.E5.88.A0.E9.99.A4.E7.BE.A4.E5.8F.91">删除群发</a>
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E9%AB%98%E7%BA%A7%E7%BE%A4%E5%8F%91%E6%8E%A5%E5%8F%A3#.E5.88.A0.E9.99.A4.E7.BE.A4.E5.8F.91">删除群发</a>
|
||||||
* @see {@link com.foxinmy.weixin4j.WeixinProxy#massNewsByGroup(List, String)}
|
* @see {@link com.foxinmy.weixin4j.WeixinProxy#massNewsByGroup(List, String)}
|
||||||
* @see {@link com.foxinmy.weixin4j.WeixinProxy#massNewsByOpenIds(List, String...)
|
* @see {@link com.foxinmy.weixin4j.WeixinProxy#massNewsByOpenIds(List, String...)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public void deleteMassNews(String msgid) throws WeixinException {
|
public void deleteMassNews(String msgid) throws WeixinException {
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
@ -913,4 +911,46 @@ public class WeixinProxy {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客服聊天记录
|
||||||
|
*
|
||||||
|
* @param openId
|
||||||
|
* 用户标识 可为空
|
||||||
|
* @param starttime
|
||||||
|
* 查询开始时间
|
||||||
|
* @param endtime
|
||||||
|
* 查询结束时间 每次查询不能跨日查询
|
||||||
|
* @param pagesize
|
||||||
|
* 每页大小 每页最多拉取1000条
|
||||||
|
* @param pageindex
|
||||||
|
* 查询第几页 从1开始
|
||||||
|
* @throws WeixinException
|
||||||
|
* @see com.foxinmy.weixin4j.model.CustomRecord
|
||||||
|
* @see <a
|
||||||
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E5%AE%A2%E6%9C%8D%E8%81%8A%E5%A4%A9%E8%AE%B0%E5%BD%95">查询客服聊天记录</a>
|
||||||
|
*/
|
||||||
|
public List<CustomRecord> getCustomRecord(String openId, long starttime,
|
||||||
|
long endtime, int pagesize, int pageindex) throws WeixinException {
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
obj.put("openId", openId == null ? "" : openId);
|
||||||
|
obj.put("starttime", starttime);
|
||||||
|
obj.put("endtime", endtime);
|
||||||
|
obj.put("pagesize", pagesize > 1000 ? 1000 : pagesize);
|
||||||
|
obj.put("pageindex", pageindex);
|
||||||
|
String custom_record_uri = WeixinConfig.getValue("custom_record_uri");
|
||||||
|
Token token = getToken();
|
||||||
|
Response response = null;
|
||||||
|
try {
|
||||||
|
response = request.post(String.format(custom_record_uri,
|
||||||
|
token.getAccess_token()),
|
||||||
|
new StringRequestEntity(obj.toJSONString(),
|
||||||
|
"application/json", "UTF-8"));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
String text = response.getAsJson().getString("recordlist");
|
||||||
|
return JSON.parseArray(text, CustomRecord.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
96
src/main/java/com/foxinmy/weixin4j/model/CustomRecord.java
Normal file
96
src/main/java/com/foxinmy/weixin4j/model/CustomRecord.java
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
package com.foxinmy.weixin4j.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客服聊天记录
|
||||||
|
*
|
||||||
|
* @className CustomRecord
|
||||||
|
* @author jy
|
||||||
|
* @date 2014年6月28日
|
||||||
|
* @since JDK 1.7
|
||||||
|
* @see <a
|
||||||
|
* href="http://mp.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E5%AE%A2%E6%9C%8D%E8%81%8A%E5%A4%A9%E8%AE%B0%E5%BD%95">客服聊天记录</a>
|
||||||
|
*/
|
||||||
|
public class CustomRecord implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4024147769411601325L;
|
||||||
|
private String worker;// 客服账号
|
||||||
|
private String openid;// 用户的标识
|
||||||
|
private Opercode opercode;// 操作ID(会话状态)
|
||||||
|
private Date time;// 操作时间
|
||||||
|
private String text;// 聊天记录
|
||||||
|
|
||||||
|
public String getWorker() {
|
||||||
|
return worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWorker(String worker) {
|
||||||
|
this.worker = worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOpenid() {
|
||||||
|
return openid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpenid(String openid) {
|
||||||
|
this.openid = openid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Opercode getOpercode() {
|
||||||
|
return opercode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpercode(Opercode opercode) {
|
||||||
|
this.opercode = opercode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTime(Date time) {
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Opercode {
|
||||||
|
MISS(1000, "创建未接入会话"), ONLINE(1001, "接入会话"), CALL(1002, "主动发起会话"), CLOSE(
|
||||||
|
1004, "关闭会话"), RASE(1005, "抢接会话"), RECEIVE1(2001, "公众号收到消息"), SEND(
|
||||||
|
2002, "客服发送消息"), RECEIVE2(2003, "客服收到消息");
|
||||||
|
private int code;
|
||||||
|
private String desc;
|
||||||
|
Opercode(int code, String desc) {
|
||||||
|
this.code = code;
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
public String getDesc() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("[CustomRecord worker=").append(worker);
|
||||||
|
sb.append(" ,openid=").append(openid);
|
||||||
|
sb.append(" ,opercode=").append(opercode);
|
||||||
|
sb.append(" ,time=").append(time);
|
||||||
|
sb.append(" ,text=").append(text);
|
||||||
|
sb.append("]");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user