mirror of
https://gitee.com/hotlcc/wechat4j.git
synced 2025-06-15 23:06:58 +08:00
提交代码:修改潜在bug
This commit is contained in:
parent
ce21807e3b
commit
4eebb0ab10
@ -39,7 +39,7 @@ import java.util.regex.Pattern;
|
|||||||
*
|
*
|
||||||
* @author Allen
|
* @author Allen
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings({"Duplicates", "unused"})
|
||||||
public class WebWeixinApi {
|
public class WebWeixinApi {
|
||||||
private static Logger logger = LoggerFactory.getLogger(WebWeixinApi.class);
|
private static Logger logger = LoggerFactory.getLogger(WebWeixinApi.class);
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ public class WebWeixinApi {
|
|||||||
private static Pattern PATTERN_UUID_2 = Pattern.compile("window.QRLogin.code = (\\d+); window.QRLogin.uuid = \"(\\S+?)\";");
|
private static Pattern PATTERN_UUID_2 = Pattern.compile("window.QRLogin.code = (\\d+); window.QRLogin.uuid = \"(\\S+?)\";");
|
||||||
private static Pattern PATTERN_REDIRECT_URI_1 = Pattern.compile("window.code=(\\d+);");
|
private static Pattern PATTERN_REDIRECT_URI_1 = Pattern.compile("window.code=(\\d+);");
|
||||||
private static Pattern PATTERN_REDIRECT_URI_2 = Pattern.compile("window.code=(\\d+);\\s*window.redirect_uri=\"(\\S+?)\";");
|
private static Pattern PATTERN_REDIRECT_URI_2 = Pattern.compile("window.code=(\\d+);\\s*window.redirect_uri=\"(\\S+?)\";");
|
||||||
private static Pattern PATTERN_REDIRECT_URI_3 = Pattern.compile("http(s*)://wx(\\d*)\\.qq\\.com\\/");
|
private static Pattern PATTERN_REDIRECT_URI_3 = Pattern.compile("http(s*)://wx(\\d*)\\.qq\\.com/");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传媒体文件分片大小
|
* 上传媒体文件分片大小
|
||||||
@ -59,6 +59,9 @@ public class WebWeixinApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取微信uuid
|
* 获取微信uuid
|
||||||
|
*
|
||||||
|
* @param httpClient http客户端
|
||||||
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject getWxUuid(HttpClient httpClient) {
|
public JSONObject getWxUuid(HttpClient httpClient) {
|
||||||
try {
|
try {
|
||||||
@ -113,7 +116,9 @@ public class WebWeixinApi {
|
|||||||
/**
|
/**
|
||||||
* 获取二维码
|
* 获取二维码
|
||||||
*
|
*
|
||||||
* @param uuid
|
* @param httpClient http客户端
|
||||||
|
* @param uuid uuid
|
||||||
|
* @return 二维码图片字节数据
|
||||||
*/
|
*/
|
||||||
public byte[] getQR(HttpClient httpClient,
|
public byte[] getQR(HttpClient httpClient,
|
||||||
String uuid) {
|
String uuid) {
|
||||||
@ -147,7 +152,10 @@ public class WebWeixinApi {
|
|||||||
/**
|
/**
|
||||||
* 获取跳转uri(等待扫码认证)
|
* 获取跳转uri(等待扫码认证)
|
||||||
*
|
*
|
||||||
* @return
|
* @param httpClient http客户端
|
||||||
|
* @param tip 登录tip
|
||||||
|
* @param uuid uuid
|
||||||
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject getRedirectUri(HttpClient httpClient,
|
public JSONObject getRedirectUri(HttpClient httpClient,
|
||||||
LoginTipEnum tip,
|
LoginTipEnum tip,
|
||||||
@ -216,6 +224,10 @@ public class WebWeixinApi {
|
|||||||
/**
|
/**
|
||||||
* 获取登录认证码
|
* 获取登录认证码
|
||||||
* 此方法执行后,其它web端微信、pc端都会下线
|
* 此方法执行后,其它web端微信、pc端都会下线
|
||||||
|
*
|
||||||
|
* @param httpClient http客户端
|
||||||
|
* @param redirectUri 调整uri
|
||||||
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject getLoginCode(HttpClient httpClient,
|
public JSONObject getLoginCode(HttpClient httpClient,
|
||||||
String redirectUri) {
|
String redirectUri) {
|
||||||
@ -236,9 +248,7 @@ public class WebWeixinApi {
|
|||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
String res = EntityUtils.toString(entity, Consts.UTF_8);
|
String res = EntityUtils.toString(entity, Consts.UTF_8);
|
||||||
|
|
||||||
JSONObject result = JSONObject.parseObject(XML.toJSONObject(res).toString()).getJSONObject("error");
|
return JSONObject.parseObject(XML.toJSONObject(res).toString()).getJSONObject("error");
|
||||||
|
|
||||||
return result;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("获取登录认证码异常", e);
|
logger.error("获取登录认证码异常", e);
|
||||||
return null;
|
return null;
|
||||||
@ -247,21 +257,25 @@ public class WebWeixinApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出登录
|
* 退出登录
|
||||||
|
*
|
||||||
|
* @param httpClient http客户端
|
||||||
|
* @param urlVersion url版本号
|
||||||
|
* @param baseRequest BaseRequest
|
||||||
*/
|
*/
|
||||||
public void logout(HttpClient httpClient,
|
public void logout(HttpClient httpClient,
|
||||||
String urlVersion,
|
String urlVersion,
|
||||||
BaseRequest BaseRequest) {
|
BaseRequest baseRequest) {
|
||||||
try {
|
try {
|
||||||
List<NameValuePair> pairList = new ArrayList<>();
|
List<NameValuePair> pairList = new ArrayList<>();
|
||||||
pairList.add(new BasicNameValuePair("sid", BaseRequest.getSid()));
|
pairList.add(new BasicNameValuePair("sid", baseRequest.getSid()));
|
||||||
pairList.add(new BasicNameValuePair("uin", BaseRequest.getUin()));
|
pairList.add(new BasicNameValuePair("uin", baseRequest.getUin()));
|
||||||
|
|
||||||
//分两步进行
|
//分两步进行
|
||||||
for (int i = 0; i <= 1; i++) {
|
for (int i = 0; i <= 1; i++) {
|
||||||
String url = new ST(PropertiesUtil.getProperty("webwx-url.logout_url"))
|
String url = new ST(PropertiesUtil.getProperty("webwx-url.logout_url"))
|
||||||
.add("urlVersion", urlVersion)
|
.add("urlVersion", urlVersion)
|
||||||
.add("type", i)
|
.add("type", i)
|
||||||
.add("skey", StringUtil.encodeURL(BaseRequest.getSkey(), Consts.UTF_8.name()))
|
.add("skey", StringUtil.encodeURL(baseRequest.getSkey(), Consts.UTF_8.name()))
|
||||||
.render();
|
.render();
|
||||||
|
|
||||||
HttpPost httpPost = new HttpPost(url);
|
HttpPost httpPost = new HttpPost(url);
|
||||||
@ -279,12 +293,16 @@ public class WebWeixinApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* push登录
|
* push登录
|
||||||
|
*
|
||||||
|
* @param httpClient http客户端
|
||||||
|
* @param urlVersion url版本号
|
||||||
|
* @param wxuin uin
|
||||||
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject pushLogin(HttpClient httpClient,
|
public JSONObject pushLogin(HttpClient httpClient,
|
||||||
String urlVersion,
|
String urlVersion,
|
||||||
String wxuin) {
|
String wxuin) {
|
||||||
try {
|
try {
|
||||||
long millis = System.currentTimeMillis();
|
|
||||||
String url = new ST(PropertiesUtil.getProperty("webwx-url.pushlogin_url"))
|
String url = new ST(PropertiesUtil.getProperty("webwx-url.pushlogin_url"))
|
||||||
.add("urlVersion", urlVersion)
|
.add("urlVersion", urlVersion)
|
||||||
.add("uin", wxuin)
|
.add("uin", wxuin)
|
||||||
@ -311,11 +329,17 @@ public class WebWeixinApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取初始化数据
|
* 获取初始化数据
|
||||||
|
*
|
||||||
|
* @param httpClient http客户端
|
||||||
|
* @param urlVersion url版本号
|
||||||
|
* @param passticket passticket
|
||||||
|
* @param baseRequest BaseRequest
|
||||||
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject webWeixinInit(HttpClient httpClient,
|
public JSONObject webWeixinInit(HttpClient httpClient,
|
||||||
String urlVersion,
|
String urlVersion,
|
||||||
String passticket,
|
String passticket,
|
||||||
BaseRequest BaseRequest) {
|
BaseRequest baseRequest) {
|
||||||
try {
|
try {
|
||||||
String url = new ST(PropertiesUtil.getProperty("webwx-url.webwxinit_url"))
|
String url = new ST(PropertiesUtil.getProperty("webwx-url.webwxinit_url"))
|
||||||
.add("urlVersion", urlVersion)
|
.add("urlVersion", urlVersion)
|
||||||
@ -327,7 +351,7 @@ public class WebWeixinApi {
|
|||||||
httpPost.setHeader("Content-type", ContentType.APPLICATION_JSON.toString());
|
httpPost.setHeader("Content-type", ContentType.APPLICATION_JSON.toString());
|
||||||
|
|
||||||
JSONObject paramJson = new JSONObject();
|
JSONObject paramJson = new JSONObject();
|
||||||
paramJson.put("BaseRequest", BaseRequest);
|
paramJson.put("BaseRequest", baseRequest);
|
||||||
HttpEntity paramEntity = new StringEntity(paramJson.toJSONString(), Consts.UTF_8);
|
HttpEntity paramEntity = new StringEntity(paramJson.toJSONString(), Consts.UTF_8);
|
||||||
httpPost.setEntity(paramEntity);
|
httpPost.setEntity(paramEntity);
|
||||||
|
|
||||||
@ -350,12 +374,17 @@ public class WebWeixinApi {
|
|||||||
/**
|
/**
|
||||||
* 开启消息状态通知
|
* 开启消息状态通知
|
||||||
*
|
*
|
||||||
* @return
|
* @param httpClient http客户端
|
||||||
|
* @param urlVersion url版本号
|
||||||
|
* @param passticket passticket
|
||||||
|
* @param baseRequest BaseRequest
|
||||||
|
* @param loginUserName 当前登录账号用户名
|
||||||
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject statusNotify(HttpClient httpClient,
|
public JSONObject statusNotify(HttpClient httpClient,
|
||||||
String urlVersion,
|
String urlVersion,
|
||||||
String passticket,
|
String passticket,
|
||||||
BaseRequest BaseRequest,
|
BaseRequest baseRequest,
|
||||||
String loginUserName) {
|
String loginUserName) {
|
||||||
try {
|
try {
|
||||||
String url = new ST(PropertiesUtil.getProperty("webwx-url.statusnotify_url"))
|
String url = new ST(PropertiesUtil.getProperty("webwx-url.statusnotify_url"))
|
||||||
@ -367,7 +396,7 @@ public class WebWeixinApi {
|
|||||||
httpPost.setHeader("Content-type", ContentType.APPLICATION_JSON.toString());
|
httpPost.setHeader("Content-type", ContentType.APPLICATION_JSON.toString());
|
||||||
|
|
||||||
JSONObject paramJson = new JSONObject();
|
JSONObject paramJson = new JSONObject();
|
||||||
paramJson.put("BaseRequest", BaseRequest);
|
paramJson.put("BaseRequest", baseRequest);
|
||||||
paramJson.put("ClientMsgId", System.currentTimeMillis());
|
paramJson.put("ClientMsgId", System.currentTimeMillis());
|
||||||
paramJson.put("Code", 3);
|
paramJson.put("Code", 3);
|
||||||
paramJson.put("FromUserName", loginUserName);
|
paramJson.put("FromUserName", loginUserName);
|
||||||
@ -393,21 +422,27 @@ public class WebWeixinApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务端状态同步心跳
|
* 服务端状态同步心跳
|
||||||
|
*
|
||||||
|
* @param httpClient http客户端
|
||||||
|
* @param urlVersion url版本号
|
||||||
|
* @param baseRequest BaseRequest
|
||||||
|
* @param syncKeyList SyncKeyList
|
||||||
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject syncCheck(HttpClient httpClient,
|
public JSONObject syncCheck(HttpClient httpClient,
|
||||||
String urlVersion,
|
String urlVersion,
|
||||||
BaseRequest BaseRequest,
|
BaseRequest baseRequest,
|
||||||
JSONArray SyncKeyList) {
|
JSONArray syncKeyList) {
|
||||||
try {
|
try {
|
||||||
long millis = System.currentTimeMillis();
|
long millis = System.currentTimeMillis();
|
||||||
String url = new ST(PropertiesUtil.getProperty("webwx-url.synccheck_url"))
|
String url = new ST(PropertiesUtil.getProperty("webwx-url.synccheck_url"))
|
||||||
.add("urlVersion", urlVersion)
|
.add("urlVersion", urlVersion)
|
||||||
.add("r", millis)
|
.add("r", millis)
|
||||||
.add("skey", StringUtil.encodeURL(BaseRequest.getSkey(), Consts.UTF_8.name()))
|
.add("skey", StringUtil.encodeURL(baseRequest.getSkey(), Consts.UTF_8.name()))
|
||||||
.add("sid", BaseRequest.getSid())
|
.add("sid", baseRequest.getSid())
|
||||||
.add("uin", BaseRequest.getUin())
|
.add("uin", baseRequest.getUin())
|
||||||
.add("deviceid", WechatUtil.createDeviceID())
|
.add("deviceid", WechatUtil.createDeviceID())
|
||||||
.add("synckey", StringUtil.encodeURL(WechatUtil.syncKeyListToString(SyncKeyList), Consts.UTF_8.name()))
|
.add("synckey", StringUtil.encodeURL(WechatUtil.syncKeyListToString(syncKeyList), Consts.UTF_8.name()))
|
||||||
.add("_", millis)
|
.add("_", millis)
|
||||||
.render();
|
.render();
|
||||||
|
|
||||||
@ -446,6 +481,12 @@ public class WebWeixinApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部联系人列表
|
* 获取全部联系人列表
|
||||||
|
*
|
||||||
|
* @param httpClient http客户端
|
||||||
|
* @param urlVersion url版本号
|
||||||
|
* @param passticket passticket
|
||||||
|
* @param skey skey
|
||||||
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject getContact(HttpClient httpClient,
|
public JSONObject getContact(HttpClient httpClient,
|
||||||
String urlVersion,
|
String urlVersion,
|
||||||
@ -479,11 +520,18 @@ public class WebWeixinApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量获取指定用户信息
|
* 批量获取指定用户信息
|
||||||
|
*
|
||||||
|
* @param httpClient http客户端
|
||||||
|
* @param urlVersion url版本号
|
||||||
|
* @param passticket passticket
|
||||||
|
* @param baseRequest BaseRequest
|
||||||
|
* @param batchContactList 联系人列表
|
||||||
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject batchGetContact(HttpClient httpClient,
|
public JSONObject batchGetContact(HttpClient httpClient,
|
||||||
String urlVersion,
|
String urlVersion,
|
||||||
String passticket,
|
String passticket,
|
||||||
BaseRequest BaseRequest,
|
BaseRequest baseRequest,
|
||||||
JSONArray batchContactList) {
|
JSONArray batchContactList) {
|
||||||
try {
|
try {
|
||||||
String url = new ST(PropertiesUtil.getProperty("webwx-url.batchgetcontact_url"))
|
String url = new ST(PropertiesUtil.getProperty("webwx-url.batchgetcontact_url"))
|
||||||
@ -496,7 +544,7 @@ public class WebWeixinApi {
|
|||||||
httpPost.setHeader("Content-type", ContentType.APPLICATION_JSON.toString());
|
httpPost.setHeader("Content-type", ContentType.APPLICATION_JSON.toString());
|
||||||
|
|
||||||
JSONObject paramJson = new JSONObject();
|
JSONObject paramJson = new JSONObject();
|
||||||
paramJson.put("BaseRequest", BaseRequest);
|
paramJson.put("BaseRequest", baseRequest);
|
||||||
paramJson.put("Count", batchContactList.size());
|
paramJson.put("Count", batchContactList.size());
|
||||||
paramJson.put("List", batchContactList);
|
paramJson.put("List", batchContactList);
|
||||||
HttpEntity paramEntity = new StringEntity(paramJson.toJSONString(), Consts.UTF_8);
|
HttpEntity paramEntity = new StringEntity(paramJson.toJSONString(), Consts.UTF_8);
|
||||||
@ -520,17 +568,24 @@ public class WebWeixinApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 从服务端同步新数据
|
* 从服务端同步新数据
|
||||||
|
*
|
||||||
|
* @param httpClient http客户端
|
||||||
|
* @param urlVersion url版本号
|
||||||
|
* @param passticket passticket
|
||||||
|
* @param baseRequest BaseRequest
|
||||||
|
* @param syncKey syncKey
|
||||||
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject webWxSync(HttpClient httpClient,
|
public JSONObject webWxSync(HttpClient httpClient,
|
||||||
String urlVersion,
|
String urlVersion,
|
||||||
String passticket,
|
String passticket,
|
||||||
BaseRequest BaseRequest,
|
BaseRequest baseRequest,
|
||||||
JSONObject SyncKey) {
|
JSONObject syncKey) {
|
||||||
try {
|
try {
|
||||||
String url = new ST(PropertiesUtil.getProperty("webwx-url.webwxsync_url"))
|
String url = new ST(PropertiesUtil.getProperty("webwx-url.webwxsync_url"))
|
||||||
.add("urlVersion", urlVersion)
|
.add("urlVersion", urlVersion)
|
||||||
.add("skey", BaseRequest.getSkey())
|
.add("skey", baseRequest.getSkey())
|
||||||
.add("sid", BaseRequest.getSid())
|
.add("sid", baseRequest.getSid())
|
||||||
.add("pass_ticket", StringUtil.encodeURL(passticket, Consts.UTF_8.name()))
|
.add("pass_ticket", StringUtil.encodeURL(passticket, Consts.UTF_8.name()))
|
||||||
.render();
|
.render();
|
||||||
|
|
||||||
@ -538,8 +593,8 @@ public class WebWeixinApi {
|
|||||||
httpPost.setHeader("Content-type", ContentType.APPLICATION_JSON.toString());
|
httpPost.setHeader("Content-type", ContentType.APPLICATION_JSON.toString());
|
||||||
|
|
||||||
JSONObject paramJson = new JSONObject();
|
JSONObject paramJson = new JSONObject();
|
||||||
paramJson.put("BaseRequest", BaseRequest);
|
paramJson.put("BaseRequest", baseRequest);
|
||||||
paramJson.put("SyncKey", SyncKey);
|
paramJson.put("SyncKey", syncKey);
|
||||||
HttpEntity paramEntity = new StringEntity(paramJson.toJSONString(), Consts.UTF_8);
|
HttpEntity paramEntity = new StringEntity(paramJson.toJSONString(), Consts.UTF_8);
|
||||||
httpPost.setEntity(paramEntity);
|
httpPost.setEntity(paramEntity);
|
||||||
|
|
||||||
@ -561,6 +616,13 @@ public class WebWeixinApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送消息
|
* 发送消息
|
||||||
|
*
|
||||||
|
* @param httpClient http客户端
|
||||||
|
* @param urlVersion url版本号
|
||||||
|
* @param passticket passticket
|
||||||
|
* @param baseRequest BaseRequest
|
||||||
|
* @param message 消息
|
||||||
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject sendMsg(HttpClient httpClient,
|
public JSONObject sendMsg(HttpClient httpClient,
|
||||||
String urlVersion,
|
String urlVersion,
|
||||||
@ -592,9 +654,7 @@ public class WebWeixinApi {
|
|||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
String res = EntityUtils.toString(entity, Consts.UTF_8);
|
String res = EntityUtils.toString(entity, Consts.UTF_8);
|
||||||
|
|
||||||
JSONObject result = JSONObject.parseObject(res);
|
return JSONObject.parseObject(res);
|
||||||
|
|
||||||
return result;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("发送消息异常", e);
|
logger.error("发送消息异常", e);
|
||||||
return null;
|
return null;
|
||||||
@ -604,17 +664,17 @@ public class WebWeixinApi {
|
|||||||
/**
|
/**
|
||||||
* 上传媒体文件(支持大文件自动分片上传)
|
* 上传媒体文件(支持大文件自动分片上传)
|
||||||
*
|
*
|
||||||
* @param httpClient
|
* @param httpClient http客户端
|
||||||
* @param urlVersion
|
* @param urlVersion url版本号
|
||||||
* @param passticket
|
* @param passticket passticket
|
||||||
* @param baseRequest
|
* @param baseRequest BaseRequest
|
||||||
* @param fromUserName
|
* @param fromUserName 发送者用户名
|
||||||
* @param toUserName
|
* @param toUserName 接受者用户名
|
||||||
* @param dataTicket
|
* @param dataTicket dataTicket
|
||||||
* @param mediaData
|
* @param mediaData 媒体文件二进制数据
|
||||||
* @param mediaName
|
* @param mediaName 媒体文件名称
|
||||||
* @param contentType
|
* @param contentType 媒体文件类型
|
||||||
* @return
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject uploadMedia(HttpClient httpClient,
|
public JSONObject uploadMedia(HttpClient httpClient,
|
||||||
String urlVersion,
|
String urlVersion,
|
||||||
@ -691,12 +751,12 @@ public class WebWeixinApi {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONObject BaseResponse = result.getJSONObject("BaseResponse");
|
JSONObject baseResponse = result.getJSONObject("BaseResponse");
|
||||||
if (BaseResponse == null) {
|
if (baseResponse == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int Ret = BaseResponse.getIntValue("Ret");
|
int ret = baseResponse.getIntValue("Ret");
|
||||||
if (Ret != 0) {
|
if (ret != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -710,6 +770,13 @@ public class WebWeixinApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送图片消息
|
* 发送图片消息
|
||||||
|
*
|
||||||
|
* @param httpClient http客户端
|
||||||
|
* @param urlVersion url版本号
|
||||||
|
* @param passticket passticket
|
||||||
|
* @param baseRequest BaseRequest
|
||||||
|
* @param message 消息
|
||||||
|
* @return 返回数据
|
||||||
*/
|
*/
|
||||||
public JSONObject sendImageMsg(HttpClient httpClient,
|
public JSONObject sendImageMsg(HttpClient httpClient,
|
||||||
String urlVersion,
|
String urlVersion,
|
||||||
@ -741,9 +808,7 @@ public class WebWeixinApi {
|
|||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
String res = EntityUtils.toString(entity, Consts.UTF_8);
|
String res = EntityUtils.toString(entity, Consts.UTF_8);
|
||||||
|
|
||||||
JSONObject result = JSONObject.parseObject(res);
|
return JSONObject.parseObject(res);
|
||||||
|
|
||||||
return result;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("发送图片消息异常", e);
|
logger.error("发送图片消息异常", e);
|
||||||
return null;
|
return null;
|
||||||
|
@ -2,16 +2,24 @@ package com.hotlcc.wechat4j.enums;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信退出类型
|
* 微信退出类型
|
||||||
|
*
|
||||||
|
* @author Allen
|
||||||
*/
|
*/
|
||||||
public enum ExitTypeEnum {
|
public enum ExitTypeEnum {
|
||||||
ERROR_EXIT("错误导致退出"),
|
/**
|
||||||
LOCAL_EXIT("本次手动退出"),
|
* 错误导致退出
|
||||||
REMOTE_EXIT("远程操作退出");
|
*/
|
||||||
|
ERROR_EXIT,
|
||||||
|
/**
|
||||||
|
* 本次手动退出
|
||||||
|
*/
|
||||||
|
LOCAL_EXIT,
|
||||||
|
/**
|
||||||
|
* 远程操作退出
|
||||||
|
*/
|
||||||
|
REMOTE_EXIT;
|
||||||
|
|
||||||
private String desc;
|
ExitTypeEnum() {
|
||||||
|
|
||||||
ExitTypeEnum(String desc) {
|
|
||||||
this.desc = desc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,22 @@ package com.hotlcc.wechat4j.enums;
|
|||||||
/**
|
/**
|
||||||
* 等待确认登录的tip
|
* 等待确认登录的tip
|
||||||
*
|
*
|
||||||
* @author https://gitee.com/hotlcc
|
* @author Allen
|
||||||
*/
|
*/
|
||||||
public enum LoginTipEnum {
|
public enum LoginTipEnum {
|
||||||
TIP_0(0, "扫码登录"),
|
/**
|
||||||
TIP_1(1, "确认登录");
|
* 扫码登录
|
||||||
|
*/
|
||||||
|
TIP_0(0),
|
||||||
|
/**
|
||||||
|
* 确认登录
|
||||||
|
*/
|
||||||
|
TIP_1(1);
|
||||||
|
|
||||||
private int code;
|
private int code;
|
||||||
private String desc;
|
|
||||||
|
|
||||||
LoginTipEnum(int code, String desc) {
|
LoginTipEnum(int code) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.desc = desc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCode() {
|
public int getCode() {
|
||||||
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Allen
|
* @author Allen
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||||
public final class QRCodeUtil {
|
public final class QRCodeUtil {
|
||||||
private static Logger logger = LoggerFactory.getLogger(QRCodeUtil.class);
|
private static Logger logger = LoggerFactory.getLogger(QRCodeUtil.class);
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ public final class QRCodeUtil {
|
|||||||
/**
|
/**
|
||||||
* 从BitMatrix中得到boolean矩阵(不去除周围空白部分)
|
* 从BitMatrix中得到boolean矩阵(不去除周围空白部分)
|
||||||
*
|
*
|
||||||
* @return
|
* @return 得到的boolean矩阵
|
||||||
*/
|
*/
|
||||||
private static boolean[][] toBoolMatrix(BitMatrix matrix) {
|
private static boolean[][] toBoolMatrix(BitMatrix matrix) {
|
||||||
return toBoolMatrix(matrix, false);
|
return toBoolMatrix(matrix, false);
|
||||||
@ -40,9 +41,9 @@ public final class QRCodeUtil {
|
|||||||
/**
|
/**
|
||||||
* 从BitMatrix中得到boolean矩阵
|
* 从BitMatrix中得到boolean矩阵
|
||||||
*
|
*
|
||||||
* @param matrix
|
* @param matrix BitMatrix
|
||||||
* @param noMargin 是否去除周围空白
|
* @param noMargin 是否去除周围空白
|
||||||
* @return
|
* @return 得到的boolean矩阵
|
||||||
*/
|
*/
|
||||||
private static boolean[][] toBoolMatrix(BitMatrix matrix, boolean noMargin) {
|
private static boolean[][] toBoolMatrix(BitMatrix matrix, boolean noMargin) {
|
||||||
int width = matrix.getWidth();
|
int width = matrix.getWidth();
|
||||||
@ -57,8 +58,8 @@ public final class QRCodeUtil {
|
|||||||
right = width - br[1] - 1;
|
right = width - br[1] - 1;
|
||||||
}
|
}
|
||||||
boolean[][] m = new boolean[height - top - bottom][width - left - right];
|
boolean[][] m = new boolean[height - top - bottom][width - left - right];
|
||||||
for (int h = 0 + top, i = 0; h < height - bottom; h++, i++) {
|
for (int h = top, i = 0; h < height - bottom; h++, i++) {
|
||||||
for (int w = 0 + left, j = 0; w < width - right; w++, j++) {
|
for (int w = left, j = 0; w < width - right; w++, j++) {
|
||||||
m[i][j] = matrix.get(w, h);
|
m[i][j] = matrix.get(w, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,8 +69,8 @@ public final class QRCodeUtil {
|
|||||||
/**
|
/**
|
||||||
* 将矩阵逆时针转90度
|
* 将矩阵逆时针转90度
|
||||||
*
|
*
|
||||||
* @param matrix
|
* @param matrix 旋转前的矩阵
|
||||||
* @return
|
* @return 旋转后的矩阵
|
||||||
*/
|
*/
|
||||||
private static boolean[][] reverseMatrix(boolean[][] matrix) {
|
private static boolean[][] reverseMatrix(boolean[][] matrix) {
|
||||||
if (matrix == null) {
|
if (matrix == null) {
|
||||||
@ -92,15 +93,14 @@ public final class QRCodeUtil {
|
|||||||
/**
|
/**
|
||||||
* 从boolMatrix左上角判断二维码定位标记的大小
|
* 从boolMatrix左上角判断二维码定位标记的大小
|
||||||
*
|
*
|
||||||
* @param boolMatrix
|
* @param boolMatrix bool矩阵
|
||||||
* @return
|
* @return 定位标记大小
|
||||||
*/
|
*/
|
||||||
private static int getBitCharSize(boolean[][] boolMatrix) {
|
private static int getBitCharSize(boolean[][] boolMatrix) {
|
||||||
int a = 0, b = 0;
|
int a = 0, b = 0;
|
||||||
out:
|
out:
|
||||||
for (int i = 0, len = boolMatrix.length; i < len; i++) {
|
for (boolean[] boolArr : boolMatrix) {
|
||||||
boolean find = false;
|
boolean find = false;
|
||||||
boolean[] boolArr = boolMatrix[i];
|
|
||||||
for (int i2 = 0, len2 = boolArr.length; i2 < len2; i2++) {
|
for (int i2 = 0, len2 = boolArr.length; i2 < len2; i2++) {
|
||||||
if (!find && boolArr[i2]) {
|
if (!find && boolArr[i2]) {
|
||||||
find = true;
|
find = true;
|
||||||
@ -119,20 +119,21 @@ public final class QRCodeUtil {
|
|||||||
/**
|
/**
|
||||||
* 从boolMatrix判断bit-char占位比
|
* 从boolMatrix判断bit-char占位比
|
||||||
*
|
*
|
||||||
* @param boolMatrix
|
* @param boolMatrix bool矩阵
|
||||||
* @return
|
* @return 占位比
|
||||||
*/
|
*/
|
||||||
private static int getBitCharRatio(boolean[][] boolMatrix) {
|
private static int getBitCharRatio(boolean[][] boolMatrix) {
|
||||||
|
int len = 4;
|
||||||
// 找出四个角的占位数
|
// 找出四个角的占位数
|
||||||
int[] size = new int[4];
|
int[] size = new int[len];
|
||||||
size[0] = getBitCharSize(boolMatrix);
|
size[0] = getBitCharSize(boolMatrix);
|
||||||
for (int i = 1; i < 4; i++) {
|
for (int i = 1; i < len; i++) {
|
||||||
boolMatrix = reverseMatrix(boolMatrix);
|
boolMatrix = reverseMatrix(boolMatrix);
|
||||||
size[i] = getBitCharSize(boolMatrix);
|
size[i] = getBitCharSize(boolMatrix);
|
||||||
}
|
}
|
||||||
// 统计每个占位数出现的次数
|
// 统计每个占位数出现的次数
|
||||||
int[] num = new int[4];
|
int[] num = new int[len];
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (int s : size) {
|
for (int s : size) {
|
||||||
if (s == size[i]) {
|
if (s == size[i]) {
|
||||||
@ -143,12 +144,12 @@ public final class QRCodeUtil {
|
|||||||
}
|
}
|
||||||
// 找出最多的次数
|
// 找出最多的次数
|
||||||
int maxNum = num[0];
|
int maxNum = num[0];
|
||||||
for (int i = 1; i < 4; i++) {
|
for (int i = 1; i < len; i++) {
|
||||||
maxNum = Math.max(maxNum, num[i]);
|
maxNum = Math.max(maxNum, num[i]);
|
||||||
}
|
}
|
||||||
// 找出出现次数最多的占位数
|
// 找出出现次数最多的占位数
|
||||||
int s = 0;
|
int s = 0;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
if (num[i] == maxNum) {
|
if (num[i] == maxNum) {
|
||||||
s = size[i];
|
s = size[i];
|
||||||
}
|
}
|
||||||
@ -160,18 +161,20 @@ public final class QRCodeUtil {
|
|||||||
/**
|
/**
|
||||||
* 将二维码图片转为字符矩阵
|
* 将二维码图片转为字符矩阵
|
||||||
*
|
*
|
||||||
* @param image
|
* @param image 二维码图片
|
||||||
* @return
|
* @param onStr 实体字符串
|
||||||
|
* @param offStr 空白字符串
|
||||||
|
* @return 字符矩阵
|
||||||
*/
|
*/
|
||||||
public static String toCharMatrix(BufferedImage image, String onStr, String offStr) {
|
public static String toCharMatrix(BufferedImage image, String onStr, String offStr) {
|
||||||
LuminanceSource source = new BufferedImageLuminanceSource(image);
|
LuminanceSource source = new BufferedImageLuminanceSource(image);
|
||||||
Binarizer binarizer = new HybridBinarizer(source);
|
Binarizer binarizer = new HybridBinarizer(source);
|
||||||
BitMatrix matrix = null;
|
BitMatrix matrix;
|
||||||
try {
|
try {
|
||||||
matrix = binarizer.getBlackMatrix();
|
matrix = binarizer.getBlackMatrix();
|
||||||
boolean[][] boolMatrix = toBoolMatrix(matrix, true);
|
boolean[][] boolMatrix = toBoolMatrix(matrix, true);
|
||||||
int ratio = getBitCharRatio(boolMatrix);
|
int ratio = getBitCharRatio(boolMatrix);
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0, len = boolMatrix.length; i < len; i += ratio) {
|
for (int i = 0, len = boolMatrix.length; i < len; i += ratio) {
|
||||||
boolean[] boolArr = boolMatrix[i];
|
boolean[] boolArr = boolMatrix[i];
|
||||||
for (int i2 = 0, len2 = boolArr.length; i2 < len2; i2 += ratio) {
|
for (int i2 = 0, len2 = boolArr.length; i2 < len2; i2 += ratio) {
|
||||||
@ -189,8 +192,8 @@ public final class QRCodeUtil {
|
|||||||
/**
|
/**
|
||||||
* 将二维码图片转为字符矩阵
|
* 将二维码图片转为字符矩阵
|
||||||
*
|
*
|
||||||
* @param image
|
* @param image 二维码图片
|
||||||
* @return
|
* @return 字符矩阵
|
||||||
*/
|
*/
|
||||||
public static String toCharMatrix(BufferedImage image) {
|
public static String toCharMatrix(BufferedImage image) {
|
||||||
return toCharMatrix(image, " ", "██");
|
return toCharMatrix(image, " ", "██");
|
||||||
@ -199,8 +202,10 @@ public final class QRCodeUtil {
|
|||||||
/**
|
/**
|
||||||
* 将二维码图片转为字符矩阵
|
* 将二维码图片转为字符矩阵
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data 二维码图片的字节数据
|
||||||
* @return
|
* @param onStr 实体字符串
|
||||||
|
* @param offStr 空白字符串
|
||||||
|
* @return 字符矩阵
|
||||||
*/
|
*/
|
||||||
public static String toCharMatrix(byte[] data, String onStr, String offStr) {
|
public static String toCharMatrix(byte[] data, String onStr, String offStr) {
|
||||||
ByteArrayInputStream bais = null;
|
ByteArrayInputStream bais = null;
|
||||||
@ -225,8 +230,8 @@ public final class QRCodeUtil {
|
|||||||
/**
|
/**
|
||||||
* 将二维码图片转为字符矩阵
|
* 将二维码图片转为字符矩阵
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data 二维码图片的字节数据
|
||||||
* @return
|
* @return 字符矩阵
|
||||||
*/
|
*/
|
||||||
public static String toCharMatrix(byte[] data) {
|
public static String toCharMatrix(byte[] data) {
|
||||||
return toCharMatrix(data, " ", "██");
|
return toCharMatrix(data, " ", "██");
|
||||||
@ -235,8 +240,8 @@ public final class QRCodeUtil {
|
|||||||
/**
|
/**
|
||||||
* 将二维码图片数据写入到临时文件
|
* 将二维码图片数据写入到临时文件
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data 二维码图片的字节数据
|
||||||
* @return
|
* @return 字符矩阵
|
||||||
*/
|
*/
|
||||||
public static File writeToTempFile(byte[] data) {
|
public static File writeToTempFile(byte[] data) {
|
||||||
FileOutputStream fos = null;
|
FileOutputStream fos = null;
|
||||||
@ -263,12 +268,12 @@ public final class QRCodeUtil {
|
|||||||
/**
|
/**
|
||||||
* 打开二维码图片
|
* 打开二维码图片
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data 二维码图片的字节数据
|
||||||
*/
|
*/
|
||||||
public static void openQRCodeImage(byte[] data) {
|
public static void openQRCodeImage(byte[] data) {
|
||||||
OperatingSystemEnum os = OperatingSystemEnum.currentOperatingSystem();
|
OperatingSystemEnum os = OperatingSystemEnum.currentOperatingSystem();
|
||||||
Runtime runtime = null;
|
Runtime runtime;
|
||||||
File tmp = null;
|
File tmp;
|
||||||
switch (os) {
|
switch (os) {
|
||||||
case WINDOWS:
|
case WINDOWS:
|
||||||
runtime = Runtime.getRuntime();
|
runtime = Runtime.getRuntime();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user