jiangping
2023-12-25 6707b8df16cf531d6654d8a3b429de45f5fe9db3
修改小程序码
已添加1个文件
已修改5个文件
278 ■■■■■ 文件已修改
server/services/src/main/java/com/doumee/core/constants/Constants.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/services/src/main/java/com/doumee/core/utils/HttpsUtil.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/services/src/main/java/com/doumee/core/utils/ImageDesignerUtil.java 132 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/services/src/main/resources/application-dev.yml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/services/src/main/java/com/doumee/core/constants/Constants.java
@@ -37,6 +37,7 @@
    public static final String FORCE_BACK_SITE = "FORCE_BACK_SITE";
    //车辆类型数据
    public static final String  BIKE_TYPE ="0,1,2,3,4,5,6,7,8" ;
    public static final String MINI_PROGRAMME_REALEASE ="MINI_PROGRAMME_REALEASE" ;
    public static String REDIS_DEBUG_STR="test_";
    public static final String AD = "AD";
    public static String REPAIR = "REPAIR";
server/services/src/main/java/com/doumee/core/utils/HttpsUtil.java
@@ -30,7 +30,6 @@
    public static String post(String url, String data, String contentType, boolean ignoreSSL) {
        return connection(url, "POST", data, contentType, ignoreSSL);
    }
    public static String connection(String url,String method,String data,String contentType,boolean ignoreSSL){
        HttpsURLConnection connection = null;
        try {
@@ -89,7 +88,48 @@
        }
        return null;
    }
    public static InputStream postJson(String url, String data){
        HttpsURLConnection connection = null;
        try {
            URL _url = new URL(url);
            connection = (HttpsURLConnection) _url.openConnection();
            connection.setRequestMethod("POST");
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setUseCaches(false);
            connection.setRequestProperty("Content-Type", "application/json");
            connection.connect();
            //信任所有ssl证书和主机
            TrustManager[] trustManagers = {new HttpsTrustManager()};
            SSLContext context = SSLContext.getInstance("TLS");
            context.init(null, trustManagers, new SecureRandom());
            connection.setSSLSocketFactory(context.getSocketFactory());
            connection.setHostnameVerifier(new HostnameVerifier() {
                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }
            });
            if(data != null){
                OutputStream outputStream = connection.getOutputStream();
                outputStream.write(data.getBytes("utf-8"));
                outputStream.close();
            }
            int responseCode = connection.getResponseCode();
            if (responseCode == HttpsURLConnection.HTTP_OK) {
                InputStream is = connection.getInputStream();
                return is;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(connection != null){
           //     connection.disconnect();
            }
        }
        return null;
    }
    /**
     * å‘送get请求
     * @param url è¯·æ±‚URL
server/services/src/main/java/com/doumee/core/utils/ImageDesignerUtil.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,132 @@
package com.doumee.core.utils;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
//import com.sun.image.codec.jpeg.JPEGCodec;
//import com.sun.image.codec.jpeg.JPEGImageEncoder;
import javax.imageio.ImageIO;
public class ImageDesignerUtil {
    private static BufferedImage image;
    private static void createImage(String fileLocation,BufferedImage image) {
    try {
//        FileOutputStream fos = new FileOutputStream(fileLocation);
//        BufferedOutputStream bos = new BufferedOutputStream(fos);
//        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
//        encoder.encode(image);
//        bos.close();
        String formatName = fileLocation.substring(fileLocation.lastIndexOf(".") + 1);
        ImageIO.write(image, formatName , new File(fileLocation) );
    } catch (Exception e) {
        e.printStackTrace();
    }
    }
    public static boolean graphicsGenerationIs(String bottom, InputStream imgurl,   String savePath) {
        try {
            int imageWidth = 320;// å›¾ç‰‡çš„宽度
            int imageHeight = 370;// å›¾ç‰‡çš„高度
            BufferedImage image = new BufferedImage(imageWidth, imageHeight,
                    BufferedImage.TYPE_INT_RGB);
            Graphics graphics = image.getGraphics();
            graphics.setColor(Color.black);
            graphics.fillRect(0, 0, imageWidth, imageHeight);
            // æ”¹æˆè¿™æ ·:
            BufferedImage bimg = null;
            try {
                bimg = javax.imageio.ImageIO.read(imgurl);
            } catch (Exception e) {
            }
            if (bimg != null)
                graphics.drawImage(bimg, 15, 15, null);
            // ------------------------背景图画结束--------------
            graphics.setColor(Color.WHITE);
            graphics.setFont(new Font("微软雅黑", Font.PLAIN, 30));
            graphics.drawString(bottom, 90, 345);
            // --------------------昵称画结束------------------
            graphics.dispose();
            createImage(savePath,image);
            return  new File(savePath).isFile();
        }catch (Exception e){
            return false;
        }
    }
    public static String graphicsGeneration(String name, String imgurl, String header,
        String qrCode,String savePath) {
    int imageWidth = 640;// å›¾ç‰‡çš„宽度
    int imageHeight = 1020;// å›¾ç‰‡çš„高度
    image = new BufferedImage(imageWidth, imageHeight,
        BufferedImage.TYPE_INT_RGB);
    Graphics graphics = image.getGraphics();
    graphics.setColor(Color.WHITE);
    graphics.fillRect(0, 0, imageWidth, imageHeight);
    // æ”¹æˆè¿™æ ·:
    BufferedImage bimg = null;
    try {
        bimg = javax.imageio.ImageIO.read(new java.io.File(imgurl));
    } catch (Exception e) {
    }
    if (bimg != null)
        graphics.drawImage(bimg, 0, 0, null);
    // ------------------------背景图画结束--------------
    // graphics.fillRect(0, 0, headWidth, headHeight);
    // æ”¹æˆè¿™æ ·:
    bimg = null;
    try {
        bimg = javax.imageio.ImageIO.read(new java.io.File(header));
    } catch (Exception e) {
    }
    if (bimg != null)
        graphics.drawImage(bimg, 26, 34, 90, 90, null);
    // --------------头像画结束---------------
    graphics.setColor(Color.BLACK);
    graphics.setFont(new Font("微软雅黑", Font.PLAIN, 30));
    graphics.drawString(name, 134, 70);
    // --------------------昵称画结束------------------
    graphics.setColor(Color.WHITE);
    // graphics.fillRect(0, 0, codeWidth, codeHeight);
    // æ”¹æˆè¿™æ ·:
    bimg = null;
    try {
        bimg = javax.imageio.ImageIO.read(new java.io.File(qrCode));
    } catch (Exception e) {
    }
    if (bimg != null)
        graphics.drawImage(bimg, 140, 547, 360, 360, null);
    // --------------二维码画结束---------------
    graphics.dispose();
    createImage(savePath,image);
    return savePath;
    }
    public static void main(String[] args) {
    ImageDesignerUtil cg = new ImageDesignerUtil();
    try {
        graphicsGeneration("我是新世界之神", "bg.png",
            "D:\\test\\head.png", "D:\\test\\code.png","D:\\test\\test0.png");
    } catch (Exception e) {
        e.printStackTrace();
    }
    }
}
server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java
@@ -6,7 +6,9 @@
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.HttpsUtil;
import com.doumee.core.utils.ID;
import com.doumee.core.utils.ImageDesignerUtil;
import com.doumee.dao.business.RefundMapper;
import com.doumee.dao.business.TransactionsMapper;
import com.doumee.dao.business.model.Locks;
@@ -22,13 +24,12 @@
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.*;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
@@ -201,6 +202,52 @@
    }
    public static void main(String[] args) throws IOException {
      /* InputStream inputStream = HttpsUtil.postJson("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=75_W8lx5-bp9WEo69pQ6hvN70fJJJCNSRby6Wi6z_R9G7Sd5GMdY7ZT8Zq3PrKWrFBq92utfgqu3P8iw1NOvJNfyZssEYCy6k94Wch-GQNXcarSV65gowLk-SA9bncWTJbAGAHEU", "{\"check_path\":false,\"is_hyaline\":false,\"page\":\"pages/index/index\",\"scene\":\"1993/90\",\"env_version\":\"trial\"}");
        File file = new File("D://test.png");
        //定义一个用于读取InputStream数据的byte数组
        byte[] buffer = new byte[1024];
//输出流,用于写入文件
        FileOutputStream outputStream = new FileOutputStream(file);
//循环读取数据并将其写入文件中
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            outputStream.write(buffer, 0, length);
        }
//关闭InputStream和OutputStream
        inputStream.close();
        outputStream.close();*/
        Map<String,Object> body = new HashMap<>();
        // åœºæ™¯ç ï¼Œä¸Žå‰ç«¯çº¦å®šï¼Œæœ€ç»ˆæ˜¯éœ€è¦å‰ç«¯è§£æž
        body.put("scene",   "1992/41" );
        // æ­£å¼ç‰ˆä¸º "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
