Ver a proveniência

[二维码生成接口][新增]

release_toaliyun_real
Stormeye.Wu há 7 anos
ascendente
cometimento
0b33a16cea
2 ficheiros alterados com 34 adições e 29 eliminações
  1. +5
    -10
      mallinkAdmin/src/main/java/com/iformall/controller/WxAppinfoController.java
  2. +29
    -19
      mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java

+ 5
- 10
mallinkAdmin/src/main/java/com/iformall/controller/WxAppinfoController.java Ver ficheiro

@@ -72,10 +72,9 @@ public class WxAppinfoController extends BaseController {


@ApiOperation("更新AccessToken, 无限制二维码生成需要更新token") @ApiOperation("更新AccessToken, 无限制二维码生成需要更新token")
@GetMapping("/accessTokenUpdate") @GetMapping("/accessTokenUpdate")
@ApiImplicitParam(name = "appId", value = "c端小程序appId", dataType = "String", paramType = "query", required = true)
public ResultData tokenUpdate(String appId) {
public ResultData tokenUpdate() {
try { try {
wxAppinfoService.tokenUpdate(appId);
wxAppinfoService.tokenUpdate(getTenantId());
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage()); logger.error(e.getMessage());
} }
@@ -83,10 +82,9 @@ public class WxAppinfoController extends BaseController {
return new ResultData(); 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") @PostMapping("/downQrCode")
public ResultData downQrCode(@RequestBody Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) {
String appId = (String) params.get("appId");
public ResultData downQrCode(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> params) {
String pageUrl = (String) params.get("pageUrl"); String pageUrl = (String) params.get("pageUrl");
String sceneParam = (String) params.get("sceneParam"); String sceneParam = (String) params.get("sceneParam");
int type = 0; int type = 0;
@@ -104,15 +102,12 @@ public class WxAppinfoController extends BaseController {
} }
String text1 = (String) params.get("text1"); String text1 = (String) params.get("text1");
String text2 = (String) params.get("text2"); String text2 = (String) params.get("text2");
if (StringUtils.isBlank(appId)) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "appId不能为空");
}
if (StringUtils.isBlank(pageUrl)) { if (StringUtils.isBlank(pageUrl)) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "pageUrl不能为空"); return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "pageUrl不能为空");
} }
try { try {
wxAppinfoService.exportQrcode(request, response, wxAppinfoService.exportQrcode(request, response,
appId, type, pageUrl, sceneParam,
getTenantId(), type, pageUrl, sceneParam,
withText, text1, text2); withText, text1, text2);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage()); logger.error(e.getMessage());


+ 29
- 19
mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java Ver ficheiro

@@ -8,6 +8,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode; import com.iformall.common.ErrorCode;
import com.iformall.domain.po.WxAppinfo; import com.iformall.domain.po.WxAppinfo;
import com.iformall.enums.EnumAppType;
import com.iformall.exception.MallinkException; import com.iformall.exception.MallinkException;
import com.iformall.mapper.WxAppinfoMapper; import com.iformall.mapper.WxAppinfoMapper;
import com.iformall.service.WxAppinfoService; import com.iformall.service.WxAppinfoService;
@@ -28,6 +29,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Date; import java.util.Date;
import java.util.List;


@Service @Service
public class WxAppinfoServiceImpl implements WxAppinfoService { public class WxAppinfoServiceImpl implements WxAppinfoService {
@@ -70,12 +72,15 @@ public class WxAppinfoServiceImpl implements WxAppinfoService {
@Override @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<WxAppinfo> appList = wxAppinfoMapper.findList(appQ);
if (appList.size() <= 0) {
return;
} }
WxAppinfo appinfo = appList.get(0);
// get access_token // get access_token
WxMaInMemoryConfig config = new WxMaInMemoryConfig(); WxMaInMemoryConfig config = new WxMaInMemoryConfig();
config.setAppid(appinfo.getAppId()); config.setAppid(appinfo.getAppId());
@@ -128,15 +133,18 @@ public class WxAppinfoServiceImpl implements WxAppinfoService {


@Override @Override
public void exportQrcode(HttpServletRequest request, HttpServletResponse response, 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 ) { int withText, String text1, String text2 ) {
// type 0 有限二维码, 1 无限制二维码 // type 0 有限二维码, 1 无限制二维码
// withText 0 不带字 1. 带下面的字,2 带下面的两行字 // 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<WxAppinfo> appList = wxAppinfoMapper.findList(appQ);
if (appList.size() <= 0) {
return; return;
} }
WxAppinfo appinfo = appList.get(0);
boolean autoColor = false; boolean autoColor = false;
boolean isHyaline = true; boolean isHyaline = true;
WxMaCodeLineColor color = new WxMaCodeLineColor("0", "0", "0"); WxMaCodeLineColor color = new WxMaCodeLineColor("0", "0", "0");
@@ -166,22 +174,24 @@ public class WxAppinfoServiceImpl implements WxAppinfoService {
} }
try { try {
Date imgDate = new Date(); 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) { if (type == 1) {
QRCodeUtils.graphicsGeneration(wxCode, dest, text1);
QRCodeUtils.graphicsGeneration(codeFile, dest, text1);
} else if (type == 2) { } 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 { } 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) { if (type == 1) {
QRCodeUtils.graphicsGeneration(wxCode, dest, text1);
QRCodeUtils.graphicsGeneration(codeFile, dest, text1);
} else if (type == 2) { } 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) { } catch (WxErrorException e) {
@@ -191,7 +201,7 @@ public class WxAppinfoServiceImpl implements WxAppinfoService {
} }


try { try {
downFile(filepath, fileName, response, request);
downFile(destPath, fileName, response, request);
org.apache.commons.io.FileUtils.forceDelete(dest); org.apache.commons.io.FileUtils.forceDelete(dest);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage()); logger.error(e.getMessage());


Carregando…
Cancelar
Guardar