Browse Source

公众号消息

Duan_xu 2 years ago
parent
commit
5b56d28f20

+ 222 - 0
src/main/java/com/caimei365/user/components/WeChatService.java

@@ -18,6 +18,7 @@ import javax.crypto.spec.SecretKeySpec;
 import java.security.AlgorithmParameters;
 import java.security.Security;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 /**
@@ -295,4 +296,225 @@ public class WeChatService {
         return map;
     }
 
+    /**
+     * 购买会员消息推送
+     * @param accessToken 微信公众号
+     * @param openid 公众号的openid
+     * @param title 标题
+     * @param name 商品名称
+     * @param money 金额
+     * @param remarkText 备注
+     * @param pagePath 跳转链接
+     */
+    public void sendTemplateMsgs(String accessToken, String openid, String title, String name,String time, Double money, String date,String remarkText, String pagePath) {
+        JSONObject first = new JSONObject();
+        first.put("value", title);
+        JSONObject keyword1 = new JSONObject();
+        keyword1.put("value", name);
+        JSONObject keyword2 = new JSONObject();
+        keyword2.put("value", time);
+        JSONObject keyword3 = new JSONObject();
+        keyword3.put("value", money.toString());
+        JSONObject keyword4 = new JSONObject();
+        keyword3.put("value", date);
+        JSONObject remark = new JSONObject();
+        remark.put("value", remarkText);
+
+        JSONObject data = new JSONObject();
+        data.put("first", first);
+        data.put("keyword1", keyword1);
+        data.put("keyword2", keyword2);
+        data.put("keyword3", keyword3);
+        data.put("keyword4", keyword4);
+        data.put("remark", remark);
+
+        JSONObject miniProgram = new JSONObject();
+        miniProgram.put("appid", miniAppId);
+        miniProgram.put("pagepath", pagePath);
+
+        JSONObject json = new JSONObject(new LinkedHashMap());
+        json.put("touser",openid);
+        json.put("template_id","Sj5QEHxYrXMOvkY0t7ptj_6LJvBE6H4O-N0TRS3l3tc");
+        json.put("url","https://www.caimei365.com/");
+        json.put("miniprogram", miniProgram);
+        json.put("data", data);
+        // json 字符串
+        String jsonString = json.toJSONString();
+        log.info(">>>>>>>>推送微信模板消息:" + jsonString);
+        try {
+            // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
+//            String requestUrl =  "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token="+accessToken;
+            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
+            // 发送请求
+            String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
+            log.info(">>>>>>>>推送结果:" + result);
+        } catch (Exception e) {
+            log.error("推送微信模板消息失败:", e);
+        }
+    }
+
+    /**
+     * 续费会员消息推送
+     * @param accessToken 微信公众号
+     * @param openid 公众号的openid
+     * @param title 标题
+     * @param name 商品名称
+     * @param remarkText 备注
+     * @param pagePath 跳转链接
+     */
+    public void sendTemplateMsg(String accessToken, String openid, String title, String name,String type,String date,String remarkText, String pagePath) {
+        JSONObject first = new JSONObject();
+        first.put("value", title);
+        JSONObject keyword1 = new JSONObject();
+        keyword1.put("value", name);
+        JSONObject keyword2 = new JSONObject();
+        keyword2.put("value", date);
+        JSONObject remark = new JSONObject();
+        remark.put("value", remarkText);
+
+        JSONObject data = new JSONObject();
+        data.put("first", first);
+        data.put("keyword1", keyword1);
+        data.put("keyword2", keyword2);
+        data.put("remark", remark);
+
+        JSONObject miniProgram = new JSONObject();
+        miniProgram.put("appid", miniAppId);
+        miniProgram.put("pagepath", pagePath);
+
+        JSONObject json = new JSONObject(new LinkedHashMap());
+        json.put("touser",openid);
+        json.put("template_id","QHsM0AhlgGaX6kJ6vFm1wAKIkNjnZdWPjFGOKopLbsM");
+        json.put("url","https://www.caimei365.com/");
+        json.put("miniprogram", miniProgram);
+        json.put("data", data);
+        // json 字符串
+        String jsonString = json.toJSONString();
+        log.info(">>>>>>>>推送微信模板消息:" + jsonString);
+        try {
+            // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
+//            String requestUrl =  "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token="+accessToken;
+            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
+            // 发送请求
+            String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
+            log.info(">>>>>>>>推送结果:" + result);
+        } catch (Exception e) {
+            log.error("推送微信模板消息失败:", e);
+        }
+    }
+
+    /**
+     * 续费会员消息推送
+     * @param accessToken 微信公众号
+     * @param openid 公众号的openid
+     * @param remarkText 备注
+     * @param pagePath 跳转链接
+     */
+    public void sendTemplateMessg(String accessToken, String openid, String nickName,String time,String remarkText, String pagePath) {
+        JSONObject first = new JSONObject();
+        first.put("value", "绑定成功提醒");
+        JSONObject keyword1 = new JSONObject();
+        keyword1.put("value", "您已成功绑定采美平台");
+        JSONObject keyword2 = new JSONObject();
+        keyword2.put("value", nickName);
+        JSONObject keyword3 = new JSONObject();
+        keyword2.put("value", time);
+        JSONObject remark = new JSONObject();
+        remark.put("value", remarkText);
+
+        JSONObject data = new JSONObject();
+        data.put("first", first);
+        data.put("keyword1", keyword1);
+        data.put("keyword2", keyword2);
+        data.put("keyword3", keyword3);
+        data.put("remark", remark);
+
+        JSONObject miniProgram = new JSONObject();
+        miniProgram.put("appid", miniAppId);
+        miniProgram.put("pagepath", pagePath);
+
+        JSONObject json = new JSONObject(new LinkedHashMap());
+        json.put("touser",openid);
+        json.put("template_id","ph3XjF5o2QPuANQW2XlO7PRYU7Y9t-3fAX5TSqwTftk");
+        json.put("url","https://www.caimei365.com/");
+        json.put("miniprogram", miniProgram);
+        json.put("data", data);
+        // json 字符串
+        String jsonString = json.toJSONString();
+        log.info(">>>>>>>>推送微信模板消息:" + jsonString);
+        try {
+            // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
+//            String requestUrl =  "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token="+accessToken;
+            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
+            // 发送请求
+            String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
+            log.info(">>>>>>>>推送结果:" + result);
+        } catch (Exception e) {
+            log.error("推送微信模板消息失败:", e);
+        }
+    }
+
+
+    /**
+     * 上架费消息推送
+     * @param accessToken 微信公众号
+     * @param openid 公众号的openid
+     * @param remarkText 备注
+     * @param pagePath 跳转链接
+     */
+    public void sendTemplate(String accessToken, String openid, String date, String newTime,String endTime,Double money,String remarkText, String pagePath) {
+        JSONObject first = new JSONObject();
+        first.put("value", "维护费到期提醒");
+        JSONObject keyword1 = new JSONObject();
+        keyword1.put("value", "尊敬的采美供应商用户,您的账号维护费用"+date+"天后即将到期!");
+        JSONObject keyword2 = new JSONObject();
+        keyword2.put("value", "维护费");
+        JSONObject keyword3 = new JSONObject();
+        keyword2.put("value", "年付");
+        JSONObject keyword4 = new JSONObject();
+        keyword2.put("value", newTime);
+        JSONObject keyword5 = new JSONObject();
+        keyword2.put("value", endTime);
+        JSONObject keyword6 = new JSONObject();
+        keyword2.put("value", money);
+        JSONObject remark = new JSONObject();
+        remark.put("value", "为了更好给您服务,请及时联系采美客服缴费!");
+
+        JSONObject data = new JSONObject();
+        data.put("first", first);
+        data.put("keyword1", keyword1);
+        data.put("keyword2", keyword2);
+        data.put("keyword3", keyword3);
+        data.put("keyword4", keyword4);
+        data.put("keyword5", keyword5);
+        data.put("keyword6", keyword6);
+        data.put("remark", remark);
+
+        JSONObject miniProgram = new JSONObject();
+        miniProgram.put("appid", miniAppId);
+        miniProgram.put("pagepath", pagePath);
+
+        JSONObject json = new JSONObject(new LinkedHashMap());
+        json.put("touser",openid);
+        json.put("template_id","QHsM0AhlgGaX6kJ6vFm1wAKIkNjnZdWPjFGOKopLbsM");
+        json.put("url","https://www.caimei365.com/");
+        json.put("miniprogram", miniProgram);
+        json.put("data", data);
+        // json 字符串
+        String jsonString = json.toJSONString();
+        log.info(">>>>>>>>推送微信模板消息:" + jsonString);
+        try {
+            // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
+//            String requestUrl =  "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token="+accessToken;
+            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
+            // 发送请求
+            String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
+            log.info(">>>>>>>>推送结果:" + result);
+        } catch (Exception e) {
+            log.error("推送微信模板消息失败:", e);
+        }
+    }
+
+
+
 }

