刘一凡 3 years ago
parent
commit
5e53c8d2e2

+ 23 - 27
src/main/java/com/chuanghai/h3c_reporting/controller/WxController.java

@@ -4,17 +4,16 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.chuanghai.h3c_reporting.common.exception.BizCodeEnume;
 import com.chuanghai.h3c_reporting.common.exception.BizCodeEnume;
 import com.chuanghai.h3c_reporting.common.exception.RRException;
 import com.chuanghai.h3c_reporting.common.exception.RRException;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.chuanghai.h3c_reporting.common.utils.CommonResult;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.http.ResponseEntity;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Controller;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.client.RestTemplate;
 
 
 import java.util.HashMap;
 import java.util.HashMap;
@@ -46,10 +45,12 @@ public class WxController {
      * 通过code换取用户手机号
      * 通过code换取用户手机号
      */
      */
     @GetMapping("/getPhone")
     @GetMapping("/getPhone")
-    public String getPhone(String code, String state) {
+    @ResponseBody
+    public CommonResult<String> getPhone(String code, String state) {
         if (access_token.equals("")) {
         if (access_token.equals("")) {
             getAccessToken();
             getAccessToken();
         }
         }
+//        System.out.println("access_token  ======>>>" + access_token);
         try {
         try {
             RestTemplate restTemplate = new RestTemplate();
             RestTemplate restTemplate = new RestTemplate();
             HttpHeaders headers = new HttpHeaders();
             HttpHeaders headers = new HttpHeaders();
@@ -59,21 +60,12 @@ public class WxController {
             HttpEntity<Map<String, String>> requestM = new HttpEntity<>(paramCardNumber, headers);
             HttpEntity<Map<String, String>> requestM = new HttpEntity<>(paramCardNumber, headers);
             String userInfoUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + access_token;
             String userInfoUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + access_token;
             ResponseEntity<String> responsem = restTemplate.postForEntity(userInfoUrl, requestM, String.class);
             ResponseEntity<String> responsem = restTemplate.postForEntity(userInfoUrl, requestM, String.class);
-            JSONObject obj = JSON.parseObject(responsem.getBody());
 
 
-            String phoneNumber = "";
-            ObjectMapper objectMapper = new ObjectMapper();
-            if (obj != null) {
-                try {
-                    Map<String, Object> jsonMap = objectMapper.readValue(obj.toString(), new TypeReference<Map<String, Object>>() {
-                    });
-                    // 内一层(获取有问题)
-                    phoneNumber = jsonMap.get("phone_info").toString();
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-            return phoneNumber;
+            JSONObject resPhoneInfo = JSON.parseObject(responsem.getBody());
+            JSONObject phoneInfo=resPhoneInfo.getJSONObject("phone_info");
+            String phoneNumber = phoneInfo.get("phoneNumber").toString();
+
+            return CommonResult.ok().setResult(phoneNumber);
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();
             throw new RRException(BizCodeEnume.WX_EXCEPTION, "获取用户绑定的手机号失败");
             throw new RRException(BizCodeEnume.WX_EXCEPTION, "获取用户绑定的手机号失败");
@@ -83,18 +75,22 @@ public class WxController {
     // 获取access_token
     // 获取access_token
     @Scheduled(cron = "0 59 0/1 * * ?")   // 每1小时59分,执行一次刷新access_token
     @Scheduled(cron = "0 59 0/1 * * ?")   // 每1小时59分,执行一次刷新access_token
     public void getAccessToken() {
     public void getAccessToken() {
-        Map<String, String> token = new HashMap<>();
-        token.put("appid", appID);
-        token.put("secret", secret);
-        token.put("grant_type", "client_credentials");
-        String url = "https://api.weixin.qq.com/cgi-bin/token";
+//        Map<String, String> token = new HashMap<>();
+//        token.put("appid", appID);
+//        token.put("secret", secret);
+//        token.put("grant_type", "client_credential");
+        String url = "https://api.weixin.qq.com/cgi-bin/token?" +
+                "grant_type=client_credential" +
+                "&appid=" + appID +
+                "&secret=" + secret;
 
 
         RestTemplate restTemplate = new RestTemplate();
         RestTemplate restTemplate = new RestTemplate();
-        HttpHeaders headers = new HttpHeaders();
-        headers.setContentType(MediaType.APPLICATION_JSON);
-        HttpEntity<Map<String, String>> request = new HttpEntity<>(token, headers);
-        ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, request, String.class);
+//        HttpHeaders headers = new HttpHeaders();
+//        headers.setContentType(MediaType.APPLICATION_JSON);
+//        HttpEntity<Map<String, String>> request = new HttpEntity<>(token, headers);
+        ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
         JSONObject objParam = JSON.parseObject(responseEntity.getBody());
         JSONObject objParam = JSON.parseObject(responseEntity.getBody());
+
         for (Map.Entry<String, Object> entry : objParam.entrySet()) {
         for (Map.Entry<String, Object> entry : objParam.entrySet()) {
             Object o = entry.getValue();
             Object o = entry.getValue();
             if (o instanceof String) {
             if (o instanceof String) {

+ 6 - 5
src/main/java/com/chuanghai/h3c_reporting/service/impl/InformationReportingServiceImpl.java

@@ -68,18 +68,19 @@ public class InformationReportingServiceImpl extends ServiceImpl<InformationRepo
 //            List list = this.queryPage(request).getList();
 //            List list = this.queryPage(request).getList();
             QueryWrapper<InformationReporting> queryWrapper = new QueryWrapper<>();
             QueryWrapper<InformationReporting> queryWrapper = new QueryWrapper<>();
             queryWrapper
             queryWrapper
-                    .like(StringUtils.hasText(request.getName()), "name", request.getName())
+                    .like(!StringUtils.isEmpty(request.getName()), "name", request.getName())
                     .like(StringUtils.hasText(request.getPhone()), "phone", request.getPhone())
                     .like(StringUtils.hasText(request.getPhone()), "phone", request.getPhone())
                     .like(StringUtils.hasText(request.getCompany()), "company", request.getCompany())
                     .like(StringUtils.hasText(request.getCompany()), "company", request.getCompany())
                     .like(StringUtils.hasText(request.getReportingTime()), "reporting_time", request.getReportingTime())
                     .like(StringUtils.hasText(request.getReportingTime()), "reporting_time", request.getReportingTime())
                     .eq("status", 1);
                     .eq("status", 1);
             List<InformationReporting> list = this.list(queryWrapper);
             List<InformationReporting> list = this.list(queryWrapper);
-            if (request.getIds() != null && request.getIds().equals("")){
-                request.setIds(null);
-            }
-            if (request.getIds() != null){
+            System.out.println(request);
+            if (request.getIds() != null && request.getIds().length > 0){
                 list = this.getBaseMapper().selectBatchIds(Arrays.asList(request.getIds()));
                 list = this.getBaseMapper().selectBatchIds(Arrays.asList(request.getIds()));
             }
             }
+//            if (request.getIds() != null){
+//                list = this.getBaseMapper().selectBatchIds(Arrays.asList(request.getIds()));
+//            }
 
 
             WriteCellStyle headWriteCellStyle = new WriteCellStyle();
             WriteCellStyle headWriteCellStyle = new WriteCellStyle();
             WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
             WriteCellStyle contentWriteCellStyle = new WriteCellStyle();

+ 2 - 2
src/main/resources/application.yml

@@ -37,5 +37,5 @@ my-security:
 
 
 #微信小程序相关配置
 #微信小程序相关配置
 wx:
 wx:
-  app_id: wx0baa0e7e965c61e8
-  secret: 07b92846b1e716975cb5e2d4ec231060
+  app_id: wx2fc3f45732fae5d3
+  secret: 7eee4a49a4470a77f9222995e8511547

File diff suppressed because it is too large
+ 71 - 66
src/main/resources/static/doc/index.html