fei.wang
7 天以前 e15f561a1f9eddfde503d59baf45a860b131928e
src/main/java/com/flow/controller/DuanxinlogController.java
@@ -1,6 +1,10 @@
package com.flow.controller;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.alipay.api.kms.aliyun.http.HttpRequest;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.flow.mapper.*;
import com.flow.pojo.*;
import com.flow.service.DuanxinlogService;
@@ -15,6 +19,13 @@
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -23,10 +34,19 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import sun.net.www.http.HttpClient;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.*;
@RestController
@RequestMapping({"/hxzk"})
@@ -53,11 +73,13 @@
    @Autowired
    ManagerMapper managerMapper;
    @GetMapping({"findDuanxinlog"})
    result<List<Duanxinlog>> findDuanxinlog(Integer page, Integer limit) {
        PageInfo<Duanxinlog> cz = this.duanxinlogService.FindDuanxinlog(page, limit);
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
    @PostMapping({"DeleteDuanxinlog"})
    public ModelAndView DeleteManager(String num) {
        this.duanxinlogService.DeleteDuanxinlog(num);
@@ -82,8 +104,9 @@
     */
//    @EnableScheduling
//    @Scheduled(cron = "*/10 * * * * ?")//测试10一次
//    @Scheduled(cron = "0 46 17 * * ?")
    @Scheduled(cron = "0 0 */1 * * ?")//一小时执行一次
    @Scheduled(cron = "0 51 15 * * ?")
//    @Scheduled(cron = "0 0 */1 * * ?")//一小时执行一次
    @Scheduled(cron = "0 0/60 8-22 * * ?")//8点到10点每10分钟执行一次
    public void smsfuwuqi() throws Exception {
        System.out.println("服务器定时器执行============》》》》》》》》》》》》》》》》");
        QueryWrapper queryWrapper1 = new QueryWrapper();
@@ -94,8 +117,9 @@
            queryWrapper3.eq("none", "0");
            queryWrapper3.eq("companyName", fuwuqiList.get(i).getCompany());
            Company companyList = (companyMapper).selectOne(queryWrapper3);
            SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            Date endDay = date2.parse(fuwuqiList.get(i).getEnddate());//结束时间
            Long starTime = date.getTime();
            Long endTime = endDay.getTime();
@@ -103,10 +127,11 @@
            //不足一天的算作一天,因此在到期天数上加1
            if (+num11 / 24 / 60 / 60 / 1000 == 19 | +num11 / 24 / 60 / 60 / 1000 == 9 | +num11 / 24 / 60 / 60 / 1000 == 4 | +num11 / 24 / 60 / 60 / 1000 == 0) {
                String dispatchDate = this.duanxinlogService.userdate(fuwuqiList.get(i).getServername());
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String dtext = formatter.format(date);
                if (dispatchDate == null || !dtext.equals(dispatchDate)) {
                if (dispatchDate == null) {
//                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                    Date dtext = formatter.parse(dispatchDate);//结束时间
//                    Long endTime1 = dtext.getTime();
//                    if ((endTime1-starTime) / 24 / 60 / 60 / 1000 != 0) {
                    // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
                    // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
                    // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
@@ -122,166 +147,770 @@
                    // 实例化一个请求对象,每个接口都会对应一个request对象
                    SendSmsRequest req = new SendSmsRequest();
//                    String[] phoneNumberSet1 = {"18701153496"};
                    String[] phoneNumberSet1 = {DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key)};
                    QueryWrapper sms = new QueryWrapper();
                    sms.eq("none", "0");
                    sms.eq("smsreception", "1");
                    List<Manager> managerList = (managerMapper).selectList(sms);
                    for (int s=0;s<managerList.size();s++){
//                    if (phone.split("[,,]").length>1){
//
//                    }
                        QueryWrapper sms = new QueryWrapper();
                        sms.eq("none", "0");
                        sms.eq("smsreception", "1");
                        List<Manager> managerList = (managerMapper).selectList(sms);
                        for (int s = 0; s < managerList.size(); s++) {
//                        System.out.println(managerList.get(s).getPhone());
//                        phoneNumberSet1[s] = managerList.get(s).getPhone();
                        String[] phoneNumberSet12  = {managerList.get(s).getPhone()};
                        System.out.println(phoneNumberSet12);
                        req.setPhoneNumberSet(phoneNumberSet12);
                            String[] phoneNumberSet12 = {managerList.get(s).getPhone()};
                            System.out.println(phoneNumberSet12);
                            req.setPhoneNumberSet(phoneNumberSet12);
                            req.setSmsSdkAppId("1400838975");
                            req.setSignName("北京华星北斗智控");
                            req.setTemplateId("2318088");
//                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
//                        String[] templateParamSet1 = {String.valueOf("您有流量卡将于:" + fuwuqiList.get(i).getEnddate() + "到期,")};
//                        req.setTemplateParamSet(templateParamSet1);
                            // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                            SendSmsResponse resp = client.SendSms(req);
                        }
                    String phone = DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key);
                    for (int j = 0; j < phone.split("[,,]").length; j++) {
                        String[] phoneNumberSet1 = {phone.split("[,,]")[j]};
                        req.setPhoneNumberSet(phoneNumberSet1);
                        req.setSmsSdkAppId("1400838975");
                        req.setSignName("北京华星北斗智控");
                        req.setTemplateId("2100321");
                        req.setTemplateId("2318088");
//                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
                        String[] templateParamSet1 = {String.valueOf("您有流量卡将于:"  + fuwuqiList.get(i).getEnddate()+"到期,")};
                        String[] templateParamSet1 = {String.valueOf("您有服务器将于:" + fuwuqiList.get(i).getEnddate() + "到期,")};
                        req.setTemplateParamSet(templateParamSet1);
                        // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                        SendSmsResponse resp = client.SendSms(req);
                        // 输出json格式的字符串回包
                        Duanxinlog duanxinlog = new Duanxinlog();
                        duanxinlog.setIdentification(fuwuqiList.get(i).getServername());
                        duanxinlog.setReceiver(fuwuqiList.get(i).getCompany());
                        duanxinlog.setNumber(phone.split("[,,]")[j]);
//                    duanxinlog.setNumber(DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key));
                        duanxinlog.setContent("尊敬的用户,您好!您有服务器将于" + fuwuqiList.get(i).getEnddate() + "到期,为避免影响您的正常使用请及时续费,您可登录华星智控公司物联网管理平台查询详情续费,如有疑问可咨询我公司客服人员,祝您生活愉快!");
                        this.duanxinlogService.addDuanxinlog(duanxinlog);
                    }
                    req.setPhoneNumberSet(phoneNumberSet1);
                    req.setSmsSdkAppId("1400838975");
                    req.setSignName("北京华星北斗智控");
                    req.setTemplateId("2100321");
//                }
                } else {
                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Date dtext = formatter.parse(dispatchDate);//结束时间
                    Long endTime1 = dtext.getTime();
                    if ((endTime1 - starTime) / 24 / 60 / 60 / 1000 != 0) {
                        // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
                        // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
                        // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
                        Credential cred = new Credential(SecretId, SecretKey);
                        // 实例化一个http选项,可选的,没有特殊需求可以跳过
                        HttpProfile httpProfile = new HttpProfile();
                        httpProfile.setEndpoint("sms.tencentcloudapi.com");
                        // 实例化一个client选项,可选的,没有特殊需求可以跳过
                        ClientProfile clientProfile = new ClientProfile();
                        clientProfile.setHttpProfile(httpProfile);
                        // 实例化要请求产品的client对象,clientProfile是可选的
                        SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
                        // 实例化一个请求对象,每个接口都会对应一个request对象
                        SendSmsRequest req = new SendSmsRequest();
//                    String[] phoneNumberSet1 = {"18701153496"};
//                        String[] phoneNumberSet1 = {DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key)};
                        QueryWrapper sms = new QueryWrapper();
                        sms.eq("none", "0");
                        sms.eq("smsreception", "1");
                        List<Manager> managerList = (managerMapper).selectList(sms);
                        for (int s = 0; s < managerList.size(); s++) {
//                        System.out.println(managerList.get(s).getPhone());
//                        phoneNumberSet1[s] = managerList.get(s).getPhone();
                            String[] phoneNumberSet12 = {managerList.get(s).getPhone()};
                            System.out.println(phoneNumberSet12);
                            req.setPhoneNumberSet(phoneNumberSet12);
                            req.setSmsSdkAppId("1400838975");
                            req.setSignName("北京华星北斗智控");
                            req.setTemplateId("2318088");
//                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
                    String[] templateParamSet1 = {String.valueOf("您有服务器将于:"  + fuwuqiList.get(i).getEnddate()+"到期,")};
                    req.setTemplateParamSet(templateParamSet1);
                    // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                    SendSmsResponse resp = client.SendSms(req);
                    // 输出json格式的字符串回包
                    Duanxinlog duanxinlog = new Duanxinlog();
                    duanxinlog.setIdentification(fuwuqiList.get(i).getServername());
                    duanxinlog.setReceiver(fuwuqiList.get(i).getCompany());
                    duanxinlog.setNumber(DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key));
                    duanxinlog.setNumber(DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key));
                    duanxinlog.setContent("尊敬的用户,您好!您有服务器将于"+fuwuqiList.get(i).getEnddate()+"到期,为避免影响您的正常使用请及时续费,您可登录华星智控公司物联网管理平台查询详情续费,如有疑问可咨询我公司客服人员,祝您生活愉快!");
                    this.duanxinlogService.addDuanxinlog(duanxinlog);
//                            String[] templateParamSet1 = {String.valueOf("您有流量卡将于:" + fuwuqiList.get(i).getEnddate() + "到期,")};
//                            req.setTemplateParamSet(templateParamSet1);
                            // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                            SendSmsResponse resp = client.SendSms(req);
                        }
                        String phone = DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key);
                        for (int j = 0; j < phone.split("[,,]").length; j++) {
                            String[] phoneNumberSet1 = {phone.split("[,,]")[j]};
                            req.setPhoneNumberSet(phoneNumberSet1);
                            req.setSmsSdkAppId("1400838975");
                            req.setSignName("北京华星北斗智控");
                            req.setTemplateId("2318088");
//                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
//                        String[] templateParamSet1 = {String.valueOf("您有服务器将于:" + fuwuqiList.get(i).getEnddate() + "到期,")};
//                        req.setTemplateParamSet(templateParamSet1);
                            // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                            SendSmsResponse resp = client.SendSms(req);
                            // 输出json格式的字符串回包
                            Duanxinlog duanxinlog = new Duanxinlog();
                            duanxinlog.setIdentification(fuwuqiList.get(i).getServername());
                            duanxinlog.setReceiver(fuwuqiList.get(i).getCompany());
                            duanxinlog.setNumber(phone.split("[,,]")[j]);
//                        duanxinlog.setNumber(DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key));
                            duanxinlog.setContent("尊敬的用户,您好!您有服务器将于" + fuwuqiList.get(i).getEnddate() + "到期,为避免影响您的正常使用请及时续费,您可登录华星智控公司物联网管理平台查询详情续费,如有疑问可咨询我公司客服人员,祝您生活愉快!");
                            this.duanxinlogService.addDuanxinlog(duanxinlog);
                        }
                    }
                }
            }
        }
    }