+ 18 - 6
src/main/java/com/caimei365/user/controller/LoginApi.java

@@ -139,14 +139,22 @@ public class LoginApi {
 
     @ApiOperation("机构站内消息改为已读")
     @GetMapping("/auth/updateMessageAsRead")
-    public Integer updateMessageAsRead(Integer messageType,Integer commonId){
-        return loginService.updateMessageAsRead(messageType,commonId);
+    public ResponseJson<Void> updateMessageAsRead(Integer messageType,Integer commonId){
+        Integer i=loginService.updateMessageAsRead(messageType,commonId);
+        if (i<=0){
+            return ResponseJson.error("没有未读消息了!", null);
+        }
+        return ResponseJson.success("标记已读成功", null);
     }
 
     @ApiOperation("供应商站内消息改为已读")
     @GetMapping("/auth/updateShopMessageAsRead")
-    public Integer updateShopMessageAsRead(Integer messageType,Integer commonId){
-        return loginService.updateShopMessageAsRead(messageType,commonId);
+    public ResponseJson<Void> updateShopMessageAsRead(Integer messageType,Integer commonId){
+        Integer i=loginService.updateShopMessageAsRead(messageType,commonId);
+        if (i<=0){
+            return ResponseJson.error("没有未读消息了!", null);
+        }
+        return ResponseJson.success("标记已读成功", null);
     }
 
     @ApiOperation("删除站内消息")
@@ -162,8 +170,12 @@ public class LoginApi {
 
     @ApiOperation("站内消息所有消息改为已读")
     @PostMapping("/auth/updateRead")
-    public Integer updateRead(Integer userType,String Id){
-        return loginService.updateRead(userType,Id);
+    public ResponseJson<Void> updateRead(Integer userType,String Id){
+        Integer i=loginService.updateRead(userType,Id);
+        if (i<=0){
+            return ResponseJson.error("id错误", null);
+        }
+        return ResponseJson.success("标记已读成功", null);
     }
 
 

+ 10 - 0
src/main/java/com/caimei365/user/mapper/MessageCenterMapper.java

@@ -38,10 +38,20 @@ public interface MessageCenterMapper {
 
     List<MessageCenter> MessageList(Integer userType,Integer messageType,Integer commonId);
 
+    String contractMobile(Integer clubID);
+
+    String getOpenidListByPermission(String unionId);
+
+    String FromUnionId(Integer userID);
+
+    Integer getVipHistoryCount(Integer userID);
+
     MessageCenter MainImage(Integer userType, Integer commonId);
 
     String receiptDate(Integer shopID);
 
+    Double receiptAmount(Integer shopID);
+
     Integer newReceiptType(Integer shopID);
 
     Integer updateMessageAsRead(Integer userType,Integer messageType,Integer commonId);

+ 214 - 121
src/main/java/com/caimei365/user/service/impl/LoginServiceImpl.java

@@ -15,10 +15,12 @@ import com.caimei365.user.model.po.OperationPo;
 import com.caimei365.user.model.po.SuperVipPo;
 import com.caimei365.user.model.vo.*;
 import com.caimei365.user.service.LoginService;
+import com.caimei365.user.service.RemoteCallService;
 import com.caimei365.user.utils.JwtUtil;
 import com.caimei365.user.utils.Md5Util;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
@@ -30,6 +32,9 @@ import javax.annotation.Resource;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
 /**
  * Description
@@ -61,6 +66,10 @@ public class LoginServiceImpl implements LoginService {
     private SellerMapper sellerMapper;
     @Resource
     private MessageCenterMapper messageCenterMapper;
+    @Resource
+    private RemoteCallService remoteCallService;
+
+
     /**
      * 小程序邀请码过期天数
      */
@@ -109,16 +118,9 @@ public class LoginServiceImpl implements LoginService {
             if(baseUser.getUserId()!=null){
                 Integer shopID=messageCenterMapper.shopID(baseUser.getUserId());
                 Integer newReceiptType= messageCenterMapper.newReceiptType(shopID);
-                if(shopID==null){
-                    savedCount= messageCenterMapper.Count(1,clubId);
-                    System.out.println(savedCount);
-                }else {
-                    savedCount= messageCenterMapper.Count(2,shopID);
-                }
-            }
             Timerw(baseUser.getUserId());
             Timesjf(baseUser.getUserId());
-
+        }
 
             // 比对密码
             String md5Password = Md5Util.md5(password);
@@ -189,12 +191,6 @@ public class LoginServiceImpl implements LoginService {
 if(userID!=null) {
     Integer shopID = messageCenterMapper.shopID(userID);
     Integer newReceiptType = messageCenterMapper.newReceiptType(shopID);
-    if (shopID == null) {
-        savedCount = messageCenterMapper.Count(1, clubId);
-        System.out.println(savedCount);
-    } else {
-        savedCount = messageCenterMapper.Count(2, shopID);
-    }
 
     Timerw(userID);
     Timesjf(userID);
@@ -271,6 +267,7 @@ if(userID!=null) {
     @Override
     public Integer updateMessageAsRead(Integer messageType,Integer commonId){
 
+
       return messageCenterMapper.updateMessageAsRead(1,messageType,commonId);
     }
 
@@ -363,127 +360,200 @@ if(userID!=null) {
 
 
     /**
-     * 每天下午3点判断
+     * 当天天下午3点推送
      */
-    @Scheduled(cron = "0 0 15 * * ?")
     private Void Timesjf(Integer userId) throws ParseException {
-        Integer shopID=messageCenterMapper.shopID(userId);
-        if(shopID!=null){
-           String receiptDate= messageCenterMapper.receiptDate(shopID);
-            Calendar calendar = Calendar.getInstance();
-
-            Integer clubId=messageCenterMapper.clubIdCule(userId);
-            if(clubId!=null){
-                Date d=new Date();
-                //1.日期格式
-                SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
-                Date time = sdf.parse(receiptDate);
-                calendar.setTime(time);
-                calendar.add(Calendar.YEAR, 1);
-               String dateStrings= sdf.format(calendar.getTime());
-                //2.到期时间
-                Date da1=sdf.parse(dateStrings);
-                //到期时间-当前时间=还剩多少天
-                Long s=(da1.getTime()-d.getTime())/24/60/60/1000;
-                //3.输出间隔天数         getTime获取的是毫秒
-                log.info("输出间隔天数----------->",s);
-                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-                String current = dateFormat.format(new Date());
-                MessageCenter messageCenter=new MessageCenter();
-                //推送信息中心-上架费服务通知
-                if(s==30){
-                    messageCenter.setShopId(shopID);
-                    messageCenter.setClubId(null);
-                    messageCenter.setUserType(2);
-                    messageCenter.setMessageType(3);
-                    messageCenter.setShopTieredType(1);
-                    messageCenter.setContent(s+"日后");
-                    messageCenter.setTime(current);
-                    messageCenterMapper.addMessageCenter(messageCenter);
-                }
-                if(s==7){
-                    messageCenter.setShopId(shopID);
-                    messageCenter.setClubId(null);
-                    messageCenter.setUserType(2);
-                    messageCenter.setMessageType(3);
-                    messageCenter.setShopTieredType(1);
-                    messageCenter.setContent(s+"日后");
-                    messageCenter.setTime(current);
-                    messageCenterMapper.addMessageCenter(messageCenter);
-                }
-                if(s==1){
-                    messageCenter.setShopId(shopID);
-                    messageCenter.setClubId(null);
-                    messageCenter.setUserType(2);
-                    messageCenter.setMessageType(3);
-                    messageCenter.setShopTieredType(1);
-                    messageCenter.setContent("今日");
-                    messageCenter.setTime(current);
-                    messageCenterMapper.addMessageCenter(messageCenter);
-                }
-                if(s<=0){
-                    messageCenter.setShopId(shopID);
-                    messageCenter.setClubId(null);
-                    messageCenter.setUserType(2);
-                    messageCenter.setMessageType(3);
-                    messageCenter.setShopTieredType(1);
-                    messageCenter.setContent("已过期");
-                    messageCenter.setTime(current);
-                    messageCenterMapper.addMessageCenter(messageCenter);
+        //1.获取下午3点的时间
+        SimpleDateFormat dnf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
+        Calendar time = Calendar.getInstance();
+        time.set(Calendar.HOUR_OF_DAY, 15);
+        time.set(Calendar.MINUTE, 00);
+        time.set(Calendar.SECOND, 00);
+
+        String times = dnf.format(time.getTime());
+        System.out.println(times);
+        //2.某天的日期
+        Date date=dnf.parse(times);
+        //与当前时间的毫秒数相减得到相差的毫秒用于定时
+        Long h=(date.getTime()-date.getTime());
+        //这里如果当前时间大于下午三点会出现负数所以就不推送
+        if(h>0) {
+            ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
+            executorService.schedule(new Runnable() {
+                @SneakyThrows
+                @Override
+                public void run() {
+                    Integer shopID = messageCenterMapper.shopID(userId);
+                    if (shopID != null) {
+                        String receiptDate = messageCenterMapper.receiptDate(shopID);
+                        Double receiptAmount=messageCenterMapper.receiptAmount(shopID);
+                        Calendar calendar = Calendar.getInstance();
+
+                        Integer clubId = messageCenterMapper.clubIdCule(userId);
+                        if (clubId != null) {
+                            Date d = new Date();
+                            //1.日期格式
+                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
+                            Date time = sdf.parse(receiptDate);
+                            calendar.setTime(time);
+                            calendar.add(Calendar.YEAR, 1);
+                            String dateStrings = sdf.format(calendar.getTime());
+                            //2.到期时间
+                            Date da1 = sdf.parse(dateStrings);
+                            //到期时间-当前时间=还剩多少天
+                            Long s = (da1.getTime() - d.getTime()) / 24 / 60 / 60 / 1000;
+                            //3.输出间隔天数         getTime获取的是毫秒
+                            log.info("输出间隔天数----------->", s);
+                            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                            String current = dateFormat.format(new Date());
+                            MessageCenter messageCenter = new MessageCenter();
+                            //推送信息中心-上架费服务通知
+                            if (s == 30) {
+                                messageCenter.setShopId(shopID);
+                                messageCenter.setClubId(null);
+                                messageCenter.setUserType(2);
+                                messageCenter.setMessageType(3);
+                                messageCenter.setShopTieredType(1);
+                                messageCenter.setContent(s + "日后");
+                                messageCenter.setTime(current);
+                                messageCenterMapper.addMessageCenter(messageCenter);
+                                String mobile = messageCenterMapper.contractMobile(clubId);
+                                String content = "【采美365】您的供应商账号上架费将于30日后到期,到期后将无法发布和编辑商品,同时也会影响到其他采美提供的支持服务。请联系采美工作人员进行续费,联系电话0755-22907771 或15338851365";
+                                remoteCallService.remoteSendSms(0, 1, mobile, content);
+                            }
+                            if (s == 7) {
+                                messageCenter.setShopId(shopID);
+                                messageCenter.setClubId(null);
+                                messageCenter.setUserType(2);
+                                messageCenter.setMessageType(3);
+                                messageCenter.setShopTieredType(1);
+                                messageCenter.setContent(s + "日后");
+                                messageCenter.setTime(current);
+                                messageCenterMapper.addMessageCenter(messageCenter);
+                                String mobile = messageCenterMapper.contractMobile(clubId);
+                                String content = "【采美365】您的供应商账号上架费将于7日后到期,到期后将无法发布和编辑商品,同时也会影响到其他采美提供的支持服务。请联系采美工作人员进行续费,联系电话0755-22907771 或15338851365";
+                                remoteCallService.remoteSendSms(0, 1, mobile, content);
+                            }
+                            if (s == 1) {
+                                messageCenter.setShopId(shopID);
+                                messageCenter.setClubId(null);
+                                messageCenter.setUserType(2);
+                                messageCenter.setMessageType(3);
+                                messageCenter.setShopTieredType(1);
+                                messageCenter.setContent("今日");
+                                messageCenter.setTime(current);
+                                messageCenterMapper.addMessageCenter(messageCenter);
+                                String mobile = messageCenterMapper.contractMobile(clubId);
+                                String content = "【采美365】您的供应商账号上架费将于今日后到期,到期后将无法发布和编辑商品,同时也会影响到其他采美提供的支持服务。请联系采美工作人员进行续费,联系电话0755-22907771 或15338851365";
+                                remoteCallService.remoteSendSms(0, 1, mobile, content);
+                            }
+                            if (s <= 0) {
+                                messageCenter.setShopId(shopID);
+                                messageCenter.setClubId(null);
+                                messageCenter.setUserType(2);
+                                messageCenter.setMessageType(3);
+                                messageCenter.setShopTieredType(1);
+                                messageCenter.setContent("已过期");
+                                messageCenter.setTime(current);
+                                messageCenterMapper.addMessageCenter(messageCenter);
+                            }
+
+                        try {
+                            log.info("***********上架费过期微信公众号推送************");
+                            String accessToken = weChatService.getAccessToken();
+                            String openid = messageCenterMapper.getOpenidListByPermission(messageCenterMapper.FromUnionId(userId));
+                           String date=s.toString();
+                            String remarkText = "如在使用中有任何疑问,请在小程序内联系在线客服";
+                            // 跳转到【小程序付款-选择支付方式页面】
+                            String pagePath = "https://www.caimei365.com/";
+                            // sendTemplateMsg(openid, 标题, 金额, 收款日期, 备注, 跳转链接
+                            log.error("获取openid>>>>>" + openid);
+                            weChatService.sendTemplate(accessToken,openid,date,receiptDate,dateStrings,receiptAmount,remarkText, pagePath);
+                        } catch (Exception e) {
+                            log.error("【上架费过期通知】获取微信公众号access_token异常!", e);
+                        }
+                        }
+                    }
                 }
-
-            }
+            }, h, TimeUnit.MILLISECONDS);
         }
-
         return null;
     }
 
 
 
-
     /**
-     * 每天下午3点判断
+     * 当天天下午3点推送超级会员过期条件
      */
-    @Scheduled(cron = "0 0 15 * * ?")
     private Void Timerw(Integer userId) throws ParseException {
-        SuperVipPo superVip = vipMapper.findSuperVip(userId);
-        Integer clubId=messageCenterMapper.clubIdCule(userId);
-        if(clubId!=null){
-            if(superVip!=null){
-                Date d=new Date();
-                //1.日期格式
-                SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
-                String endTime = sdf.format(superVip.getEndTime());
-                //2.某天的日期
-                Date da1=sdf.parse(endTime);
-                Long s=(d.getTime()-da1.getTime())/24/60/60/1000;
-                //3.输出间隔天数         getTime获取的是毫秒
-                log.info("输出间隔天数----------->",s);
-                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-                String current = dateFormat.format(new Date());
-                MessageCenter messageCenter=new MessageCenter();
-                //推送信息中心-账户通知
-                if(s==7){
-                    messageCenter.setShopId(null);
-                    messageCenter.setClubId(clubId);
-                    messageCenter.setUserType(1);
-                    messageCenter.setMessageType(2);
-                    messageCenter.setAccountType(3);
-                    messageCenter.setContent(s+"日后");
-                    messageCenter.setTime(current);
-                    messageCenterMapper.addMessageCenter(messageCenter);
-                }
-                if(s==1){
-                    messageCenter.setShopId(null);
-                    messageCenter.setClubId(clubId);
-                    messageCenter.setUserType(1);
-                    messageCenter.setMessageType(2);
-                    messageCenter.setAccountType(3);
-                    messageCenter.setContent("今日后");
-                    messageCenter.setTime(current);
-                    messageCenterMapper.addMessageCenter(messageCenter);
+        //1.获取下午3点的时间
+        SimpleDateFormat dnf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
+        Calendar time = Calendar.getInstance();
+        time.set(Calendar.HOUR_OF_DAY, 15);
+        time.set(Calendar.MINUTE, 00);
+        time.set(Calendar.SECOND, 00);
+
+        String times = dnf.format(time.getTime());
+        System.out.println(times);
+        //2.某天的日期
+        Date date=dnf.parse(times);
+        //与当前时间的毫秒数相减得到相差的毫秒用于定时
+        Long h=(date.getTime()-date.getTime());
+        //这里如果当前时间大于下午三点会出现负数所以就不推送
+        if(h>0){
+        ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
+        executorService.schedule(new Runnable() {
+            @SneakyThrows
+            @Override
+            public void run() {
+                SuperVipPo superVip = vipMapper.findSuperVip(userId);
+                Integer clubId = messageCenterMapper.clubIdCule(userId);
+                if (clubId != null) {
+                    if (superVip != null) {
+                        Date d = new Date();
+                        //1.日期格式
+                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
+                        String endTime = sdf.format(superVip.getEndTime());
+                        //2.某天的日期
+                        Date da1 = sdf.parse(endTime);
+                        Long s = (d.getTime() - da1.getTime()) / 24 / 60 / 60 / 1000;
+                        //3.输出间隔天数         getTime获取的是毫秒
+                        log.info("输出间隔天数----------->", s);
+                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                        String current = dateFormat.format(new Date());
+                        MessageCenter messageCenter = new MessageCenter();
+                        //推送信息中心-账户通知
+                        if (s == 7) {
+                            messageCenter.setShopId(null);
+                            messageCenter.setClubId(clubId);
+                            messageCenter.setUserType(1);
+                            messageCenter.setMessageType(2);
+                            messageCenter.setAccountType(3);
+                            messageCenter.setContent(s + "日后");
+                            messageCenter.setTime(current);
+                            messageCenterMapper.addMessageCenter(messageCenter);
+                            String mobile = messageCenterMapper.contractMobile(clubId);
+                            String content = "【采美365】您的超级会员将于7日后到期,到期后将无法享受专属会员权益,快戳采美网站链接www.caimei365.com 或微信搜索“采美采购商城”小程序登录采美平台续费吧。关注公众号“采美网”可获取更多优惠和精彩资讯。";
+                            remoteCallService.remoteSendSms(0, 1, mobile, content);
+
+                        }
+                        if (s == 1) {
+                            messageCenter.setShopId(null);
+                            messageCenter.setClubId(clubId);
+                            messageCenter.setUserType(1);
+                            messageCenter.setMessageType(2);
+                            messageCenter.setAccountType(3);
+                            messageCenter.setContent("今日后");
+                            messageCenter.setTime(current);
+                            messageCenterMapper.addMessageCenter(messageCenter);
+                            String mobile = messageCenterMapper.contractMobile(clubId);
+                            String content = "【采美365】您的超级会员将于今日到期,到期后将无法享受专属会员权益,快戳采美网站链接www.caimei365.com 或微信搜索“采美采购商城”小程序登录采美平台续费吧。关注公众号“采美网”可获取更多优惠和精彩资讯。";
+                            remoteCallService.remoteSendSms(0, 1, mobile, content);
+                        }
+                    }
                 }
             }
+        }, h, TimeUnit.MILLISECONDS);
         }
         return null;
     }
@@ -912,6 +982,29 @@ if(userID!=null) {
             messageCenter.setContent(nickName);
             messageCenter.setTime(current);
             messageCenterMapper.addMessageCenter(messageCenter);
+            //发短信
+           String message = "【采美365】恭喜您成功成为运营人员,您可通过微信直接登录采美商城进行采购。";
+            String mobile = messageCenterMapper.contractMobile(operation.getClubId());
+            if (mobile != null && mobile != "") {
+                remoteCallService.remoteSendSms(2, 3, mobile, message);
+            }
+
+            try {
+                log.info("***********机构通过邀请码登入微信公众号推送************");
+                String accessToken = weChatService.getAccessToken();
+                String openid = messageCenterMapper.getOpenidListByPermission(unionId);
+                String time=current;
+                String remarkText = "绑定成功后,您可通过微信直接访问采美商城进行采购。";
+                // 跳转到【小程序付款-选择支付方式页面】
+                String pagePath = "https://www.caimei365.com/";
+                // sendTemplateMsg(openid, 标题, 金额, 收款日期, 备注, 跳转链接
+                log.error("获取openid>>>>>" + openid);
+                weChatService.sendTemplateMessg(accessToken,openid,nickName,time,remarkText, pagePath);
+            } catch (Exception e) {
+                log.error("【机构通过邀请码登入通知】获取微信公众号access_token异常!", e);
+            }
+
+
 
         } else {
             // 供应商Id

+ 89 - 37
src/main/java/com/caimei365/user/service/impl/RegisterServiceImpl.java

@@ -27,9 +27,7 @@ import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Map;
+import java.util.*;
 
 /**
  * Description
@@ -65,6 +63,8 @@ public class RegisterServiceImpl implements RegisterService {
     private MessageCenterMapper messageCenterMapper;
     @Resource
     private RemoteCallService remoteCallService;
+    @Resource
+    private WeChatService weChatService;
 
     /**
      * 检查账号可以注册
@@ -230,12 +230,12 @@ public class RegisterServiceImpl implements RegisterService {
         messageCenterMapper.addMessageCenter(messageCenter);
 
         // 注册成功短信
-        String content = "注册成功!您可以通过手机号"+clubRegisterDto.getBindMobile()+"登录。";
-        boolean smsFlag = remoteCallService.remoteSendSms(0, 1, clubRegisterDto.getBindMobile(), content);
-        if (!smsFlag) {
-            // 短信发送失败重试一次
-            remoteCallService.remoteSendSms(0, 1, clubRegisterDto.getBindMobile(), content);
-        }
+//        String content = "注册成功!您可以通过手机号"+clubRegisterDto.getBindMobile()+"登录。";
+//        boolean smsFlag = remoteCallService.remoteSendSms(0, 1, clubRegisterDto.getBindMobile(), content);
+//        if (!smsFlag) {
+//            // 短信发送失败重试一次
+//            remoteCallService.remoteSendSms(0, 1, clubRegisterDto.getBindMobile(), content);
+//        }
         /*
             绑定微信,成为机构运营人员
          */
@@ -295,9 +295,9 @@ public class RegisterServiceImpl implements RegisterService {
             log.info("注册普通机构,默认绑定为机构运营人员");
         }
         log.info("注册普通机构成功,手机号>>>" + clubRegisterDto.getBindMobile());
-        if (!smsFlag) {
-            log.info("短信发送失败,手机号:" + clubRegisterDto.getBindMobile());
-        }
+//        if (!smsFlag) {
+//            log.info("短信发送失败,手机号:" + clubRegisterDto.getBindMobile());
+//        }
         //新用户自主注册送1000采美豆
         UserBeansHistoryPo beansHistory = new UserBeansHistoryPo();
         beansHistory.setUserId(user.getUserId());
@@ -1051,7 +1051,7 @@ public class RegisterServiceImpl implements RegisterService {
      * @param headers
      */
     @Override
-    public ResponseJson<Integer> superVipUpByPay(Integer userId, Integer packageId, HttpHeaders headers){
+    public ResponseJson<Integer> superVipUpByPay(Integer userId, Integer packageId, HttpHeaders headers) {
         SuperVipDto endFlag = findEnd(userId);
         VipPackage pac = vipMapper.findUserPackage(packageId);
         if (null == pac) {
@@ -1065,10 +1065,14 @@ public class RegisterServiceImpl implements RegisterService {
         }
         cal.setTime(beginTime);
         cal.add(Calendar.MONTH, pac.getDuration());
+
+
         // 查询未支付的当前超级会员套餐购买记录
         Integer dbHistoryId = vipMapper.getVipHistoryId(userId, packageId);
         //userId, packageId, beginTime, endTime, payStatus, payWay, payType, price, userBeans, payTime
         VipPayHistoryPo payHistory = new VipPayHistoryPo();
+
+
         payHistory.setUserBeans(0d);
         payHistory.setUserId(userId);
         payHistory.setPackageId(packageId);
@@ -1079,6 +1083,60 @@ public class RegisterServiceImpl implements RegisterService {
         // 线上支付
         payHistory.setPayWay(1);
         payHistory.setPrice(pac.getPrice());
+
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String current = dateFormat.format(new Date());
+        //1.日期格式
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
+        String endTime = sdf.format(payHistory.getEndTime());
+        //2.会员有效期(月)
+        Long s = (payHistory.getBeginTime().getTime() - payHistory.getEndTime().getTime()) / 24 / 60 / 60 / 30 / 1000;
+        //2.会员有效期(日)
+        Long t = (payHistory.getBeginTime().getTime() - payHistory.getEndTime().getTime()) / 24 / 60 / 60 / 1000;
+        Integer count =messageCenterMapper.getVipHistoryCount(userId);
+        if(count==0){
+            String name = "0";
+            try {
+                log.info("***********会员办理微信公众号推送************");
+                String accessToken = weChatService.getAccessToken();
+                String openid = messageCenterMapper.getOpenidListByPermission(messageCenterMapper.FromUnionId(userId));
+                name = "恭喜成为采美商城超级会员";
+                String time="超级会员("+s+"个月)";
+                String associateTitle = "会员办理成功通知";
+                String date=s+"天";
+                Double money =  payHistory.getPrice();
+                String remarkText = "如在使用中有任何疑问,请在小程序内联系在线客服";
+                // 跳转到【小程序付款-选择支付方式页面】
+                String pagePath = "/pages/user/member/member";
+                // sendTemplateMsg(openid, 标题, 金额, 收款日期, 备注, 跳转链接
+                log.error("获取openid>>>>>" + openid);
+                weChatService.sendTemplateMsgs(accessToken, openid, associateTitle, name, time, money,date ,remarkText, pagePath);
+            } catch (Exception e) {
+                log.error("【订单下单通知】获取微信公众号access_token异常!", e);
+            }
+        }else {
+            String name = "0";
+            SimpleDateFormat dnf=new SimpleDateFormat("yyyy年MM月dd日");
+
+            try {
+                log.info("***********会员续费微信公众号推送************");
+                String accessToken = weChatService.getAccessToken();
+                String openid = messageCenterMapper.getOpenidListByPermission(messageCenterMapper.FromUnionId(userId));
+                name = "恭喜您成功续费采美超级会员";
+                String type="超级会员";
+                String associateTitle = "续费成功提醒";
+                String date=dnf.format(payHistory.getEndTime());
+                String remarkText = "如在使用中有任何疑问,请在小程序内联系在线客服";
+                // 跳转到【小程序付款-选择支付方式页面】
+                String pagePath = "/pages/user/member/member";
+                // sendTemplateMsg(openid, 标题, 金额, 收款日期, 备注, 跳转链接
+                log.error("获取openid>>>>>" + openid);
+                weChatService.sendTemplateMsg(accessToken,openid, associateTitle,name,type,date,remarkText, pagePath);
+            } catch (Exception e) {
+                log.error("【订单下单通知】获取微信公众号access_token异常!", e);
+            }
+        }
+
         if (null != dbHistoryId && dbHistoryId > 0) {
             payHistory.setId(dbHistoryId);
             // 更新未支付的当前超级会员购买记录
@@ -1087,30 +1145,24 @@ public class RegisterServiceImpl implements RegisterService {
             // 新增超级会员购买记录
             vipMapper.addPayHistory(payHistory);
         }
+        //推送信息中心-账户通知
         if (payHistory.getId() > 0) {
-           Integer clubId=messageCenterMapper.clubIdCule(userId);
-           if(clubId!=null){
-               //推送信息中心-账户通知
-               SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-               String current = dateFormat.format(new Date());
-               //1.日期格式
-               SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
-               String endTime = sdf.format(payHistory.getEndTime());
-               //2.某天的日期
-               Long s=(payHistory.getBeginTime().getTime()-payHistory.getEndTime().getTime())/24/60/60/30/1000;;
-               //3.输出间隔天数         getTime获取的是毫秒
-               log.info("输出间隔月份----------->",s);
-               MessageCenter messageCenter=new MessageCenter();
-               messageCenter.setShopId(null);
-               messageCenter.setClubId(clubId);
-               messageCenter.setUserType(1);
-               messageCenter.setMessageType(2);
-               messageCenter.setAccountType(2);
-               messageCenter.setContent(s+"个月");
-               messageCenter.setTime(current);
-               messageCenterMapper.addMessageCenter(messageCenter);
-           }
-            return ResponseJson.success(payHistory.getId());
+            Integer clubId = messageCenterMapper.clubIdCule(userId);
+            if (clubId != null) {
+
+                //3.输出间隔天数         getTime获取的是毫秒
+                log.info("输出间隔月份----------->", s);
+                MessageCenter messageCenter = new MessageCenter();
+                messageCenter.setShopId(null);
+                messageCenter.setClubId(clubId);
+                messageCenter.setUserType(1);
+                messageCenter.setMessageType(2);
+                messageCenter.setAccountType(2);
+                messageCenter.setContent(s + "个月");
+                messageCenter.setTime(current);
+                messageCenterMapper.addMessageCenter(messageCenter);
+                return ResponseJson.success(payHistory.getId());
+            }
         }
         return ResponseJson.error("支付开通超级会员异常!", null);
     }
@@ -1118,7 +1170,6 @@ public class RegisterServiceImpl implements RegisterService {
 
 
 
-
     /**
      * 根据userId查是否过期,返回dto对象,flag=0未买过,-1过期,1有效,endTime过期时间
      */
@@ -1161,6 +1212,7 @@ public class RegisterServiceImpl implements RegisterService {
                 messageCenterMapper.addMessageCenter(messageCenter);
 
 
+
             }
         }
 

+ 17 - 0
src/main/java/com/caimei365/user/service/impl/ShopServiceImpl.java

@@ -21,8 +21,10 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import redis.clients.jedis.Jedis;
 
 import javax.annotation.Resource;
 import java.util.*;
@@ -372,6 +374,11 @@ public class ShopServiceImpl implements ShopService {
         // 9.已下架数量
         Integer downNum = shopMapper.getShopProductCount(user.getShopId(), 3);
         result.put("downNum", downNum);
+        Jedis jedis=new Jedis("172.31.165.27", 6379);
+        jedis.auth("6#xsI%b4o@5c3RoE");
+        jedis.lpush("constraint","1");
+        result.put("constraint", jedis.rpop("constraint"));
+
         // 10.单品销售排名
         List<Map<String, Object>> salesRankingList = shopMapper.getSalesRankingList(user.getShopId());
         if (salesRankingList != null && salesRankingList.size() > 0) {
@@ -412,6 +419,16 @@ public class ShopServiceImpl implements ShopService {
         return ResponseJson.success(result);
     }
 
+    /**
+     *constraint加入缓存
+     */
+    @Scheduled(cron = "0 0 23 * * ?")
+    public void Open() {
+        Jedis jedis=new Jedis("172.31.165.27", 6379);
+        jedis.auth("6#xsI%b4o@5c3RoE");
+        jedis.del("constraint");
+    }
+
     @Override
     public ResponseJson<Map<String, Object>> getShopArticleById(Integer articleId) {
         Map<String, Object> map = new HashMap<>(2);

+ 74 - 3
src/main/java/com/caimei365/user/utils/RequestUtil.java

@@ -1,11 +1,16 @@
 package com.caimei365.user.utils;
 
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
+import org.springframework.util.StringUtils;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import java.io.*;
 import java.net.URL;
 import java.net.URLConnection;
 import java.nio.charset.StandardCharsets;
+import java.security.cert.X509Certificate;
 import java.util.List;
 import java.util.Map;
 
@@ -113,4 +118,70 @@ public class RequestUtil {
         return result.toString();
     }
 
+    /**
+     * 向指定 URL 发送请求
+     * @param requestUrl 发送请求的 URL
+     * @param requestMethod 请求方法GET/POST
+     * @param jsonString json字符串参数
+     * @return 远程资源的响应结果
+     */
+    public static String httpRequest(String requestUrl, String requestMethod, String jsonString) {
+        StringBuffer buffer = new StringBuffer();
+        try {
+            // 创建SSLContext对象,并使用我们指定的信任管理器初始化
+            TrustManager[] tm = {
+                    new javax.net.ssl.X509TrustManager(){
+                        @Override
+                        public void checkClientTrusted(X509Certificate[] chain, String authType) {
+                        }
+                        @Override
+                        public void checkServerTrusted(X509Certificate[] chain, String authType) {
+                        }
+                        @Override
+                        public X509Certificate[] getAcceptedIssuers() {
+                            return null;
+                        }
+                    }
+            };
+            SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
+            sslContext.init(null, tm, new java.security.SecureRandom());
+            // 从上述SSLContext对象中得到SSLSocketFactory对象
+            SSLSocketFactory ssf = sslContext.getSocketFactory();
+
+            URL url = new URL(requestUrl);
+            HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();
+            httpUrlConn.setSSLSocketFactory(ssf);
+            httpUrlConn.setDoOutput(true);
+            httpUrlConn.setDoInput(true);
+            httpUrlConn.setUseCaches(false);
+            // 设置请求方式(GET/POST)
+            httpUrlConn.setRequestMethod(requestMethod);
+            if ("GET".equalsIgnoreCase(requestMethod)) {
+                httpUrlConn.connect();
+            }
+            // 当有数据需要提交时
+            if (StringUtils.hasLength(jsonString)) {
+                OutputStream outputStream = httpUrlConn.getOutputStream();
+                // 注意编码格式,防止中文乱码
+                outputStream.write(jsonString.getBytes(StandardCharsets.UTF_8));
+                outputStream.close();
+            }
+
+            // 将返回的输入流转换成字符串
+            InputStream inputStream = httpUrlConn.getInputStream();
+            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
+            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
+            String str = null;
+            while ((str = bufferedReader.readLine()) != null) {
+                buffer.append(str);
+            }
+            bufferedReader.close();
+            inputStreamReader.close();
+            // 释放资源
+            inputStream.close();
+            httpUrlConn.disconnect();
+            return buffer.toString();
+        } catch (Exception ignored) {}
+        return null;
+    }
 }

+ 33 - 0
src/main/resources/mapper/MessageCenter.xml

@@ -14,6 +14,10 @@
         SELECT shopID FROM `shop` WHERE userId=#{userId}
     </select>
 
+    <select id="shopID" resultType="java.lang.Integer">
+        SELECT shopID FROM `shop` WHERE userId=#{userId}
+    </select>
+
     <select id="clubList" resultType="com.caimei365.user.model.vo.UserVo">
         SELECT * FROM `user` WHERE userId=#{userId}
     </select>
@@ -75,6 +79,24 @@
         ORDER BY id DESC
     </select>
 
+    <select id="contractMobile" resultType="java.lang.String">
+        SELECT contractMobile FROM club WHERE clubID=#{clubID}
+    </select>
+
+    <select id="getOpenidListByPermission" resultType="java.lang.String">
+        SELECT openid FROM `wechat_user` WHERE unionId= #{unionId}
+    </select>
+
+    <select id="FromUnionId" resultType="java.lang.String">
+        SELECT unionID FROM `cm_order` WHERE userID=#{userID}
+    </select>
+
+    <select id="getVipHistoryCount" resultType="java.lang.Integer">
+        SELECT count(1)
+        FROM cm_svip_history
+        WHERE  userId = #{userId}
+    </select>
+
     <select id="MainImage" resultType="com.caimei365.user.model.vo.MessageCenter">
         SELECT co.refundType,COUNT(p.productID)AS productCount ,p.mainImage,co.onlinePayFlag,p.name as productName,co.orderID as orderID
         FROM cm_order co
@@ -106,6 +128,17 @@
         a.shopID=#{shopID}
         AND a.newReceiptType=1
     </select>
+
+    <select id="receiptAmount" resultType="java.lang.Double">
+        SELECT
+            a.receiptAmount
+        FROM cm_discern_receipt a
+                 LEFT JOIN shop s ON s.shopID = a.shopID
+        where
+            a.shopID=#{shopID}
+          AND a.newReceiptType=1
+    </select>
+
 <select id="newReceiptType" resultType="java.lang.Integer">
     SELECT
         a.newReceiptType