Ver a proveniência

fix alipay

release_toaliyun_real
xiaohanzi há 5 anos
ascendente
cometimento
7891973a0f
2 ficheiros alterados com 186 adições e 1 eliminações
  1. +186
    -0
      mallinkAdmin/src/main/java/com/iformall/controller/pay/AlipayController.java
  2. +0
    -1
      pom.xml

+ 186
- 0
mallinkAdmin/src/main/java/com/iformall/controller/pay/AlipayController.java Ver ficheiro

@@ -0,0 +1,186 @@
package com.iformall.controller.pay;

import com.iformall.annotation.SystemControllerLog;
import com.iformall.controller.base.BaseController;
import io.swagger.annotations.Api;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Map;

import javax.imageio.ImageIO;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode;
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.service.WxMallService;
import com.iformall.service.WxPayAccountService;
import com.iformall.service.pay.alipay.AliPayUtil;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("alipay")
public class AlipayController extends BaseController {
private final Logger logger = LoggerFactory.getLogger(this.getClass());

@Autowired
private AliPayUtil aliPayUtil;
@Autowired
private WxMallService mallService;

@ApiOperation("获取应用授权链接")
@GetMapping("getAppAuthUrl")
@ApiImplicitParam(name = "mallId", value = "wx_mall id", dataType = "Long", paramType = "query", required = true)
public ResultData getAppAuthUrl(Long mallId) {
WxMall wxMall = mallService.getById(mallId);
if (null == wxMall ) {
return new ResultData(Result.ERROR,"wxMall未查询到");
}
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) {
String tenantId = param.get("tenantId");
if (StringUtils.isBlank(tenantId)) {
return new ResultData(Result.ERROR,"tenantId不能为空");
}
WxMall wxMall = mallService.getByTenantId(tenantId);
if (null == wxMall ) {
return new ResultData(Result.ERROR,"wxMall未查询到");
}
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);
}
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,"上传错误");
}
}
@ApiOperation("创建商圈会员卡")
@PostMapping(value = "/merchantMemberConfig", consumes = "multipart/*", headers = "content-type=multipart/form-data")
@SystemControllerLog(description = "支付账号-新增")
public ResultData merchantMemberConfig(@RequestBody Map<String, String> param) {
String tenantId = param.get("tenantId");
if (StringUtils.isBlank(tenantId)) {
return new ResultData(Result.ERROR,"tenantId不能为空");
}
WxMall wxMall = mallService.getByTenantId(tenantId);
if (null == wxMall ) {
return new ResultData(Result.ERROR,"wxMall未查询到");
}
if(StringUtils.isBlank(wxMall.getAlipayAppAuthToken())) {
return new ResultData(Result.ERROR,"wxMall alipayAppAuthToken为空");
}
String logoId = param.get("logoId");
if (StringUtils.isBlank(logoId)) {
return new ResultData(Result.ERROR,"logoId不能为空");
}
String backgroundId = param.get("backgroundId");
if (StringUtils.isBlank(backgroundId)) {
return new ResultData(Result.ERROR,"backgroundId不能为空");
}
try {
String templateId = aliPayUtil.createSmartDistrictMemberCardModel(wxMall.getAlipayAppAuthToken(), wxMall.getName()+"会员卡", logoId, backgroundId);
if (StringUtils.isBlank(templateId)) {
return new ResultData(Result.ERROR,"模板创建失败,模板Id返回空[createSmartDistrictMemberCardModel]");
}
boolean result = aliPayUtil.setSmartDistrictMemberCardModelConfig(wxMall.getAlipayAppAuthToken(), templateId);
if (!result) {
return new ResultData(Result.ERROR,"会员卡模板配置失败[setSmartDistrictMemberCardModelConfig]");
}else {
//设置模板编号
wxMall.setAlipayMemberTemplateId(templateId);
mallService.update(wxMall);
return new ResultData();
}
} catch (Exception e) {
logger.error("merchantMemberConfig error.",e);
return new ResultData(Result.ERROR,"merchantMemberConfig error.");
}
}
@ApiOperation("消息订阅")
@PostMapping(value = "/topicSubscribe")
@SystemControllerLog(description = "支付账号-新增")
public ResultData topicSubscribe(@RequestBody Map<String, String> param) {
String tenantId = param.get("tenantId");
if (StringUtils.isBlank(tenantId)) {
return new ResultData(Result.ERROR,"tenantId不能为空");
}
WxMall wxMall = mallService.getByTenantId(tenantId);
if (null == wxMall ) {
return new ResultData(Result.ERROR,"wxMall未查询到");
}
if(StringUtils.isBlank(wxMall.getAlipayAppAuthToken())) {
return new ResultData(Result.ERROR,"wxMall alipayAppAuthToken为空");
}
try {
boolean result = aliPayUtil.smartDistrictTopicSubscribe(wxMall.getAlipayAppAuthToken());
if (result) {
return new ResultData();
}else {
return new ResultData(Result.ERROR,"消息订阅失败");
}
} catch (Exception e) {
logger.error("topicSubscribe error.",e);
return new ResultData(Result.ERROR,"topicSubscribe error.");
}
}
}

+ 0
- 1
pom.xml Ver ficheiro

@@ -16,7 +16,6 @@
<module>mallinkService</module>
<module>mallinkCallback</module>
<module>mallinkAdmin</module>
<module>mallinkSysAdmin</module>
<module>mallinkCApi</module>
<module>mallinkBApi</module>
<module>mallinkPosApi</module>


Carregando…
Cancelar
Guardar