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 |  151 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 146 insertions(+), 5 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 98e673b..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
@@ -2,6 +2,7 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.alipay.api.internal.util.codec.Base64;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 import com.stylefeng.guns.core.common.constant.JwtConstants;
@@ -20,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;
@@ -27,11 +29,19 @@
 import org.apache.shiro.util.ByteSource;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+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;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.io.*;
 import java.math.BigDecimal;
+import java.security.SecureRandom;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -157,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 + "\"}");
@@ -191,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;
         }
 
@@ -1549,8 +1559,139 @@
         redisUtil.remove("DEVICE_" + id);//清除车载端登录的标识
         return ResultUtil.success();
     }
+    @Autowired
+    private WeChatUtil weChatUtil;
+    @Autowired
+    private RestTemplate restTemplate;
+    @Override
+    public Driver generateCode(Driver userInfo) {
+        generateQrCode(userInfo);
+        return userInfo;
+    }
 
+    private void generateQrCode(Driver userInfo) {
+        if (userInfo.getCode()!=null){
+            return;
+        }
+        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="+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); // 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 参数仅对小程序码生效
+            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);
+            userInfo.setCode(pictureName);
+            this.updateById(userInfo);
+
+        } 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();
+                }
+            }
+        }
+    }
+    @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