|
@@ -3,13 +3,16 @@ package com.iamberry.wechat.service.wechat;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
+import com.iamberry.wechat.tools.*;
|
|
import net.sf.json.JSONObject;
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
|
|
|
+import org.apache.commons.lang3.StringEscapeUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -40,11 +43,6 @@ import com.iamberry.wechat.service.MessageUtil;
|
|
import com.iamberry.wechat.service.ShopUtil;
|
|
import com.iamberry.wechat.service.ShopUtil;
|
|
import com.iamberry.wechat.service.mapper.PlaceInfoMapper;
|
|
import com.iamberry.wechat.service.mapper.PlaceInfoMapper;
|
|
import com.iamberry.wechat.service.relationship.Dao.WdRelationDao;
|
|
import com.iamberry.wechat.service.relationship.Dao.WdRelationDao;
|
|
-import com.iamberry.wechat.tools.DateTimeUtil;
|
|
|
|
-import com.iamberry.wechat.tools.NameUtils;
|
|
|
|
-import com.iamberry.wechat.tools.QQFace;
|
|
|
|
-import com.iamberry.wechat.tools.ResultInfo;
|
|
|
|
-import com.iamberry.wechat.tools.WeixinUtil;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* description : wechat handler的核心服务类
|
|
* description : wechat handler的核心服务类
|
|
@@ -166,33 +164,51 @@ public class WeChatServiceImpl implements WeChatService {
|
|
} else if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_EVENT)) {// 事件推送
|
|
} else if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_EVENT)) {// 事件推送
|
|
|
|
|
|
String eventType = requestMap.get("Event");// 事件类型
|
|
String eventType = requestMap.get("Event");// 事件类型
|
|
-
|
|
|
|
|
|
+ String eventKey = requestMap.get("EventKey");
|
|
if(eventType.equals("SCAN")){
|
|
if(eventType.equals("SCAN")){
|
|
- // 已关注用户扫描二维码事件
|
|
|
|
- int flag = subUserScannQrcodeEvent(requestMap, fromUserName);
|
|
|
|
- if (flag == 1 ) {
|
|
|
|
|
|
+ //扫描机器二维码返回跳转到完善信息页面
|
|
|
|
+ if (eventKey.indexOf(ResultInfo.barCodePrefix) != -1) {
|
|
|
|
+ Status status = scannQrcodeGiveGift(requestMap, fromUserName);
|
|
|
|
+ if (status.isFlag()) {
|
|
|
|
+ return status.getCountext();
|
|
|
|
+ }
|
|
|
|
+ respContent = status.getCountext();
|
|
|
|
+ } else {
|
|
|
|
+ // 已关注用户扫描二维码事件
|
|
|
|
+ int flag = subUserScannQrcodeEvent(requestMap, fromUserName);
|
|
|
|
+ if (flag == 1) {
|
|
/*Status status = getCouponImgText(requestMap);
|
|
/*Status status = getCouponImgText(requestMap);
|
|
if (status.isFlag()) {
|
|
if (status.isFlag()) {
|
|
return status.getCountext();
|
|
return status.getCountext();
|
|
}
|
|
}
|
|
respContent = 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 {
|
|
|
|
- respContent = "欢迎您关注美国watero,恭喜您成为金牌会员。自己购买或者推荐朋友购买水机均将享受3280元优惠价,并免费赠送3年滤芯哦!点击菜单“分销中心-代理分销”可进入您的专属分销管理中心。";
|
|
|
|
|
|
+ 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 {
|
|
|
|
+ respContent = "欢迎您关注美国watero,恭喜您成为金牌会员。自己购买或者推荐朋友购买水机均将享受3280元优惠价,并免费赠送3年滤芯哦!点击菜单“分销中心-代理分销”可进入您的专属分销管理中心。";
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else if (eventType.equals(MessageUtil.EVENT_TYPE_SUBSCRIBE)) {
|
|
} else if (eventType.equals(MessageUtil.EVENT_TYPE_SUBSCRIBE)) {
|
|
// 订阅
|
|
// 订阅
|
|
if(requestMap.get("Ticket") != null){
|
|
if(requestMap.get("Ticket") != null){
|
|
- //未关注用户扫描二维码关注事件处理
|
|
|
|
- Status status = scannQRcodeSub(requestMap, fromUserName);
|
|
|
|
- if (status.isFlag()) {
|
|
|
|
- return status.getCountext();
|
|
|
|
|
|
+ //扫描机器二维码返回跳转到完善信息页面
|
|
|
|
+ if (eventKey.indexOf(ResultInfo.barCodePrefix) != -1) {
|
|
|
|
+ Status status = scannQrcodeSubGiveGift(requestMap, fromUserName);
|
|
|
|
+ if (status.isFlag()) {
|
|
|
|
+ return status.getCountext();
|
|
|
|
+ }
|
|
|
|
+ respContent = status.getCountext();
|
|
|
|
+ } else {
|
|
|
|
+ //未关注用户扫描二维码关注事件处理
|
|
|
|
+ Status status = scannQRcodeSub(requestMap, fromUserName);
|
|
|
|
+ if (status.isFlag()) {
|
|
|
|
+ return status.getCountext();
|
|
|
|
+ }
|
|
|
|
+ respContent = status.getCountext();
|
|
}
|
|
}
|
|
- respContent = status.getCountext();
|
|
|
|
} else {
|
|
} else {
|
|
// 搜索公众号关注
|
|
// 搜索公众号关注
|
|
Status status = queryWechatSub(fromUserName, requestMap);
|
|
Status status = queryWechatSub(fromUserName, requestMap);
|
|
@@ -230,6 +246,76 @@ public class WeChatServiceImpl implements WeChatService {
|
|
}
|
|
}
|
|
return respMessage;
|
|
return respMessage;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 扫码进入赠送礼品信息页面(已关注)
|
|
|
|
+ * @param requestMap
|
|
|
|
+ */
|
|
|
|
+ public Status scannQrcodeGiveGift(Map<String, String> requestMap, String fromUserName) {
|
|
|
|
+ Status status = new Status();
|
|
|
|
+ String senceid = requestMap.get("EventKey");//场景值
|
|
|
|
+ senceid = senceid.replaceAll(ResultInfo.barCodePrefix,"");//替换标识前的字符串
|
|
|
|
+ String str = bindingMachine(senceid, fromUserName);
|
|
|
|
+ status.setCountext(str);
|
|
|
|
+ status.setFlag(false);
|
|
|
|
+ return status;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 扫码进入赠送礼品信息页面(未关注)
|
|
|
|
+ * @param requestMap
|
|
|
|
+ * @param fromUserName
|
|
|
|
+ */
|
|
|
|
+ public Status scannQrcodeSubGiveGift(Map<String, String> requestMap, String fromUserName) {
|
|
|
|
+ //赋值&更新数据
|
|
|
|
+ Status status = new Status();
|
|
|
|
+ Member member = refreshUserInfo(fromUserName);
|
|
|
|
+ String senceid = requestMap.get("EventKey");//场景值
|
|
|
|
+ senceid = senceid.replaceAll(ResultInfo.barCodePrefix,"");//替换标识前的字符串
|
|
|
|
+ String str = bindingMachine(senceid.trim(), fromUserName);
|
|
|
|
+ status.setCountext(str);
|
|
|
|
+ status.setFlag(false);
|
|
|
|
+ return status;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 上海wateroPF扫码绑定机器关系
|
|
|
|
+ * @param senceid //机器条形码
|
|
|
|
+ * @param fromUserName
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public String bindingMachine(String senceid, String fromUserName) {
|
|
|
|
+ StringBuilder str = new StringBuilder();
|
|
|
|
+ String url = NameUtils.getConfig("rst_base_url") + senceid;
|
|
|
|
+ Map<String,String> params = new HashMap<String,String>();
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ try {
|
|
|
|
+ //查询百胜订单信息
|
|
|
|
+ String resultJson = HttpClient431Util.doGet(params,url,null,null,null);
|
|
|
|
+ resultJson = StringEscapeUtils.unescapeJava(resultJson); // unicode
|
|
|
|
+ inLongLogger.info("==========================获取机器信息成功,返回值为:" + resultJson + "=========================");
|
|
|
|
+ JSONObject jsonObject = JSONObject.fromObject(resultJson);
|
|
|
|
+ if (jsonObject.getInt("resultCode") != 200) {
|
|
|
|
+ str.append("没有查到该机器信息,请确认二维码是否正确!");
|
|
|
|
+ return str.toString();
|
|
|
|
+ }
|
|
|
|
+ JSONObject jsonMessage = jsonObject.getJSONObject("message");
|
|
|
|
+ if (jsonMessage.getInt("isBeing") == 2) {
|
|
|
|
+ str.append("没有查到该机器信息,请确认二维码是否正确!");
|
|
|
|
+ return str.toString();
|
|
|
|
+ }
|
|
|
|
+ str.append("您的<");
|
|
|
|
+ str.append(jsonMessage.getString("productType"));
|
|
|
|
+ str.append(">为正品,生产日期为:");
|
|
|
|
+ str.append(format.format(new Date(jsonMessage.getLong("producedTime")*1000)));
|
|
|
|
+ str.append("。请放心使用。");
|
|
|
|
+ return str.toString();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ inLongLogger.info("==========================获取机器信息失败,机器条形码为:" + senceid + "=========================");
|
|
|
|
+ str.append("没有查到该机器信息,请确认二维码是否正确!");
|
|
|
|
+ return str.toString();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 绑定代理商信息(激活 微信openid绑定商户)
|
|
* 绑定代理商信息(激活 微信openid绑定商户)
|