|
|
|
@@ -23,9 +23,11 @@ import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.WxMall; |
|
|
|
import com.iformall.domain.po.WxPayAccount; |
|
|
|
import com.iformall.domain.po.base.TenantEntity; |
|
|
|
import com.iformall.service.WxMallService; |
|
|
|
import com.iformall.service.WxPayAccountService; |
|
|
|
import com.iformall.service.pay.alipay.AliPayUtil; |
|
|
|
import com.iformall.utils.ImgUtil; |
|
|
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParam; |
|
|
|
import io.swagger.annotations.ApiImplicitParams; |
|
|
|
@@ -53,9 +55,18 @@ public class AlipayController extends BaseController { |
|
|
|
return new ResultData(aliPayUtil.getAppAuthUrl(wxMall.getTenantId())); |
|
|
|
} |
|
|
|
|
|
|
|
@ApiOperation("图片上传") |
|
|
|
@PostMapping(value = "/imageUpload",consumes = "multipart/*", headers = "content-type=multipart/form-data") |
|
|
|
public ResultData imageUpload(@RequestParam("file") MultipartFile multiReq,@RequestParam Map<String, String> param) { |
|
|
|
/** |
|
|
|
* 图片上传 |
|
|
|
* |
|
|
|
* @param multiReq |
|
|
|
* @return |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
@PostMapping(value = "/imageUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") |
|
|
|
@ApiOperation("上传图片") |
|
|
|
@SystemControllerLog(description = "上传图片") |
|
|
|
public ResultData imageUpload(@RequestParam("files") MultipartFile multiReq |
|
|
|
,@RequestParam Map<String, String> param) { |
|
|
|
String tenantId = param.get("tenantId"); |
|
|
|
if (StringUtils.isBlank(tenantId)) { |
|
|
|
return new ResultData(Result.ERROR,"tenantId不能为空"); |
|
|
|
@@ -67,45 +78,55 @@ public class AlipayController extends BaseController { |
|
|
|
if(StringUtils.isBlank(wxMall.getAlipayAppAuthToken())) { |
|
|
|
return new ResultData(Result.ERROR,"wxMall alipayAppAuthToken为空"); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
long size = multiReq.getSize(); |
|
|
|
final long length = 2097152; |
|
|
|
if (size > length) { |
|
|
|
return new ResultData(ErrorCode.PICTURE_SIZE_EXCEED); |
|
|
|
} |
|
|
|
long maxSize = 0l; |
|
|
|
try { |
|
|
|
maxSize = Long.parseLong(param.get("size")); |
|
|
|
} catch (NumberFormatException e) {} |
|
|
|
if(maxSize > 0l && size > maxSize*1024){ |
|
|
|
return new ResultData(ErrorCode.PICTURE_SIZE_CUSTOMIZE); |
|
|
|
|
|
|
|
long size = multiReq.getSize(); |
|
|
|
final long length = 2097152; |
|
|
|
if (size > length) { |
|
|
|
return new ResultData(ErrorCode.PICTURE_SIZE_EXCEED); |
|
|
|
} |
|
|
|
|
|
|
|
String fileFormat = ""; |
|
|
|
try { |
|
|
|
int dot = multiReq.getOriginalFilename().lastIndexOf('.'); |
|
|
|
if (dot >= 0) { |
|
|
|
fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); |
|
|
|
} |
|
|
|
BufferedImage bufferedImage = ImageIO.read(multiReq.getInputStream()); |
|
|
|
if(bufferedImage != null){ |
|
|
|
int width = 0;int hight = 0; |
|
|
|
|
|
|
|
String imgFormat = ImgUtil.getImgFormat(fileFormat); |
|
|
|
if(StringUtils.isNotBlank(imgFormat)) { |
|
|
|
long maxSize = 0l; |
|
|
|
try { |
|
|
|
width = Integer.parseInt(param.get("width")); |
|
|
|
hight = Integer.parseInt(param.get("hight")); |
|
|
|
maxSize = Long.parseLong(param.get("size")); |
|
|
|
} catch (NumberFormatException e) {} |
|
|
|
Integer relWidth = bufferedImage.getWidth(); |
|
|
|
Integer relHeight = bufferedImage.getHeight(); |
|
|
|
if((width > 0 && width != relWidth.intValue()) |
|
|
|
|| (hight > 0 && hight != relHeight.intValue())){ |
|
|
|
return new ResultData(ErrorCode.PICTURE_W_H_CUSTOMIZE); |
|
|
|
if(maxSize > 0l && size > maxSize*1024){ |
|
|
|
return new ResultData(ErrorCode.PICTURE_SIZE_CUSTOMIZE); |
|
|
|
} |
|
|
|
} |
|
|
|
String imageId = aliPayUtil.merchantImageUpload(wxMall.getAlipayAppAuthToken(), multiReq.getOriginalFilename(), multiReq.getBytes()); |
|
|
|
BufferedImage bufferedImage = ImageIO.read(multiReq.getInputStream()); |
|
|
|
if(bufferedImage != null){ |
|
|
|
int width = 0;int hight = 0; |
|
|
|
try { |
|
|
|
width = Integer.parseInt(param.get("width")); |
|
|
|
hight = Integer.parseInt(param.get("hight")); |
|
|
|
} catch (NumberFormatException e) {} |
|
|
|
Integer relWidth = bufferedImage.getWidth(); |
|
|
|
Integer relHeight = bufferedImage.getHeight(); |
|
|
|
if((width > 0 && width != relWidth.intValue()) |
|
|
|
|| (hight > 0 && hight != relHeight.intValue())){ |
|
|
|
return new ResultData(ErrorCode.PICTURE_W_H_CUSTOMIZE); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
String imageId = aliPayUtil.merchantImageUpload(wxMall.getAlipayAppAuthToken(), multiReq.getOriginalFilename(), multiReq.getBytes()); |
|
|
|
if (StringUtils.isBlank(imageId)) { |
|
|
|
return new ResultData(Result.ERROR,"imageId 返回空"); |
|
|
|
}else { |
|
|
|
return new ResultData(imageId); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
logger.error("alipay imageUpload error.",e); |
|
|
|
return new ResultData(Result.ERROR,"上传错误"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("解析图片",e); |
|
|
|
return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ApiOperation("创建商圈会员卡") |
|
|
|
|