Sfoglia il codice sorgente

获取微信二维码修复

lqc 5 anni fa
parent
commit
7fe322e9c5

+ 15 - 0
src/main/java/com/mokamrp/privates/PrivateServerStart.java

@@ -3,8 +3,14 @@ package com.mokamrp.privates;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.Arrays;
 
 @EnableAsync
 @EnableScheduling
@@ -14,4 +20,13 @@ public class PrivateServerStart {
     public static void main(String[] args) {
         SpringApplication.run(PrivateServerStart.class, args);
     }
+
+    @Bean
+    public RestTemplate restTemplate() {
+        RestTemplate restTemplate = new RestTemplate();
+        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
+        mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.IMAGE_JPEG, MediaType.IMAGE_PNG));
+        restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);
+        return restTemplate;
+    }
 }

+ 1 - 1
src/main/java/com/mokamrp/privates/controller/pangu/FosterwxTaskListController.java

@@ -151,7 +151,7 @@ public class FosterwxTaskListController extends BaseController<FosterwxTaskList>
 
         LambdaQueryWrapper<FosterwxTaskList> taskListLambdaQueryWrapper = new LambdaQueryWrapper<>();
         taskListLambdaQueryWrapper.eq(FosterwxTaskList::getTemplateId, templateId);
-        taskListLambdaQueryWrapper.orderByDesc(FosterwxTaskList::getTaskName);
+        taskListLambdaQueryWrapper.orderByDesc(FosterwxTaskList::getId);
         taskListLambdaQueryWrapper.last("Limit 1");
 
         FosterwxTaskList maxList = fosterwxTaskListService.getOne(taskListLambdaQueryWrapper);

+ 27 - 12
src/main/java/com/mokamrp/privates/service/impl/WechatApiServiceImpl.java

@@ -1,16 +1,19 @@
 package com.mokamrp.privates.service.impl;
 
 import com.alibaba.fastjson.JSON;
-import com.mokamrp.privates.service.CoralApiService;
 import com.mokamrp.privates.service.FileService;
 import com.mokamrp.privates.service.WechatApiService;
 import com.mokamrp.privates.utils.http.HttpUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.Resource;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
 
-import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -21,6 +24,9 @@ public class WechatApiServiceImpl implements WechatApiService {
     @Autowired
     public FileService fileService;
 
+    @Autowired
+    public RestTemplate restTemplate;
+
     private String wechatApi = "https://api.weixin.qq.com";
 
     /**
@@ -29,16 +35,25 @@ public class WechatApiServiceImpl implements WechatApiService {
      * @param page
      * @return
      */
-    public String BuildBoxUnlimited(String token,String scene,String page){
-        String url = "/wxa/getwxacodeunlimit?access_token="+token;
-        Map<String,String> body = new HashMap<>();
-        body.put("scene",scene);
-        body.put("page",page);
+    public String BuildBoxUnlimited(String token, String scene, String page) {
+        String url = "/wxa/getwxacodeunlimit?access_token=" + token;
+        Map<String, String> body = new HashMap<>();
+        body.put("scene", scene);
+        body.put("page", page);
         String jsonStr = JSON.toJSONString(body);
-        String qrcodeStr = HttpUtils.sendPost(wechatApi+url,jsonStr,"utf-8");
-        byte[] imageB = qrcodeStr.getBytes();
-        InputStream is = new ByteArrayInputStream(imageB);
-        String ossUrl = fileService.uploadIsToOss(is,".png");
+        String qrcodeStr = HttpUtils.sendPost(wechatApi + url, jsonStr, "utf-8");
+
+        HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(body, null);
+        ResponseEntity<Resource> jsonObject = restTemplate.exchange(wechatApi + url, HttpMethod.POST, requestEntity, Resource.class);
+        String ossUrl = null;
+        try {
+            InputStream in = jsonObject.getBody().getInputStream();
+            // byte[] imageB = qrcodeStr.getBytes();
+            // InputStream is = new ByteArrayInputStream(imageB);
+            ossUrl = fileService.uploadIsToOss(in, ".jpeg");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
         return ossUrl;
     }
 

+ 1 - 0
src/main/java/com/mokamrp/privates/service/pangu/impl/FosterwxTaskListServiceImpl.java

@@ -39,6 +39,7 @@ public class FosterwxTaskListServiceImpl extends ServiceImpl<FosterwxTaskListMap
         Page<FosterwxTaskList> pageObj = new Page<FosterwxTaskList>(page, pageSize);
 
         LambdaQueryWrapper<FosterwxTaskList> taskListLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        taskListLambdaQueryWrapper.eq(FosterwxTaskList::getTemplateId, handle.getTemplateId());
         if (null != handle.getTaskName() && !handle.getTaskName().isEmpty())
             taskListLambdaQueryWrapper.eq(FosterwxTaskList::getTaskName, handle.getTaskName());
         if (null != handle.getTaskContent() && !handle.getTaskContent().isEmpty())