Browse Source

1、小程序推广二维码

master
Aug 2 months ago
parent
commit
5034619f44
6 changed files with 1449 additions and 35 deletions
  1. +50
    -35
      .idea/workspace.xml
  2. +34
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/massageController/ShareController.java
  3. +1119
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiBean/HttpClientUtil.java
  4. +14
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiBean/WxQrCodeVo.java
  5. +8
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/ShareService.java
  6. +224
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/impl/ShareServiceImpl.java

+ 50
- 35
.idea/workspace.xml View File

@ -1,7 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="8b88b979-c3fa-4858-8fa6-d3a5d334cf69" name="Default Changelist" comment="" />
<list default="true" id="8b88b979-c3fa-4858-8fa6-d3a5d334cf69" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/massageController/ShareController.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiBean/HttpClientUtil.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiBean/WxQrCodeVo.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/ShareService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/impl/ShareServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -63,9 +70,9 @@
</component>
<component name="RecentsManager">
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="org.jeecg.modules.apiBean" />
<recent name="org.jeecg.modules.api.massageController" />
<recent name="org.jeecg.modules.apiService.impl" />
<recent name="org.jeecg.modules.apiBean" />
</key>
</component>
<component name="RunManager">
@ -152,7 +159,7 @@
<updated>1741573014101</updated>
<workItem from="1741573016746" duration="4323000" />
<workItem from="1741580646045" duration="5038000" />
<workItem from="1741852577555" duration="27910000" />
<workItem from="1741852577555" duration="30130000" />
</task>
<task id="LOCAL-00001" summary="1、项目初始化">
<created>1741919155045</created>
@ -175,7 +182,14 @@
<option name="project" value="LOCAL" />
<updated>1742296303138</updated>
</task>
<option name="localTasksCounter" value="4" />
<task id="LOCAL-00004" summary="1、积分模块修改">
<created>1742296430585</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1742296430585</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -197,7 +211,8 @@
<MESSAGE value="1、项目初始化" />
<MESSAGE value="接口上传:&#10;1、轮播图模块&#10;2、公告模块&#10;3、配置信息模块&#10;4、推拿项目模块&#10;5、订单模块&#10;6、个人信息模块" />
<MESSAGE value="接口上传:&#10;1、商家模块&#10;2、积分模块&#10;3、个人中心基础数据" />
<option name="LAST_COMMIT_MESSAGE" value="接口上传:&#10;1、商家模块&#10;2、积分模块&#10;3、个人中心基础数据" />
<MESSAGE value="1、积分模块修改" />
<option name="LAST_COMMIT_MESSAGE" value="1、积分模块修改" />
</component>
<component name="WindowStateProjectService">
<state x="734" y="358" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1741573453098">
@ -216,70 +231,70 @@
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state x="1010" y="449" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.2560.1400@0.0.2560.1400" timestamp="1741587414527" />
<state x="679" y="297" key="CommitChangelistDialog2" timestamp="1742296349173">
<state x="679" y="297" key="CommitChangelistDialog2" timestamp="1742296430186">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state x="679" y="297" key="CommitChangelistDialog2/0.0.2560.1400@0.0.2560.1400" timestamp="1742296349173" />
<state x="92" y="92" width="2376" height="1216" key="DiffContextDialog" timestamp="1742296347640">
<state x="679" y="297" key="CommitChangelistDialog2/0.0.2560.1400@0.0.2560.1400" timestamp="1742296430186" />
<state x="92" y="92" width="2376" height="1216" key="DiffContextDialog" timestamp="1742296412150">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state x="92" y="92" width="2376" height="1216" key="DiffContextDialog/0.0.2560.1400@0.0.2560.1400" timestamp="1742296347640" />
<state width="2517" height="388" key="GridCell.Tab.0.bottom" timestamp="1742296385340">
<state x="92" y="92" width="2376" height="1216" key="DiffContextDialog/0.0.2560.1400@0.0.2560.1400" timestamp="1742296412150" />
<state width="2517" height="388" key="GridCell.Tab.0.bottom" timestamp="1742347666652">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state width="2517" height="388" key="GridCell.Tab.0.bottom/0.0.2560.1400@0.0.2560.1400" timestamp="1742296385340" />
<state width="2517" height="388" key="GridCell.Tab.0.center" timestamp="1742296385340">
<state width="2517" height="388" key="GridCell.Tab.0.bottom/0.0.2560.1400@0.0.2560.1400" timestamp="1742347666652" />
<state width="2517" height="388" key="GridCell.Tab.0.center" timestamp="1742347666652">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state width="2517" height="388" key="GridCell.Tab.0.center/0.0.2560.1400@0.0.2560.1400" timestamp="1742296385340" />
<state width="2517" height="388" key="GridCell.Tab.0.left" timestamp="1742296385339">
<state width="2517" height="388" key="GridCell.Tab.0.center/0.0.2560.1400@0.0.2560.1400" timestamp="1742347666652" />
<state width="2517" height="388" key="GridCell.Tab.0.left" timestamp="1742347666652">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state width="2517" height="388" key="GridCell.Tab.0.left/0.0.2560.1400@0.0.2560.1400" timestamp="1742296385339" />
<state width="2517" height="388" key="GridCell.Tab.0.right" timestamp="1742296385340">
<state width="2517" height="388" key="GridCell.Tab.0.left/0.0.2560.1400@0.0.2560.1400" timestamp="1742347666652" />
<state width="2517" height="388" key="GridCell.Tab.0.right" timestamp="1742347666652">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state width="2517" height="388" key="GridCell.Tab.0.right/0.0.2560.1400@0.0.2560.1400" timestamp="1742296385340" />
<state width="2517" height="388" key="GridCell.Tab.1.bottom" timestamp="1742296384886">
<state width="2517" height="388" key="GridCell.Tab.0.right/0.0.2560.1400@0.0.2560.1400" timestamp="1742347666652" />
<state width="2517" height="388" key="GridCell.Tab.1.bottom" timestamp="1742347666572">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state width="2517" height="388" key="GridCell.Tab.1.bottom/0.0.2560.1400@0.0.2560.1400" timestamp="1742296384886" />
<state width="2517" height="388" key="GridCell.Tab.1.center" timestamp="1742296384886">
<state width="2517" height="388" key="GridCell.Tab.1.bottom/0.0.2560.1400@0.0.2560.1400" timestamp="1742347666572" />
<state width="2517" height="388" key="GridCell.Tab.1.center" timestamp="1742347666572">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state width="2517" height="388" key="GridCell.Tab.1.center/0.0.2560.1400@0.0.2560.1400" timestamp="1742296384886" />
<state width="2517" height="388" key="GridCell.Tab.1.left" timestamp="1742296384886">
<state width="2517" height="388" key="GridCell.Tab.1.center/0.0.2560.1400@0.0.2560.1400" timestamp="1742347666572" />
<state width="2517" height="388" key="GridCell.Tab.1.left" timestamp="1742347666572">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state width="2517" height="388" key="GridCell.Tab.1.left/0.0.2560.1400@0.0.2560.1400" timestamp="1742296384886" />
<state width="2517" height="388" key="GridCell.Tab.1.right" timestamp="1742296384886">
<state width="2517" height="388" key="GridCell.Tab.1.left/0.0.2560.1400@0.0.2560.1400" timestamp="1742347666572" />
<state width="2517" height="388" key="GridCell.Tab.1.right" timestamp="1742347666572">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state width="2517" height="388" key="GridCell.Tab.1.right/0.0.2560.1400@0.0.2560.1400" timestamp="1742296384886" />
<state width="2517" height="388" key="GridCell.Tab.2.bottom" timestamp="1742296384887">
<state width="2517" height="388" key="GridCell.Tab.1.right/0.0.2560.1400@0.0.2560.1400" timestamp="1742347666572" />
<state width="2517" height="388" key="GridCell.Tab.2.bottom" timestamp="1742347666573">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state width="2517" height="388" key="GridCell.Tab.2.bottom/0.0.2560.1400@0.0.2560.1400" timestamp="1742296384887" />
<state width="2517" height="388" key="GridCell.Tab.2.center" timestamp="1742296384887">
<state width="2517" height="388" key="GridCell.Tab.2.bottom/0.0.2560.1400@0.0.2560.1400" timestamp="1742347666573" />
<state width="2517" height="388" key="GridCell.Tab.2.center" timestamp="1742347666573">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state width="2517" height="388" key="GridCell.Tab.2.center/0.0.2560.1400@0.0.2560.1400" timestamp="1742296384887" />
<state width="2517" height="388" key="GridCell.Tab.2.left" timestamp="1742296384887">
<state width="2517" height="388" key="GridCell.Tab.2.center/0.0.2560.1400@0.0.2560.1400" timestamp="1742347666573" />
<state width="2517" height="388" key="GridCell.Tab.2.left" timestamp="1742347666572">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state width="2517" height="388" key="GridCell.Tab.2.left/0.0.2560.1400@0.0.2560.1400" timestamp="1742296384887" />
<state width="2517" height="388" key="GridCell.Tab.2.right" timestamp="1742296384887">
<state width="2517" height="388" key="GridCell.Tab.2.left/0.0.2560.1400@0.0.2560.1400" timestamp="1742347666572" />
<state width="2517" height="388" key="GridCell.Tab.2.right" timestamp="1742347666573">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state width="2517" height="388" key="GridCell.Tab.2.right/0.0.2560.1400@0.0.2560.1400" timestamp="1742296384887" />
<state width="2517" height="388" key="GridCell.Tab.2.right/0.0.2560.1400@0.0.2560.1400" timestamp="1742347666573" />
<state x="783" y="345" key="SettingsEditor" timestamp="1741573035388">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state x="783" y="345" key="SettingsEditor/0.0.2560.1400@0.0.2560.1400" timestamp="1741573035388" />
<state x="872" y="436" key="Vcs.Push.Dialog.v2" timestamp="1742296308288">
<state x="872" y="436" key="Vcs.Push.Dialog.v2" timestamp="1742296434198">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state x="872" y="436" key="Vcs.Push.Dialog.v2/0.0.2560.1400@0.0.2560.1400" timestamp="1742296308288" />
<state x="872" y="436" key="Vcs.Push.Dialog.v2/0.0.2560.1400@0.0.2560.1400" timestamp="1742296434198" />
<state x="972" y="527" key="com.intellij.ide.util.TipDialog" timestamp="1741580728988">
<screen x="0" y="0" width="2560" height="1400" />
</state>


