|
@@ -1,11 +1,13 @@
|
|
package com.caimei365.wechat.service.impl;
|
|
package com.caimei365.wechat.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.caimei365.wechat.dao.WeChatDao;
|
|
import com.caimei365.wechat.dao.WeChatDao;
|
|
import com.caimei365.wechat.entity.WeChatConstant;
|
|
import com.caimei365.wechat.entity.WeChatConstant;
|
|
import com.caimei365.wechat.entity.WechatArticleDetail;
|
|
import com.caimei365.wechat.entity.WechatArticleDetail;
|
|
import com.caimei365.wechat.entity.WechatReply;
|
|
import com.caimei365.wechat.entity.WechatReply;
|
|
import com.caimei365.wechat.service.WechatServerService;
|
|
import com.caimei365.wechat.service.WechatServerService;
|
|
|
|
+import com.caimei365.wechat.utils.HttpUtil;
|
|
import com.caimei365.wechat.utils.MessageUtil;
|
|
import com.caimei365.wechat.utils.MessageUtil;
|
|
import com.caimei365.wechat.utils.SignUtil;
|
|
import com.caimei365.wechat.utils.SignUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -96,43 +98,42 @@ public class WechatServerServiceImpl implements WechatServerService {
|
|
}
|
|
}
|
|
// 根据keyword匹配数据库回复配置
|
|
// 根据keyword匹配数据库回复配置
|
|
WechatReply reply = weChatDao.getReplyByParams("input", keyword, wxType);
|
|
WechatReply reply = weChatDao.getReplyByParams("input", keyword, wxType);
|
|
-// if (null == reply) {
|
|
|
|
-// reply = weChatDao.getReplyByParams("input", "autoReply", wxType);
|
|
|
|
-// }
|
|
|
|
-// if (null == reply) {
|
|
|
|
-// // 将消息转发到到客服系统
|
|
|
|
-// return MessageUtil.setCustomerXml(openid, wxType);
|
|
|
|
-// }
|
|
|
|
- log.info(">>>>>>>>>>匹配已配置关键词:" + keyword);
|
|
|
|
- String replyXml = setXmlByDatabaseReply(openid, wxType, reply);
|
|
|
|
- if (replyXml != null) {
|
|
|
|
- return replyXml;
|
|
|
|
|
|
+ if (null != reply) {
|
|
|
|
+ log.info(">>>>>>>>>>匹配已配置关键词:" + keyword);
|
|
|
|
+ String replyXml = setXmlByDatabaseReply(openid, wxType, reply);
|
|
|
|
+ if (StringUtils.hasLength(replyXml)) {
|
|
|
|
+ return replyXml;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
log.info(">>>>>>>>>>模糊搜索:" + keyword);
|
|
log.info(">>>>>>>>>>模糊搜索:" + keyword);
|
|
WechatArticleDetail article = null;
|
|
WechatArticleDetail article = null;
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
// https://core.caimei365.com/commodity/search/query/product?keyword=
|
|
// https://core.caimei365.com/commodity/search/query/product?keyword=
|
|
- String uri = coreDomain + "commodity/search/query/product?keyword="+keyword;
|
|
|
|
- JSONObject forObject = restTemplate.getForObject(uri, JSONObject.class);
|
|
|
|
- if(forObject != null){
|
|
|
|
- String data = forObject.getString("data");
|
|
|
|
- if(StringUtils.hasLength(data)){
|
|
|
|
- JSONObject parse = JSONObject.parseObject(data);
|
|
|
|
- if(parse != null){
|
|
|
|
- Integer total = parse.getInteger("total");
|
|
|
|
- if(total>0){
|
|
|
|
- article = new WechatArticleDetail();
|
|
|
|
- article.setTitle("帮您匹配到"+ total + "个商品,点击查看");
|
|
|
|
- article.setPicUrl(imageDomain + "/group1/M00/03/EC/rB-lGGHg9ZOAe8VdAAJevlD1ofg562.png");
|
|
|
|
- String url = wwwDomain + "product/list.html?keyword="+keyword;
|
|
|
|
- try {
|
|
|
|
- url = URLEncoder.encode(url, "UTF-8");
|
|
|
|
- } catch (UnsupportedEncodingException ignored) {}
|
|
|
|
- article.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + caimeiAppid + "&redirect_uri=" + url +"&response_type=code&scope=snsapi_base&state=reLogin#wechat_redirect");
|
|
|
|
|
|
+ String uri = coreDomain + "/commodity/search/query/product?keyword="+keyword;
|
|
|
|
+ try {
|
|
|
|
+ String jsonResult = HttpUtil.httpRequest(URLEncoder.encode(uri, "UTF-8"), "GET", null);
|
|
|
|
+ log.info(">>>>>>>>>>uri:" + uri + ",jsonResult:" + jsonResult);
|
|
|
|
+ if(StringUtils.hasLength(jsonResult)){
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(jsonResult);
|
|
|
|
+ String data = jsonObject.getString("data");
|
|
|
|
+ if(StringUtils.hasLength(data)){
|
|
|
|
+ JSONObject parse = JSONObject.parseObject(data);
|
|
|
|
+ if(parse != null){
|
|
|
|
+ Integer total = parse.getInteger("total");
|
|
|
|
+ if(total>0){
|
|
|
|
+ article = new WechatArticleDetail();
|
|
|
|
+ article.setTitle("帮您匹配到"+ total + "个商品,点击查看");
|
|
|
|
+ article.setPicUrl(imageDomain + "/group1/M00/03/EC/rB-lGGHg9ZOAe8VdAAJevlD1ofg562.png");
|
|
|
|
+ String url = wwwDomain + "product/list.html?keyword="+keyword;
|
|
|
|
+ try {
|
|
|
|
+ url = URLEncoder.encode(url, "UTF-8");
|
|
|
|
+ } catch (UnsupportedEncodingException ignored) {}
|
|
|
|
+ article.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + caimeiAppid + "&redirect_uri=" + url +"&response_type=code&scope=snsapi_base&state=reLogin#wechat_redirect");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ } catch (Exception ignored) {}
|
|
if (null != article) {
|
|
if (null != article) {
|
|
List<WechatArticleDetail> articles = new ArrayList<>();
|
|
List<WechatArticleDetail> articles = new ArrayList<>();
|
|
articles.add(article);
|
|
articles.add(article);
|
|
@@ -140,10 +141,11 @@ public class WechatServerServiceImpl implements WechatServerService {
|
|
}
|
|
}
|
|
log.info(">>>>>>>>>>默认无关键字匹配回复图文1220");
|
|
log.info(">>>>>>>>>>默认无关键字匹配回复图文1220");
|
|
List<WechatArticleDetail> defaultList = weChatDao.getArticleDetailList(1220);
|
|
List<WechatArticleDetail> defaultList = weChatDao.getArticleDetailList(1220);
|
|
- if (CollectionUtils.isEmpty(defaultList)) {
|
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(defaultList)) {
|
|
return MessageUtil.setArticleXml(openid, wxType, defaultList);
|
|
return MessageUtil.setArticleXml(openid, wxType, defaultList);
|
|
}
|
|
}
|
|
- return null;
|
|
|
|
|
|
+ // 将消息转发到到客服系统
|
|
|
|
+ return MessageUtil.setCustomerXml(openid, wxType);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -277,7 +279,8 @@ public class WechatServerServiceImpl implements WechatServerService {
|
|
if ("news".equals(reply.getResponseType())) {
|
|
if ("news".equals(reply.getResponseType())) {
|
|
// 回复图文
|
|
// 回复图文
|
|
List<WechatArticleDetail> articleList = weChatDao.getArticleDetailList(reply.getRelateId());
|
|
List<WechatArticleDetail> articleList = weChatDao.getArticleDetailList(reply.getRelateId());
|
|
- if (CollectionUtils.isEmpty(articleList)) {
|
|
|
|
|
|
+ log.info(">>>>>>>>>>匹配到图文内容数量:" + articleList.size());
|
|
|
|
+ if (!CollectionUtils.isEmpty(articleList)) {
|
|
return MessageUtil.setArticleXml(openid, wxType, articleList);
|
|
return MessageUtil.setArticleXml(openid, wxType, articleList);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|