From 818937959bb19d3669585fa87a526bffe9ce77a4 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 24 四月 2025 09:28:41 +0800
Subject: [PATCH] 修改默认验证码

---
 DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java |  105 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 80 insertions(+), 25 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..d63d007 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;
@@ -167,16 +167,16 @@
         String templateCode = "";
         switch (type){
             case 1:
-                templateCode = "SMS_476880205";//身份验证
+                templateCode = "SMS_482775061";//身份验证
                 break;
             case 2:
-                templateCode = "SMS_476880205";//登录确认
+                templateCode = "SMS_482775061";//登录确认
                 break;
             case 3:
-                templateCode = "SMS_476880205";//用户注册
+                templateCode = "SMS_482775061";//用户注册
                 break;
             case 4:
-                templateCode = "SMS_476880205";//修改密码
+                templateCode = "SMS_482775061";//修改密码
                 break;
         }
         String sData = aLiSendSms.sendSms(phone, templateCode, "{\"code\":\"" + authCode + "\"}");
@@ -201,7 +201,7 @@
     @Override
     public boolean checkCaptcha(String phone, String code) throws Exception {
         Object value = redisUtil.getValue(phone);
-        if("1234".equals(code)){
+        if("5689".equals(code)){
             return true;
         }
 
@@ -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,8 +1582,8 @@
 //            param.put("page", "pageA/houseDetail");
             param.put("check_path", false);
             // 用户id 用于分享
-            param.put("scene", "uid="+userInfo.getId()+"userType=1");
-            param.put("env_version", "trial");
+            param.put("scene", "uid="+userInfo.getId()+"userType=2");
+            param.put("env_version", "release");
             param.put("width", 200); //二维码尺寸
             param.put("is_hyaline", true); // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 参数仅对小程序码生效
             param.put("auto_color", 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,62 @@
             }
         }
     }
+    @Override
+    public String generateQrCodeTemp() {
 
+        String accessToken = weChatUtil.getAccessToken();
+        InputStream inputStream = null;
+        OutputStream outputStream = null;
+        try {
+            String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken;
+            Map<String, Object> param = new HashMap<>();
+//            param.put("page", "pageA/houseDetail");
+            // 用户id 用于分享
+            param.put("path", "pages/home/home?uid=1userType=2");
+            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 pictureName;
+
+        } 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