zhs vor 3 Jahren
Ursprung
Commit
dbaadd6c9e

+ 2 - 2
build.gradle

@@ -38,8 +38,8 @@ dependencies {
     implementation 'ws.schild:jave-core:3.1.1'
     implementation 'ws.schild:jave-nativebin-win64:3.1.1'
     implementation 'commons-fileupload:commons-fileupload:1.3.2'
-    implementation 'com.github.wechatpay-apiv3:wechatpay-apache-httpclient:0.3.0'//微信支付
-    implementation 'org.apache.httpcomponents:httpclient:4.3.2'  //post get请求包
+//    implementation 'com.github.wechatpay-apiv3:wechatpay-apache-httpclient:0.3.0'//微信支付
+//    implementation 'org.apache.httpcomponents:httpclient:4.3.2'  //post get请求包
     implementation 'com.baidubce:api-explorer-sdk:1.0.3.1'//百度翻译
     implementation fileTree(dir:'lib',includes:['*jar'])
     annotationProcessor 'org.projectlombok:lombok'

Datei-Diff unterdrückt, da er zu groß ist
+ 4 - 4
src/main/java/com/travel/controller/AKeyToLogInController.java


+ 6 - 2
src/main/java/com/travel/controller/PersonalController.java

@@ -42,6 +42,7 @@ public class PersonalController {
      */
     @GetMapping("/login")
     @ResponseBody
+    @AccessLimit(seconds = 1, maxCount = 1)
     public Map<String, Object> login(HttpServletRequest request) {
         Map<String, Object> map = new HashMap<>();
         //无实体类赋值
@@ -60,7 +61,8 @@ public class PersonalController {
             //如果手机号不存在则新增
             if(list.size() == 0){
 //                int maxId = loginService.getMaxId(user);//查询最大的id
-                Integer maxId = loginService.insetUser(user); //先新增信息 新增之后返回唯一自增标识 id用id生成编号跟用户昵称
+                loginService.insetUser(user); //先新增信息
+                Integer maxId = loginService.getMaxId(user);
                 user.setId(maxId.toString()).setName("tuya_" + (maxId + 1)).setCode("CUS0000000" + (maxId + 1)).setHeadpir("https://lidaotech.oss-cn-beijing.aliyuncs.com/test/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20220622112747.png");
                 loginService.updateKeyToLog(user);//添加用户昵称  编号  头像
             }
@@ -87,6 +89,7 @@ public class PersonalController {
      */
     @GetMapping("checkTele")
     @ResponseBody
+    @AccessLimit(seconds = 1, maxCount = 1)
     public Map<String, Object> checkTele(User user, HttpServletResponse response) {
         response.setHeader("Access-Control-Allow-Origin", "*");
         Map<String, Object> map = new HashMap<>();
@@ -130,6 +133,7 @@ public class PersonalController {
      */
     @GetMapping("checkCaptcha")
     @ResponseBody
+    @AccessLimit(seconds = 1, maxCount = 1)
     public String checkCaptcha(User user, HttpServletResponse response) {
         response.setHeader("Access-Control-Allow-Origin", "*");
         try {
@@ -151,7 +155,7 @@ public class PersonalController {
      */
     @GetMapping("updateUser")
     @ResponseBody
-    @AccessLimit(seconds = 5, maxCount = 5)
+    @AccessLimit(seconds = 1, maxCount = 1)
     public Map<String, Object> updateUser(User user, HttpServletResponse response){
         response.setHeader("Access-Control-Allow-Origin", "*");
         Map<String, Object> map = new HashMap<>();

+ 89 - 89
src/main/java/com/travel/controller/WechatPay.java

@@ -1,95 +1,95 @@
-package com.travel.controller;
-
-import com.alibaba.fastjson.JSONObject;
-import com.travel.wxPay.PayBeanConfig;
-import com.travel.wxPay.WechatPayApi;
-import com.travel.wxPay.WxPayConfigure;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.util.EntityUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import java.text.SimpleDateFormat;
-import org.apache.http.client.methods.HttpPost;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Random;
-
-@RestController
-@RequestMapping("wxPay")
-@Slf4j
-public class WechatPay {
-
-//    @Autowired
-//    private PayBeanConfig payBeanConfig;
-
-    @Autowired
-    private WxPayConfigure payConfig;
+//package com.travel.controller;
+//
+//import com.alibaba.fastjson.JSONObject;
+//import com.travel.wxPay.PayBeanConfig;
+//import com.travel.wxPay.WechatPayApi;
+//import com.travel.wxPay.WxPayConfigure;
+//import lombok.extern.slf4j.Slf4j;
+//import org.apache.http.client.methods.CloseableHttpResponse;
+//import org.apache.http.entity.StringEntity;
+//import org.apache.http.impl.client.CloseableHttpClient;
+//import org.apache.http.util.EntityUtils;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.web.bind.annotation.PostMapping;
+//import org.springframework.web.bind.annotation.RequestMapping;
+//import org.springframework.web.bind.annotation.RestController;
+//import java.text.SimpleDateFormat;
+//import org.apache.http.client.methods.HttpPost;
+//import java.util.Date;
+//import java.util.HashMap;
+//import java.util.Map;
+//import java.util.Random;
+//
+//@RestController
+//@RequestMapping("wxPay")
+//@Slf4j
+//public class WechatPay {
+//
+////    @Autowired
+////    private PayBeanConfig payBeanConfig;
 //
 //    @Autowired
-//    private CloseableHttpClient wechatPayClient;
-
-    @PostMapping("wxPayPost")
-    public Map<String, Object> wxPayPost(String amount){
-        Map<String, Object> map = new HashMap<>();
-        JSONObject payObj = new JSONObject();
-
-        payObj.put("mchid", payConfig.getMchId());
-        payObj.put("out_trade_no", getOrderNo());
-        payObj.put("appid", payConfig.getWxPayAppid());
-        payObj.put("description", "王师傅的红包");
-        payObj.put("notify_url", payConfig.getCallbackUrl());
-
-        //订单总金额,单位为分。
-        JSONObject amountObj = new JSONObject();
-        amountObj.put("total", amount);
-        amountObj.put("currency","CNY");
-        payObj.put("amount", amountObj);
-
-        String body = payObj.toJSONString();
-
-        log.info("请求参数:{}",body);
-
-        StringEntity entity = new StringEntity(body,"utf-8");
-        entity.setContentType("application/json");
-
-        HttpPost httpPost = new HttpPost(WechatPayApi.NATIVE_ORDER);
-        httpPost.setHeader("Accept","application/json");
-        httpPost.setEntity(entity);
-
-//        try(CloseableHttpResponse response = wechatPayClient.execute(httpPost)){
+//    private WxPayConfigure payConfig;
+////
+////    @Autowired
+////    private CloseableHttpClient wechatPayClient;
+//
+//    @PostMapping("wxPayPost")
+//    public Map<String, Object> wxPayPost(String amount){
+//        Map<String, Object> map = new HashMap<>();
+//        JSONObject payObj = new JSONObject();
+//
+//        payObj.put("mchid", payConfig.getMchId());
+//        payObj.put("out_trade_no", getOrderNo());
+//        payObj.put("appid", payConfig.getWxPayAppid());
+//        payObj.put("description", "王师傅的红包");
+//        payObj.put("notify_url", payConfig.getCallbackUrl());
+//
+//        //订单总金额,单位为分。
+//        JSONObject amountObj = new JSONObject();
+//        amountObj.put("total", amount);
+//        amountObj.put("currency","CNY");
+//        payObj.put("amount", amountObj);
+//
+//        String body = payObj.toJSONString();
+//
+//        log.info("请求参数:{}",body);
+//
+//        StringEntity entity = new StringEntity(body,"utf-8");
+//        entity.setContentType("application/json");
+//
+//        HttpPost httpPost = new HttpPost(WechatPayApi.NATIVE_ORDER);
+//        httpPost.setHeader("Accept","application/json");
+//        httpPost.setEntity(entity);
 //
-//            //响应码
-//            int statusCode = response.getStatusLine().getStatusCode();
-//            //响应体
-//            String responseStr = EntityUtils.toString(response.getEntity());
+////        try(CloseableHttpResponse response = wechatPayClient.execute(httpPost)){
+////
+////            //响应码
+////            int statusCode = response.getStatusLine().getStatusCode();
+////            //响应体
+////            String responseStr = EntityUtils.toString(response.getEntity());
+////
+////            log.info("下单响应码:{},响应体:{}",statusCode,responseStr);
+////
+////        }catch (Exception e){
+////            e.printStackTrace();
+////        }
 //
-//            log.info("下单响应码:{},响应体:{}",statusCode,responseStr);
+//        return map;
+//    }
 //
-//        }catch (Exception e){
-//            e.printStackTrace();
+//    /**
+//     * 生成订单号
+//     * @return
+//     */
+//    public static String getOrderNo() {
+//        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+//        String newDate = sdf.format(new Date());
+//        String result = "";
+//        Random random = new Random();
+//        for (int i = 0; i < 3; i++) {
+//            result += random.nextInt(10);
 //        }
-
-        return map;
-    }
-
-    /**
-     * 生成订单号
-     * @return
-     */
-    public static String getOrderNo() {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
-        String newDate = sdf.format(new Date());
-        String result = "";
-        Random random = new Random();
-        for (int i = 0; i < 3; i++) {
-            result += random.nextInt(10);
-        }
-        return newDate + result;
-    }
-}
+//        return newDate + result;
+//    }
+//}

+ 1 - 1
src/main/java/com/travel/mapper/LoginMapper.java

@@ -8,7 +8,7 @@ import java.util.List;
 public interface LoginMapper {
     List<User> getUser(User user);
 
-    Integer insetUser(User user);
+    void insetUser(User user);
 
     int checkTele(User user);
 

+ 1 - 1
src/main/java/com/travel/service/LoginService.java

@@ -6,7 +6,7 @@ import java.util.List;
 public interface LoginService {
     List<User> getUser(User user);
 
-    Integer insetUser(User user);
+    void insetUser(User user);
 
     int checkTele(User user);
 

+ 2 - 3
src/main/java/com/travel/service/impl/LoginServiceImpl.java

@@ -22,9 +22,8 @@ public class LoginServiceImpl implements LoginService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Integer insetUser(User user) {
-        Integer id = loginMapper.insetUser(user);
-        return id;
+    public void insetUser(User user) {
+        loginMapper.insetUser(user);
     }
 
     @Override

+ 1 - 1
src/main/java/com/travel/util/SessionInterceptor.java

@@ -33,7 +33,7 @@ public class SessionInterceptor extends HandlerInterceptorAdapter {
             int maxCount = accessLimit.maxCount();
 
             //获取用户ip
-            String ip = request.getHeader("x-forwarded-for");      // 有可能ip是代理的
+            String ip = request.getHeader("x-forwarded-for");      // 有可能ip是代理的X
             if(ip ==null || ip.length() ==0 || "unknown".equalsIgnoreCase(ip)) {
                 ip = request.getHeader("Proxy-Client-IP");
             }

+ 103 - 103
src/main/java/com/travel/wxPay/PayBeanConfig.java

@@ -1,103 +1,103 @@
-package com.travel.wxPay;
-
-import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
-import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;
-import com.wechat.pay.contrib.apache.httpclient.auth.ScheduledUpdateCertificatesVerifier;
-import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials;
-import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.ClassPathResource;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.security.KeyFactory;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.PKCS8EncodedKeySpec;
-import java.util.Base64;
-import java.util.stream.Collectors;
-
-//@Configuration
-@Slf4j
-public class PayBeanConfig {
-    @Autowired
-    private WxPayConfigure payConfig;
-
-
-    /**
-     * 加载秘钥
-     *
-     * @return
-     * @throws IOException
-     */
-    public PrivateKey getPrivateKey() throws IOException {
-        InputStream inputStream = new ClassPathResource(payConfig.getPrivateKeyPath()
-                .replace("classpath:", "")).getInputStream();
-
-        String content = new BufferedReader(new InputStreamReader(inputStream))
-                .lines().collect(Collectors.joining(System.lineSeparator()));
-
-        try {
-            String privateKey = content.replace("-----BEGIN PRIVATE KEY-----", "")
-                    .replace("-----END PRIVATE KEY-----", "")
-                    .replaceAll("\\s+", "");
-            KeyFactory kf = KeyFactory.getInstance("RSA");
-
-            PrivateKey finalPrivateKey = kf.generatePrivate(
-                    new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey)));
-
-            return finalPrivateKey;
-
-        } catch (NoSuchAlgorithmException e) {
-            throw new RuntimeException("当前Java环境不支持RSA", e);
-        } catch (InvalidKeySpecException e) {
-            throw new RuntimeException("无效的密钥格式");
-        }
-    }
-
-
-    /**
-     * 定时获取微信签名验证器,自动获取微信平台证书(证书里面包括微信平台公钥)
-     *
-     * @return
-     */
-    @Bean
-    public ScheduledUpdateCertificatesVerifier getCertificatesVerifier() throws IOException {
-
-        // 使用定时更新的签名验证器,不需要传入证书
-        ScheduledUpdateCertificatesVerifier verifier = null;
-        verifier = new ScheduledUpdateCertificatesVerifier(
-                new WechatPay2Credentials(payConfig.getMchId(),
-                        new PrivateKeySigner(payConfig.getMchSerialNo(),
-                                getPrivateKey())),
-                payConfig.getApiV3Key().getBytes(StandardCharsets.UTF_8));
-
-        return verifier;
-    }
-
-
-    /**
-     * 获取http请求对象,会自动的处理签名和验签,
-     * 并进行证书自动更新
-     *
-     * @return
-     */
-    @Bean("wechatPayClient")
-    public CloseableHttpClient getWechatPayClient(ScheduledUpdateCertificatesVerifier verifier) throws IOException {
-        WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create()
-                .withMerchant(payConfig.getMchId(),payConfig.getMchSerialNo() , getPrivateKey())
-                .withValidator(new WechatPay2Validator(verifier));
-
-        // 通过WechatPayHttpClientBuilder构造的HttpClient,会自动的处理签名和验签,并进行证书自动更新
-        CloseableHttpClient httpClient = builder.build();
-
-        return httpClient;
-    }
-}
+//package com.travel.wxPay;
+//
+//import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
+//import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;
+//import com.wechat.pay.contrib.apache.httpclient.auth.ScheduledUpdateCertificatesVerifier;
+//import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials;
+//import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator;
+//import lombok.extern.slf4j.Slf4j;
+//import org.apache.http.impl.client.CloseableHttpClient;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.core.io.ClassPathResource;
+//import java.io.BufferedReader;
+//import java.io.IOException;
+//import java.io.InputStream;
+//import java.io.InputStreamReader;
+//import java.nio.charset.StandardCharsets;
+//import java.security.KeyFactory;
+//import java.security.NoSuchAlgorithmException;
+//import java.security.PrivateKey;
+//import java.security.spec.InvalidKeySpecException;
+//import java.security.spec.PKCS8EncodedKeySpec;
+//import java.util.Base64;
+//import java.util.stream.Collectors;
+//
+////@Configuration
+//@Slf4j
+//public class PayBeanConfig {
+//    @Autowired
+//    private WxPayConfigure payConfig;
+//
+//
+//    /**
+//     * 加载秘钥
+//     *
+//     * @return
+//     * @throws IOException
+//     */
+//    public PrivateKey getPrivateKey() throws IOException {
+//        InputStream inputStream = new ClassPathResource(payConfig.getPrivateKeyPath()
+//                .replace("classpath:", "")).getInputStream();
+//
+//        String content = new BufferedReader(new InputStreamReader(inputStream))
+//                .lines().collect(Collectors.joining(System.lineSeparator()));
+//
+//        try {
+//            String privateKey = content.replace("-----BEGIN PRIVATE KEY-----", "")
+//                    .replace("-----END PRIVATE KEY-----", "")
+//                    .replaceAll("\\s+", "");
+//            KeyFactory kf = KeyFactory.getInstance("RSA");
+//
+//            PrivateKey finalPrivateKey = kf.generatePrivate(
+//                    new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey)));
+//
+//            return finalPrivateKey;
+//
+//        } catch (NoSuchAlgorithmException e) {
+//            throw new RuntimeException("当前Java环境不支持RSA", e);
+//        } catch (InvalidKeySpecException e) {
+//            throw new RuntimeException("无效的密钥格式");
+//        }
+//    }
+//
+//
+//    /**
+//     * 定时获取微信签名验证器,自动获取微信平台证书(证书里面包括微信平台公钥)
+//     *
+//     * @return
+//     */
+//    @Bean
+//    public ScheduledUpdateCertificatesVerifier getCertificatesVerifier() throws IOException {
+//
+//        // 使用定时更新的签名验证器,不需要传入证书
+//        ScheduledUpdateCertificatesVerifier verifier = null;
+//        verifier = new ScheduledUpdateCertificatesVerifier(
+//                new WechatPay2Credentials(payConfig.getMchId(),
+//                        new PrivateKeySigner(payConfig.getMchSerialNo(),
+//                                getPrivateKey())),
+//                payConfig.getApiV3Key().getBytes(StandardCharsets.UTF_8));
+//
+//        return verifier;
+//    }
+//
+//
+//    /**
+//     * 获取http请求对象,会自动的处理签名和验签,
+//     * 并进行证书自动更新
+//     *
+//     * @return
+//     */
+//    @Bean("wechatPayClient")
+//    public CloseableHttpClient getWechatPayClient(ScheduledUpdateCertificatesVerifier verifier) throws IOException {
+//        WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create()
+//                .withMerchant(payConfig.getMchId(),payConfig.getMchSerialNo() , getPrivateKey())
+//                .withValidator(new WechatPay2Validator(verifier));
+//
+//        // 通过WechatPayHttpClientBuilder构造的HttpClient,会自动的处理签名和验签,并进行证书自动更新
+//        CloseableHttpClient httpClient = builder.build();
+//
+//        return httpClient;
+//    }
+//}

+ 1 - 4
src/main/resources/config/mapping/LoginMapper.xml

@@ -9,9 +9,6 @@
     </select>
     <!-- 新增用户 -->
     <insert id="insetUser" parameterType="User">
-        <selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
-            select LAST_INSERT_ID()
-        </selectKey>
         INSERT INTO sys_users (code,name,sex,age,pass,phone,jdrq,headpir,remake,wxid,wxtoken,flag,captcha)
         VALUES(#{code},#{name},#{sex},#{age},#{pass},#{phone},GETDATE(),#{headpir},#{remake},#{wxid},#{wxtoken},0,#{captcha})
     </insert>
@@ -71,7 +68,7 @@
     </select>
     <!-- 查询最大的id作为编号拼接 -->
     <select id="getMaxId" resultType="int">
-        select max(id) from sys_users
+        select id from sys_users where phone=#{phone}
     </select>
     <!-- 删除用户-->
     <delete id="deleteUser" parameterType="String">