+ 34
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/massageController/ShareController.java View File

@ -0,0 +1,34 @@
package org.jeecg.modules.api.massageController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.apiService.ShareService;
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;
import javax.annotation.Resource;
@Api(tags="我的-邀请好友")
@RestController
@RequestMapping("/massage/share")
@Slf4j
public class ShareController {
/******************************************************************************************************************/
//邀请好友
@Resource
private ShareService shareService;
/******************************************************************************************************************/
//我的-邀请好友
@ApiOperation(value="我的-邀请好友", notes="我的服务-邀请好友")
@RequestMapping(value = "/getInviteCode", method = {RequestMethod.POST})
public Result<?> getInviteCode(@RequestHeader("X-Access-Token") String token){
return shareService.getInviteCode(token);
}
}

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


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

@ -0,0 +1,14 @@
package org.jeecg.modules.apiBean;
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/apiService/ShareService.java View File

@ -0,0 +1,8 @@
package org.jeecg.modules.apiService;
import org.jeecg.common.api.vo.Result;
public interface ShareService {
//我的-邀请好友
public Result<?> getInviteCode(String token);
}

+ 224
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/impl/ShareServiceImpl.java View File

@ -0,0 +1,224 @@
package org.jeecg.modules.apiService.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.jeecg.common.api.vo.Result;
import org.jeecg.config.shiro.ShiroRealm;
import org.jeecg.modules.apiBean.HttpClientUtil;
import org.jeecg.modules.apiBean.WxQrCodeVo;
import org.jeecg.modules.apiService.ShareService;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService;
import org.jeecg.modules.massageConfig.entity.MassageConfig;
import org.jeecg.modules.massageConfig.service.IMassageConfigService;
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
public class ShareServiceImpl implements ShareService {
/*************************************************************************************/
//权限验证
@Resource
private ShiroRealm shiroRealm;
//用户信息
@Resource
private IHanHaiMemberService hanHaiMemberService;
//配置信息
@Resource
private IMassageConfigService massageConfigService;
private String appid = "wx77ba4c7131677a74";//小程序appid
private String secret = "fb915d623f92d455f2e70934f75fb96c";//小程序密钥
@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;
/*************************************************************************************/
//获取个人推荐二维码
@Override
public Result<?> getInviteCode(String token) {
//权限验证
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token);
//获取版本信息
MassageConfig vsion = massageConfigService.lambdaQuery()
.eq(MassageConfig::getParamCode, "v_sion")
.one();
Integer vsionStr = Integer.parseInt(vsion.getParamValueText());
String trial = "release";
if(vsionStr == 0){
trial= "release";
}else if(vsionStr == 1){
trial= "trial";
}else{
trial= "develop";
}
Map<String, Object> param = new HashMap<>();
//获取跳转路径信息
MassageConfig xcxSharePage = massageConfigService.lambdaQuery()
.eq(MassageConfig::getParamCode, "xcxSharePage")
.one();
String key = "shareId=" + hanHaiMember.getId();
param.put("path", xcxSharePage.getParamValueText() + "?" + key); //跳转页面
String accessToken = this.getAccessToken();
RestTemplate rest = new RestTemplate();
InputStream inputStream = null;
OutputStream outputStream = null;
File file = null;
//获取存储地址
MassageConfig oneImage = massageConfigService.lambdaQuery()
.eq(MassageConfig::getParamCode, "codeImg")
.one();
String codeImg = oneImage.getParamValueText();
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 = "massage";
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;
}
}

Loading…
Cancel
Save