From 19c35c58f8b767d7d9c57d0cf910fd091dc7669f Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期四, 27 二月 2025 16:37:08 +0800
Subject: [PATCH] 2.0新增

---
 DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java |  103 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 84 insertions(+), 19 deletions(-)

diff --git a/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java b/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java
index 9fed505..d2cd7d2 100644
--- a/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java
+++ b/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java
@@ -21,6 +21,7 @@
 import com.stylefeng.guns.modular.system.warpper.LoginWarpper;
 import com.stylefeng.guns.modular.system.warpper.RegisteredWarpper;
 import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
+import org.apache.http.entity.ContentType;
 import org.apache.shiro.authc.SimpleAuthenticationInfo;
 import org.apache.shiro.authc.UsernamePasswordToken;
 import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
@@ -28,9 +29,8 @@
 import org.apache.shiro.util.ByteSource;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.ResponseEntity;
+import org.springframework.http.*;
+import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.stereotype.Service;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
@@ -1568,16 +1568,7 @@
         generateQrCode(userInfo);
         return userInfo;
     }
-    public MultipartFile convertInputStreamToMultipartFile(InputStream inputStream, String fileName, String contentType) throws IOException {
-        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-        byte[] buffer = new byte[1024];
-        int bytesRead;
-        while ((bytesRead = inputStream.read(buffer)) != -1) {
-            byteArrayOutputStream.write(buffer, 0, bytesRead);
-        }
-        byte[] data = byteArrayOutputStream.toByteArray();
-        return new CustomMultipartFile(data, fileName, contentType);
-    }
+
     private void generateQrCode(Driver userInfo) {
         if (userInfo.getCode()!=null){
             return;
@@ -1591,7 +1582,7 @@
 //            param.put("page", "pageA/houseDetail");
             param.put("check_path", false);
             // 用户id 用于分享
-            param.put("scene", "uid="+userInfo.getId()+"userType=1");
+            param.put("scene", "uid="+userInfo.getId()+"userType=2");
             param.put("env_version", "trial");
             param.put("width", 200); //二维码尺寸
             param.put("is_hyaline", true); // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 参数仅对小程序码生效
@@ -1602,17 +1593,26 @@
             line_color.put("b", 0);
             param.put("line_color", line_color);
             System.err.println("调用生成微信URL接口传参:" + param);
-            MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
             HttpEntity requestEntity = new HttpEntity(param, headers);
-            ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]);
+//            HashMap<String, String> map = new HashMap<>();
+//            map.put("path", path);
+//            HttpHeaders headers = new HttpHeaders();
+//            headers.setContentType(MediaType.APPLICATION_JSON);
+//            HttpEntity requestEntity = new HttpEntity(map, headers);
+//            ResponseEntity<byte[]> rep = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class);
+//            byte[] bytes = rep.getBody();
+            ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class);
             System.err.println("调用小程序生成微信永久小程序码URL接口返回结果:" + entity.getBody());
             byte[] result = entity.getBody();
             System.err.println(Base64.encodeBase64String(result));
 
             inputStream = new ByteArrayInputStream(result);
-            String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpeg";
-            MultipartFile multipartFile = convertInputStreamToMultipartFile(inputStream, finalFileName, "image/jpeg");
-            String pictureName = OssUploadUtil.ossUploadCode(multipartFile);
+            String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpg";
+            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(result);
+            MultipartFile file = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), byteArrayInputStream);
+            String pictureName = OssUploadUtil.ossUploadCode(file,finalFileName);
             System.err.println(pictureName);
             userInfo.setCode(pictureName);
             this.updateById(userInfo);
@@ -1636,7 +1636,72 @@
             }
         }
     }
+    @Override
+    public String generateQrCodeTemp() {
 
+        String accessToken = weChatUtil.getAccessToken();
+        InputStream inputStream = null;
+        OutputStream outputStream = null;
+        try {
+            String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken;
+            Map<String, Object> param = new HashMap<>();
+//            param.put("page", "pageA/houseDetail");
+            param.put("check_path", false);
+            // 用户id 用于分享
+            param.put("scene", "uid="+1+"userType=1");
+//            param.put("env_version", "trial");
+//            param.put("width", 200); //二维码尺寸
+//            param.put("is_hyaline", true); // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 参数仅对小程序码生效
+//            param.put("auto_color", true); // 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 参数仅对小程序码生效
+//            Map<String, Object> line_color = new HashMap<>();
+//            line_color.put("r", 0);
+//            line_color.put("g", 0);
+//            line_color.put("b", 0);
+//            param.put("line_color", line_color);
+            System.err.println("调用生成微信URL接口传参:" + param);
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity requestEntity = new HttpEntity(param, headers);
+//            HashMap<String, String> map = new HashMap<>();
+//            map.put("path", path);
+//            HttpHeaders headers = new HttpHeaders();
+//            headers.setContentType(MediaType.APPLICATION_JSON);
+//            HttpEntity requestEntity = new HttpEntity(map, headers);
+//            ResponseEntity<byte[]> rep = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class);
+//            byte[] bytes = rep.getBody();
+            ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class);
+            System.err.println("调用小程序生成微信永久小程序码URL接口返回结果:" + entity.getBody());
+            byte[] result = entity.getBody();
+            System.err.println(Base64.encodeBase64String(result));
+
+            inputStream = new ByteArrayInputStream(result);
+            String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpg";
+            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(result);
+            MultipartFile file = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), byteArrayInputStream);
+            String pictureName = OssUploadUtil.ossUploadCode(file,finalFileName);
+            System.err.println(pictureName);
+            return Base64.encodeBase64String(result);
+
+        } catch (Exception e) {
+            System.err.println("调用小程序生成微信永久小程序码URL接口异常" + e);
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (outputStream != null) {
+                try {
+                    outputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return "";
+    }
     /**
      * 获取编号
      * @return

--
Gitblit v1.7.1