Browse Source

1、二维码接口补充

master
Aug 3 days ago
parent
commit
a96bbd7e46
6 changed files with 1329 additions and 1 deletions
  1. +1122
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/bean/HttpClientUtil.java
  2. +14
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/bean/WxQrCodeVo.java
  3. +8
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/educationController/ConfigController.java
  4. +2
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/service/ConfigService.java
  5. +182
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/service/impl/ConfigServiceImpl.java
  6. +1
    -1
      jeecg-boot-module-system/src/main/resources/application-dev.yml

+ 1122
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/bean/HttpClientUtil.java
File diff suppressed because it is too large
View File


+ 14
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/bean/WxQrCodeVo.java View File

@ -0,0 +1,14 @@
package org.jeecg.modules.api.bean;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class WxQrCodeVo {
/**图片地址*/
@ApiModelProperty(value = "图片地址")
private String url;
@ApiModelProperty(value = "名称")
private String name;
}

+ 8
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/educationController/ConfigController.java View File

@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.api.bean.PageBean;
import org.jeecg.modules.api.service.ConfigService;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@ -79,4 +80,11 @@ public class ConfigController {
return configService.queryCategoryPeriodList(pageBean);
}
//生成二维码
@ApiOperation(value="生成二维码", notes="生成二维码")
@RequestMapping(value = "/getInviteCode", method = {RequestMethod.POST})
public Result<?> getInviteCode(String path){
return configService.getInviteCode(path);
}
}

+ 2
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/service/ConfigService.java View File

@ -24,5 +24,7 @@ public interface ConfigService {
public Result<?> queryCategoryMajorList(PageBean pageBean);
//获取阶段分类列表
public Result<?> queryCategoryPeriodList(PageBean pageBean);
//生成二维码
public Result<?> getInviteCode(String path);
}

+ 182
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/service/impl/ConfigServiceImpl.java View File

@ -1,11 +1,19 @@
package org.jeecg.modules.api.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.api.bean.HttpClientUtil;
import org.jeecg.modules.api.bean.PageBean;
import org.jeecg.modules.api.bean.WxQrCodeVo;
import org.jeecg.modules.api.service.ConfigService;
import org.jeecg.modules.educationCategoryMajor.entity.EducationCategoryMajor;
import org.jeecg.modules.educationCategoryMajor.service.IEducationCategoryMajorService;
@ -19,15 +27,40 @@ import org.jeecg.modules.educationConfig.entity.EducationConfig;
import org.jeecg.modules.educationConfig.service.IEducationConfigService;
import org.jeecg.modules.educationSummary.entity.EducationSummary;
import org.jeecg.modules.educationSummary.service.IEducationSummaryService;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
@Service
@Slf4j
public class ConfigServiceImpl implements ConfigService {
/******************************************************************************************************************/
private String appid = "wx489ca73503f461be";//小程序appid
private String secret = "4b9e851c8fe2181c00a041b926d297cd";//小程序密钥
@Value("${jeecg.oss.endpoint}")
private String endpoint;
@Value("${jeecg.oss.accessKey}")
private String accessKey;
@Value("${jeecg.oss.secretKey}")
private String secretKey;
@Value("${jeecg.oss.bucketName}")
private String bucketName;
@Value("${jeecg.oss.staticDomain}")
private String staticDomain;
//系统配置信息
@Resource
private IEducationConfigService educationConfigService;
@ -305,4 +338,153 @@ public class ConfigServiceImpl implements ConfigService {
}
}
@Override
public Result<?> getInviteCode(String path) {
//获取版本信息
EducationConfig vsion = educationConfigService.lambdaQuery()
.eq(EducationConfig::getParamCode, "v_sion")
.one();
Integer vsionStr = Integer.parseInt(vsion.getParamText());
String trial = "release";
if(vsionStr == 0){
trial= "release";
}else if(vsionStr == 1){
trial= "trial";
}else{
trial= "develop";
}
Map<String, Object> param = new HashMap<>();
param.put("path", path); //跳转页面
String accessToken = this.getAccessToken();
RestTemplate rest = new RestTemplate();
InputStream inputStream = null;
OutputStream outputStream = null;
File file = null;
//存储地址
String codeImg = "/employ";
try{
String url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + accessToken;
//param.put("scene", hanHaiMember.getId());
param.put("width", 150);
param.put("auto_color", false);
param.put("env_version", trial);
Map<String, Object> line_color = new HashMap<>();
line_color.put("r", 0);
line_color.put("g", 0);
line_color.put("b", 0);
param.put("line_color", line_color);
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
org.springframework.http.HttpEntity requestEntity = new org.springframework.http.HttpEntity(JSON.toJSONString(param), headers);
ResponseEntity<byte[]> entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]);
byte[] result = entity.getBody();
inputStream = new ByteArrayInputStream(result);
String tempSave = codeImg;
String filePath = tempSave;
file = new File(filePath);
if (!file.exists()) {
file.createNewFile();
}
outputStream = new FileOutputStream(file);
int len = 0;
byte[] buf = new byte[1024];
while ((len = inputStream.read(buf, 0, 1024)) != -1) {
outputStream.write(buf, 0, len);
}
outputStream.flush();
//将文件上传至阿里云
DiskFileItemFactory factory = new DiskFileItemFactory(16, null);
FileItem item = factory.createItem("File", "text/plain", true, file.getName());
int bytesRead = 0;
byte[] buffer = new byte[8192];
try {
FileInputStream fis = new FileInputStream(file);
OutputStream os = item.getOutputStream();
while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
MultipartFile mf = new CommonsMultipartFile(item);
//返回图片下载地址
WxQrCodeVo wxCodeVo = new WxQrCodeVo();
wxCodeVo.setUrl(staticDomain+this.uploadAliYunOss(mf));
wxCodeVo.setName("海报二维码");
return Result.OK(wxCodeVo);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//删除文件
if (file.exists()) {
file.delete();
}
}
return null;
}
/**
* 获取令牌
*
* @return
*/
private String getAccessToken() {
String requestUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret;
String doGet2 = HttpClientUtil.doGet2(requestUrl);
Map<String, String> map = JSON.parseObject(doGet2, new TypeReference<Map<String, String>>() {
});
return map.get("access_token");
}
/**
* 上传文件至阿里云oss
*
* @return
*/
private String uploadAliYunOss(MultipartFile mf) throws Exception {
String uploadFile = "education";
String fileName = new StringBuffer(mf.getOriginalFilename()).append(".jpg").toString();// 获取文件名
String dbpath = uploadFile + File.separator + fileName;
if (dbpath.contains("\\")) {
dbpath = dbpath.replace("\\", "/");
}
String endpoint = this.endpoint;
String accessKey = this.accessKey;
String secretKey = this.secretKey;
// 创建OSSClient实例
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKey, secretKey);
// 上传Byte数组
byte[] content = mf.getBytes();
String bucketName = this.bucketName;
ossClient.putObject(bucketName, dbpath, new ByteArrayInputStream(content));
// 关闭OSSClient
ossClient.shutdown();
return dbpath;
}
}

+ 1
- 1
jeecg-boot-module-system/src/main/resources/application-dev.yml View File

@ -196,7 +196,7 @@ jeecg :
secretKey: p1SrIJdzp47jWjYNXXKfjDIMwSCYcw
endpoint: oss-cn-shanghai.aliyuncs.com
bucketName: jgyt
staticDomain: https://image.jgyt.chat
staticDomain: https://image.jgyt.chat/
# ElasticSearch 6设置
elasticsearch:
cluster-name: jeecg-ES


Loading…
Cancel
Save