Przeglądaj źródła

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

release_toaliyun_real
Stormeye.Wu 7 lat temu
rodzic
commit
0b33a16cea
2 zmienionych plików z 34 dodań i 29 usunięć
  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 Wyświetl plik

@@ -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<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 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());


+ 29
- 19
mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java Wyświetl plik

@@ -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<WxAppinfo> 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<WxAppinfo> 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());


Ładowanie…
Anuluj
Zapisz