//
//    /*
//     * 函数名     : sms
//     * 说明      : 查询所有卡号数据
//                    使用当前时间减去结束时间
//                    使用号码查询短信表取出发送日期,如果当前日期大于发送日期
//                        发送短信
//                        发送短信
//
//     * 返回值            : 无
//     * 作者            : 王飞
////     * 日期    : 2024年2月28日
//     */
////    @EnableScheduling
////    @Scheduled(cron = "*/10 * * * * ?")//测试10秒执行一次
////    @Scheduled(cron = "0 48 10 * * ?")
//    @Scheduled(cron = "0 0 */1 * * ?")//一小时执行一次
//    public void sms() throws Exception {
//        System.out.println("短信定时器执行============》》》》》》》》》》》》》》》》");
//        //查询数据库中所有的引擎数据
//        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq("none", "0");
////        queryWrapper.eq("num", "1");
//        List<Card> cardList = (cardMapper).selectList(queryWrapper);
//        for (int i = 0; i < cardList.size(); i++) {
//            QueryWrapper queryWrapper3 = new QueryWrapper();
//            queryWrapper3.eq("none", "0");
//            queryWrapper3.eq("companyName", cardList.get(i).getCompany());
//            Company companyList = new Company();
//            companyList = (companyMapper).selectOne(queryWrapper3);
//            if (companyList == null) {
//                QueryWrapper queryWrapper4 = new QueryWrapper();
//                queryWrapper4.eq("none", "0");
//                queryWrapper4.eq("companyabbname", cardList.get(i).getCompany());
//                companyList = (companyMapper).selectOne(queryWrapper4);
//            }
////            System.out.println("333333");
//            SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd");
//            Date date = new Date();
//            Date endDay = date2.parse(cardList.get(i).getEnddate());//结束时间
//            Long starTime = date.getTime();
//            Long endTime = endDay.getTime();
//            Long num11 = endTime - starTime;//时间戳
////            System.out.println("22222222");
////            System.out.println(+num11 / 24 / 60 / 60 / 1000);
//            if (+num11 / 24 / 60 / 60 / 1000 == 19 | +num11 / 24 / 60 / 60 / 1000 == 9 | +num11 / 24 / 60 / 60 / 1000 == 4 | +num11 / 24 / 60 / 60 / 1000 == 0) {
//                System.out.println("1111111111111111111");
//                String dispatchDate = this.duanxinlogService.userdate(cardList.get(i).getCardnumber());
//                if (dispatchDate==null){
////                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
////                    Date dtext = formatter.parse(dispatchDate);//结束时间
////                    Long endTime1 = dtext.getTime();
////                    if ((endTime1-starTime) / 24 / 60 / 60 / 1000 != 0) {
//                        String randomNumber = new String();
//                        // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
//                        // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
//                        // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
//                        Credential cred = new Credential(SecretId, SecretKey);
//                        // 实例化一个http选项,可选的,没有特殊需求可以跳过
//                        HttpProfile httpProfile = new HttpProfile();
//                        httpProfile.setEndpoint("sms.tencentcloudapi.com");
//                        // 实例化一个client选项,可选的,没有特殊需求可以跳过
//                        ClientProfile clientProfile = new ClientProfile();
//                        clientProfile.setHttpProfile(httpProfile);
//                        // 实例化要请求产品的client对象,clientProfile是可选的
//                        SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
//                        // 实例化一个请求对象,每个接口都会对应一个request对象
//                        SendSmsRequest req = new SendSmsRequest();
////                        String[] phoneNumberSet1 = {cardList.get(i).getCardnumber()};
//                        String[] phoneNumberSet1 = {DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key)};
////                    String[] phoneNumberSet1 = {"18701153496"};
//                        QueryWrapper sms = new QueryWrapper();
//                        sms.eq("none", "0");
//                        sms.eq("smsreception", "1");
//                        List<Manager> managerList = (managerMapper).selectList(sms);
//                        String string = new String();
//                        for (int s=0;s<managerList.size();s++){
//
//                            if (s!=0){
//                                string+=",";
//                            }
//                            string += managerList.get(s).getPhone();
//                            String[] phoneNumberSet12  = {managerList.get(s).getPhone()};
//                            System.out.println(phoneNumberSet12);
//                            req.setPhoneNumberSet(phoneNumberSet12);
//
//                            req.setSmsSdkAppId("1400838975");
//                            req.setSignName("北京华星北斗智控");
//                            req.setTemplateId("2100321");
//
////                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
//                            String[] templateParamSet1 = {String.valueOf("您有流量卡将于:"  + cardList.get(i).getEnddate()+"到期,")};
//                            req.setTemplateParamSet(templateParamSet1);
//                            // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
//                            SendSmsResponse resp = client.SendSms(req);
//                        }
////                    phoneNumberSet1[managerList.size()] = DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key);
////                    System.out.println(phoneNumberSet1);
//                        req.setPhoneNumberSet(phoneNumberSet1);
//
//                        req.setSmsSdkAppId("1400838975");
//                        req.setSignName("北京华星北斗智控");
//                        req.setTemplateId("2100321");
//
////                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
//                        String[] templateParamSet1 = {String.valueOf("您有流量卡将于:"  + cardList.get(i).getEnddate()+"到期,")};
//                        req.setTemplateParamSet(templateParamSet1);
//                        // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
//                        SendSmsResponse resp = client.SendSms(req);
//                        System.out.println(SendSmsResponse.toJsonString(resp));
//                        // 输出json格式的字符串回包
//                        Duanxinlog duanxinlog = new Duanxinlog();
//                        duanxinlog.setIdentification(cardList.get(i).getCardnumber());
//                        duanxinlog.setReceiver(cardList.get(i).getCompany());
//                        duanxinlog.setNumber(string);
//                        duanxinlog.setContent("尊敬的用户,您好!您有流量卡将于"+cardList.get(i).getEnddate()+"到期,为避免影响您的正常使用请及时续费,您可登录华星智控公司物联网管理平台查询详情续费,如有疑问可咨询我公司客服人员,祝您生活愉快!"
//                        );
//                        this.duanxinlogService.addDuanxinlog(duanxinlog);
////                    }
//                }else{
//                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//                    Date dtext = formatter.parse(dispatchDate);//结束时间
//                    Long endTime1 = dtext.getTime();
////                    System.out.println(dtext);
////                    System.out.println(dispatchDate);
////                    System.out.println(starTime);
////                    System.out.println(endTime1);
////                    System.out.println((starTime-endTime1) / 24);
////                    System.out.println((starTime-endTime1) / 24 / 60 / 60 / 1000);
////                    System.out.println((starTime-endTime1) / 24 / 60 / 60 / 1000 > 0);
//                    if ((starTime-endTime1) / 24 / 60 / 60 / 1000  != 0) {
//                        String randomNumber = new String();
//                        // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
//                        // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
//                        // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
//                        Credential cred = new Credential(SecretId, SecretKey);
//                        // 实例化一个http选项,可选的,没有特殊需求可以跳过
//                        HttpProfile httpProfile = new HttpProfile();
//                        httpProfile.setEndpoint("sms.tencentcloudapi.com");
//                        // 实例化一个client选项,可选的,没有特殊需求可以跳过
//                        ClientProfile clientProfile = new ClientProfile();
//                        clientProfile.setHttpProfile(httpProfile);
//                        // 实例化要请求产品的client对象,clientProfile是可选的
//                        SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
//                        // 实例化一个请求对象,每个接口都会对应一个request对象
//                        SendSmsRequest req = new SendSmsRequest();
////                        String[] phoneNumberSet1 = {cardList.get(i).getCardnumber()};
//                        String[] phoneNumberSet1 = {DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key)};
////                    String[] phoneNumberSet1 = {"18701153496"};
//                        QueryWrapper sms = new QueryWrapper();
//                        sms.eq("none", "0");
//                        sms.eq("smsreception", "1");
//                        List<Manager> managerList = (managerMapper).selectList(sms);
//                        String string = new String();
//                        for (int s=0;s<managerList.size();s++){
//
//                            if (s!=0){
//                                string+=",";
//                            }
//                            string += managerList.get(s).getPhone();
//                            String[] phoneNumberSet12  = {managerList.get(s).getPhone()};
//                            System.out.println(phoneNumberSet12);
//                            req.setPhoneNumberSet(phoneNumberSet12);
//
//                            req.setSmsSdkAppId("1400838975");
//                            req.setSignName("北京华星北斗智控");
//                            req.setTemplateId("2100321");
//
////                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
//                            String[] templateParamSet1 = {String.valueOf("您有流量卡将于:"  + cardList.get(i).getEnddate()+"到期,")};
//                            req.setTemplateParamSet(templateParamSet1);
//                            // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
//                            SendSmsResponse resp = client.SendSms(req);
//                        }
////                    phoneNumberSet1[managerList.size()] = DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key);
////                    System.out.println(phoneNumberSet1);
//                        req.setPhoneNumberSet(phoneNumberSet1);
//
//                        req.setSmsSdkAppId("1400838975");
//                        req.setSignName("北京华星北斗智控");
//                        req.setTemplateId("2100321");
//
////                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
//                        String[] templateParamSet1 = {String.valueOf("您有流量卡将于:"  + cardList.get(i).getEnddate()+"到期,")};
//                        req.setTemplateParamSet(templateParamSet1);
//                        // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
//                        SendSmsResponse resp = client.SendSms(req);
//                        System.out.println(SendSmsResponse.toJsonString(resp));
//                        // 输出json格式的字符串回包
//                        Duanxinlog duanxinlog = new Duanxinlog();
//                        duanxinlog.setIdentification(cardList.get(i).getCardnumber());
//                        duanxinlog.setReceiver(cardList.get(i).getCompany());
//                        duanxinlog.setNumber(string);
//                        duanxinlog.setContent("尊敬的用户,您好!您有流量卡将于"+cardList.get(i).getEnddate()+"到期,为避免影响您的正常使用请及时续费,您可登录华星智控公司物联网管理平台查询详情续费,如有疑问可咨询我公司客服人员,祝您生活愉快!"
//                        );
//                        this.duanxinlogService.addDuanxinlog(duanxinlog);
//                    }
//                }
////                    String dispatchDate = this.duanxinlogService.userdate(cardList.get(i).getCardnumber());
//
//            }
//
//        }
//    }
    /*
     * 函数名     : sms
     * 说明      : 查询所有卡号数据
                    使用当前时间减去结束时间
                    使用号码查询短信表取出发送日期,如果当前日期大于发送日期
                        发送短信
                        发送短信
    * 函数名     : sms
    * 说明      : 查询所有卡号数据
                   使用当前时间减去结束时间
                   使用号码查询短信表取出发送日期,如果当前日期大于发送日期
                       发送短信
                       发送短信
     * 返回值            : 无
     * 作者            : 王飞
    * 返回值            : 无
    * 作者            : 王飞
//     * 日期    : 2024年2月28日
     */
    */
//    @EnableScheduling
//    @Scheduled(cron = "*/10 * * * * ?")//测试10秒执行一次
//    @Scheduled(cron = "0 49 10 * * ?")
    @Scheduled(cron = "0 0 */1 * * ?")//一小时执行一次
//    @Scheduled(cron = "0 54 15 * * ?")
    @Scheduled(cron = "0 0/10 8-22 * * ?")//8点到10点每10分钟执行一次
    public void sms() throws Exception {
        System.out.println("短信定时器执行============》》》》》》》》》》》》》》》》");
        //查询数据库中所有的引擎数据
        //查询数据库中所有的公司数据
        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq("num", "1");
        queryWrapper.eq("none", "0");
//        queryWrapper.eq("num", "8");
        List<Card> cardList = (cardMapper).selectList(queryWrapper);
        for (int i = 0; i < cardList.size(); i++) {
            QueryWrapper queryWrapper3 = new QueryWrapper();
            queryWrapper3.eq("none", "0");
            queryWrapper3.eq("companyName", cardList.get(i).getCompany());
            Company companyList = new Company();
            companyList = (companyMapper).selectOne(queryWrapper3);
            if (companyList == null) {
                QueryWrapper queryWrapper4 = new QueryWrapper();
                queryWrapper4.eq("none", "0");
                queryWrapper4.eq("companyabbname", cardList.get(i).getCompany());
                companyList = (companyMapper).selectOne(queryWrapper4);
            }
            SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = new Date();
            Date endDay = date2.parse(cardList.get(i).getEnddate());//结束时间
            Long starTime = date.getTime();
            Long endTime = endDay.getTime();
            Long num11 = endTime - starTime;//时间戳
            if (+num11 / 24 / 60 / 60 / 1000 == 19 | +num11 / 24 / 60 / 60 / 1000 == 9 | +num11 / 24 / 60 / 60 / 1000 == 4 | +num11 / 24 / 60 / 60 / 1000 == 0) {
                String dispatchDate = this.duanxinlogService.userdate(cardList.get(i).getCardnumber());
//                    String dispatchDate = this.duanxinlogService.userdate(cardList.get(i).getCardnumber());
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String dtext = formatter.format(date);
                if (dispatchDate == null || !dtext.equals(dispatchDate)) {
                    String randomNumber = new String();
                    // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
                    // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
                    // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
                    Credential cred = new Credential(SecretId, SecretKey);
                    // 实例化一个http选项,可选的,没有特殊需求可以跳过
                    HttpProfile httpProfile = new HttpProfile();
                    httpProfile.setEndpoint("sms.tencentcloudapi.com");
                    // 实例化一个client选项,可选的,没有特殊需求可以跳过
                    ClientProfile clientProfile = new ClientProfile();
                    clientProfile.setHttpProfile(httpProfile);
                    // 实例化要请求产品的client对象,clientProfile是可选的
                    SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
                    // 实例化一个请求对象,每个接口都会对应一个request对象
                    SendSmsRequest req = new SendSmsRequest();
        List<Company> companyList = (companyMapper).selectList(queryWrapper);
        //获取当前年月日时间
        SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String s = date2.format(date);
        for (int i = 0; i < companyList.size(); i++) {
            //判断条件是否发送短信和发送短信日期
            if (!Objects.equals(companyList.get(i).getSenddate(), s)) {
                //根据公司名称查询卡号
                List<Card> cardList = this.cardMapper.findAllcompanycard(companyList.get(i).getCompanyname(), companyList.get(i).getCompanyabbname());
                for (int j = 0; j < cardList.size(); j++) {
                        if (cardList.get(j).getEnddate()!=null){
                            Date endDay = date2.parse(cardList.get(j).getEnddate());//结束时间
                            Long starTime = date.getTime();
                            Long endTime = endDay.getTime();
                            Long num11 = endTime - starTime;//时间戳
                            if ((+num11 / 24 / 60 / 60 / 1000 == 19) || (+num11 / 24 / 60 / 60 / 1000 == 14) || (+num11 / 24 / 60 / 60 / 1000 == 9) || (+num11 / 24 / 60 / 60 / 1000 == 4) || (+num11 / 24 / 60 / 60 / 1000 == 0)) {
                                //发送短信
                                // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
                                // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
                                // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
                                Credential cred = new Credential(SecretId, SecretKey);
                                // 实例化一个http选项,可选的,没有特殊需求可以跳过
                                HttpProfile httpProfile = new HttpProfile();
                                httpProfile.setEndpoint("sms.tencentcloudapi.com");
                                // 实例化一个client选项,可选的,没有特殊需求可以跳过
                                ClientProfile clientProfile = new ClientProfile();
                                clientProfile.setHttpProfile(httpProfile);
                                // 实例化要请求产品的client对象,clientProfile是可选的
                                SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
                                // 实例化一个请求对象,每个接口都会对应一个request对象
                                SendSmsRequest req = new SendSmsRequest();
//                        String[] phoneNumberSet1 = {cardList.get(i).getCardnumber()};
                    String[] phoneNumberSet1 = {DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key)};
//                    String[] phoneNumberSet1 = {"18701153496"};
                    QueryWrapper sms = new QueryWrapper();
                    sms.eq("none", "0");
                    sms.eq("smsreception", "1");
                    List<Manager> managerList = (managerMapper).selectList(sms);
                    for (int s=0;s<managerList.size();s++){
//                        System.out.println(managerList.get(s).getPhone());
//                        phoneNumberSet1[s] = managerList.get(s).getPhone();
                        String[] phoneNumberSet12  = {managerList.get(s).getPhone()};
                        System.out.println(phoneNumberSet12);
                        req.setPhoneNumberSet(phoneNumberSet12);
//                                String[] phoneNumberSet1 = {DESUtil.decrypt(companyList.get(i).getLoginphone(), DESUtil.key)};
//                    String[] phoneNumberSet1 = {"18582279726"};
                                //查询有接收短信权限的管理员给他们发送短信通知
                                QueryWrapper sms = new QueryWrapper();
                                sms.eq("none", "0");
                                sms.eq("smsreception", "1");
                                List<Manager> managerList = (managerMapper).selectList(sms);
                                String string = new String();
                                System.out.println(cardList.get(j));
                                for (int s1 = 0; s1 < managerList.size(); s1++) {
                        req.setSmsSdkAppId("1400838975");
                        req.setSignName("北京华星北斗智控");
                        req.setTemplateId("2100321");
                                    if (s1 != 0) {
                                        string += ",";
                                    }
                                    string += managerList.get(s1).getPhone();
                                    String[] phoneNumberSet12 = {managerList.get(s1).getPhone()};
                                    System.out.println(phoneNumberSet12);
                                    req.setPhoneNumberSet(phoneNumberSet12);
                                    req.setSmsSdkAppId("1400838975");
                                    req.setSignName("北京华星北斗智控");
                                    req.setTemplateId("2089627");
                                    String[] templateParamSet1 = {String.valueOf("有使用的物联网卡还有"+(+num11 / 24 / 60 / 60 / 1000+1)),String.valueOf(cardList.get(j).getEnddate())};
                                    req.setTemplateParamSet(templateParamSet1);
                                    // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                                    SendSmsResponse resp = client.SendSms(req);
                                }
                                String phone = DESUtil.decrypt(companyList.get(i).getLoginphone(), DESUtil.key);
                                for (int p = 0; p < phone.split("[,,]").length; p++) {
                                    String[] phoneNumberSet1 = {phone.split("[,,]")[p]};
                                    System.out.println(phoneNumberSet1);
                                    req.setPhoneNumberSet(phoneNumberSet1);
//                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
                        String[] templateParamSet1 = {String.valueOf("您有流量卡将于:"  + cardList.get(i).getEnddate()+"到期,")};
                        req.setTemplateParamSet(templateParamSet1);
                        // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                        SendSmsResponse resp = client.SendSms(req);
                    }
//                    phoneNumberSet1[managerList.size()] = DESUtil.decrypt(companyList.getLoginphone(), DESUtil.key);
//                    System.out.println(phoneNumberSet1);
                    req.setPhoneNumberSet(phoneNumberSet1);
                                    req.setSmsSdkAppId("1400838975");
                                    req.setSignName("北京华星北斗智控");
                                    req.setTemplateId("2089627");
                                    String[] templateParamSet1 = {String.valueOf("有使用的物联网卡还有" + (+num11 / 24 / 60 / 60 / 1000 + 1)), String.valueOf(cardList.get(j).getEnddate())};
                                    req.setTemplateParamSet(templateParamSet1);
//                            String[] templateParamSet1 = {String.valueOf("您有流量卡将于:" + cardList.get(i).getEnddate() + "到期,")};
//                            req.setTemplateParamSet(templateParamSet1);
                                    // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                                    SendSmsResponse resp = client.SendSms(req);
                                    System.out.println(SendSmsResponse.toJsonString(resp));
                                    companyList.get(i).setSenddate(s);
                                    //发送短信后修改公司发送短信字段和日期字段
                                    QueryWrapper queryWrapper2 = new QueryWrapper();
                                    queryWrapper2.eq("companyId", companyList.get(i).getCompanyid());
                                    companyMapper.update(companyList.get(i), queryWrapper2);
                                    // 输出json格式的字符串回包
                                    Duanxinlog duanxinlog = new Duanxinlog();
                                    duanxinlog.setIdentification(cardList.get(j).getCardnumber());
                                    duanxinlog.setReceiver(cardList.get(j).getCompany());
                                    duanxinlog.setNumber(phone.split("[,,]")[p]);
                                    duanxinlog.setContent("您有使用的物联网卡还有" + (+num11 / 24 / 60 / 60 / 1000 + 1) + "天即将到期,请在" + cardList.get(j).getEnddate() + "之前续费,如已续费忽略该提示信息,拒收请回复R"
                                    );
                                    this.duanxinlogService.addDuanxinlog(duanxinlog);
                                    break;
                                }
                                break;
                            }
//                        }
                            //判断结束日期距当前日期还有多久
                    req.setSmsSdkAppId("1400838975");
                    req.setSignName("北京华星北斗智控");
                    req.setTemplateId("2100321");
                        }
//                    String[] templateParamSet1 = {String.valueOf(+num11 / 24 / 60 / 60 / 1000)};
                    String[] templateParamSet1 = {String.valueOf("您有流量卡将于:"  + cardList.get(i).getEnddate()+"到期,")};
                    req.setTemplateParamSet(templateParamSet1);
                    // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
                    SendSmsResponse resp = client.SendSms(req);
                    System.out.println(SendSmsResponse.toJsonString(resp));
                    // 输出json格式的字符串回包
                    Duanxinlog duanxinlog = new Duanxinlog();
                    duanxinlog.setIdentification(cardList.get(i).getCardnumber());
                    duanxinlog.setReceiver(cardList.get(i).getCompany());
                    duanxinlog.setNumber(phoneNumberSet1[0]);
                    duanxinlog.setContent("尊敬的用户,您好!您有流量卡将于"+cardList.get(i).getEnddate()+"到期,为避免影响您的正常使用请及时续费,您可登录华星智控公司物联网管理平台查询详情续费,如有疑问可咨询我公司客服人员,祝您生活愉快!"
                    );
                    this.duanxinlogService.addDuanxinlog(duanxinlog);
                }
            }
        }
    }
//    @PostMapping({"sendudp"})
//    public Boolean sendudp(String message,String phone) {
////        String phone = "";
//        // 假设物联网卡平台的短信接口地址
//        String apiUrl = "https://api.spruceiot.cn/api/v1/sms/send";
//        // 假设平台的API密钥
//        String apiKey = "your_api_key_here";
//        // 假设平台的短信模板ID(如果需要)
//        String templateId = "your_template_id_here";
//        String accessKey = "448c2cedcdce41428a290d144e81ab6e";
//        String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
//        String accessSecret = "RgoIWycMYGmQfrLwLuT2VWawAhwMO8w7P9zh2dZp";
//        // 构造请求参数
//        Map<String, String> params = new HashMap<>();
//        params.put("apiKey", apiKey);
//        params.put("to", phone);
//        params.put("message", message);
//        params.put("templateId", templateId);
//
//        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
//            HttpPost httpPost = new HttpPost(apiUrl);
//            httpPost.setHeader("Content-Type", "application/json");
//            httpPost.setEntity(new StringEntity(new ObjectMapper().writeValueAsString(params)));
//
//            HttpResponse response = httpClient.execute(httpPost);
//            HttpEntity responseEntity = response.getEntity();
//
//            if (response.getStatusLine().getStatusCode() == 200) {
//                // 发送成功
//                return true;
//            } else {
//                // 发送失败
//                System.out.println("Failed to send SMS: " + EntityUtils.toString(responseEntity));
//                return false;
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            return false;
//        }
//    }
    @PostMapping({"sendudp"})
    public JSONObject sendudp(String conext,String phone) throws Exception {
        String accessKey = "448c2cedcdce41428a290d144e81ab6e";
        String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String accessSecret = "RgoIWycMYGmQfrLwLuT2VWawAhwMO8w7P9zh2dZp";
        String nonce = "";
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String Timestamp = dateFormat.format(now);
        int length = 30;
        Random random = new Random();
        for (int i = length; i > 0; --i) {
            int index = random.nextInt(str.length());
            nonce = nonce + str.charAt(index);
        }
        String stringSignTemp = accessKey + nonce + Timestamp;
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(accessSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
        sha256Hmac.init(secretKeySpec);
        byte[] hmacBytes = sha256Hmac.doFinal(stringSignTemp.getBytes(StandardCharsets.UTF_8));
        String sign = Base64.getEncoder().encodeToString(hmacBytes);
        String targetUrl = "https://api.spruceiot.cn/api/v1/sms/send";
        URL url = new URL(targetUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setRequestProperty("Accept-Charset", "UTF-8");
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        connection.setRequestProperty("Access-Control-Allow-Origin", "http://localhost:8080");
        connection.setRequestProperty("AccessKey", accessKey);
        connection.setRequestProperty("Nonce", nonce);
        connection.setRequestProperty("Timestamp", Timestamp);
        connection.setRequestProperty("Sign", sign);
        // 构造请求体
        JSONObject requestBody = new JSONObject();
        requestBody.put("msisdn",phone );
        requestBody.put("content", conext);
        // 将请求体写入输出流
        OutputStream os = connection.getOutputStream();
        os.write(requestBody.toString().getBytes("UTF-8"));
        os.flush();
        os.close();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        StringBuilder response1 = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            response1.append(line);
        }
        reader.close();
        connection.disconnect();
        JSONObject jsonObject = new JSONObject(response1);
        int code = jsonObject.getInt("code");
        String message = jsonObject.getStr("message");
        JSONObject result = jsonObject.getJSONObject("result");
//        int total1 = result.getInt("total");
//        JSONArray list = result.getJSONArray("list");
//        for (int i = 0; i < list.size(); ++i) {
//            JSONObject item = list.getJSONObject(i);
//            String msisdn = item.getStr("msisdn");
//            String iccid = item.getStr("iccid");
//            String imsi = item.getStr("imsi");
//            System.out.println("msisdn: " + msisdn + ", iccid: " + iccid + ", imsi: " + imsi);
//        }
//        if (code!=0){
//            return message;
//        }else{
        if (code!=0){
        }else{
            result.set("eStatus", this.getendlog());
        }
            return jsonObject;
//        }
    }
    public String getendlog( ) throws Exception {
        String accessKey = "448c2cedcdce41428a290d144e81ab6e";
        String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String accessSecret = "RgoIWycMYGmQfrLwLuT2VWawAhwMO8w7P9zh2dZp";
        String nonce = "";
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String Timestamp = dateFormat.format(now);
        int length = 30;
        Random random = new Random();
        for (int i = length; i > 0; --i) {
            int index = random.nextInt(str.length());
            nonce = nonce + str.charAt(index);
        }
        String stringSignTemp = accessKey + nonce + Timestamp;
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(accessSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
        sha256Hmac.init(secretKeySpec);
        byte[] hmacBytes = sha256Hmac.doFinal(stringSignTemp.getBytes(StandardCharsets.UTF_8));
        String sign = Base64.getEncoder().encodeToString(hmacBytes);
        String targetUrl = "https://api.spruceiot.cn/api/v1/sms/log/query?pageIndex=1&pageSize=1";
        URL url = new URL(targetUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Accept-Charset", "UTF-8");
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        connection.setRequestProperty("Access-Control-Allow-Origin", "http://localhost:8080");
        connection.setRequestProperty("AccessKey", accessKey);
        connection.setRequestProperty("Nonce", nonce);
        connection.setRequestProperty("Timestamp", Timestamp);
        connection.setRequestProperty("Sign", sign);
        connection.connect();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        StringBuilder response1 = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            response1.append(line);
        }
        reader.close();
        connection.disconnect();
        JSONObject jsonObject = new JSONObject(response1);
        int code = jsonObject.getInt("code");
        String message = jsonObject.getStr("message");
        JSONObject result = jsonObject.getJSONObject("result");
        JSONArray list = result.getJSONArray("list");
//        if (code!=0){
//            return "";
//        }else{
//            return result.get("status").toString();
//        }
//        for (int i = 0; i < list.size(); ++i) {
            JSONObject item = list.getJSONObject(0);
//            String msisdn = item.getStr("msisdn");
//            String iccid = item.getStr("iccid");
//            String imsi = item.getStr("imsi");
//            System.out.println("msisdn: " + msisdn + ", iccid: " + iccid + ", imsi: " + imsi);
//        }
        if (item.get("status")=="3"){
            return item.get("message").toString();
        }else{
            return item.get("status").toString();
        }
    }
    @PostMapping({"send"})
    public ModelAndView send(String phone,Integer id,String vname,String enddate) throws Exception {
        SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String s = date2.format(date);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("none", "0");
        queryWrapper.eq("num", id);
        Card cardList = (cardMapper).selectOne(queryWrapper);
        Date endDay = date2.parse(enddate);//结束时间
        Long starTime = date.getTime();
        Long endTime = endDay.getTime();
        Long num11 = endTime - starTime;//时间戳
        //判断结束日期距当前日期还有多久
        Credential cred = new Credential(this.SecretId, this.SecretKey);
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint("sms.tencentcloudapi.com");
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
        SendSmsRequest req = new SendSmsRequest();
        String[] phoneNumberSet1 = new String[]{phone};
        req.setPhoneNumberSet(phoneNumberSet1);
        req.setSmsSdkAppId("1400838975");
        req.setSignName("北京华星北斗智控");
        req.setTemplateId("2089627");
        String[] templateParamSet1 = {String.valueOf("有使用的物联网卡还有"+num11 / 24 / 60 / 60 / 1000),String.valueOf(enddate)};
        req.setTemplateParamSet(templateParamSet1);
        // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
        SendSmsResponse resp = client.SendSms(req);
        System.out.println(SendSmsResponse.toJsonString(resp));
        Company companyList = this.companyMapper.findAllcompanycompany(cardList.getCompany());
        companyList.setSenddate(s);
        //发送短信后修改公司发送短信字段和日期字段
        QueryWrapper queryWrapper2 = new QueryWrapper();
        queryWrapper2.eq("companyId", companyList.getCompanyid());
        companyMapper.update(companyList, queryWrapper2);
        // 输出json格式的字符串回包
        Duanxinlog duanxinlog = new Duanxinlog();
        duanxinlog.setIdentification(cardList.getCardnumber());
        duanxinlog.setReceiver(cardList.getCompany());
        duanxinlog.setNumber(phone);
        duanxinlog.setContent("您有使用的物联网卡还有"+num11 / 24 / 60 / 60 / 1000+"天即将到期,请在" + cardList.getEnddate() + "之前续费,如已续费忽略该提示信息,拒收请回复R"
        );
        this.duanxinlogService.addDuanxinlog(duanxinlog);
        ModelAndView modelAndView = new ModelAndView();
        if (Objects.equals(vname, "index")){
            modelAndView.setViewName("/page/index1.jsp");
        }else{
            modelAndView.setViewName("/page/XinXi.jsp");
        }
        return modelAndView;
    }
    @PostMapping({"sendfuwu"})
    public ModelAndView sendfuwu(String phone,Integer id,String vname) throws Exception {
        SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String s = date2.format(date);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("none", "0");
        queryWrapper.eq("id", id);
        TbFuwuqi fuwuqiList = (tbFuwuqiMapper).selectOne(queryWrapper);
        Credential cred = new Credential(this.SecretId, this.SecretKey);
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint("sms.tencentcloudapi.com");
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
        SendSmsRequest req = new SendSmsRequest();
        String[] phoneNumberSet1 = new String[]{phone};
        req.setPhoneNumberSet(phoneNumberSet1);
        req.setSmsSdkAppId("1400838975");
        req.setSignName("北京华星北斗智控");
        req.setTemplateId("2100321");
        String[] templateParamSet1 = {String.valueOf("您有服务器将于:" + fuwuqiList.getEnddate() + "到期,")};
        req.setTemplateParamSet(templateParamSet1);
        // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
        SendSmsResponse resp = client.SendSms(req);
        System.out.println(SendSmsResponse.toJsonString(resp));
        Company companyList = this.companyMapper.findAllcompanycompany(fuwuqiList.getCompany());
        companyList.setSenddate(s);
        //发送短信后修改公司发送短信字段和日期字段
        QueryWrapper queryWrapper2 = new QueryWrapper();
        queryWrapper2.eq("companyId", companyList.getCompanyid());
        companyMapper.update(companyList, queryWrapper2);
        // 输出json格式的字符串回包
        Duanxinlog duanxinlog = new Duanxinlog();
        duanxinlog.setIdentification(fuwuqiList.getServername());
        duanxinlog.setReceiver(fuwuqiList.getCompany());
        duanxinlog.setNumber(phone);
        duanxinlog.setContent("尊敬的用户,您好!您有服务器将于" + fuwuqiList.getEnddate() + "到期,为避免影响您的正常使用请及时续费,您可登录华星智控公司物联网管理平台查询详情续费,如有疑问可咨询我公司客服人员,祝您生活愉快!"
        );
        this.duanxinlogService.addDuanxinlog(duanxinlog);
        ModelAndView modelAndView = new ModelAndView();
        if (Objects.equals(vname, "index")){
            modelAndView.setViewName("/page/Fuwuqi.jsp");
        }else{
            modelAndView.setViewName("/page/XinXi.jsp");
        }
        return modelAndView;
    }
}