//        body.put("env_version", "release");
        body.put("env_version", "trial");
        // é€æ˜Žï¼Œæ ¹æ®ä½ çš„场景自行设置body参数
        body.put("is_hyaline",false);
        body.put("check_path", false);
        body.put("page","pages/index/index");
        OkHttpClient client = new OkHttpClient().newBuilder().build();
        okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
        log.info("=========================================="+JSONObject.toJSONString(body));
        okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(mediaType, JSONObject.toJSONString(body));
        Request request = new Request.Builder().url("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=75_MppLyM-Fy1rWPbJE8ccXfy90Afg_3wdENqKBEshglyyARP3egjvsti3agoaZJ0UVKHh_wwuIDcbu41ptPKleUcaD1vDRi4BrH8oN8TEHPTUCb1Kcp6ZoMJNNWScZKChAIAHSK").method("POST", requestBody).build();
        try {
            Response response = client.newCall(request).execute();
            if (response.isSuccessful()) {
                InputStream inputStream = new ByteArrayInputStream(response.body().bytes());
                String nowDate = DateUtil.getNowShortDate();
                File file = new File("D://test1.png");
                FileUtils.copyInputStreamToFile(inputStream,file);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * ç”Ÿæˆå°ç¨‹åºç 
@@ -212,20 +259,63 @@
        if(Objects.isNull(systemDictData)){
            return;
        }
         String url =  "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+ systemDictData.getCode();
        String release =   systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.MINI_PROGRAMME_REALEASE).getCode();
        //生成图片上传OSS
        Map<String,Object> body = new HashMap<>();
        // åœºæ™¯ç ï¼Œä¸Žå‰ç«¯çº¦å®šï¼Œæœ€ç»ˆæ˜¯éœ€è¦å‰ç«¯è§£æž
        body.put("scene", locks.getSiteId() + "/" +locks.getCode() );
        // æ­£å¼ç‰ˆä¸º "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
        body.put("env_version", "release");
        body.put("env_version", "trial");
//        body.put("env_version", "release");
        body.put("env_version", StringUtils.defaultString(release, "release"));
        // é€æ˜Žï¼Œæ ¹æ®ä½ çš„场景自行设置body参数
        body.put("is_hyaline", false);
        body.put("check_path", false);
        body.put("width", 290);
        body.put("page","pages/index/index");
        log.info("=========================================="+url+"\n"+JSONObject.toJSONString(body));
        try {
            InputStream inputStream  =HttpsUtil.postJson(url,JSONObject.toJSONString(body));;
            if (inputStream !=null) {
                String nowDate = DateUtil.getNowShortDate();
                String name =locks.getSiteId()+"-"+locks.getCode()+"-"+nowDate+".png";
                String fileName =prePath+path+"/"+name;
//                File file = new File(prePath+path,locks.getSiteId()+"-"+locks.getCode()+"-"+nowDate+".png");
//                FileUtils.copyInputStreamToFile(inputStream,file);
                if(ImageDesignerUtil.graphicsGenerationIs(locks.getSiteId()+"/"+locks.getCode(),inputStream,fileName)){
                    locks.setInfo(name);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * ç”Ÿæˆå°ç¨‹åºç 
     * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html
     * @return
     */
    public void generateWXMiniCodeOld(Locks locks,SystemDictData systemDictData,String prePath,String path){
        if(Objects.isNull(systemDictData)){
            return;
        }
      String release =   systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.MINI_PROGRAMME_REALEASE).getCode();
        //生成图片上传OSS
        Map<String,Object> body = new HashMap<>();
        // åœºæ™¯ç ï¼Œä¸Žå‰ç«¯çº¦å®šï¼Œæœ€ç»ˆæ˜¯éœ€è¦å‰ç«¯è§£æž
        body.put("scene", locks.getSiteId() + "/" +locks.getCode() );
        // æ­£å¼ç‰ˆä¸º "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
//        body.put("env_version", "release");
        body.put("env_version", StringUtils.defaultString(release, "release"));
        // é€æ˜Žï¼Œæ ¹æ®ä½ çš„场景自行设置body参数
        body.put("is_hyaline", Boolean.FALSE.toString());
        body.put("check_path", Boolean.FALSE.toString());
        body.put("page","pages/index/index");
        OkHttpClient client = new OkHttpClient().newBuilder().build();
        okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
        okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(mediaType, JSONObject.toJSONString(body));
        log.info("=========================================="+JSONObject.toJSONString(body));
        Request request = new Request.Builder().url("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+systemDictData.getCode()).method("POST", requestBody).build();
        try {
            Response response = client.newCall(request).execute();
server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java
@@ -792,7 +792,7 @@
            if(Objects.nonNull(sites)){
                Sites sites1 = new Sites();
                sites1.setId(sites.getId());
                sites1.setLockNum(sites.getLockNum()+1);
                sites1.setLockNum(Constants.formatIntegerNum(sites.getLockNum())+1);
                sitesMapper.updateById(sites1);
            }
        }else{
server/services/src/main/resources/application-dev.yml
@@ -5,6 +5,7 @@
    username: postgres
    password: Doumee@168
    driver-class-name: org.postgresql.Driver
  jpa:
    properties:
      hibernate: