|
@@ -10,6 +10,7 @@ import com.iamberry.wechat.core.entity.wx.*;
|
|
|
import com.iamberry.wechat.face.activity.ActivityService;
|
|
|
import com.iamberry.wechat.face.admin.SystemService;
|
|
|
import com.iamberry.wechat.face.channel.AttenStatisticsService;
|
|
|
+import com.iamberry.wechat.face.customer.CustomerService;
|
|
|
import com.iamberry.wechat.face.drp.PlaceInfoService;
|
|
|
import com.iamberry.wechat.face.home.HomeService;
|
|
|
import com.iamberry.wechat.face.machineNumber.MachineNumberService;
|
|
@@ -77,6 +78,8 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
private ActivityService activityService;
|
|
|
@Autowired
|
|
|
private AttenStatisticsService attenStatisticsService;
|
|
|
+ @Autowired
|
|
|
+ private CustomerService customerService;
|
|
|
|
|
|
/**
|
|
|
* 处理微信发来的请求
|
|
@@ -97,10 +100,14 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
requestMap.put("EventKey", EventKey);
|
|
|
|
|
|
String respMessage = null;
|
|
|
- String fromUserName = null;// 发送方帐号(open_id)
|
|
|
- String toUserName = null;// 公众帐号
|
|
|
- long createTime = 0L;// 时间
|
|
|
- String msgType = null;// 消息类型
|
|
|
+ // 发送方帐号(open_id)
|
|
|
+ String fromUserName = null;
|
|
|
+ // 公众帐号
|
|
|
+ String toUserName = null;
|
|
|
+ // 时间
|
|
|
+ long createTime = 0L;
|
|
|
+ // 消息类型
|
|
|
+ String msgType = null;
|
|
|
try {
|
|
|
// 默认返回的文本消息内容
|
|
|
String respContent = "";
|
|
@@ -108,7 +115,7 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
fromUserName = requestMap.get("FromUserName");
|
|
|
toUserName = requestMap.get("ToUserName");
|
|
|
msgType = requestMap.get("MsgType");
|
|
|
- createTime = new Date().getTime();
|
|
|
+ createTime = System.currentTimeMillis();
|
|
|
|
|
|
// 准备返回给微信服务器的文本消息对象
|
|
|
TextMessage textMessage = new TextMessage();
|
|
@@ -116,7 +123,6 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
textMessage.setToUserName(fromUserName);
|
|
|
textMessage.setFromUserName(toUserName);
|
|
|
textMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_TEXT);
|
|
|
-
|
|
|
//多客服处理
|
|
|
String intxml = "<xml>"+
|
|
|
"<ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>" +
|
|
@@ -126,22 +132,27 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
/*
|
|
|
* 各种消息处理
|
|
|
*/
|
|
|
- if(msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)){ //文本消息
|
|
|
- String content = requestMap.get("Content").trim();//去空格
|
|
|
- if(!(content != null && !"".equals(content))) { // 消息为空的处理
|
|
|
+ if(msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)){
|
|
|
+ //文本消息
|
|
|
+ // 消息为空的处理
|
|
|
+ String content = requestMap.get("Content");
|
|
|
+ if(!(content != null && !"".equals(content))) {
|
|
|
respContent = ResultInfo.messageIsNullResponseText;
|
|
|
}
|
|
|
+ //去空格
|
|
|
+ content = requestMap.get("Content").trim();
|
|
|
|
|
|
- if(QQFace.isQqFace(content)){// QQ表情的处理
|
|
|
- String xml = "<xml>"+
|
|
|
+ // QQ表情的处理
|
|
|
+ if(QQFace.isQqFace(content)){
|
|
|
+ return "<xml>"+
|
|
|
"<ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>" +
|
|
|
- "<FromUserName><![CDATA[" + toUserName + "]]></FromUserName>" +
|
|
|
+ "<FromUserName><![CDATA[" + toUserName + "]]></FromUserName>" +
|
|
|
"<CreateTime>" + createTime + "</CreateTime>" +
|
|
|
"<MsgType><![CDATA[transfer_customer_service]]></MsgType></xml>";
|
|
|
- return xml;
|
|
|
}
|
|
|
|
|
|
- if (content.startsWith(NameUtils.getConfig("PLACE_CODE_PREFIX"))) {// 激活码为“CODE”开头 则为代理商绑定
|
|
|
+ // 激活码为“CODE”开头 则为代理商绑定
|
|
|
+ if (content.startsWith(NameUtils.getConfig("PLACE_CODE_PREFIX"))) {
|
|
|
content = StringUtils.trim(content);
|
|
|
respContent = bulidPlace(content, fromUserName);
|
|
|
} else {
|
|
@@ -153,44 +164,66 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
respContent = status.getCountext();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- } else if(msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_IMAGE)){// 图片消息
|
|
|
- //转发到多客服系统
|
|
|
- return intxml;
|
|
|
- } else if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_LOCATION)) {// 地理位置消息
|
|
|
- // 解析出地理位置消息
|
|
|
- return intxml;
|
|
|
- } else if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_LINK)) {// 链接消息
|
|
|
- return intxml;
|
|
|
- } else if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_VOICE)) {// 音频消息
|
|
|
- return intxml;
|
|
|
- } else if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_EVENT)) {// 事件推送
|
|
|
-
|
|
|
- String eventType = requestMap.get("Event");// 事件类型
|
|
|
+ } else if(msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_IMAGE)){
|
|
|
+ // 图片消息
|
|
|
+ Status status = joinUpCustomer(fromUserName, toUserName, createTime+"");
|
|
|
+ if (status.isFlag()) {
|
|
|
+ return status.getCountext();
|
|
|
+ } else {
|
|
|
+ respContent = status.getCountext();
|
|
|
+ }
|
|
|
+ } else if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_LOCATION)) {
|
|
|
+ // 地理位置消息
|
|
|
+ Status status = joinUpCustomer(fromUserName, toUserName, createTime+"");
|
|
|
+ if (status.isFlag()) {
|
|
|
+ return status.getCountext();
|
|
|
+ } else {
|
|
|
+ respContent = status.getCountext();
|
|
|
+ }
|
|
|
+ } else if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_LINK)) {
|
|
|
+ // 链接消息
|
|
|
+ Status status = joinUpCustomer(fromUserName, toUserName, createTime+"");
|
|
|
+ if (status.isFlag()) {
|
|
|
+ return status.getCountext();
|
|
|
+ } else {
|
|
|
+ respContent = status.getCountext();
|
|
|
+ }
|
|
|
+ } else if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_VIDEO)) {
|
|
|
+ // 视频消息
|
|
|
+ Status status = joinUpCustomer(fromUserName, toUserName, createTime+"");
|
|
|
+ if (status.isFlag()) {
|
|
|
+ return status.getCountext();
|
|
|
+ } else {
|
|
|
+ respContent = status.getCountext();
|
|
|
+ }
|
|
|
+ } else if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_VOICE)) {
|
|
|
+ // 音频消息
|
|
|
+ Status status = joinUpCustomer(fromUserName, toUserName, createTime+"");
|
|
|
+ if (status.isFlag()) {
|
|
|
+ return status.getCountext();
|
|
|
+ } else {
|
|
|
+ respContent = status.getCountext();
|
|
|
+ } } else if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_EVENT)) {
|
|
|
+ // 事件推送
|
|
|
+ String eventType = requestMap.get("Event");
|
|
|
String eventKey = requestMap.get("EventKey");
|
|
|
-
|
|
|
-// for(String s:requestMap.keySet()){
|
|
|
-// logger.info("===事件推送:" + s +"="+ requestMap.get(s));
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
// 事件列表:CLICK(点击自定义菜单)/subscribe(关注)/unsubscribe(取消关注)/SCAN(扫描二维码)/LOCATION(上报地理位置)
|
|
|
if(eventType.equals("SCAN")){
|
|
|
|
|
|
//扫描机器二维码返回跳转到完善信息页面
|
|
|
- if (eventKey.indexOf(ResultInfo.barCodePrefix) != -1) {
|
|
|
+ if (eventKey.contains(ResultInfo.barCodePrefix)) {
|
|
|
Status status = scannQrcodeGiveGift(requestMap, fromUserName);
|
|
|
if (status.isFlag()) {
|
|
|
return status.getCountext();
|
|
|
}
|
|
|
respContent = status.getCountext();
|
|
|
- }else if(eventKey.indexOf(ResultInfo.barCodeActivity) != -1){
|
|
|
+ }else if(eventKey.contains(ResultInfo.barCodeActivity)){
|
|
|
Status status = bindingActivity(requestMap, fromUserName,true);
|
|
|
if (status.isFlag()) {
|
|
|
return status.getCountext();
|
|
|
}
|
|
|
respContent = status.getCountext();
|
|
|
- }else if(eventKey.indexOf(ResultInfo.barCodeMainChannelId) != -1){
|
|
|
+ }else if(eventKey.contains(ResultInfo.barCodeMainChannelId)){
|
|
|
Status status = bindingMainChannelId(requestMap, fromUserName,false);
|
|
|
if (status.isFlag()) {
|
|
|
return status.getCountext();
|
|
@@ -200,17 +233,13 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
// 已关注用户扫描二维码事件
|
|
|
int flag = subUserScannQrcodeEvent(requestMap, fromUserName);
|
|
|
if (flag == 1 ) {
|
|
|
- /*Status status = getCouponImgText(requestMap);
|
|
|
- if (status.isFlag()) {
|
|
|
- return status.getCountext();
|
|
|
- }
|
|
|
- respContent = status.getCountext();*/
|
|
|
respContent = ResultInfo.subDefaultResponseText;
|
|
|
} else if ( flag == 0){
|
|
|
respContent = ResultInfo.subDefaultResponseText;
|
|
|
} else if (flag == 4) {
|
|
|
respContent = "欢迎您关注美国watero!您已享受购买水机终身优惠价3280元(普通会员销售价3680元),并且购买即赠三年滤芯套装,快来购买吧!<a href=\"http://w.iamberry.com/watero/wechat/wxCart/goProductList\">点击购买</a>";
|
|
|
- } else if (flag == 5) { //618好友助力
|
|
|
+ } else if (flag == 5) {
|
|
|
+ //618好友助力
|
|
|
respContent = "哇!确认过眼神,你将获得我们618天猫上朵旗舰店隐藏福利!</br>";
|
|
|
}else {
|
|
|
respContent = "欢迎您关注美国watero,恭喜您成为金牌会员。自己购买或者推荐朋友购买水机均将享受3280元优惠价,并免费赠送3年滤芯哦!点击菜单“分销中心-代理分销”可进入您的专属分销管理中心。";
|
|
@@ -221,19 +250,19 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
if(requestMap.get("Ticket") != null){
|
|
|
|
|
|
//扫描机器二维码返回跳转到完善信息页面
|
|
|
- if (eventKey.indexOf(ResultInfo.barCodePrefix) != -1) {
|
|
|
+ if (eventKey.contains(ResultInfo.barCodePrefix)) {
|
|
|
Status status = scannQrcodeSubGiveGift(requestMap, fromUserName);
|
|
|
if (status.isFlag()) {
|
|
|
return status.getCountext();
|
|
|
}
|
|
|
respContent = status.getCountext();
|
|
|
- } else if(eventKey.indexOf(ResultInfo.barCodeActivity) != -1){
|
|
|
+ } else if(eventKey.contains(ResultInfo.barCodeActivity)){
|
|
|
Status status = bindingActivity(requestMap, fromUserName,false);
|
|
|
if (status.isFlag()) {
|
|
|
return status.getCountext();
|
|
|
}
|
|
|
respContent = status.getCountext();
|
|
|
- }else if(eventKey.indexOf(ResultInfo.barCodeMainChannelId) != -1){
|
|
|
+ }else if(eventKey.contains(ResultInfo.barCodeMainChannelId)){
|
|
|
Status status = bindingMainChannelId(requestMap, fromUserName,false);
|
|
|
if (status.isFlag()) {
|
|
|
return status.getCountext();
|
|
@@ -242,7 +271,7 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
} else {
|
|
|
//未关注用户扫描二维码关注事件处理
|
|
|
Status status = scannQRcodeSub(requestMap, fromUserName);
|
|
|
- Member member = refreshUserInfo(fromUserName); //更新用户信息
|
|
|
+ Member member = refreshUserInfo(fromUserName);
|
|
|
if (status.isFlag()) {
|
|
|
return status.getCountext();
|
|
|
}
|
|
@@ -251,7 +280,7 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
} else {
|
|
|
// 搜索公众号关注
|
|
|
Status status = queryWechatSub(fromUserName, requestMap);
|
|
|
- Member member = refreshUserInfo(fromUserName); //更新用户信息
|
|
|
+ Member member = refreshUserInfo(fromUserName);
|
|
|
if (status.isFlag()) {
|
|
|
return status.getCountext();
|
|
|
}
|
|
@@ -265,7 +294,7 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
} else if (eventType.equals(MessageUtil.EVENT_TYPE_CLICK) || eventType.equals("VIEW")) {
|
|
|
// 自定义菜单点击事件
|
|
|
Status status = clickWechatMenuEnent(requestMap);
|
|
|
- Member member = refreshUserInfo(fromUserName); //更新用户信息
|
|
|
+ Member member = refreshUserInfo(fromUserName);
|
|
|
if (status.isFlag()) {
|
|
|
return status.getCountext();
|
|
|
}
|
|
@@ -294,16 +323,14 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
*/
|
|
|
public Status bindingActivity(Map<String, String> requestMap, String fromUserName,Boolean isSubscription) {
|
|
|
Status status = new Status();
|
|
|
- String senceid = requestMap.get("EventKey");//场景值
|
|
|
+ String senceid = requestMap.get("EventKey");
|
|
|
|
|
|
Member member = refreshUserInfo(fromUserName);
|
|
|
|
|
|
- System.out.println("更改之前的值:"+senceid);
|
|
|
- senceid = senceid.replaceAll(ResultInfo.barCodeActivity,"");//替换标识前的字符串
|
|
|
+ senceid = senceid.replaceAll(ResultInfo.barCodeActivity,"");
|
|
|
if(!isSubscription){
|
|
|
- senceid = senceid.replaceAll(ResultInfo.barCode,"");//替换标识前的字符串
|
|
|
+ senceid = senceid.replaceAll(ResultInfo.barCode,"");
|
|
|
}
|
|
|
- System.out.println("更改之后的值:"+senceid);
|
|
|
StringBuilder str = new StringBuilder();
|
|
|
try {
|
|
|
Integer flag = activityService.addActivityHelp(senceid,fromUserName);
|
|
@@ -334,16 +361,12 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
*/
|
|
|
public Status bindingMainChannelId(Map<String, String> requestMap, String fromUserName,Boolean isSubscription) {
|
|
|
Status status = new Status();
|
|
|
- String senceid = requestMap.get("EventKey");//场景值
|
|
|
-
|
|
|
- //Member member = refreshUserInfo(fromUserName);
|
|
|
+ String senceid = requestMap.get("EventKey");
|
|
|
|
|
|
- System.out.println("更改之前的值:"+senceid);
|
|
|
- senceid = senceid.replaceAll(ResultInfo.barCodeMainChannelId,"");//替换标识前的字符串
|
|
|
+ senceid = senceid.replaceAll(ResultInfo.barCodeMainChannelId,"");
|
|
|
if(!isSubscription){
|
|
|
- senceid = senceid.replaceAll(ResultInfo.barCode,"");//替换标识前的字符串
|
|
|
+ senceid = senceid.replaceAll(ResultInfo.barCode,"");
|
|
|
}
|
|
|
- System.out.println("更改之后的值:"+senceid);
|
|
|
|
|
|
AttenStatistics attenStatistics = new AttenStatistics();
|
|
|
attenStatistics.setAttenStatisticsOpenId(fromUserName);
|
|
@@ -351,20 +374,16 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
attenStatistics.setChannelType(1);
|
|
|
List<AttenStatistics> attenStatisticsList = attenStatisticsService.getAttenStatisticsList(attenStatistics);
|
|
|
if(attenStatisticsList == null || attenStatisticsList.size() < 1){
|
|
|
- String eventType = requestMap.get("Event");// 事件类型
|
|
|
+ String eventType = requestMap.get("Event");
|
|
|
if(eventType.equals("SCAN")){
|
|
|
attenStatistics.setAttenStatisticsStatus(1);
|
|
|
- }else if(eventType.equals("subscribe")){ //扫码订阅
|
|
|
+ }else if(eventType.equals("subscribe")){
|
|
|
+ //扫码订阅
|
|
|
attenStatistics.setAttenStatisticsStatus(2);
|
|
|
}else{
|
|
|
attenStatistics.setAttenStatisticsStatus(3);
|
|
|
}
|
|
|
Integer flag = attenStatisticsService.save(attenStatistics);
|
|
|
- if(flag > 0){
|
|
|
- System.out.println("添加渠道"+ senceid +"统计数据成功,openid为:"+ fromUserName);
|
|
|
- }else{
|
|
|
- System.out.println("添加渠道"+ senceid +"统计数据失败,openid为:"+ fromUserName);
|
|
|
- }
|
|
|
}
|
|
|
status.setFlag(false);
|
|
|
status.setCountext(ResultInfo.subDefaultResponseText);
|
|
@@ -377,8 +396,8 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
*/
|
|
|
public Status scannQrcodeGiveGift(Map<String, String> requestMap, String fromUserName) {
|
|
|
Status status = new Status();
|
|
|
- String senceid = requestMap.get("EventKey");//场景值
|
|
|
- senceid = senceid.replaceAll(ResultInfo.barCodePrefix,"");//替换标识前的字符串
|
|
|
+ String senceid = requestMap.get("EventKey");
|
|
|
+ senceid = senceid.replaceAll(ResultInfo.barCodePrefix,"");
|
|
|
String str = bindingMachine(senceid, fromUserName);
|
|
|
status.setCountext(str);
|
|
|
status.setFlag(false);
|
|
@@ -393,8 +412,8 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
public Status scannQrcodeSubGiveGift(Map<String, String> requestMap, String fromUserName) {
|
|
|
//赋值&更新数据
|
|
|
Status status = new Status();
|
|
|
- String senceid = requestMap.get("EventKey");//场景值
|
|
|
- senceid = senceid.replaceAll(ResultInfo.barCodePrefix,"");//替换标识前的字符串
|
|
|
+ String senceid = requestMap.get("EventKey");
|
|
|
+ senceid = senceid.replaceAll(ResultInfo.barCodePrefix,"");
|
|
|
String str = bindingMachine(senceid, fromUserName);
|
|
|
status.setCountext(str);
|
|
|
status.setFlag(false);
|
|
@@ -415,8 +434,8 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
try {
|
|
|
//查询百胜订单信息
|
|
|
String resultJson = HttpClient431Util.doGet(params,url,null,null,null);
|
|
|
- resultJson = StringEscapeUtils.unescapeJava(resultJson); // unicode
|
|
|
- inLongLogger.info("==========================获取机器信息成功,返回值为:" + resultJson + "=========================");
|
|
|
+ // unicode
|
|
|
+ resultJson = StringEscapeUtils.unescapeJava(resultJson);
|
|
|
JSONObject jsonObject = JSONObject.fromObject(resultJson);
|
|
|
if (jsonObject.getInt("resultCode") != 200) {
|
|
|
str.append("没有查到该机器信息,请确认二维码是否正确!");
|
|
@@ -434,7 +453,6 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
str.append("。请放心使用。");
|
|
|
return str.toString();
|
|
|
} catch (Exception e) {
|
|
|
- inLongLogger.info("==========================获取机器信息失败,机器条形码为:" + senceid + "=========================");
|
|
|
str.append("没有查到该机器信息,请确认二维码是否正确!");
|
|
|
return str.toString();
|
|
|
}
|
|
@@ -469,26 +487,13 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
}
|
|
|
|
|
|
// 判断当前代理商是否能产生二维码
|
|
|
- if (!(info.getHasQrcode()==1)) { // 不支持删除二维码的角色,到此为止
|
|
|
+ if (!(info.getHasQrcode()==1)) {
|
|
|
+ // 不支持删除二维码的角色,到此为止
|
|
|
String ruleStr = info.getRoleName();
|
|
|
- StringBuffer buffer = new StringBuffer(ResultInfo.initPorxySuccessPrifix);
|
|
|
- buffer.append(ruleStr).append(ResultInfo.initPorxySuccessSuffix);
|
|
|
- return buffer.toString();
|
|
|
+ return ResultInfo.initPorxySuccessPrifix + ruleStr + ResultInfo.initPorxySuccessSuffix;
|
|
|
}
|
|
|
String ruleStr = info.getRoleName();
|
|
|
- StringBuffer buffer = new StringBuffer(ResultInfo.initPorxySuccessPrifix);
|
|
|
- buffer.append(ruleStr).append(ResultInfo.initPorxySuccessSuffix);
|
|
|
- return buffer.toString();
|
|
|
- /*// 产生二维码
|
|
|
- QrcodeResult qrcodeResult = qrcodeService.applyPlaceQrcodeUrl(info.getId());
|
|
|
- if (qrcodeResult.isSuccess()) {
|
|
|
- String ruleStr = info.getRoleName();
|
|
|
- StringBuffer buffer = new StringBuffer(ResultInfo.initPorxySuccessPrifix);
|
|
|
- buffer.append(ruleStr).append(ResultInfo.initPorxySuccessSuffix);
|
|
|
- return buffer.toString();
|
|
|
- } else {
|
|
|
- return qrcodeResult.getQroceUrl();
|
|
|
- }*/
|
|
|
+ return ResultInfo.initPorxySuccessPrifix + ruleStr + ResultInfo.initPorxySuccessSuffix;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -498,20 +503,16 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public int subUserScannQrcodeEvent(Map<String, String> requestMap, String fromUserName) throws Exception {
|
|
|
- String senceid = requestMap.get("EventKey");//已经关注用户扫描二维码触发事件:获取二维码场景值
|
|
|
-
|
|
|
- System.out.println("场景值sxx:"+senceid);
|
|
|
-
|
|
|
+ //已经关注用户扫描二维码触发事件:获取二维码场景值
|
|
|
+ String senceid = requestMap.get("EventKey");
|
|
|
Member member = refreshUserInfo(fromUserName);
|
|
|
// 是否更新数据
|
|
|
boolean isNew = false;
|
|
|
//没绑关系、没有来源、上线是代理商时的id为空、没有微代理层关系 时, 则可以绑定用户关系
|
|
|
- if (member.getUserIsFlag() != null && member.getUserIsFlag().intValue() == 1) {
|
|
|
+ if (member.getUserIsFlag() != null && member.getUserIsFlag() == 1) {
|
|
|
isNew = true;
|
|
|
}
|
|
|
- /* QrcodeResult qr = temporaryQrcodeService.applyTempQrcode(fromUserName);//为用户生成二维码
|
|
|
- inLongLogger.info("为用户-->" + fromUserName + ",生成二维码:" + qr.getQroceUrl());*/
|
|
|
- return buildRelation(member, senceid, isNew); //为用户绑定关系
|
|
|
+ return buildRelation(member, senceid, isNew);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -523,30 +524,21 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
*/
|
|
|
public Status scannQRcodeSub(Map<String, String> requestMap, String fromUserName) throws Exception {
|
|
|
// 解析场景值
|
|
|
- String senceid = requestMap.get("EventKey");//场景值
|
|
|
+ String senceid = requestMap.get("EventKey");
|
|
|
//赋值&更新数据
|
|
|
Member member = refreshUserInfo(fromUserName);
|
|
|
// 是否更新数据
|
|
|
boolean isNew = false;
|
|
|
|
|
|
- if (member.getUserIsFlag() != null && member.getUserIsFlag().intValue() == 1) {
|
|
|
+ if (member.getUserIsFlag() != null && member.getUserIsFlag() == 1) {
|
|
|
isNew = true;
|
|
|
}
|
|
|
int isMessage = buildRelation(member, senceid, isNew);
|
|
|
Status status = new Status();
|
|
|
- if (isMessage == 1) {//成功绑定关系 则推送优惠券图文
|
|
|
- /*status = getCouponImgText(requestMap);*/
|
|
|
+ if (isMessage == 1) {
|
|
|
status.setFlag(false);
|
|
|
status.setCountext(ResultInfo.subDefaultResponseText);
|
|
|
}else if(isMessage == 0){
|
|
|
- /* 用在分享二维码页面 从未关注公众号的用户B,通过点击用户A分享的二维码,关系就已经绑定,但是仍需要推送优惠券图文
|
|
|
- * 故 判断A初始从未关注,而关系已经绑定,则推送优惠券 */
|
|
|
- /*if(oldStatus == 1){
|
|
|
- status = getCouponImgText(requestMap);
|
|
|
- }else{
|
|
|
- status.setFlag(false);
|
|
|
- status.setCountext(ResultInfo.subDefaultResponseText);
|
|
|
- }*/
|
|
|
status.setFlag(false);
|
|
|
status.setCountext(ResultInfo.subDefaultResponseText);
|
|
|
} else if (isMessage == 4) {
|
|
@@ -556,8 +548,6 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
status.setFlag(false);
|
|
|
status.setCountext("欢迎您关注美国watero,恭喜您成为金牌会员。自己购买或者推荐朋友购买水机均将享受3280元优惠价,并免费赠送3年滤芯哦!点击菜单“分销中心-代理分销”可进入您的专属分销管理中心。");
|
|
|
}
|
|
|
- /*QrcodeResult qr = temporaryQrcodeService.applyTempQrcode(fromUserName);//为用户生成二维码
|
|
|
- inLongLogger.info("为用户-->" + fromUserName + ",生成二维码:" + qr.getQroceUrl());*/
|
|
|
//返回数据
|
|
|
return status;
|
|
|
}
|
|
@@ -572,12 +562,6 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
public Status queryWechatSub(String fromUserName, Map<String, String> requestMap) throws Exception {
|
|
|
//赋值&更新数据
|
|
|
refreshUserInfo(fromUserName);
|
|
|
- //memberDao.updateUserFlagByOpenId(fromUserName); // 绑定用户关系
|
|
|
- /*QrcodeResult qr = temporaryQrcodeService.applyTempQrcode(fromUserName);//为用户生成二维码
|
|
|
- if(qr != null ){
|
|
|
- inLongLogger.info("为用户-->" + fromUserName + ",生成二维结果成功!");
|
|
|
- }*/
|
|
|
-
|
|
|
Status status = new Status();
|
|
|
String respContent = ResultInfo.subDefaultResponseText;
|
|
|
status.setCountext(respContent);
|
|
@@ -591,18 +575,13 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
private Member refreshUserInfo(String openId){
|
|
|
System.out.println("====更新用户信息"+openId);
|
|
|
JSONObject jsonObject = WeixinUtil.getUserInfo(openId);
|
|
|
- String sex = jsonObject.getString("sex");//值为1时是男性,值为2时是女性,值为0时是未知
|
|
|
+ String sex = jsonObject.getString("sex");
|
|
|
String city = jsonObject.getString("city");
|
|
|
String country = jsonObject.getString("country");
|
|
|
String province = jsonObject.getString("province");
|
|
|
String nickname = jsonObject.getString("nickname");
|
|
|
String headimgurl = jsonObject.getString("headimgurl");
|
|
|
- /*try {
|
|
|
- nickname = URLEncoder.encode(jsonObject.getString("nickname"), "UTF-8");
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
- nickname = "";
|
|
|
- inLongLogger.error(this, e.getMessage());
|
|
|
- }*/
|
|
|
+
|
|
|
Member member = homeService.selectMemberInfoByOpenId(openId);
|
|
|
//赋值&更新会员数据
|
|
|
if (member != null && member.getUserId() != null) {
|
|
@@ -613,7 +592,7 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
member.setUserHead(headimgurl);
|
|
|
//userIsBought 暂存旧的关注状态
|
|
|
member.setUserIsBought(member.getUserStatus() == null ? 1 : member.getUserStatus());
|
|
|
- member.setUserStatus(2); // 已关注
|
|
|
+ member.setUserStatus(2);
|
|
|
homeService.updateWechatMemberInfoByByOpenid(member);
|
|
|
} else {
|
|
|
member = new Member();
|
|
@@ -621,7 +600,7 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
member.setUserSex(Integer.parseInt(sex));
|
|
|
member.setUserAddr(country+"-"+province+"-"+city);
|
|
|
member.setUserHead(headimgurl);
|
|
|
- member.setUserStatus(2); // 已关注
|
|
|
+ member.setUserStatus(2);
|
|
|
member.setUserOpenid(openId);
|
|
|
member.setUserIsBought(1);
|
|
|
member.setUserIsFlag(1);
|
|
@@ -630,38 +609,6 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
return member;
|
|
|
}
|
|
|
|
|
|
- // /**
|
|
|
-// * 用户自己关注事件 返回数据
|
|
|
-// * @param requestMap
|
|
|
-// * @return
|
|
|
-// * @throws Exception
|
|
|
-// */
|
|
|
-// public Status subUserReturnString(Map<String, String> requestMap) throws Exception {
|
|
|
-// Status status = new Status();
|
|
|
-// List<ImageTextMore> imagetextMoreList = null;
|
|
|
-// int couponImgTextId = systemService.selectOneShopRuleById(113).getRuleNum().intValue(); //100元优惠券图文id
|
|
|
-// ImageTextInfo imageTextInfo = imageTextInfoService.findImageTextInfoById(Long.valueOf(couponImgTextId));
|
|
|
-// String respContent = ResultInfo.subDefaultResponseText;
|
|
|
-// if(imageTextInfo != null) {
|
|
|
-// //判断是否多图文
|
|
|
-// if("2".equals(imageTextInfo.getImageTextType())){
|
|
|
-// imagetextMoreList = imageTextMoreService.findImageTextmore(imageTextInfo.getImageTextNo());
|
|
|
-// }
|
|
|
-// try {
|
|
|
-// respContent = MessageManager.getImageTextInfo(requestMap, imageTextInfo, imagetextMoreList);
|
|
|
-// } catch (Exception e) {
|
|
|
-// // TODO Auto-generated catch block
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// status.setFlag(true);
|
|
|
-// }else{
|
|
|
-// status.setFlag(false);
|
|
|
-// }
|
|
|
-// status.setCountext(respContent);
|
|
|
-// return status;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 绑定关系
|
|
|
* @param member 当前用户
|
|
@@ -676,7 +623,8 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
|
|
|
int isMessage = 0;
|
|
|
if (senceid != null && senceid.length() >= 8) {
|
|
|
- senceid = senceid.substring(8, senceid.length());//qrscene_
|
|
|
+ //qrscene_
|
|
|
+ senceid = senceid.substring(8, senceid.length());
|
|
|
}
|
|
|
|
|
|
String regex = "^\\d+$";
|
|
@@ -691,16 +639,16 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
//二维码用户信息
|
|
|
Member dealer = homeService.selectMemberInfoByOpenId(tempQrcoude.getQrOpenid());
|
|
|
|
|
|
- boolean isFlag = ShopUtil.isFlag(dealer); //二维码用户可否发展下线
|
|
|
- if(isFlag){ //绑定关系
|
|
|
+ boolean isFlag = ShopUtil.isFlag(dealer);
|
|
|
+ if(isFlag){
|
|
|
if(dealer.getUserDealers() != null){
|
|
|
- member.setUserDealers(dealer.getUserDealers()); // 代理商关系直接copy
|
|
|
+ member.setUserDealers(dealer.getUserDealers());
|
|
|
}
|
|
|
if(dealer.getTemplateId() != null){
|
|
|
member.setTemplateId(dealer.getTemplateId());
|
|
|
}
|
|
|
- homeService.updateUserResAndTypeByOpenid(member); // 更新
|
|
|
- wdRelationDao.insertWdrelation(dealer,member); //插入微代理层关系
|
|
|
+ homeService.updateUserResAndTypeByOpenid(member);
|
|
|
+ wdRelationDao.insertWdrelation(dealer,member);
|
|
|
isMessage = 0;
|
|
|
}
|
|
|
}
|
|
@@ -732,7 +680,7 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
// 判断是否为发展金牌会员的时间
|
|
|
try {
|
|
|
long activeEndDate = DateTimeUtil.pasreStringToLong("2016-12-30 23:59:59", null);
|
|
|
- if (new Date().getTime() <= activeEndDate) {
|
|
|
+ if (System.currentTimeMillis() <= activeEndDate) {
|
|
|
// 判断当前OpenID是否绑定已经成为金牌会员
|
|
|
Integer info = placeInfoMapper.selectPlaceIdByOpenId(member.getUserOpenid());
|
|
|
|
|
@@ -763,11 +711,11 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
}
|
|
|
|
|
|
// 自动将当前用户绑定到金牌会员下
|
|
|
- member.setUserDealers(nowPlaceInfo.getPlaceIds()); // bilud顶级代理商关系
|
|
|
+ member.setUserDealers(nowPlaceInfo.getPlaceIds());
|
|
|
member.setTemplateId(nowPlaceInfo.getTemplateId());
|
|
|
member.setUserResType(3);
|
|
|
- member.setUserIsFlag(2); // 关系绑定
|
|
|
- homeService.updateUserResAndTypeByOpenid(member); // 更新
|
|
|
+ member.setUserIsFlag(2);
|
|
|
+ homeService.updateUserResAndTypeByOpenid(member);
|
|
|
// 清除wd的数据
|
|
|
wdRelationDao.updateStatus(member.getUserOpenid());
|
|
|
isMessage = 3;
|
|
@@ -779,15 +727,18 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
PlaceInfo info = placeInfoMapper.selectPlaceInfobyId(Integer.parseInt(qrcode.getQrcodeReplaceOpenid()));
|
|
|
if (info.getHasQrcode() == 2) {
|
|
|
if (info != null) {
|
|
|
- member.setUserDealers(info.getPlaceIds()); // bilud顶级代理商关系
|
|
|
+ // bilud顶级代理商关系
|
|
|
+ member.setUserDealers(info.getPlaceIds());
|
|
|
member.setTemplateId(info.getTemplateId());
|
|
|
}
|
|
|
member.setUserResType(3);
|
|
|
- homeService.updateUserResAndTypeByOpenid(member); // 更新
|
|
|
+ // 更新
|
|
|
+ homeService.updateUserResAndTypeByOpenid(member);
|
|
|
|
|
|
// 清除wd的数据
|
|
|
wdRelationDao.updateStatus(member.getUserOpenid());
|
|
|
- if(info.getTemplateId() != 23){//美容师下线不回复优惠券
|
|
|
+ if(info.getTemplateId() != 23){
|
|
|
+ //美容师下线不回复优惠券
|
|
|
isMessage = 0;
|
|
|
}
|
|
|
|
|
@@ -836,9 +787,11 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
MenuKeySet menuKeySet = menuKeySetService.selectByPubNoAndKeyWord(NameUtils.getConfig("pubNo"), eventKey);
|
|
|
String respContent = ResultInfo.subDefaultResponseText;
|
|
|
if(menuKeySet != null){
|
|
|
- if("1".equals(menuKeySet.getReType())){ //文本
|
|
|
+ if("1".equals(menuKeySet.getReType())){
|
|
|
+ //文本
|
|
|
respContent = menuKeySet.getRefText();
|
|
|
- }else if("2".equals(menuKeySet.getReType())){//图文
|
|
|
+ }else if("2".equals(menuKeySet.getReType())){
|
|
|
+ //图文
|
|
|
List<ImageTextMore> imagetextMoreList = null;
|
|
|
ImageTextInfo imageTextInfo = imageTextInfoService.findImageTextInfoById(Long.parseLong(menuKeySet.getRefImageTextId()));
|
|
|
if(imageTextInfo != null) {
|
|
@@ -854,36 +807,7 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
status.setCountext(respContent);
|
|
|
return status;
|
|
|
}
|
|
|
- /**
|
|
|
- * 获取优惠券图文 扫码绑定关系后推送给用户
|
|
|
- * @param requestMap
|
|
|
- * @return
|
|
|
- */
|
|
|
-// private Status getCouponImgText(Map<String, String> requestMap){
|
|
|
-// Status status = new Status();
|
|
|
-// List<ImageTextMore> imagetextMoreList = null;
|
|
|
-// int couponImgTextId = 0;
|
|
|
-// couponImgTextId = systemService.selectOneShopRuleById(110).getRuleNum().intValue(); //400元商品图文id
|
|
|
-// ImageTextInfo imageTextInfo = imageTextInfoService.findImageTextInfoById(Long.valueOf(couponImgTextId));
|
|
|
-// String respContent = ResultInfo.subDefaultResponseText;
|
|
|
-// if(imageTextInfo != null) {
|
|
|
-// //判断是否多图文
|
|
|
-// if("2".equals(imageTextInfo.getImageTextType())){
|
|
|
-// imagetextMoreList = imageTextMoreService.findImageTextmore(imageTextInfo.getImageTextNo());
|
|
|
-// }
|
|
|
-// try {
|
|
|
-// respContent = MessageManager.getImageTextInfo(requestMap, imageTextInfo, imagetextMoreList);
|
|
|
-// } catch (Exception e) {
|
|
|
-// // TODO Auto-generated catch block
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// status.setFlag(true);
|
|
|
-// }else{
|
|
|
-// status.setFlag(false);
|
|
|
-// }
|
|
|
-// status.setCountext(respContent);
|
|
|
-// return status;
|
|
|
-// }
|
|
|
+
|
|
|
/***
|
|
|
* 消息处理
|
|
|
* @param content
|
|
@@ -899,19 +823,25 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
status.setFlag(true);
|
|
|
KeyWord keyword = null;
|
|
|
try {
|
|
|
- keyword = keyWordService.getByKeyWord(content);//是否命中关键字
|
|
|
+ //是否命中关键字
|
|
|
+ keyword = keyWordService.getByKeyWord(content);
|
|
|
} catch (Exception e) {
|
|
|
inLongLogger.info(e.getMessage() + "," + content);
|
|
|
}
|
|
|
- if(keyword != null) {//判断是否存在关键字回复
|
|
|
- if("1".equals(keyword.getReType())) {//文本
|
|
|
+ if(keyword != null) {
|
|
|
+ //判断是否存在关键字回复
|
|
|
+ if("1".equals(keyword.getReType())) {
|
|
|
+ //文本
|
|
|
status.setCountext(keyword.getRefText());
|
|
|
status.setFlag(false);
|
|
|
- } else if("2".equals(keyword.getReType())){//图文
|
|
|
+ } else if("2".equals(keyword.getReType())){
|
|
|
+ //图文
|
|
|
List<ImageTextMore> imagetextMoreList = null;
|
|
|
ImageTextInfo imageTextInfo = imageTextInfoService.findImageTextInfoById(keyword.getRefImageTextId());
|
|
|
- if(imageTextInfo != null) {//判断是否为多图文
|
|
|
- if("2".equals(imageTextInfo.getImageTextType())){//判断是否多图文
|
|
|
+ if(imageTextInfo != null) {
|
|
|
+ //判断是否为多图文
|
|
|
+ if("2".equals(imageTextInfo.getImageTextType())){
|
|
|
+ //判断是否多图文
|
|
|
imagetextMoreList = imageTextMoreService.findImageTextmore(imageTextInfo.getImageTextNo());
|
|
|
}
|
|
|
try {
|
|
@@ -924,16 +854,38 @@ public class WeChatServiceImpl implements WeChatService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } else { // 如果没有命中关键字,直接接入到客服
|
|
|
+ } else {
|
|
|
+ // 如果没有命中关键字,直接接入到客服
|
|
|
+ return joinUpCustomer(fromUserName, toUserName, createTime);
|
|
|
+ }
|
|
|
+ return status;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Status joinUpCustomer(String fromUserName, String toUserName, String createTime) {
|
|
|
+ Status result = new Status();
|
|
|
+ // 查询当前是否有客服在线
|
|
|
+ int num = customerService.count(1);
|
|
|
+ if (num >= 1) {
|
|
|
String xml = "<xml>"+
|
|
|
"<ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>" +
|
|
|
"<FromUserName><![CDATA[" + toUserName + "]]></FromUserName>" +
|
|
|
"<CreateTime>" + createTime + "</CreateTime>" +
|
|
|
"<MsgType><![CDATA[transfer_customer_service]]></MsgType></xml>";
|
|
|
- status.setCountext(xml);
|
|
|
- status.setFlag(true);
|
|
|
+ result.setCountext(xml);
|
|
|
+ result.setFlag(true);
|
|
|
+ return result;
|
|
|
}
|
|
|
- return status;
|
|
|
+ // 判断客服是否离开
|
|
|
+ num = customerService.count(2);
|
|
|
+ if (num >= 1) {
|
|
|
+ result.setCountext("尊敬的用户您好,我们每天的服务时段为:9:00-12:00;14:00-18:00,如您在非服务时段内咨询,我们将在看到后第一时间答复,请您耐心等待。");
|
|
|
+ result.setFlag(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 客服下线
|
|
|
+ result.setCountext("尊敬的用户您好,我们每天的服务时段为 9:00-18:00,如您在非服务时段内咨询,我们将在看到后第一时间答复;您也可拨打上朵全国客户服务热线:400-678-1860");
|
|
|
+ result.setFlag(false);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
}
|