lige
2023-11-20 487c4921b481da06d485182aaaa94297c70f149a
通知
2个文件已修改
3个文件已添加
576 ■■■■■ 已修改文件
ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReservationController.java 102 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-admin/src/main/java/com/ltkj/web/controller/mall/WxMallOrderController.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-admin/src/main/java/com/ltkj/web/wxUtils/HttpClientUtils.java 289 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-admin/src/main/java/com/ltkj/web/wxUtils/WxUtil.java 89 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-admin/src/test/java/lgTest.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReservationController.java
@@ -1,6 +1,7 @@
package com.ltkj.web.controller.app;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.base.Joiner;
@@ -15,6 +16,7 @@
import com.ltkj.mall.service.IMallTimeConfigService;
import com.ltkj.system.service.ISysConfigService;
import com.ltkj.web.config.redis.OrderDelayService;
import com.ltkj.web.wxUtils.WxUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -24,10 +26,7 @@
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.*;
/**
 * @Author: 西安路泰科技有限公司
@@ -153,6 +152,47 @@
                config.setNowNum(config.getNowNum()-1);
                mallTimeConfigService.updateById(config);
            }
            //发订单信息给wx订阅服务消息————————————————start————————————————————————————————————————
            Map<String, Object> res = new HashMap<>();
            res.put("touser",wxuser.getOpenid());
            res.put("template_id","M4K_BNVG7g4hOAcrIDO18ux8KOTneHeNide5GdPW3kc");
            res.put("page","pages/mine/index");
            res.put("miniprogram_state","trial");
            //订阅消息参数值
            JSONObject data = new JSONObject();
            JSONObject name1 = new JSONObject();
            name1.put("value",tjReservation.getName());
            data.put("thing1", name1);
            JSONObject amount3 = new JSONObject();
            amount3.put("value", "体检中心");
            data.put("thing2", amount3);
            JSONObject time4 = new JSONObject();
            String dateFormat = DateUtil.format(tjReservation.getReservationTime(), "yyyy-MM-dd");
            time4.put("value", dateFormat);
            data.put("time4", time4);
            final TjPackage byId = packageService.getById(tjReservation.getPacId());
            if (byId!=null){
                JSONObject thing5 = new JSONObject();
                thing5.put("value",byId.getPacName());
                data.put("thing5", thing5);
            }else {
                JSONObject thing5 = new JSONObject();
                thing5.put("value","未知");
                data.put("thing5", thing5);
            }
            JSONObject thing6 = new JSONObject();
            thing6.put("value", "体检前一天请您进清淡饮食,勿饮酒!");
            data.put("thing6", thing6);
            WxUtil.sendCommonSubscribeMessage(res,data);
            //发订单信息给wx订阅服务消息————————————————end————————————————————————————————————————
            return AjaxResult.success("预约成功!!!",tjReservation.getId());
        }
        return AjaxResult.error("预约失败");
@@ -162,10 +202,15 @@
    @ApiOperation(value = "撤销个人预约")
    @Transactional
    public AjaxResult cusDeletedReservation(@RequestBody TjReservation reservation) {
        LambdaQueryWrapper<TjReservation> wq = new LambdaQueryWrapper<>();
        wq.eq(TjReservation::getIdCard, reservation.getIdCard());
        wq.eq(TjReservation::getIsExpire, 2);
        TjReservation one = reservationService.getOne(wq);
        Wxuser wxuser = UserHoder.getWxuser();
//        LambdaQueryWrapper<TjReservation> wq = new LambdaQueryWrapper<>();
//        wq.eq(TjReservation::getIdCard, reservation.getIdCard());
//        wq.eq(TjReservation::getIsExpire, 2);
//        TjReservation one = reservationService.getOne(wq);
        if (reservation.getId()==null){
            return AjaxResult.success("出错了,请联系工作人员!");
        }
        TjReservation one = reservationService.getById(reservation.getId());
        if (null != one) {
            String isPays = configService.selectConfigByKey("isPay");
            if(null !=isPays  && isPays.equals("true") ){
@@ -181,7 +226,46 @@
            transitionService.deletedTbTransitionByCusId(reservation.getIdCard());
            reservationService.removeById(one);
            return AjaxResult.success();
            //发订单信息给wx订阅服务消息————————————————start————————————————————————————————————————
            Map<String, Object> res = new HashMap<>();
            res.put("touser",wxuser.getOpenid());
            res.put("template_id","X467Xtd8HnFDNk-IoT0ChcdoBnClLZJQQwP7DMztYQ8");
            res.put("page","pages/mine/index");
            res.put("miniprogram_state","trial");
            //订阅消息参数值
            JSONObject data = new JSONObject();
            JSONObject amount3 = new JSONObject();
            amount3.put("value", "体检中心");
            data.put("thing3", amount3);
            JSONObject name1 = new JSONObject();
            name1.put("value",reservation.getName());
            data.put("name1", name1);
            final TjPackage byId = packageService.getById(reservation.getPacId());
            if (byId!=null){
                JSONObject thing5 = new JSONObject();
                thing5.put("value",byId.getPacName());
                data.put("thing4", thing5);
            }else {
                JSONObject thing5 = new JSONObject();
                thing5.put("value","未知");
                data.put("thing4", thing5);
            }
            JSONObject time4 = new JSONObject();
            String dateFormat = DateUtil.format(reservation.getReservationTime(), "yyyy-MM-dd");
            time4.put("value", dateFormat);
            data.put("date2", time4);
            JSONObject thing6 = new JSONObject();
            thing6.put("value", "您已成功取消本次预约,欢迎再次使用!");
            data.put("thing5", thing6);
            WxUtil.sendCommonSubscribeMessage(res,data);
            //发订单信息给wx订阅服务消息————————————————end————————————————————————————————————————
            return AjaxResult.success("取消成功");
        }
        return AjaxResult.success("暂无预约信息");
    }
ltkj-admin/src/main/java/com/ltkj/web/controller/mall/WxMallOrderController.java
@@ -2,6 +2,8 @@
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
@@ -29,6 +31,7 @@
import com.ltkj.mall.mallOrderUtils.OrderUtil;
import com.ltkj.system.service.ISysConfigService;
import com.ltkj.web.config.redis.OrderDelayService;
import com.ltkj.web.wxUtils.WxUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@@ -465,6 +468,53 @@
//        final MallTimeConfig one = mallTimeConfigService.getOne(wq);
//        one.setNowNum(one.getNowNum()-1);
//        mallTimeConfigService.updateById(one);
        //发订单信息给wx订阅服务消息————————————————start————————————————————————————————————————
        Map<String, Object> res = new HashMap<>();
        res.put("touser",UserHoder.getWxuser().getOpenid());
        res.put("template_id","Gzc2BgzSsEY9uki6FThNQRLD1_An6uqpSve3PaU58PQ");
        res.put("page","pages/mine/index");
        res.put("miniprogram_state","trial");
        //订阅消息参数值
        JSONObject data = new JSONObject();
        JSONObject amount3 = new JSONObject();
        amount3.put("value", order.getOrderSn());
        data.put("character_string2", amount3);
        JSONObject time4 = new JSONObject();
        String dateFormat = DateUtil.format(order.getCreateTime(), "yyyy-MM-dd HH:mm:ss");
        time4.put("value", dateFormat);
        data.put("time1", time4);
        final TjPackage byId = packageService.getById(order.getPacId());
        if (byId!=null){
            JSONObject thing5 = new JSONObject();
            thing5.put("value",byId.getPacName());
            data.put("thing3", thing5);
        }else {
            JSONObject thing5 = new JSONObject();
            thing5.put("value","体检项目");
            data.put("thing3", thing5);
        }
        JSONObject name1 = new JSONObject();
        name1.put("value",order.getActualPrice()+"元");
        data.put("amount4", name1);
        if (order.getPayId()!=null){
            JSONObject thing6 = new JSONObject();
            thing6.put("value", "已付款");
            data.put("phrase8", thing6);
        }else {
            JSONObject thing6 = new JSONObject();
            thing6.put("value", "未付款");
            data.put("phrase8", thing6);
        }
        WxUtil.sendCommonSubscribeMessage(res,data);
        //发订单信息给wx订阅服务消息————————————————end————————————————————————————————————————
        return AjaxResult.success();
    }
ltkj-admin/src/main/java/com/ltkj/web/wxUtils/HttpClientUtils.java
New file
@@ -0,0 +1,289 @@
package com.ltkj.web.wxUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import com.ltkj.web.wxUtils.HttpClientUtils;
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
import org.apache.http.conn.util.PublicSuffixMatcher;
import org.apache.http.conn.util.PublicSuffixMatcherLoader;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;
import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * httpClient 工具类
 * @create 2019-02-10 下午 2:49
 */
