diff --git a/pom.xml b/pom.xml index c96194afb..9d457b4a8 100644 --- a/pom.xml +++ b/pom.xml @@ -204,6 +204,17 @@ vod20170321 2.0.0 + + + com.aliyun + aliyun-java-sdk-core + 4.0.6 + + + com.aliyun + aliyun-java-sdk-dysmsapi + 1.1.0 + diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/common/CommonController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/common/CommonController.java index 961de15e5..928dc1510 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/common/CommonController.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/common/CommonController.java @@ -7,11 +7,7 @@ import com.stdiet.common.core.redis.RedisCache; import com.stdiet.common.utils.StringUtils; import com.stdiet.common.utils.file.FileUploadUtils; import com.stdiet.common.utils.file.FileUtils; -import com.stdiet.custom.domain.wechat.WxAccessToken; -import com.stdiet.custom.domain.wechat.WxFileUploadResult; -import com.stdiet.custom.utils.WxTokenUtils; import com.stdiet.framework.config.ServerConfig; -import org.aspectj.weaver.loadtime.Aj; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -23,7 +19,6 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.net.URLDecoder; -import java.util.concurrent.TimeUnit; /** * 通用请求处理 diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/CusWxController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/CusWxController.java deleted file mode 100644 index ca9a95318..000000000 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/CusWxController.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.stdiet.web.controller.custom; - -import com.stdiet.common.core.controller.BaseController; -import com.stdiet.common.core.domain.AjaxResult; -import com.stdiet.common.core.redis.RedisCache; -import com.stdiet.custom.service.ISysWxService; -import com.stdiet.custom.utils.WxTokenUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; - -@RestController -@RequestMapping("/wx") -public class CusWxController extends BaseController { - - @Autowired - public ISysWxService sysWxService; - - @Autowired - public RedisCache redisCache; - - @GetMapping("/checkSign") - public String wxCheckAuth(@RequestParam String signature, @RequestParam String timestamp, @RequestParam String nonce, @RequestParam String echostr) { - return sysWxService.wxCheckAuth(signature, timestamp, nonce, echostr); - } - - @PostMapping("/checkSign") - public String autoResponse(HttpServletRequest request) { - return sysWxService.autoResponse(request); - } - - @GetMapping("/accessToken") - public AjaxResult getAccessToken() { - return sysWxService.getAccessToken(); - } - - @GetMapping("/clearAccessToken") - public AjaxResult clearAccessToken() { - redisCache.deleteObject(WxTokenUtils.KEY_ACCESS_TOKEN); - return AjaxResult.success(); - } -} diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java index f4c6c4834..00bf3fc8a 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java @@ -451,17 +451,24 @@ public class WechatAppletController extends BaseController { if (StringUtils.isNotEmpty(sysWxUserInfo.getPhone())) { SysCustomer sysCustomer = iSysCustomerService.getCustomerByPhone(sysWxUserInfo.getPhone()); if (StringUtils.isNull(sysCustomer)) { - return AjaxResult.error(5003, "未查到用户信息,请联系销售顾问"); +// return AjaxResult.error(5003, "未查到用户信息,请联系销售顾问"); + // 创建新客户 + sysCustomer = new SysCustomer(); + sysCustomer.setName(sysWxUserInfo.getNickName()); + sysCustomer.setPhone(sysWxUserInfo.getPhone()); + sysCustomer.setUpdateTime(DateUtils.getNowDate()); + sysCustomer.setCreateTime(DateUtils.getNowDate()); + iSysCustomerService.insertSysCustomer(sysCustomer); } sysWxUserInfo.setCusId(sysCustomer.getId()); + sysWxUserInfo.setUpdateTime(DateUtils.getNowDate()); if (StringUtils.isNull(curWxUserInfo)) { // 新增sys_wx_user_info sysWxUserInfo.setCreateTime(DateUtils.getNowDate()); sysWxUserInfoService.insertSysWxUserInfo(sysWxUserInfo); } else { // 更新sys_wx_user_info数据, - sysWxUserInfo.setUpdateTime(DateUtils.getNowDate()); sysWxUserInfoService.updateSysWxUserInfo(sysWxUserInfo); } // 更新对象 @@ -486,6 +493,23 @@ public class WechatAppletController extends BaseController { List plans = sysRecipesPlanService.selectRecipesPlanListInfoByCusId(cusId); + SysRecipesPlanListInfo tmpPlan; + for (int i = 0; i < plans.size(); i++) { + tmpPlan = plans.get(i); + tmpPlan.setStatus(1); + if (StringUtils.isNull(tmpPlan.getSendFlag()) || tmpPlan.getSendFlag() == 0) { + tmpPlan.setSendFlag(0); + tmpPlan.setMenus(new ArrayList<>()); + } + // 从excel转到线上的客户,之前的食谱无效 + if (i > 0 && plans.get(i - 1).getRecipesId() == null && i < plans.size() - 1 && plans.get(i + 1).getRecipesId() != null) { + for (int j = 0; j < i; j++) { + plans.get(j).setStatus(0); + } + } + } + + SysOrderPause orderPause = new SysOrderPause(); orderPause.setCusId(cusId); List pauses = sysOrderPauseService.selectSysOrderPauseList(orderPause); @@ -534,10 +558,27 @@ public class WechatAppletController extends BaseController { } @GetMapping("/getToken") - public String getToken(@RequestParam String appId) throws Exception { + public String getToken(@RequestParam String appId) { return iWechatAppletService.getAccessToken(appId); } + @GetMapping("/subscribe") + public AjaxResult subscribe(@RequestParam String customerId, @RequestParam Long planId, @RequestParam Integer subscribed) { +// Long cusId = StringUtils.isNotEmpty(customerId) ? Long.parseLong(AesUtils.decrypt(customerId)) : 0L; + + SysRecipesPlan info = new SysRecipesPlan(); + info.setId(planId); + info.setSubscribed(subscribed); + + return AjaxResult.success(sysRecipesPlanService.updateSysRecipesPlan(info)); + } + + + @GetMapping("/subscribe/post") + public AjaxResult subscribePost(@RequestParam Long cusId, @RequestParam Long planId, @RequestParam String name, @RequestParam String startDate, @RequestParam String endDate, @RequestParam String remark) { + return AjaxResult.success(iWechatAppletService.postSubscribeMessage(cusId, planId, name, startDate, endDate, remark)); + } + } diff --git a/stdiet-custom/libs/aliyun-java-sdk-core-3.3.1.jar b/stdiet-custom/libs/aliyun-java-sdk-core-3.3.1.jar new file mode 100644 index 000000000..3e339947f Binary files /dev/null and b/stdiet-custom/libs/aliyun-java-sdk-core-3.3.1.jar differ diff --git a/stdiet-custom/libs/aliyun-java-sdk-dysmsapi-1.0.0.jar b/stdiet-custom/libs/aliyun-java-sdk-dysmsapi-1.0.0.jar new file mode 100644 index 000000000..3e68bdf66 Binary files /dev/null and b/stdiet-custom/libs/aliyun-java-sdk-dysmsapi-1.0.0.jar differ diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysRecipesPlan.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysRecipesPlan.java index 48da9b9b8..911ef5b1d 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysRecipesPlan.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysRecipesPlan.java @@ -148,4 +148,15 @@ public class SysRecipesPlan { // 0-普通 1-模板 private Integer type; + + /** + * 订阅推送 + */ + private Integer subscribed; + + private String remark; + + private Integer subSend; + + private Integer smsSend; } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysRecipesPlanListInfo.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysRecipesPlanListInfo.java index 926e9925c..e333258da 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysRecipesPlanListInfo.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysRecipesPlanListInfo.java @@ -25,4 +25,10 @@ public class SysRecipesPlanListInfo { private List menus; + private Integer sendFlag; + + private Integer subscribed; + + private Integer status; + } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/WxPush.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/WxPush.java deleted file mode 100644 index 047ff2e50..000000000 --- a/stdiet-custom/src/main/java/com/stdiet/custom/domain/WxPush.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.stdiet.custom.domain; - -import java.io.Serializable; - -public class WxPush implements Serializable { - private static final long serialVersionUID = 1L; - - -} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/WxXmlData.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/WxXmlData.java deleted file mode 100644 index 2c665e6b4..000000000 --- a/stdiet-custom/src/main/java/com/stdiet/custom/domain/WxXmlData.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.stdiet.custom.domain; - - -import com.thoughtworks.xstream.annotations.XStreamAlias; -import lombok.Data; - -import java.io.Serializable; - -@Data -@XStreamAlias("xml") -public class WxXmlData implements Serializable { - @XStreamAlias("ToUserName") - private String toUserName; - @XStreamAlias("FromUserName") - private String fromUserName; - @XStreamAlias("CreateTime") - private Long createTime; - @XStreamAlias("MsgType") - private String msgType; - @XStreamAlias("Content") - private String content; - @XStreamAlias("MsgId") - private String msgId; - // - @XStreamAlias("Title") - private String title; - @XStreamAlias("Description") - private String description; - @XStreamAlias("Url") - private String url; - /** - * 订阅或者取消订阅的事件 - */ - @XStreamAlias("Event") - private String event; - @XStreamAlias("EventKey") - private String eventkey; - -} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/wechat/WxSubscribePostLog.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/wechat/WxSubscribePostLog.java new file mode 100644 index 000000000..1fcca40a7 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/wechat/WxSubscribePostLog.java @@ -0,0 +1,19 @@ +package com.stdiet.custom.domain.wechat; + +import com.alibaba.fastjson.JSONObject; +import lombok.Data; + +import java.util.Date; + +@Data +public class WxSubscribePostLog { + Long id; + String appid; + String openid; + String phone; + Long planId; + Date sendTime; + JSONObject result; + JSONObject data; + Integer type; +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysWxSubscribePostLogMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysWxSubscribePostLogMapper.java new file mode 100644 index 000000000..e875e5c87 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysWxSubscribePostLogMapper.java @@ -0,0 +1,11 @@ +package com.stdiet.custom.mapper; + +import com.stdiet.custom.domain.wechat.WxSubscribePostLog; + +import java.util.List; + +public interface SysWxSubscribePostLogMapper { + public int insertWxSubscribePostLog(WxSubscribePostLog postLog); + + public List selectWxSubscribePostLog(WxSubscribePostLog postLog); +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysWxUserInfoMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysWxUserInfoMapper.java index 5173878a0..7081917fb 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysWxUserInfoMapper.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysWxUserInfoMapper.java @@ -19,6 +19,8 @@ public interface SysWxUserInfoMapper */ public SysWxUserInfo selectSysWxUserInfoById(String openid); + public SysWxUserInfo selectSysWxUserInfoByCusId(Long cusId); + /** * 查询微信用户列表 * diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysWxService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysWxService.java deleted file mode 100644 index d45fc3f63..000000000 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysWxService.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.stdiet.custom.service; - -import com.stdiet.common.core.domain.AjaxResult; -import com.stdiet.custom.domain.WxXmlData; - -import javax.servlet.http.HttpServletRequest; - -public interface ISysWxService { - /** - * 微信token验证 - * - * @param signature - * @param timestamp - * @param nonce - * @return - */ - public String wxCheckAuth(String signature, String timestamp, String nonce, String echostr); - - public String autoResponse(HttpServletRequest request); - - public AjaxResult getAccessToken(); -} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysWxUserInfoService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysWxUserInfoService.java index 45dd721fe..3dc8acb61 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysWxUserInfoService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysWxUserInfoService.java @@ -19,6 +19,8 @@ public interface ISysWxUserInfoService */ public SysWxUserInfo selectSysWxUserInfoById(String openid); + public SysWxUserInfo selectSysWxUserInfoByCusId(Long cusId); + /** * 查询微信用户列表 * diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/IWechatAppletService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/IWechatAppletService.java index 61b66e351..9dc1cda90 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/IWechatAppletService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/IWechatAppletService.java @@ -2,7 +2,9 @@ package com.stdiet.custom.service; public interface IWechatAppletService { - public String getAccessToken(String appId) throws Exception; + public String getAccessToken(String appId); - public void postRecipesMessage(String appId, String openId, String name, String startDate, String endDate, String remark) throws Exception; + public Integer postSubscribeMessage(Long cusId, Long planId, String name, String startDate, String endDate, String remark); + + public Integer postSms(Long cusId, Long planId, String plan); } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/IWxSubscribePostLogService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/IWxSubscribePostLogService.java new file mode 100644 index 000000000..d033d59b9 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/IWxSubscribePostLogService.java @@ -0,0 +1,11 @@ +package com.stdiet.custom.service; + +import com.stdiet.custom.domain.wechat.WxSubscribePostLog; + +import java.util.List; + +public interface IWxSubscribePostLogService { + public int insertWxSubscribePostLog(WxSubscribePostLog postLog); + + public List selectWxSubscribePostLog(WxSubscribePostLog postLog); +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysRecipesPlanServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysRecipesPlanServiceImpl.java index 24f91e547..a386f35c0 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysRecipesPlanServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysRecipesPlanServiceImpl.java @@ -9,14 +9,13 @@ import com.stdiet.custom.domain.SysOrderPause; import com.stdiet.custom.domain.SysRecipesPlan; import com.stdiet.custom.domain.SysRecipesPlanListInfo; import com.stdiet.custom.mapper.SysRecipesPlanMapper; -import com.stdiet.custom.service.ISysOrderPauseService; -import com.stdiet.custom.service.ISysOrderService; -import com.stdiet.custom.service.ISysRecipesPlanService; +import com.stdiet.custom.service.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.*; @@ -30,8 +29,8 @@ import java.util.*; @Service("sysRecipesPlanService") @Transactional public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { - public static final String generateRecipesPlanLockKey = "generateRecipesPlanLock::%s"; + static final SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd"); @Autowired private SysRecipesPlanMapper sysRecipesPlanMapper; @Autowired @@ -40,6 +39,10 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { private ISysOrderPauseService sysOrderPauseService; @Autowired private SynchrolockUtil synchrolockUtil; + @Autowired + private IWechatAppletService wechatAppletService; + @Autowired + private ISysCustomerService sysCustomerService; /** * 查询食谱计划 @@ -83,9 +86,36 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { */ @Override public int updateSysRecipesPlan(SysRecipesPlan sysRecipesPlan) { + sysRecipesPlan.setUpdateTime(DateUtils.getNowDate()); - //目前只能修改发送状态,所以修改时加上发送时间 - sysRecipesPlan.setSendTime(DateUtils.getNowDate()); + if (StringUtils.isNotNull(sysRecipesPlan.getSubscribed())) { + // 客户端修改订阅状态 + } else if (StringUtils.isNotNull(sysRecipesPlan.getSendFlag())) { + // 后台修改发送状态 + sysRecipesPlan.setSendTime(DateUtils.getNowDate()); + SysRecipesPlan recipesPlan = sysRecipesPlanMapper.selectSysRecipesPlanById(sysRecipesPlan.getId()); + if (StringUtils.isNotNull(sysRecipesPlan.getSendFlag()) && sysRecipesPlan.getSendFlag() == 1) { + // 未发送过 + String name = "第" + recipesPlan.getStartNumDay() + "至" + recipesPlan.getEndNumDay() + "天"; + String startDate = ft.format(recipesPlan.getStartDate()); + String endDate = ft.format(recipesPlan.getEndDate()); + // 发送微信订阅 + if (StringUtils.isNotNull(recipesPlan) && recipesPlan.getSubSend() == 0) { + Integer code = wechatAppletService.postSubscribeMessage(recipesPlan.getCusId(), recipesPlan.getId(), name, startDate, endDate, recipesPlan.getRemark()); + if (code == 0) { + sysRecipesPlan.setSubSend(1); + } + } + // 发送通知短信 + if(StringUtils.isNotNull(recipesPlan) && recipesPlan.getSmsSend() == 0) { + Integer smsCode = wechatAppletService.postSms(recipesPlan.getCusId(), recipesPlan.getId(), name); + if (smsCode == 0) { + sysRecipesPlan.setSmsSend(1); + } + } + } + } + return sysRecipesPlanMapper.updateSysRecipesPlan(sysRecipesPlan); } @@ -237,11 +267,11 @@ public class SysRecipesPlanServiceImpl implements ISysRecipesPlanService { if (beforeOrderLastPlan != null && sysOrder.getRecipesPlanContinue().intValue() == 1) { long differDay = ChronoUnit.DAYS.between(DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()), serverStartDate); //检查之前食谱的结束时间和目前该订单的开始时间是否连续 - if(differDay <= 1){ + if (differDay <= 1) { //判断前一个订单食谱是否满七天,不满则需要接上 int differNum = beforeOrderLastPlan.getEndNumDay() - beforeOrderLastPlan.getStartNumDay(); - if(differNum < 6){ + if (differNum < 6) { //更新该食谱计划 beforeOrderLastPlan.setEndNumDay(beforeOrderLastPlan.getStartNumDay() + 6); beforeOrderLastPlan.setEndDate(DateUtils.localDateToDate(DateUtils.dateToLocalDate(beforeOrderLastPlan.getEndDate()).plusDays(6 - differNum))); diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysWxServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysWxServiceImpl.java deleted file mode 100644 index d860fdb79..000000000 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysWxServiceImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.stdiet.custom.service.impl; - -import com.stdiet.common.core.domain.AjaxResult; -import com.stdiet.common.utils.StringUtils; -import com.stdiet.custom.domain.WxXmlData; -import com.stdiet.custom.service.ISysWxService; -import com.stdiet.custom.utils.WechatMessageUtil; -import com.stdiet.custom.utils.WxTokenUtils; -import com.thoughtworks.xstream.XStream; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.servlet.http.HttpServletRequest; -import java.io.IOException; - -@Service -@Transactional -public class SysWxServiceImpl implements ISysWxService { - - @Override - public String wxCheckAuth(String signature, String timestamp, String nonce, String echostr) { - return WxTokenUtils.checkSignature(signature, timestamp, nonce) ? echostr : null; - } - - @Override - public String autoResponse(HttpServletRequest request) { - try { - WxXmlData wxData = WxTokenUtils.resolveXmlData(request.getInputStream()); - - WxXmlData resultXmlData = new WxXmlData(); - resultXmlData.setToUserName(wxData.getFromUserName()); //收到的消息是谁发来的再发给谁 - resultXmlData.setFromUserName(wxData.getToUserName()); // - if (wxData.getMsgType().equals(WechatMessageUtil.MESSAGE_EVENT)) { - if (wxData.getEvent().equals(WechatMessageUtil.MESSAGE_EVENT_SUBSCRIBE)) { - resultXmlData.setMsgType("text"); - resultXmlData.setCreateTime(System.currentTimeMillis()); - resultXmlData.setContent("欢迎来到胜唐体控,这是一条测试用的关注信息"); - } else if (wxData.getEvent().equals(WechatMessageUtil.MESSAGE_EVENT_UNSUBSCRIBE)) { - - } - } else if (wxData.getMsgType().equals(WechatMessageUtil.MESSAGE_TEXT)) { - resultXmlData.setMsgType("text"); - resultXmlData.setCreateTime(System.currentTimeMillis()); - resultXmlData.setContent("点击该链接,获取博客解锁验证码"); - } else { - resultXmlData.setMsgType("text"); - resultXmlData.setCreateTime(System.currentTimeMillis()); - resultXmlData.setContent("公众号正在开发中。后期请多多关注!"); - } - XStream xstream = new XStream(); - xstream.processAnnotations(WxXmlData.class); - xstream.setClassLoader(WxXmlData.class.getClassLoader()); - return xstream.toXML(resultXmlData); //XStream的方法,直接将对象转换成 xml数据 - } catch (IOException e) { - return null; - } - } - - @Override - public AjaxResult getAccessToken() { - return AjaxResult.success(WxTokenUtils.fetchAccessToken()); - } - - -} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysWxUserInfoServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysWxUserInfoServiceImpl.java index a1ccb0e84..94f1ffb95 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysWxUserInfoServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysWxUserInfoServiceImpl.java @@ -1,12 +1,13 @@ package com.stdiet.custom.service.impl; -import java.util.List; import com.stdiet.common.utils.DateUtils; +import com.stdiet.custom.domain.SysWxUserInfo; +import com.stdiet.custom.mapper.SysWxUserInfoMapper; +import com.stdiet.custom.service.ISysWxUserInfoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.stdiet.custom.mapper.SysWxUserInfoMapper; -import com.stdiet.custom.domain.SysWxUserInfo; -import com.stdiet.custom.service.ISysWxUserInfoService; + +import java.util.List; /** * 微信用户Service业务层处理 @@ -15,8 +16,7 @@ import com.stdiet.custom.service.ISysWxUserInfoService; * @date 2020-11-28 */ @Service -public class SysWxUserInfoServiceImpl implements ISysWxUserInfoService -{ +public class SysWxUserInfoServiceImpl implements ISysWxUserInfoService { @Autowired private SysWxUserInfoMapper sysWxUserInfoMapper; @@ -27,11 +27,15 @@ public class SysWxUserInfoServiceImpl implements ISysWxUserInfoService * @return 微信用户 */ @Override - public SysWxUserInfo selectSysWxUserInfoById(String openid) - { + public SysWxUserInfo selectSysWxUserInfoById(String openid) { return sysWxUserInfoMapper.selectSysWxUserInfoById(openid); } + @Override + public SysWxUserInfo selectSysWxUserInfoByCusId(Long cusId) { + return sysWxUserInfoMapper.selectSysWxUserInfoByCusId(cusId); + } + /** * 查询微信用户列表 * @@ -39,8 +43,7 @@ public class SysWxUserInfoServiceImpl implements ISysWxUserInfoService * @return 微信用户 */ @Override - public List selectSysWxUserInfoList(SysWxUserInfo sysWxUserInfo) - { + public List selectSysWxUserInfoList(SysWxUserInfo sysWxUserInfo) { return sysWxUserInfoMapper.selectSysWxUserInfoList(sysWxUserInfo); } @@ -56,8 +59,7 @@ public class SysWxUserInfoServiceImpl implements ISysWxUserInfoService * @return 结果 */ @Override - public int insertSysWxUserInfo(SysWxUserInfo sysWxUserInfo) - { + public int insertSysWxUserInfo(SysWxUserInfo sysWxUserInfo) { sysWxUserInfo.setCreateTime(DateUtils.getNowDate()); return sysWxUserInfoMapper.insertSysWxUserInfo(sysWxUserInfo); } @@ -69,8 +71,7 @@ public class SysWxUserInfoServiceImpl implements ISysWxUserInfoService * @return 结果 */ @Override - public int updateSysWxUserInfo(SysWxUserInfo sysWxUserInfo) - { + public int updateSysWxUserInfo(SysWxUserInfo sysWxUserInfo) { sysWxUserInfo.setUpdateTime(DateUtils.getNowDate()); return sysWxUserInfoMapper.updateSysWxUserInfo(sysWxUserInfo); } @@ -82,8 +83,7 @@ public class SysWxUserInfoServiceImpl implements ISysWxUserInfoService * @return 结果 */ @Override - public int deleteSysWxUserInfoByIds(String[] openids) - { + public int deleteSysWxUserInfoByIds(String[] openids) { return sysWxUserInfoMapper.deleteSysWxUserInfoByIds(openids); } @@ -94,8 +94,7 @@ public class SysWxUserInfoServiceImpl implements ISysWxUserInfoService * @return 结果 */ @Override - public int deleteSysWxUserInfoById(String openid) - { + public int deleteSysWxUserInfoById(String openid) { return sysWxUserInfoMapper.deleteSysWxUserInfoById(openid); } } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WeChartAppletServiceImp.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WeChartAppletServiceImp.java index 21199866f..271b6f92c 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WeChartAppletServiceImp.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WeChartAppletServiceImp.java @@ -1,21 +1,36 @@ package com.stdiet.custom.service.impl; import com.alibaba.fastjson.JSONObject; -import com.google.gson.JsonObject; +import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; import com.stdiet.common.core.redis.RedisCache; +import com.stdiet.common.utils.DateUtils; import com.stdiet.common.utils.StringUtils; +import com.stdiet.custom.domain.SysCustomer; +import com.stdiet.custom.domain.SysWxUserInfo; +import com.stdiet.custom.domain.wechat.WxSubscribePostLog; +import com.stdiet.custom.service.ISysCustomerService; +import com.stdiet.custom.service.ISysWxUserInfoService; import com.stdiet.custom.service.IWechatAppletService; +import com.stdiet.custom.service.IWxSubscribePostLogService; +import com.stdiet.custom.utils.SmsUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; + @Service public class WeChartAppletServiceImp implements IWechatAppletService { + static final String WX_TEM_ID = "Ow0j0Jt4OJhjy6GruBstOMLTGjAVagM4hTZRLAaxqJo"; + + static final String SMS_TEM_ID = "SMS_216839183"; + static final String SMS_SIGN_NAME = "胜唐体控"; @Autowired private RedisCache redisCache; @@ -23,8 +38,17 @@ public class WeChartAppletServiceImp implements IWechatAppletService { @Autowired private RestTemplate restTemplate; + @Autowired + private ISysWxUserInfoService sysWxUserInfoService; + + @Autowired + private IWxSubscribePostLogService wxSubscribePostLogService; + + @Autowired + private ISysCustomerService sysCustomerService; + @Override - public String getAccessToken(String appId) throws Exception { + public String getAccessToken(String appId) { String accessToken = redisCache.getCacheObject(appId); if (StringUtils.isNull(accessToken)) { String appSecret = ""; @@ -49,35 +73,88 @@ public class WeChartAppletServiceImp implements IWechatAppletService { } @Override - public void postRecipesMessage(String appId, String openId, String name, String startDate, String endDate, String remark) throws Exception { - String accessToken = getAccessToken(appId); - if (StringUtils.isNull(accessToken)) { - return; + public Integer postSubscribeMessage(Long cusId, Long planId, String name, String startDate, String endDate, String remark) { + SysWxUserInfo sysWxUserInfo = sysWxUserInfoService.selectSysWxUserInfoByCusId(cusId); + if (StringUtils.isNull(sysWxUserInfo)) { + return null; + } + + String accessToken = getAccessToken(sysWxUserInfo.getAppid()); + if (StringUtils.isNull(accessToken)) { + return -1; } - String tmpId = ""; String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken; - JsonObject param = new JsonObject(); - param.addProperty("access_token", accessToken); - param.addProperty("touser", openId); - param.addProperty("template_id", tmpId); - param.addProperty("page", "pages/recipes/index"); + JSONObject param = new JSONObject(); + param.put("access_token", accessToken); + param.put("touser", sysWxUserInfo.getOpenid()); + param.put("template_id", WX_TEM_ID); + param.put("page", "pages/recipes/index"); - JsonObject dataParam = new JsonObject(); - dataParam.addProperty("key1", name); - dataParam.addProperty("key2", startDate); - dataParam.addProperty("key3", endDate); - dataParam.addProperty("key4", remark); - param.add("data", dataParam); + JSONObject dataParam = new JSONObject(); + dataParam.put("thing1", JSONObject.parse("{\"value\":\"" + name + "\"}")); + dataParam.put("time2", JSONObject.parse("{\"value\":\"" + startDate + "\"}")); + dataParam.put("time3", JSONObject.parse("{\"value\":\"" + endDate + "\"}")); + String mRemark = StringUtils.isNull(remark) ? "" : remark; + dataParam.put("thing4", JSONObject.parse("{\"value\":\"" + mRemark + "\"}")); - ResponseEntity entity = restTemplate.postForEntity(url, param, String.class); + param.put("data", dataParam); + + restTemplate.getMessageConverters() + .add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8)); + ResponseEntity entity = restTemplate.postForEntity(url, param.toJSONString(), String.class); JSONObject resultObj = JSONObject.parseObject(entity.getBody()); - System.out.println(resultObj.toJSONString()); -// Integer errcode = resultObj.getInteger("errcode"); + WxSubscribePostLog postLog = new WxSubscribePostLog(); + postLog.setAppid(sysWxUserInfo.getAppid()); + postLog.setOpenid(sysWxUserInfo.getOpenid()); + int errCode = resultObj.getInteger("errcode"); + postLog.setType(0); + postLog.setResult(resultObj); + postLog.setSendTime(DateUtils.getNowDate()); + postLog.setPlanId(planId); + // + dataParam.put("tmpId", WX_TEM_ID); + postLog.setData(dataParam); + wxSubscribePostLogService.insertWxSubscribePostLog(postLog); + return errCode; } + + @Override + public Integer postSms(Long cusId, Long planId, String plan) { + try { + SysCustomer customer = sysCustomerService.selectSysCustomerById(cusId); + SendSmsResponse response = SmsUtils.sendSms(customer.getPhone(), plan, SMS_TEM_ID, SMS_SIGN_NAME); + + WxSubscribePostLog postLog = new WxSubscribePostLog(); + postLog.setPhone(customer.getPhone()); + postLog.setPlanId(planId); + JSONObject resultObj = new JSONObject(); + resultObj.put("requestId", response.getRequestId()); + resultObj.put("bizId", response.getBizId()); + resultObj.put("code", response.getCode()); + resultObj.put("message", response.getMessage()); + postLog.setResult(resultObj); + JSONObject dataParam = new JSONObject(); + dataParam.put("phone", customer.getPhone()); + dataParam.put("plan", plan); + dataParam.put("tmpCode", SMS_TEM_ID); + dataParam.put("signName", SMS_SIGN_NAME); + postLog.setData(dataParam); + postLog.setSendTime(DateUtils.getNowDate()); + postLog.setType(1); + wxSubscribePostLogService.insertWxSubscribePostLog(postLog); + + return response.getCode().equals("OK") ? 0 : -1; + } catch (Exception e) { + System.out.println(e); + } + return -1; + } + + } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WxSubscribePostLogServiceImp.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WxSubscribePostLogServiceImp.java new file mode 100644 index 000000000..4137d7e47 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WxSubscribePostLogServiceImp.java @@ -0,0 +1,26 @@ +package com.stdiet.custom.service.impl; + +import com.stdiet.custom.domain.wechat.WxSubscribePostLog; +import com.stdiet.custom.mapper.SysWxSubscribePostLogMapper; +import com.stdiet.custom.service.IWxSubscribePostLogService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class WxSubscribePostLogServiceImp implements IWxSubscribePostLogService { + + @Autowired + SysWxSubscribePostLogMapper sysWxSubscribePostLogMapper; + + @Override + public int insertWxSubscribePostLog(WxSubscribePostLog postLog) { + return sysWxSubscribePostLogMapper.insertWxSubscribePostLog(postLog); + } + + @Override + public List selectWxSubscribePostLog(WxSubscribePostLog postLog) { + return sysWxSubscribePostLogMapper.selectWxSubscribePostLog(postLog); + } +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/utils/HttpPostUtil.java b/stdiet-custom/src/main/java/com/stdiet/custom/utils/HttpPostUtil.java deleted file mode 100644 index 5a7e9f087..000000000 --- a/stdiet-custom/src/main/java/com/stdiet/custom/utils/HttpPostUtil.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.stdiet.custom.utils; - -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLEncoder; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Set; - -/** - * [url=home.php?mod=space&uid=49329]@author[/url] Sunlight - */ -public class HttpPostUtil { - private URL url; - private HttpURLConnection conn; - private String boundary = "--------httppost123"; - private HashMap textParams = new HashMap(); - private HashMap fileparams = new HashMap(); - private DataOutputStream outputStream; - - public HttpPostUtil(String url) throws Exception { - this.url = new URL(url); - } - - /** - * 重新设置要请求的服务器地址,即上传文件的地址。 - * - * @param url - * @throws Exception - */ - public void setUrl(String url) throws Exception { - this.url = new URL(url); - } - - /** - * 增加一个普通字符串数据到form表单数据中 - * - * @param name - * @param value - */ - public void addParameter(String name, String value) { - textParams.put(name, value); - } - - /** - * 增加一个文件到form表单数据中 - * - * @param name - * @param value - */ - public void addParameter(String name, File value) { - fileparams.put(name, value); - } - - /** - * 清空所有已添加的form表单数据 - */ - public void clearAllParameters() { - textParams.clear(); - fileparams.clear(); - } - - /** - * 发送数据到服务器,返回一个字节包含服务器的返回结果的数组 - * - * @return - * @throws Exception - */ - public String send() throws Exception { - initConnection(); - conn.connect(); - outputStream = new DataOutputStream(conn.getOutputStream()); - writeFileParams(); - writeStringParams(); - paramsEnd(); - int code = conn.getResponseCode(); - if (code == 200) { - InputStream in = conn.getInputStream(); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - byte[] buf = new byte[1024 * 8]; - int len; - while ((len = in.read(buf)) != -1) { - out.write(buf, 0, len); - } - conn.disconnect(); - String s = new String(out.toByteArray(), "utf-8"); - return s; - } - return null; - } - - /** - * 文件上传的connection的一些必须设置 - * - * @throws Exception - */ - private void initConnection() throws Exception { - conn = (HttpURLConnection) this.url.openConnection(); - conn.setDoOutput(true); - conn.setUseCaches(false); - conn.setConnectTimeout(10000); // 连接超时为10秒 - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); - } - - /** - * 普通字符串数据 - * - * @throws Exception - */ - private void writeStringParams() throws Exception { - Set keySet = textParams.keySet(); - for (Iterator it = keySet.iterator(); it.hasNext(); ) { - String name = it.next(); - String value = textParams.get(name); - outputStream.writeBytes("--" + boundary + "\r\n"); - outputStream.writeBytes("Content-Disposition: form-data; name=" + name + "\r\n"); - outputStream.writeBytes("\r\n"); - outputStream.writeBytes(encode(value) + "\r\n"); - } - } - - /** - * 文件数据 - * - * @throws Exception - */ - private void writeFileParams() throws Exception { - Set keySet = fileparams.keySet(); - for (Iterator it = keySet.iterator(); it.hasNext(); ) { - String name = it.next(); - File value = fileparams.get(name); - outputStream.writeBytes("--" + boundary + "\r\n"); - outputStream.writeBytes("Content-Disposition: form-data; name=" + name + "; filename=" + encode(value.getName()) + "\r\n"); - outputStream.writeBytes("Content-Type: " + getContentType(value) + "\r\n"); - outputStream.writeBytes("\r\n"); - outputStream.write(getBytes(value)); - outputStream.writeBytes("\r\n"); - } - } - - /** - * 获取文件的上传类型,图片格式为image/png,image/jpeg等。非图片为application /octet-stream - * - * @param f - * @return - * @throws Exception - */ - private String getContentType(File f) throws Exception { - return "application/octet-stream"; - } - - /** - * 把文件转换成字节数组 - * - * @param f - * @return - * @throws Exception - */ - private byte[] getBytes(File f) throws Exception { - FileInputStream in = new FileInputStream(f); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - byte[] b = new byte[1024]; - int n; - while ((n = in.read(b)) != -1) { - out.write(b, 0, n); - } - in.close(); - return out.toByteArray(); - } - - /** - * 添加结尾数据 - * - * @throws Exception - */ - private void paramsEnd() throws Exception { - outputStream.writeBytes("--" + boundary + "--" + "\r\n"); - outputStream.writeBytes("\r\n"); - } - - /** - * 对包含中文的字符串进行转码,此为UTF-8。服务器那边要进行一次解码 - * - * @param value - * @return - * @throws Exception - */ - private String encode(String value) throws Exception { - return URLEncoder.encode(value, "UTF-8"); - } -} \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/utils/SmsUtils.java b/stdiet-custom/src/main/java/com/stdiet/custom/utils/SmsUtils.java new file mode 100644 index 000000000..176842e27 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/utils/SmsUtils.java @@ -0,0 +1,91 @@ +package com.stdiet.custom.utils; + +import com.alibaba.fastjson.JSONObject; +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest; +import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse; +import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; +import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; +import com.aliyuncs.exceptions.ClientException; +import com.aliyuncs.profile.DefaultProfile; +import com.aliyuncs.profile.IClientProfile; +import com.stdiet.common.config.AliyunOSSConfig; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class SmsUtils { + //产品名称:云通信短信API产品,开发者无需替换 + static final String product = "Dysmsapi"; + //产品域名,开发者无需替换 + static final String domain = "dysmsapi.aliyuncs.com"; + + public static SendSmsResponse sendSms(String phone, String plan, String tmpCode, String signName) throws ClientException { + + //可自助调整超时时间 + System.setProperty("sun.net.client.defaultConnectTimeout", "10000"); + System.setProperty("sun.net.client.defaultReadTimeout", "10000"); + + //初始化acsClient,暂不支持region化 + IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", AliyunOSSConfig.AccessKeyID, AliyunOSSConfig.AccessKeySecret); + DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain); + IAcsClient acsClient = new DefaultAcsClient(profile); + + //组装请求对象-具体描述见控制台-文档部分内容 + SendSmsRequest request = new SendSmsRequest(); + //必填:待发送手机号 + request.setPhoneNumbers(phone); + //必填:短信签名-可在短信控制台中找到 + request.setSignName(signName); + //必填:短信模板-可在短信控制台中找到 + request.setTemplateCode(tmpCode); + //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为 + JSONObject paramObj = new JSONObject(); + paramObj.put("plan", plan); + request.setTemplateParam(paramObj.toJSONString()); + + //选填-上行短信扩展码(无特殊需求用户请忽略此字段) + //request.setSmsUpExtendCode("90997"); + + //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者 + request.setOutId("yourOutId"); + + //hint 此处可能会抛出异常,注意catch + SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); + + return sendSmsResponse; + } + + + public static QuerySendDetailsResponse querySendDetails(String bizId) throws ClientException { + + //可自助调整超时时间 + System.setProperty("sun.net.client.defaultConnectTimeout", "10000"); + System.setProperty("sun.net.client.defaultReadTimeout", "10000"); + + //初始化acsClient,暂不支持region化 + IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", AliyunOSSConfig.AccessKeyID, AliyunOSSConfig.AccessKeySecret); + DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain); + IAcsClient acsClient = new DefaultAcsClient(profile); + + //组装请求对象 + QuerySendDetailsRequest request = new QuerySendDetailsRequest(); + //必填-号码 + request.setPhoneNumber("15000000000"); + //可选-流水号 + request.setBizId(bizId); + //必填-发送日期 支持30天内记录查询,格式yyyyMMdd + SimpleDateFormat ft = new SimpleDateFormat("yyyyMMdd"); + request.setSendDate(ft.format(new Date())); + //必填-页大小 + request.setPageSize(10L); + //必填-当前页码从1开始计数 + request.setCurrentPage(1L); + + //hint 此处可能会抛出异常,注意catch + QuerySendDetailsResponse querySendDetailsResponse = acsClient.getAcsResponse(request); + + return querySendDetailsResponse; + } +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/utils/WechatMessageUtil.java b/stdiet-custom/src/main/java/com/stdiet/custom/utils/WechatMessageUtil.java deleted file mode 100644 index 2b7195c10..000000000 --- a/stdiet-custom/src/main/java/com/stdiet/custom/utils/WechatMessageUtil.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.stdiet.custom.utils; - -public class WechatMessageUtil { - // 各种消息类型,除了扫带二维码事件 - /** - * 文本消息 - */ - public static final String MESSAGE_TEXT = "text"; - /** - * 图片消息 - */ - public static final String MESSAtGE_IMAGE = "image"; - /** - * 图文消息 - */ - public static final String MESSAGE_NEWS = "news"; - /** - * 语音消息 - */ - public static final String MESSAGE_VOICE = "voice"; - /** - * 视频消息 - */ - public static final String MESSAGE_VIDEO = "video"; - /** - * 小视频消息 - */ - public static final String MESSAGE_SHORTVIDEO = "shortvideo"; - /** - * 地理位置消息 - */ - public static final String MESSAGE_LOCATION = "location"; - /** - * 链接消息 - */ - public static final String MESSAGE_LINK = "link"; - /** - * 事件推送消息 - */ - public static final String MESSAGE_EVENT = "event"; - /** - * 事件推送消息中,事件类型,subscribe(订阅) - */ - public static final String MESSAGE_EVENT_SUBSCRIBE = "subscribe"; - /** - * 事件推送消息中,事件类型,unsubscribe(取消订阅) - */ - public static final String MESSAGE_EVENT_UNSUBSCRIBE = "unsubscribe"; - /** - * 事件推送消息中,上报地理位置事件 - */ - public static final String MESSAGE_EVENT_LOCATION_UP = "LOCATION"; - /** - * 事件推送消息中,自定义菜单事件,点击菜单拉取消息时的事件推送 - */ - public static final String MESSAGE_EVENT_CLICK = "CLICK"; - /** - * 事件推送消息中,自定义菜单事件,点击菜单跳转链接时的事件推送 - */ - public static final String MESSAGE_EVENT_VIEW = "VIEW"; - - -} \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/utils/WxTokenUtils.java b/stdiet-custom/src/main/java/com/stdiet/custom/utils/WxTokenUtils.java deleted file mode 100644 index 5a42a8bab..000000000 --- a/stdiet-custom/src/main/java/com/stdiet/custom/utils/WxTokenUtils.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.stdiet.custom.utils; - -import com.alibaba.fastjson.JSONObject; -import com.stdiet.common.utils.StringUtils; -import com.stdiet.common.utils.http.HttpUtils; -import com.stdiet.custom.domain.WxXmlData; -import com.stdiet.custom.domain.wechat.WxAccessToken; -import com.stdiet.custom.domain.wechat.WxFileUploadResult; -import com.thoughtworks.xstream.XStream; -import org.apache.commons.io.IOUtils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public class WxTokenUtils { - - public static final String KEY_ACCESS_TOKEN = "wx:access_token"; - public static final String KEY_ACCESS_TOKEN_WATHER = "wx:access_token_watcher"; - - // 与接口配置信息中的Token要一致 - private static String token = "shengtangdiet"; - // 胜唐体控 - private static String appId = "wx4a9c1fc9dba53202"; - private static String appSecret = "fff029ade5d3575df755f4cf9e52f8da"; - // 胜唐体控李晓 -// private static String appId = "wxaf10fe560ea043a0"; -// private static String appSecret = "afb47e477337df23b7562c3c1f965826"; - private static String tokenUrl = "https://api.weixin.qq.com/cgi-bin/token"; - private static String uploadMaterialUrl = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN&type=image"; - - - public static WxAccessToken fetchAccessToken() { - try { - String resStr = HttpUtils.sendGet(tokenUrl, "grant_type=client_credential&appid=" + appId + "&secret=" + appSecret); - if (StringUtils.isEmpty(resStr)) { - return null; - } - JSONObject obj = JSONObject.parseObject(resStr); - - WxAccessToken token = JSONObject.toJavaObject(obj, WxAccessToken.class); - return token; - } catch (Exception e) { - return null; - } - } - - /** - * 模拟form表单的形式 ,上传文件 以输出流的形式把文件写入到url中,然后用输入流来获取url的响应 - * - * @return String url的响应信息返回值 - * @throws IOException - */ - public static WxFileUploadResult uploadImage(String filePath, String fileName, String accessToken) throws Exception { - String[] cmds = {"curl", uploadMaterialUrl.replaceAll("ACCESS_TOKEN", accessToken), "-F" - , "media=@" + filePath + ";filename=" + fileName};//必须分开写,不能有空格 - - ProcessBuilder process = new ProcessBuilder(cmds); - Process p = process.start(); - BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); - StringBuilder builder = new StringBuilder(); - String line = null; - while ((line = reader.readLine()) != null) { - builder.append(line); - builder.append(System.getProperty("line.separator")); - } - JSONObject obj = JSONObject.parseObject(builder.toString()); - return JSONObject.toJavaObject(obj, WxFileUploadResult.class); - - } - - /** - * 验证签名 - * - * @param signature - * @param timestamp - * @param nonce - * @return - */ - public static boolean checkSignature(String signature, String timestamp, String nonce) { - String[] arr = new String[]{token, timestamp, nonce}; - // 将token、timestamp、nonce三个参数进行字典序排序 - // Arrays.sort(arr); - sort(arr); - StringBuilder content = new StringBuilder(); - for (int i = 0; i < arr.length; i++) { - content.append(arr[i]); - } - MessageDigest md = null; - String tmpStr = null; - - try { - md = MessageDigest.getInstance("SHA-1"); - // 将三个参数字符串拼接成一个字符串进行sha1加密 - byte[] digest = md.digest(content.toString().getBytes()); - tmpStr = byteToStr(digest); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - content = null; - // 将sha1加密后的字符串可与signature对比,标识该请求来源于微信 - return tmpStr != null ? tmpStr.equals(signature.toUpperCase()) : false; - } - - /** - * 将字节数组转换为十六进制字符串 - * - * @param byteArray - * @return - */ - private static String byteToStr(byte[] byteArray) { - String strDigest = ""; - for (int i = 0; i < byteArray.length; i++) { - strDigest += byteToHexStr(byteArray[i]); - } - return strDigest; - } - - /** - * 将字节转换为十六进制字符串 - * - * @param mByte - * @return - */ - private static String byteToHexStr(byte mByte) { - char[] Digit = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - char[] tempArr = new char[2]; - tempArr[0] = Digit[(mByte >>> 4) & 0X0F]; - tempArr[1] = Digit[mByte & 0X0F]; - String s = new String(tempArr); - return s; - } - - public static void sort(String a[]) { - for (int i = 0; i < a.length - 1; i++) { - for (int j = i + 1; j < a.length; j++) { - if (a[j].compareTo(a[i]) < 0) { - String temp = a[i]; - a[i] = a[j]; - a[j] = temp; - } - } - } - } - - public static WxXmlData resolveXmlData(InputStream in) { - WxXmlData wxXmlData = null; - try { - String xmlData = IOUtils.toString(in, StandardCharsets.UTF_8.name()); - XStream xstream = new XStream(); - //这个必须要加 不然无法转换成WxXmlData对象 - xstream.setClassLoader(WxXmlData.class.getClassLoader()); - xstream.processAnnotations(WxXmlData.class); - xstream.alias("xml", WxXmlData.class); - wxXmlData = (WxXmlData) xstream.fromXML(xmlData); -// log.info("【wxXmlData: {}】 ", wxXmlData); - } catch (Exception e) { -// log.error("【error】{}", e.getMessage()); - } - return wxXmlData; - } -} diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysRecipesPlanMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysRecipesPlanMapper.xml index 279f143ff..dae2693d4 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysRecipesPlanMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysRecipesPlanMapper.xml @@ -14,7 +14,7 @@ - + @@ -22,6 +22,9 @@ + + + @@ -37,7 +40,7 @@ - select id, order_id, cus_id, out_id, start_date, end_date, start_num_day, end_num_day, recipes_id, send_flag, send_time, pause_date, create_time, create_by, update_time, update_by, del_flag, review_status from sys_recipes_plan + select id, order_id, cus_id, out_id, start_date, end_date, start_num_day, end_num_day, recipes_id, send_flag, send_time, pause_date, create_time, create_by, update_time, update_by, del_flag, review_status, sub_send, sms_send from sys_recipes_plan - select srp.* from sys_recipes_plan srp left join sys_order so on so.order_id = srp.order_id and so.del_flag = 0 @@ -135,6 +138,9 @@ update_by = #{updateBy}, del_flag = #{delFlag}, review_status = #{reviewStatus}, + subscribed = #{subscribed}, + sub_send = #{subSend}, + sms_send = #{smsSend}, where id = #{id} and del_flag = 0 @@ -153,10 +159,12 @@ INSERT INTO sys_recipes_plan - (order_id, cus_id, out_id, start_date, end_date, start_num_day, end_num_day, send_flag, send_time, pause_date, recipes_id) + (order_id, cus_id, out_id, start_date, end_date, start_num_day, end_num_day, send_flag, send_time, pause_date, + recipes_id) VALUES - (#{plan.orderId}, #{plan.cusId}, #{plan.outId}, #{plan.startDate}, #{plan.endDate}, #{plan.startNumDay}, #{plan.endNumDay}, + (#{plan.orderId}, #{plan.cusId}, #{plan.outId}, #{plan.startDate}, #{plan.endDate}, #{plan.startNumDay}, + #{plan.endNumDay}, #{plan.sendFlag}, #{plan.sendTime}, #{plan.pauseDate}, #{plan.recipesId}) @@ -177,8 +185,10 @@ FROM sys_recipes_plan srp LEFT JOIN sys_order sr ON sr.order_id = srp.order_id LEFT JOIN sys_customer sc ON sc.id = srp.cus_id - LEFT JOIN sys_user su_nutritionist ON su_nutritionist.user_id = sr.nutritionist_id AND su_nutritionist.del_flag = 0 - LEFT JOIN sys_user su_nutritionist_assis ON su_nutritionist_assis.user_id = sr.nutri_assis_id AND su_nutritionist_assis.del_flag = 0 + LEFT JOIN sys_user su_nutritionist ON su_nutritionist.user_id = sr.nutritionist_id AND su_nutritionist.del_flag + = 0 + LEFT JOIN sys_user su_nutritionist_assis ON su_nutritionist_assis.user_id = sr.nutri_assis_id AND + su_nutritionist_assis.del_flag = 0 WHERE srp.del_flag = 0 AND sr.del_flag = 0 AND srp.type = 0 AND srp.order_id = #{orderId} AND srp.send_flag = #{sendFlag} @@ -238,16 +248,21 @@ + + - + + @@ -265,6 +280,7 @@ - update sys_recipes_plan set start_date = #{startDate},end_date = #{endDate},pause_date=#{pauseDate} where id = #{id} + update sys_recipes_plan set start_date = #{startDate},end_date = #{endDate},pause_date=#{pauseDate} where id = + #{id} \ No newline at end of file diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysWxSubscribePostLogMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysWxSubscribePostLogMapper.xml new file mode 100644 index 000000000..e83d9a82f --- /dev/null +++ b/stdiet-custom/src/main/resources/mapper/custom/SysWxSubscribePostLogMapper.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + insert into sys_wx_subscribe_post_log + + appid, + openid, + plan_id, + send_time, + result, + phone, + data, + type, + + + #{appid}, + #{openid}, + #{planId}, + #{sendTime}, + #{result, jdbcType=OTHER, typeHandler=com.stdiet.custom.typehandler.ObjectJsonHandler}, + #{phone}, + #{data, jdbcType=OTHER, typeHandler=com.stdiet.custom.typehandler.ObjectJsonHandler}, + #{type}, + + + + + + + diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserInfoMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserInfoMapper.xml index 213c2a3a7..f5d31376b 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserInfoMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserInfoMapper.xml @@ -32,6 +32,7 @@ and nick_name like concat('%', #{nickName}, '%') and appid = #{appid} + and cus_id = #{cusId} and phone = #{phone} and sex = #{sex} @@ -45,6 +46,11 @@ order by wxuser.update_time desc + +