|
|
|
@@ -1,14 +1,21 @@ |
|
|
|
package com.iformall.controller; |
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.WxAppinfo; |
|
|
|
import com.iformall.enums.EnumAppType; |
|
|
|
import com.iformall.service.WxAppinfoService; |
|
|
|
import com.iformall.service.wechat.FmOpenService; |
|
|
|
import com.iformall.utils.Constant; |
|
|
|
import com.iformall.utils.QRCodeUtils; |
|
|
|
import io.swagger.annotations.ApiImplicitParam; |
|
|
|
import io.swagger.annotations.ApiImplicitParams; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import me.chanjar.weixin.common.error.WxErrorException; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
@@ -17,6 +24,11 @@ import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@RestController |
|
|
|
@@ -27,6 +39,9 @@ public class WxAppinfoController extends BaseController { |
|
|
|
@Autowired |
|
|
|
private WxAppinfoService wxAppinfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private FmOpenService openService; |
|
|
|
|
|
|
|
@ApiOperation("分页列表接口") |
|
|
|
@GetMapping("list") |
|
|
|
@ApiImplicitParams({ |
|
|
|
@@ -99,7 +114,7 @@ public class WxAppinfoController extends BaseController { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "pageUrl不能为空"); |
|
|
|
} |
|
|
|
try { |
|
|
|
wxAppinfoService.exportQrcode(request, response, |
|
|
|
exportQrcode(request, response, |
|
|
|
getTenantId(), type, pageUrl, sceneParam, |
|
|
|
withText, text1, text2); |
|
|
|
} catch (Exception e) { |
|
|
|
@@ -109,5 +124,111 @@ public class WxAppinfoController extends BaseController { |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
private void exportQrcode(HttpServletRequest request, HttpServletResponse response, |
|
|
|
String tenantId, int type, String pageUrl, String sceneParam, |
|
|
|
int withText, String text1, String text2 ) { |
|
|
|
// type 0 有限二维码, 1 无限制二维码 |
|
|
|
// withText 0 不带字 1. 带下面的字,2 带下面的两行字 |
|
|
|
WxAppinfo appinfo = wxAppinfoService.getCAppInfo(tenantId); |
|
|
|
boolean autoColor = false; |
|
|
|
boolean isHyaline = true; |
|
|
|
WxMaCodeLineColor color = new WxMaCodeLineColor("0", "0", "0"); |
|
|
|
|
|
|
|
WxMaService wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appinfo.getAppId()); |
|
|
|
|
|
|
|
String pathStr = ""; |
|
|
|
if (StringUtils.isNotBlank(sceneParam)) { |
|
|
|
pathStr = pageUrl + "?scene="+sceneParam; |
|
|
|
} else { |
|
|
|
pathStr = pageUrl; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String filepath = Constant.fileDirectory; |
|
|
|
String fileName = sceneParam + ".png"; |
|
|
|
String destPath1 = filepath + "1_" + fileName; |
|
|
|
String destPath = filepath + fileName; |
|
|
|
|
|
|
|
File dest = new File(destPath); |
|
|
|
File pDest = dest.getParentFile(); |
|
|
|
if (!pDest.exists()) { |
|
|
|
pDest.mkdirs(); |
|
|
|
} |
|
|
|
try { |
|
|
|
if(type == 0) { |
|
|
|
final File codeFile = wxMaService.getQrcodeService().createQrcode(pathStr, QRCodeUtils.QR_WIDTH); |
|
|
|
if (withText == 1) { |
|
|
|
File dest1 = new File(destPath1); |
|
|
|
org.apache.commons.io.FileUtils.copyFile(codeFile, dest1); |
|
|
|
QRCodeUtils.graphicsGeneration(dest1, dest, text1); |
|
|
|
org.apache.commons.io.FileUtils.forceDelete(dest1); |
|
|
|
} else if (withText == 2) { |
|
|
|
File dest1 = new File(destPath1); |
|
|
|
org.apache.commons.io.FileUtils.copyFile(codeFile, dest1); |
|
|
|
QRCodeUtils.graphicsGeneration2(dest1, dest, text1, text2); |
|
|
|
org.apache.commons.io.FileUtils.forceDelete(dest1); |
|
|
|
} else { |
|
|
|
org.apache.commons.io.FileUtils.copyFile(codeFile, dest); |
|
|
|
} |
|
|
|
org.apache.commons.io.FileUtils.forceDelete(codeFile); |
|
|
|
} else { |
|
|
|
final File codeFile = wxMaService.getQrcodeService().createWxaCodeUnlimit(sceneParam, pageUrl, QRCodeUtils.QR_WIDTH, autoColor, color, isHyaline); |
|
|
|
if (withText == 1) { |
|
|
|
File dest1 = new File(destPath1); |
|
|
|
org.apache.commons.io.FileUtils.copyFile(codeFile, dest1); |
|
|
|
QRCodeUtils.graphicsGeneration(dest1, dest, text1); |
|
|
|
org.apache.commons.io.FileUtils.forceDelete(dest1); |
|
|
|
} else if (withText == 2) { |
|
|
|
File dest1 = new File(destPath1); |
|
|
|
org.apache.commons.io.FileUtils.copyFile(codeFile, dest1); |
|
|
|
QRCodeUtils.graphicsGeneration2(dest1, dest, text1, text2); |
|
|
|
org.apache.commons.io.FileUtils.forceDelete(dest1); |
|
|
|
} else { |
|
|
|
org.apache.commons.io.FileUtils.copyFile(codeFile, dest); |
|
|
|
} |
|
|
|
org.apache.commons.io.FileUtils.forceDelete(codeFile); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (WxErrorException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
downFile(destPath, fileName, response, request); |
|
|
|
org.apache.commons.io.FileUtils.forceDelete(dest); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void downFile(String filePath, String filename, HttpServletResponse response, HttpServletRequest req) throws IOException { |
|
|
|
try { |
|
|
|
response.reset(); |
|
|
|
response.setContentType("bin"); |
|
|
|
String agent = req.getHeader("user-agent"); |
|
|
|
if (agent.contains("Firefox")) { |
|
|
|
response.setHeader("Content-disposition", |
|
|
|
"attachment; filename=" |
|
|
|
+ new String(filename.getBytes("GB2312"),"ISO-8859-1")); |
|
|
|
} else { |
|
|
|
response.setHeader("Content-disposition", |
|
|
|
"attachment; filename=" |
|
|
|
+ java.net.URLEncoder.encode(filename,"UTF-8")); |
|
|
|
} |
|
|
|
// 循环取出流中的数据 |
|
|
|
byte[] b = new byte[1024]; |
|
|
|
int len; |
|
|
|
InputStream inStream = new FileInputStream(filePath); |
|
|
|
while ((len = inStream.read(b)) > 0) |
|
|
|
response.getOutputStream().write(b, 0, len); |
|
|
|
inStream.close(); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |