From 0b33a16cead9ba028e9e4c8a9a51c9904d47bf9f Mon Sep 17 00:00:00 2001 From: "Stormeye.Wu" Date: Fri, 12 Oct 2018 13:33:58 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BA=8C=E7=BB=B4=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3][=E6=96=B0=E5=A2=9E]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WxAppinfoController.java | 15 ++---- .../service/impl/WxAppinfoServiceImpl.java | 48 +++++++++++-------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxAppinfoController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxAppinfoController.java index 67fcc5a35..a79832b43 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxAppinfoController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxAppinfoController.java @@ -72,10 +72,9 @@ public class WxAppinfoController extends BaseController { @ApiOperation("更新AccessToken, 无限制二维码生成需要更新token") @GetMapping("/accessTokenUpdate") - @ApiImplicitParam(name = "appId", value = "c端小程序appId", dataType = "String", paramType = "query", required = true) - public ResultData tokenUpdate(String appId) { + public ResultData tokenUpdate() { try { - wxAppinfoService.tokenUpdate(appId); + wxAppinfoService.tokenUpdate(getTenantId()); } catch (Exception e) { logger.error(e.getMessage()); } @@ -83,10 +82,9 @@ public class WxAppinfoController extends BaseController { return new ResultData(); } - @ApiOperation(value = "下载二维码", notes = "参数{\"appId\":\"String\", \"pageUrl\":\"String\", \"sceneParam\":\"二维码参数\", \"type\":\"0:有限二维码,1:无限二维码\",\"withText\":\"int(0:不带字, 1:加一行字,2:加两行字)\",\"text1\":\"String\",\"text2\":\"String\"") + @ApiOperation(value = "下载二维码", notes = "参数{\"pageUrl\":\"String\", \"sceneParam\":\"二维码参数\", \"type\":\"0:有限二维码,1:无限二维码\",\"withText\":\"int(0:不带字, 1:加一行字,2:加两行字)\",\"text1\":\"String\",\"text2\":\"String\"}") @PostMapping("/downQrCode") - public ResultData downQrCode(@RequestBody Map params, HttpServletRequest request, HttpServletResponse response) { - String appId = (String) params.get("appId"); + public ResultData downQrCode(HttpServletRequest request, HttpServletResponse response, @RequestBody Map params) { String pageUrl = (String) params.get("pageUrl"); String sceneParam = (String) params.get("sceneParam"); int type = 0; @@ -104,15 +102,12 @@ public class WxAppinfoController extends BaseController { } String text1 = (String) params.get("text1"); String text2 = (String) params.get("text2"); - if (StringUtils.isBlank(appId)) { - return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "appId不能为空"); - } if (StringUtils.isBlank(pageUrl)) { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "pageUrl不能为空"); } try { wxAppinfoService.exportQrcode(request, response, - appId, type, pageUrl, sceneParam, + getTenantId(), type, pageUrl, sceneParam, withText, text1, text2); } catch (Exception e) { logger.error(e.getMessage()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java index 537a80708..1cb71983a 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java @@ -8,6 +8,7 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.iformall.common.ErrorCode; import com.iformall.domain.po.WxAppinfo; +import com.iformall.enums.EnumAppType; import com.iformall.exception.MallinkException; import com.iformall.mapper.WxAppinfoMapper; import com.iformall.service.WxAppinfoService; @@ -28,6 +29,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Date; +import java.util.List; @Service public class WxAppinfoServiceImpl implements WxAppinfoService { @@ -70,12 +72,15 @@ public class WxAppinfoServiceImpl implements WxAppinfoService { @Override - public void tokenUpdate(String appId) { - WxAppinfo appinfo = wxAppinfoMapper.findByAppId(appId); - if (appinfo == null) { - logger.error("APPID Not found: ", appId); - throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + public void tokenUpdate(String tenantId) { + WxAppinfo appQ = new WxAppinfo(); + appQ.setTenantId(tenantId); + appQ.setType(EnumAppType.C.getCode()); + List appList = wxAppinfoMapper.findList(appQ); + if (appList.size() <= 0) { + return; } + WxAppinfo appinfo = appList.get(0); // get access_token WxMaInMemoryConfig config = new WxMaInMemoryConfig(); config.setAppid(appinfo.getAppId()); @@ -128,15 +133,18 @@ public class WxAppinfoServiceImpl implements WxAppinfoService { @Override public void exportQrcode(HttpServletRequest request, HttpServletResponse response, - String appId, int type, String pageUrl, String sceneParam, + String tenantId, int type, String pageUrl, String sceneParam, int withText, String text1, String text2 ) { // type 0 有限二维码, 1 无限制二维码 // withText 0 不带字 1. 带下面的字,2 带下面的两行字 - WxAppinfo appinfo = wxAppinfoMapper.findByAppId(appId); - if (appinfo == null) { - logger.error("APPID Not found: ", appId); + WxAppinfo appQ = new WxAppinfo(); + appQ.setTenantId(tenantId); + appQ.setType(EnumAppType.C.getCode()); + List appList = wxAppinfoMapper.findList(appQ); + if (appList.size() <= 0) { return; } + WxAppinfo appinfo = appList.get(0); boolean autoColor = false; boolean isHyaline = true; WxMaCodeLineColor color = new WxMaCodeLineColor("0", "0", "0"); @@ -166,22 +174,24 @@ public class WxAppinfoServiceImpl implements WxAppinfoService { } try { Date imgDate = new Date(); - if(StringUtils.isBlank(sceneParam)) { - final File wxCode = wxMaService.getQrcodeService().createQrcode(pathStr, QRCodeUtils.QR_WIDTH); + if(type == 0) { + final File codeFile = wxMaService.getQrcodeService().createQrcode(pathStr, QRCodeUtils.QR_WIDTH); if (type == 1) { - QRCodeUtils.graphicsGeneration(wxCode, dest, text1); + QRCodeUtils.graphicsGeneration(codeFile, dest, text1); } else if (type == 2) { - QRCodeUtils.graphicsGeneration2(wxCode, dest, text1, text2); + QRCodeUtils.graphicsGeneration2(codeFile, dest, text1, text2); } - wxCode.renameTo(dest); + org.apache.commons.io.FileUtils.copyFile(codeFile, dest); + org.apache.commons.io.FileUtils.forceDelete(codeFile); } else { - final File wxCode = wxMaService.getQrcodeService().createWxaCodeUnlimit(sceneParam, pageUrl, QRCodeUtils.QR_WIDTH, autoColor, color, isHyaline); + final File codeFile = wxMaService.getQrcodeService().createWxaCodeUnlimit(sceneParam, pageUrl, QRCodeUtils.QR_WIDTH, autoColor, color, isHyaline); if (type == 1) { - QRCodeUtils.graphicsGeneration(wxCode, dest, text1); + QRCodeUtils.graphicsGeneration(codeFile, dest, text1); } else if (type == 2) { - QRCodeUtils.graphicsGeneration2(wxCode, dest, text1, text2); + QRCodeUtils.graphicsGeneration2(codeFile, dest, text1, text2); } - wxCode.renameTo(dest); + org.apache.commons.io.FileUtils.copyFile(codeFile, dest); + org.apache.commons.io.FileUtils.forceDelete(codeFile); } } catch (WxErrorException e) { @@ -191,7 +201,7 @@ public class WxAppinfoServiceImpl implements WxAppinfoService { } try { - downFile(filepath, fileName, response, request); + downFile(destPath, fileName, response, request); org.apache.commons.io.FileUtils.forceDelete(dest); } catch (Exception e) { logger.error(e.getMessage());