Просмотр исходного кода

[qrcode][修改]:二维码生成问题

release_toaliyun_real
Stormeye Wu 6 лет назад
Родитель
Сommit
4ae7c822fd
9 измененных файлов: 110 добавлений и 57 удалений
  1. +3
    -3
      mallinkAdmin/src/main/java/com/iformall/controller/app/WxAppinfoController.java
  2. +1
    -1
      mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantController.java
  3. +1
    -1
      mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java
  4. +4
    -1
      mallinkService/src/main/java/com/iformall/service/QrCodeService.java
  5. +97
    -47
      mallinkService/src/main/java/com/iformall/service/impl/QrCodeServiceImpl.java
  6. +1
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxCampaignServiceImpl.java
  7. +1
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java
  8. +1
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java
  9. +1
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxTopicServiceImpl.java

+ 3
- 3
mallinkAdmin/src/main/java/com/iformall/controller/app/WxAppinfoController.java Просмотреть файл

@@ -55,7 +55,7 @@ public class WxAppinfoController extends BaseController {
@Override
public void run() {
String param = merchant.getWeappScene();
ResultData resultData = qrCodeService.exportQrcode(null, null, merchant.getTenantId(), 1, pageUrl, param, 0, "", "", "店铺详情", true);
ResultData resultData = qrCodeService.uploadQrcode(merchant.getTenantId(), 1, pageUrl, param, 0, "", "", "店铺详情");
Map<String, String> map = (Map) resultData.data;
if(map!=null && map.get("url") !=null) {
String url = map.get("url");
@@ -81,7 +81,7 @@ public class WxAppinfoController extends BaseController {
@Override
public void run() {
String param = couponChannel.getWeappScene();
ResultData resultData = qrCodeService.exportQrcode(null,null,couponChannel.getTenantId(),1,pageUrl,param,0,"","","卷",true);
ResultData resultData = qrCodeService.uploadQrcode(couponChannel.getTenantId(),1,pageUrl,param,0,"","","卷");
Map<String,String> map = (Map)resultData.data;
if(map!=null && map.get("url") !=null) {
String url = map.get("url");
@@ -124,7 +124,7 @@ public class WxAppinfoController extends BaseController {
qrCodeService.exportQrcode(request, response,
getTenantId(), type, pageUrl, sceneParam,
withText, text1, text2,
name,false);
name);
} catch (Exception e) {
logger.error(e.getMessage());
throw new MallinkException(Result.ERROR, "下载异常");


+ 1
- 1
mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantController.java Просмотреть файл

@@ -138,7 +138,7 @@ public class WxMerchantController extends BaseController {
//加载二维码图片
String pageUrl = "pages/index/index";
String param = "t:md:"+resultData.data;
ResultData resultQrCode = qrCodeService.exportQrcode(null,null,wxMerchant.getTenantId(),1,pageUrl,param,0,"","","店铺详情",true);
ResultData resultQrCode = qrCodeService.uploadQrcode(wxMerchant.getTenantId(),1,pageUrl,param,0,"","","店铺详情");
Map<String,String> map = (Map)resultQrCode.data;
if(map!=null && map.get("url") !=null) {
String url = map.get("url");


+ 1
- 1
mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java Просмотреть файл

@@ -86,7 +86,7 @@ public class WxCouponChannelController extends BaseController {
if(couponChannel!=null){
String pageUrl = "pages/index/index";
String param = couponChannel.getWeappScene();
ResultData resultDataQ = qrCodeService.exportQrcode(null,null,couponChannel.getTenantId(),1,pageUrl,param,0,"","","卷",true);
ResultData resultDataQ = qrCodeService.uploadQrcode(couponChannel.getTenantId(),1,pageUrl,param,0,"","","卷");
Map<String,String> map = (Map)resultDataQ.data;
if(map!=null && map.get("url") !=null) {
String url = map.get("url");


+ 4
- 1
mallinkService/src/main/java/com/iformall/service/QrCodeService.java Просмотреть файл

@@ -18,6 +18,9 @@ public interface QrCodeService {
ResultData exportQrcode(HttpServletRequest request, HttpServletResponse response,
String tenantId, int type, String pageUrl, String sceneParam,
int withText, String text1, String text2,
String name, boolean upload);
String name);
ResultData uploadQrcode(String tenantId, int type, String pageUrl, String sceneParam,
int withText, String text1, String text2,
String name);
ResultData awsUpload(InputStream inputStream, ObjectMetadata metadata, String fileName, String tenantId);
}

+ 97
- 47
mallinkService/src/main/java/com/iformall/service/impl/QrCodeServiceImpl.java Просмотреть файл

@@ -151,7 +151,7 @@ public class QrCodeServiceImpl implements QrCodeService {
exportQrcode(request, response,
tenantId, type, pageUrl, sceneParam,
withText, text1, text2,
name,false);
name);
} catch (Exception e) {
logger.error(e.getMessage());
throw new MallinkException(Result.ERROR, "下载异常");
@@ -162,7 +162,7 @@ public class QrCodeServiceImpl implements QrCodeService {
public ResultData exportQrcode(HttpServletRequest request, HttpServletResponse response,
String tenantId, int type, String pageUrl, String sceneParam,
int withText, String text1, String text2,
String name, boolean upload) {
String name) {
// type 0 有限二维码, 1 无限制二维码
// withText 0 不带字 1. 带下面的字,2 带下面的两行字
WxAppinfo appinfo = wxAppinfoService.getCAppInfo(tenantId);
@@ -198,35 +198,73 @@ public class QrCodeServiceImpl implements QrCodeService {
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);
}
copyFileToDest(withText, text1, text2, destPath1, dest, codeFile);
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);
}
copyFileToDest(withText, text1, text2, destPath1, dest, codeFile);
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());
}
return new ResultData();
}

@Override
public ResultData uploadQrcode(String tenantId, int type, String pageUrl, String sceneParam,
int withText, String text1, String text2,
String name) {
// 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;
if(isFmOpen) {
wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appinfo.getAppId());
} else {
wxMaService = MaUtil.getWeappService(appinfo);
}

String pathStr = "";
if (StringUtils.isNotBlank(sceneParam)) {
pathStr = pageUrl + "?scene="+sceneParam;
} else {
pathStr = pageUrl;
}


String filepath = fmUploadDir;
String fileName = name + ".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);
copyFileToDest(withText, text1, text2, destPath1, dest, codeFile);
org.apache.commons.io.FileUtils.forceDelete(codeFile);
} else {
final File codeFile = wxMaService.getQrcodeService().createWxaCodeUnlimit(sceneParam, pageUrl, QRCodeUtils.QR_WIDTH, autoColor, color, isHyaline);
copyFileToDest(withText, text1, text2, destPath1, dest, codeFile);
org.apache.commons.io.FileUtils.forceDelete(codeFile);
}

@@ -238,34 +276,46 @@ public class QrCodeServiceImpl implements QrCodeService {

try {
//上传
if (upload){
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("image/jpeg");
metadata.setContentLength(dest.length());

FileOutputStream fos = null;
BufferedInputStream fs = null;

String fn = UUID.randomUUID().toString();
int dot = fileName.lastIndexOf('.');
if (dot >= 0) {
fn = tenantId + "/" + fn + dest.getName().substring(dot, dest.getName().length());
} else {
fn = tenantId + "/" + fn;
}

ResultData data = awsUpload(new FileInputStream(dest), metadata, fn, tenantId);
return data;
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("image/jpeg");
metadata.setContentLength(dest.length());

FileOutputStream fos = null;
BufferedInputStream fs = null;

String fn = UUID.randomUUID().toString();
int dot = fileName.lastIndexOf('.');
if (dot >= 0) {
fn = tenantId + "/" + fn + dest.getName().substring(dot, dest.getName().length());
} else {
fn = tenantId + "/" + fn;
}

downFile(destPath, fileName, response, request);
ResultData data = awsUpload(new FileInputStream(dest), metadata, fn, tenantId);
org.apache.commons.io.FileUtils.forceDelete(dest);
return data;
} catch (Exception e) {
logger.error(e.getMessage());
}
return new ResultData();
}

private void copyFileToDest(int withText, String text1, String text2, String destPath1, File dest, File codeFile) throws IOException {
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);
}
}

private void downFile(String filePath, String filename, HttpServletResponse response, HttpServletRequest req) throws IOException {
try {
response.reset();


+ 1
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxCampaignServiceImpl.java Просмотреть файл

@@ -269,7 +269,7 @@ public class WxCampaignServiceImpl implements WxCampaignService {
couponChannel.setId(wxCouponChannel.getId());
couponChannel.setType(wxCouponChannel.getType());
String param = couponChannel.getWeappScene();
ResultData resultDataQ = qrCodeService.exportQrcode(null,null,wxCoupon.getTenantId(),1,pageUrl,param,0,"","","卷",true);
ResultData resultDataQ = qrCodeService.uploadQrcode(wxCoupon.getTenantId(),1,pageUrl,param,0,"","","卷");
Map<String,String> map = (Map)resultDataQ.data;
if(map!=null && map.get("url") !=null) {
String url = map.get("url");


+ 1
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java Просмотреть файл

@@ -265,7 +265,7 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService {
couponChannel.setId(vo.getId());
couponChannel.setType(vo.getType());
String param = couponChannel.getWeappScene();
ResultData resultDataQ = qrCodeService.exportQrcode(null,null,wxCoupon.getTenantId(),1,pageUrl,param,0,"","","卷",true);
ResultData resultDataQ = qrCodeService.uploadQrcode(wxCoupon.getTenantId(),1,pageUrl,param,0,"","","卷");
Map<String,String> map = (Map)resultDataQ.data;
if(map!=null && map.get("url") !=null) {
String url = map.get("url");


+ 1
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java Просмотреть файл

@@ -317,7 +317,7 @@ public class WxGameServiceImpl implements WxGameService {
couponChannel.setId(wxCouponChannel.getId());
couponChannel.setType(wxCouponChannel.getType());
String param = couponChannel.getWeappScene();
ResultData resultDataQ = qrCodeService.exportQrcode(null,null,wxCoupon.getTenantId(),1,pageUrl,param,0,"","","卷",true);
ResultData resultDataQ = qrCodeService.uploadQrcode(wxCoupon.getTenantId(),1,pageUrl,param,0,"","","卷");
Map<String,String> map = (Map)resultDataQ.data;
if(map!=null && map.get("url") !=null) {
String url = map.get("url");


+ 1
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxTopicServiceImpl.java Просмотреть файл

@@ -140,7 +140,7 @@ public class WxTopicServiceImpl implements WxTopicService {
couponChannel.setId(wxCouponChannel.getId());
couponChannel.setType(wxCouponChannel.getType());
String param = couponChannel.getWeappScene();
ResultData resultDataQ = qrCodeService.exportQrcode(null,null,wxCoupon.getTenantId(),1,pageUrl,param,0,"","","卷",true);
ResultData resultDataQ = qrCodeService.uploadQrcode(wxCoupon.getTenantId(),1,pageUrl,param,0,"","","卷");
Map<String,String> map = (Map)resultDataQ.data;
if(map!=null && map.get("url") !=null) {
String url = map.get("url");


Загрузка…
Отмена
Сохранить