|
@@ -7,6 +7,8 @@ import com.linkwechat.common.core.domain.AjaxResult;
|
|
|
import com.linkwechat.common.core.page.TableDataInfo;
|
|
import com.linkwechat.common.core.page.TableDataInfo;
|
|
|
import com.linkwechat.common.utils.QrCodeGenerator;
|
|
import com.linkwechat.common.utils.QrCodeGenerator;
|
|
|
import com.linkwechat.common.utils.QrcodeUtils;
|
|
import com.linkwechat.common.utils.QrcodeUtils;
|
|
|
|
|
+import com.linkwechat.common.utils.createQrCode.CreateQRCodeByCodeVO;
|
|
|
|
|
+import com.linkwechat.common.utils.createQrCode.WxMiniProgramGetQRCodeByCommonUtil;
|
|
|
import com.linkwechat.domain.weGroupFission.dto.DistDto;
|
|
import com.linkwechat.domain.weGroupFission.dto.DistDto;
|
|
|
import com.linkwechat.domain.weGroupFission.dto.WeGroupFissionDetailDto;
|
|
import com.linkwechat.domain.weGroupFission.dto.WeGroupFissionDetailDto;
|
|
|
import com.linkwechat.domain.weGroupFission.dto.WeGroupFissionDto;
|
|
import com.linkwechat.domain.weGroupFission.dto.WeGroupFissionDto;
|
|
@@ -22,13 +24,16 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -51,6 +56,18 @@ public class WeGroupFissionController extends BaseController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ISysUserService sysUserService;
|
|
private ISysUserService sysUserService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private WxMiniProgramGetQRCodeByCommonUtil wxMiniProgramGetQRCodeByCommonUtil;
|
|
|
|
|
+
|
|
|
|
|
+ //微信小程序的appid
|
|
|
|
|
+ @Value("${wechat.app_id}")
|
|
|
|
|
+ private String lifeWechatAppId;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //微信小程序的appid
|
|
|
|
|
+ @Value("${wechat.secret}")
|
|
|
|
|
+ private String lifeWechatSecret;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @version
|
|
* @version
|
|
|
* @author: hxl
|
|
* @author: hxl
|
|
@@ -245,44 +262,28 @@ public class WeGroupFissionController extends BaseController {
|
|
|
* @Description: 获取短链二进制流
|
|
* @Description: 获取短链二进制流
|
|
|
*/
|
|
*/
|
|
|
@PostMapping(value = "/getWechatGroupFissionUrlStream")
|
|
@PostMapping(value = "/getWechatGroupFissionUrlStream")
|
|
|
- public ResponseEntity<byte[]> getWechatGroupFissionUrlStream(@RequestBody CreateWechatGroupFissionUrlVo createWechatGroupFissionUrlVo) {
|
|
|
|
|
|
|
+ public void getWechatGroupFissionUrlStream(@RequestBody CreateWechatGroupFissionUrlVo createWechatGroupFissionUrlVo,HttpServletResponse servletResponse){
|
|
|
if(StringUtils.isBlank(createWechatGroupFissionUrlVo.getUrl())){
|
|
if(StringUtils.isBlank(createWechatGroupFissionUrlVo.getUrl())){
|
|
|
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("生成页面路径不能为空:".getBytes());
|
|
|
|
|
|
|
+ throw new RuntimeException("生成页面路径不能为空");
|
|
|
}
|
|
}
|
|
|
if(StringUtils.isBlank(createWechatGroupFissionUrlVo.getGroupFissionId())){
|
|
if(StringUtils.isBlank(createWechatGroupFissionUrlVo.getGroupFissionId())){
|
|
|
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("群裂变活动id不能为空:".getBytes());
|
|
|
|
|
|
|
+ throw new RuntimeException("群裂变活动id不能为空");
|
|
|
}
|
|
}
|
|
|
if(StringUtils.isBlank(createWechatGroupFissionUrlVo.getVersion())){
|
|
if(StringUtils.isBlank(createWechatGroupFissionUrlVo.getVersion())){
|
|
|
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("版本不能为空:".getBytes());
|
|
|
|
|
- }
|
|
|
|
|
- try {
|
|
|
|
|
- String wechatUrl = weGroupFissionService.getWechatGroupFissionUrl(createWechatGroupFissionUrlVo);
|
|
|
|
|
- log.info("生成二维码的微信链接:{}", wechatUrl);
|
|
|
|
|
- byte[] qrcodeBytes = QrCodeGenerator.createQrCode(wechatUrl, "PNG", 300, 300);
|
|
|
|
|
-
|
|
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
- headers.setContentType(MediaType.IMAGE_PNG);
|
|
|
|
|
- headers.setContentLength(qrcodeBytes.length);
|
|
|
|
|
- return new ResponseEntity<>(qrcodeBytes, headers, HttpStatus.OK);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("生成微信打卡二维码失败", e);
|
|
|
|
|
- String errorMsg = "生成微信打卡二维码失败:" + e.getMessage();
|
|
|
|
|
- return buildErrorResponse(errorMsg, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
+ throw new RuntimeException("版本不能为空");
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 统一构建错误响应
|
|
|
|
|
- */
|
|
|
|
|
- private ResponseEntity<byte[]> buildErrorResponse(String errorMsg, HttpStatus status) {
|
|
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
- headers.setContentType(MediaType.TEXT_PLAIN);
|
|
|
|
|
- try {
|
|
|
|
|
- // 明确指定UTF-8编码,避免中文乱码
|
|
|
|
|
- return new ResponseEntity<>(errorMsg.getBytes("UTF-8"), headers, status);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- // 兜底:使用默认编码
|
|
|
|
|
- return new ResponseEntity<>(errorMsg.getBytes(), headers, status);
|
|
|
|
|
|
|
+ CreateQRCodeByCodeVO createQRCode = new CreateQRCodeByCodeVO();
|
|
|
|
|
+ createQRCode.setKeyName("id");
|
|
|
|
|
+ createQRCode.setKeyValue(createWechatGroupFissionUrlVo.getGroupFissionId());
|
|
|
|
|
+ createQRCode.setSharePath(createWechatGroupFissionUrlVo.getUrl());
|
|
|
|
|
+ createQRCode.setEnv_version(createWechatGroupFissionUrlVo.getVersion());
|
|
|
|
|
+ createQRCode.setWidth(300); // 小程序码宽度
|
|
|
|
|
+ createQRCode.setAuto_color(false); // 不自动配色
|
|
|
|
|
+ createQRCode.setIs_hyaline(false); // 不透明
|
|
|
|
|
+ try{
|
|
|
|
|
+ wxMiniProgramGetQRCodeByCommonUtil.createQRCode(createQRCode,lifeWechatAppId,lifeWechatSecret,servletResponse);
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ throw new RuntimeException("生成二维码错误");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|