@Component
public class HttpClientUtils {
    /**
     * 默认参数设置
     * setConnectTimeout:设置连接超时时间,单位毫秒。
     * setConnectionRequestTimeout:设置从connect Manager获取Connection 超时时间,单位毫秒。
     * setSocketTimeout:请求获取数据的超时时间,单位毫秒。访问一个接口,多少时间内无法返回数据,就直接放弃此次调用。 暂时定义15分钟
     */
    private RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(600000).setConnectTimeout(600000).setConnectionRequestTimeout(600000).build();
    /**
     * 静态内部类---作用:单例产生类的实例
     * @author Administrator
     *
     */
    private static class LazyHolder {
        private static final HttpClientUtils INSTANCE = new HttpClientUtils();
    }
    HttpClientUtils(){}
    public static HttpClientUtils getInstance(){
        return LazyHolder.INSTANCE;
    }
    /**
     * 发送 post请求
     * @param httpUrl 地址
     */
    public String sendHttpPost(String httpUrl) {
        HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost
        return sendHttpPost(httpPost);
    }
    /**
     * 发送 post请求
     * @param httpUrl 地址
     * @param params 参数(格式:key1=value1&key2=value2)
     */
    public String sendHttpPost(String httpUrl, String params) {
        HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost
        try {
            //设置参数
            StringEntity stringEntity = new StringEntity(params, "UTF-8");
            stringEntity.setContentType("application/x-www-form-urlencoded");
            httpPost.setEntity(stringEntity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sendHttpPost(httpPost);
    }
    /**
     * 发送 post请求
     * @param httpUrl 地址
     * @param maps 参数
     */
    public String sendHttpPost(String httpUrl, Map<String, String> maps) {
        HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost
        // 创建参数队列
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        for (String key : maps.keySet()) {
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));
        }
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sendHttpPost(httpPost);
    }
    /**
     * 发送Post请求
     * @param httpPost
     * @return
     */
    private String sendHttpPost(HttpPost httpPost) {
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse response = null;
        HttpEntity entity = null;
        String responseContent = null;
        try {
            // 创建默认的httpClient实例
            httpClient = HttpClients.createDefault();
            httpPost.setConfig(requestConfig);
            // 执行请求
            long execStart = System.currentTimeMillis();
            response = httpClient.execute(httpPost);
            long execEnd = System.currentTimeMillis();
            System.out.println("=================执行post请求耗时:"+(execEnd-execStart)+"ms");
            long getStart = System.currentTimeMillis();
            entity = response.getEntity();
            responseContent = EntityUtils.toString(entity, "UTF-8");
            long getEnd = System.currentTimeMillis();
            System.out.println("=================获取响应结果耗时:"+(getEnd-getStart)+"ms");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                // 关闭连接,释放资源
                if (response != null) {
                    response.close();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return responseContent;
    }
    /**
     * 发送 get请求
     * @param httpUrl
     */
    public String sendHttpGet(String httpUrl) {
        HttpGet httpGet = new HttpGet(httpUrl);// 创建get请求
        return sendHttpGet(httpGet);
    }
    /**
     * 发送 get请求Https
     * @param httpUrl
     */
    public String sendHttpsGet(String httpUrl) {
        HttpGet httpGet = new HttpGet(httpUrl);// 创建get请求
        return sendHttpsGet(httpGet);
    }
    /**
     * 发送Get请求
     * @param httpGet
     * @return
     */
    private String sendHttpGet(HttpGet httpGet) {
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse response = null;
        HttpEntity entity = null;
        String responseContent = null;
        try {
            // 创建默认的httpClient实例.
            httpClient = HttpClients.createDefault();
            httpGet.setConfig(requestConfig);
            // 执行请求
            response = httpClient.execute(httpGet);
            entity = response.getEntity();
            responseContent = EntityUtils.toString(entity, "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                // 关闭连接,释放资源
                if (response != null) {
                    response.close();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return responseContent;
    }
    /**
     * 发送Get请求Https
     * @param httpGet
     * @return
     */
    private String sendHttpsGet(HttpGet httpGet) {
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse response = null;
        HttpEntity entity = null;
        String responseContent = null;
        try {
            // 创建默认的httpClient实例.
            PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.load(new URL(httpGet.getURI().toString()));
            DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher);
            httpClient = HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier).build();
            httpGet.setConfig(requestConfig);
            // 执行请求
            response = httpClient.execute(httpGet);
            entity = response.getEntity();
            responseContent = EntityUtils.toString(entity, "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                // 关闭连接,释放资源
                if (response != null) {
                    response.close();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return responseContent;
    }
    /**
     * 发送xml数据
     * @param url
     * @param xmlData
     * @return
     * @throws ClientProtocolException
     * @throws IOException
     */
    public static HttpResponse sendXMLDataByPost(String url, String xmlData)
            throws ClientProtocolException, IOException {
        HttpClient httpClient = HttpClients.createDefault();
        HttpPost httppost = new HttpPost(url);
        StringEntity entity = new StringEntity(xmlData);
        httppost.setEntity(entity);
        httppost.setHeader("Content-Type", "text/xml;charset=UTF-8");
        HttpResponse response = httpClient.execute(httppost);
        return response;
    }
    /**
     * 获得响应HTTP实体内容
     *
     * @param response
     * @return
     * @throws IOException
     * @throws UnsupportedEncodingException
     */
    public static String getHttpEntityContent(HttpResponse response) throws IOException, UnsupportedEncodingException {
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream is = entity.getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            String line = br.readLine();
            StringBuilder sb = new StringBuilder();
            while (line != null) {
                sb.append(line + "\n");
                line = br.readLine();
            }
            return sb.toString();
        }
        return "";
    }
}
ltkj-admin/src/main/java/com/ltkj/web/wxUtils/WxUtil.java
New file
@@ -0,0 +1,89 @@
package com.ltkj.web.wxUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
public class WxUtil {
    @Value("${wx.miniapp.appid}")
    private static String APPID;
    @Value("${wx.miniapp.secret}")
    private static String APPSECRET;
    public static String getAccessToken(){
        String APPID="wx40a545f1a8eb1d9d";
        String APPSECRET="c86c1ff7f91c16380111878e9a259237";
        String accessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+APPID+"&secret="+APPSECRET;
        System.out.println("accessTokenUrl = " + accessTokenUrl);
        HttpClientUtils hru = new HttpClientUtils();
        String access_token = hru.sendHttpGet(accessTokenUrl);
        JSONObject jsonObject= JSON.parseObject(access_token);
        String token = jsonObject.get("access_token").toString();//获取access_token
        System.out.println("access_token = " + token);
        return token;
    }
    /**
     * 调用微信开放接口subscribeMessage.send发送订阅消息    通用类
     * POST https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN
     */
    public static void sendCommonSubscribeMessage(Map<String,Object> params,JSONObject data){
        HttpURLConnection httpConn = null;
        InputStream is = null;
        BufferedReader rd = null;
        String accessToken = null;
        String str = null;
        try
        {
            //获取token  小程序全局唯一后台接口调用凭据
            accessToken = getAccessToken();
            JSONObject xmlData = new JSONObject();
            xmlData.put("touser", params.get("touser"));//接收者(用户)的 openid
            xmlData.put("template_id", params.get("template_id"));//所需下发的订阅模板id
            xmlData.put("page", params.get("page"));//点击模板卡片后的跳转页面,仅限本小程序内的页面
            xmlData.put("miniprogram_state", params.get("miniprogram_state"));//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
            xmlData.put("lang", "zh_CN");//进入小程序查看”的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN返回值
            xmlData.put("data", data);//小程序模板数据
            System.out.println("发送模板消息xmlData:" + xmlData);
            URL url = new URL(
                    "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="
                            + accessToken);
            httpConn = (HttpURLConnection)url.openConnection();
            httpConn.setRequestProperty("Host", "https://api.weixin.qq.com");
            // httpConn.setRequestProperty("Content-Length", String.valueOf(xmlData.));
            httpConn.setRequestProperty("Content-Type", "text/xml; charset=\"UTF-8\"");
            httpConn.setRequestMethod("POST");
            httpConn.setDoInput(true);
            httpConn.setDoOutput(true);
            OutputStream out = httpConn.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(out, "UTF-8");
            osw.write(xmlData.toString());
            osw.flush();
            osw.close();
            out.close();
            is = httpConn.getInputStream();
            rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            while ((str = rd.readLine()) != null)
            {
                System.out.println("返回数据:" + str);
            }
        }
        catch (Exception e)
        {
            System.out.println("发送模板消息失败.." + e.getMessage());
        }
    }
}
ltkj-admin/src/test/java/lgTest.java
New file
@@ -0,0 +1,46 @@
import com.ltkj.LtkjApplication;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.List;
/**
 * @Company: 西安路泰科技有限公司
 * @Author: lige
 * @Date: 2023/11/16 16:42
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = LtkjApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Slf4j
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
public class lgTest {
    @Test
    public void lige() {
//        List<String> a=new ArrayList<>();
//        a.add("ozImg61ibpygYZNRWLqtrdpoICh4");
////        a.add("ozImg66H5FbsXzzAHto5Ue_SN5W4");
////        a.add("ozImg64_ViFuhCWvnwLtMWyUCz7g");
////        a.add("ozImg61ibpygYZNRWLqtrdpoICh4");
//
//        for (String s : a) {
//            WxUtil.sendSubscribeMessage(s);
//        }
        //String openid = "o524m6a1xomIOW5fymo7WmE-z3Dg";//需要该用户已经授权过该订阅消息才能发送
    }
    public static void main(String[] args) {
        Long a=12L;
        final long l = a + 10000;
        final String s = "V" + l;
        System.out.println(s);
    }
}