|
@@ -16,11 +16,13 @@ import org.apache.http.protocol.HTTP;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+
|
|
@Service
|
|
@Service
|
|
public class MiniAppService {
|
|
public class MiniAppService {
|
|
@Autowired
|
|
@Autowired
|
|
@@ -29,6 +31,7 @@ public class MiniAppService {
|
|
private DcIntroducerService dcIntroducerService;
|
|
private DcIntroducerService dcIntroducerService;
|
|
public static final String qrcode = Constant.QRCODE;
|
|
public static final String qrcode = Constant.QRCODE;
|
|
public static final String httpqrcode = Constant.HTTPQRCODE;
|
|
public static final String httpqrcode = Constant.HTTPQRCODE;
|
|
|
|
+
|
|
public String createQrCode(String phone) {
|
|
public String createQrCode(String phone) {
|
|
try {
|
|
try {
|
|
MiniAppInfo miniAppInfo = miniAppInfoDao.getMiniAppInfo();
|
|
MiniAppInfo miniAppInfo = miniAppInfoDao.getMiniAppInfo();
|
|
@@ -36,11 +39,11 @@ public class MiniAppService {
|
|
// 创建httpclient对象
|
|
// 创建httpclient对象
|
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
// 创建post方式请求对象
|
|
// 创建post方式请求对象
|
|
- HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + access_token );
|
|
|
|
|
|
+ HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + access_token);
|
|
Map<String, Object> paras = new HashMap<>();
|
|
Map<String, Object> paras = new HashMap<>();
|
|
- paras.put("scene",phone);
|
|
|
|
- paras.put("page","pages/index/index");
|
|
|
|
- paras.put("width","1280px");
|
|
|
|
|
|
+ paras.put("scene", phone);
|
|
|
|
+ paras.put("page", "pages/index/index");
|
|
|
|
+ paras.put("width", "1280px");
|
|
paras.put("auto_color", true);
|
|
paras.put("auto_color", true);
|
|
String jsonstr = JSON.toJSONString(paras);
|
|
String jsonstr = JSON.toJSONString(paras);
|
|
StringEntity stringEntity = new StringEntity(jsonstr);
|
|
StringEntity stringEntity = new StringEntity(jsonstr);
|
|
@@ -49,6 +52,10 @@ public class MiniAppService {
|
|
httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json");
|
|
httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json");
|
|
httpPost.setEntity(stringEntity);
|
|
httpPost.setEntity(stringEntity);
|
|
stringEntity.setContentType("image/png");
|
|
stringEntity.setContentType("image/png");
|
|
|
|
+ File fileDel = new File(qrcode + "/" + phone + ".png");
|
|
|
|
+ if (fileDel.exists()) {
|
|
|
|
+ fileDel.delete();
|
|
|
|
+ }
|
|
CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
|
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
|
InputStream inputStream = response.getEntity().getContent();
|
|
InputStream inputStream = response.getEntity().getContent();
|
|
@@ -56,7 +63,7 @@ public class MiniAppService {
|
|
//保存到数据库
|
|
//保存到数据库
|
|
byte[] buffer = new byte[8192];
|
|
byte[] buffer = new byte[8192];
|
|
int bytesRead = 0;
|
|
int bytesRead = 0;
|
|
- while((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
|
|
|
|
|
|
+ while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
|
|
out.write(buffer, 0, bytesRead);
|
|
out.write(buffer, 0, bytesRead);
|
|
}
|
|
}
|
|
out.flush();
|
|
out.flush();
|
|
@@ -70,15 +77,17 @@ public class MiniAppService {
|
|
return "error";
|
|
return "error";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
public int initQrcode() {
|
|
public int initQrcode() {
|
|
try {
|
|
try {
|
|
List<DcIntroducer> dcIntroducers = dcIntroducerService.initIntroducers();
|
|
List<DcIntroducer> dcIntroducers = dcIntroducerService.initIntroducers();
|
|
- for (DcIntroducer di:dcIntroducers){
|
|
|
|
|
|
+ for (DcIntroducer di : dcIntroducers) {
|
|
DcIntroducer dcIntroducerNew = new DcIntroducer();
|
|
DcIntroducer dcIntroducerNew = new DcIntroducer();
|
|
dcIntroducerNew.setId(di.getId());
|
|
dcIntroducerNew.setId(di.getId());
|
|
dcIntroducerNew.setWv_phone(di.getWv_phone());
|
|
dcIntroducerNew.setWv_phone(di.getWv_phone());
|
|
dcIntroducerNew.setWv_qrcode(createQrCode(di.getWv_phone()));
|
|
dcIntroducerNew.setWv_qrcode(createQrCode(di.getWv_phone()));
|
|
dcIntroducerService.updateDcIntroducer(dcIntroducerNew);
|
|
dcIntroducerService.updateDcIntroducer(dcIntroducerNew);
|
|
|
|
+ Thread.sleep(3000);
|
|
}
|
|
}
|
|
} catch (Exception ex) {
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
ex.printStackTrace();
|