|
|
@@ -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;
|
|
|
}
|
|
|
|