|
|
@ -5,18 +5,30 @@ import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
import com.aliyun.oss.OSS; |
|
|
|
import com.aliyun.oss.OSSClientBuilder; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.tomcat.util.http.fileupload.FileItem; |
|
|
|
import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory; |
|
|
|
import org.apache.commons.fileupload.FileItem; |
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
|
|
|
import org.jeecg.api.service.AppletInfoService; |
|
|
|
import org.jeecg.api.wxUtils.HttpClientUtil; |
|
|
|
import org.jeecg.api.wxUtils.WxQrCodeVo; |
|
|
|
import org.jeecg.common.api.vo.Result; |
|
|
|
import org.jeecg.config.shiro.ShiroRealm; |
|
|
|
import org.jeecg.modules.commonConfig.entity.CommonConfig; |
|
|
|
import org.jeecg.modules.commonConfig.service.ICommonConfigService; |
|
|
|
import org.jeecg.modules.commonMember.entity.CommonMember; |
|
|
|
import org.jeecg.modules.commonMember.service.ICommonMemberService; |
|
|
|
import org.jeecg.modules.commonMoney.entity.CommonMoney; |
|
|
|
import org.jeecg.modules.commonMoney.service.ICommonMoneyService; |
|
|
|
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember; |
|
|
|
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
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.CommonsLogWriter; |
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
@ -25,7 +37,9 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.*; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@Slf4j |
|
|
@ -36,7 +50,55 @@ public class AppletInfoServiceImpl implements AppletInfoService { |
|
|
|
private ShiroRealm shiroRealm; |
|
|
|
@Autowired |
|
|
|
private IHanHaiMemberService hanHaiMemberService; |
|
|
|
@Autowired |
|
|
|
private ICommonMoneyService commonMoneyService; |
|
|
|
@Autowired |
|
|
|
private ICommonConfigService commonConfigService; |
|
|
|
@Value("${wechat-dm.mpAppId}") |
|
|
|
private String appid; |
|
|
|
@Value("${wechat-dm.mpAppSecret}") |
|
|
|
private String secret; |
|
|
|
@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; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<?> getUserInfoVip(String token){ |
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
Map map = new HashMap(); |
|
|
|
map.put("user_sum",1000); |
|
|
|
|
|
|
|
map.put("z_sum",900); |
|
|
|
map.put("j_sum",100); |
|
|
|
map.put("pidInfo",hanHaiMember); |
|
|
|
map.put("money",888); |
|
|
|
map.put("sum_money",888); |
|
|
|
map.put("get_money",99); |
|
|
|
map.put("vip_time",new Date()); |
|
|
|
return Result.OK(map); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<?> getUserInfoVipList(String token){ |
|
|
|
Page<HanHaiMember> page = new Page<HanHaiMember>(1, 10); |
|
|
|
IPage<HanHaiMember> pageList = hanHaiMemberService.page(page); |
|
|
|
return Result.OK(pageList); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<?> getWalletList(String token, Integer state){ |
|
|
|
Page<CommonMoney> page = new Page<CommonMoney>(1, 10); |
|
|
|
IPage<CommonMoney> pageList = commonMoneyService.page(page); |
|
|
|
return Result.OK(pageList); |
|
|
|
} |
|
|
|
|
|
|
|
//获取个人资料信息 |
|
|
|
@Override |
|
|
@ -61,189 +123,190 @@ public class AppletInfoServiceImpl implements AppletInfoService { |
|
|
|
//获取推广二维码 |
|
|
|
@Override |
|
|
|
public Result<?> getQrCode(String token){ |
|
|
|
// HanHaiMember member = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
// |
|
|
|
// CityConf vsion = cityConfService.lambdaQuery() |
|
|
|
// .eq(CityConf::getKeyIcon, "v_sion") |
|
|
|
// .one(); |
|
|
|
// Integer vsionStr = Integer.parseInt(vsion.getKeyValue()); |
|
|
|
// String trial = "release"; |
|
|
|
// if(vsionStr == 0){ |
|
|
|
// trial= "release"; |
|
|
|
// }else if(vsionStr == 1){ |
|
|
|
// trial= "trial"; |
|
|
|
// }else{ |
|
|
|
// trial= "develop"; |
|
|
|
// } |
|
|
|
// |
|
|
|
//// WxQrCodeVo o = (WxQrCodeVo)redisUtil.get("CodeImage::" + trial+ member.getId()); |
|
|
|
//// if(o!=null){ |
|
|
|
//// |
|
|
|
//// |
|
|
|
//// o.setName("瑶都万能墙欢迎您的加入"); |
|
|
|
//// return Result.OK(o); |
|
|
|
//// } |
|
|
|
// |
|
|
|
// Map<String, Object> param = new HashMap<>(); |
|
|
|
// |
|
|
|
// CityConf xcxSharePage = cityConfService.lambdaQuery() |
|
|
|
// .eq(CityConf::getKeyIcon, "xcxSharePage") |
|
|
|
// .one(); |
|
|
|
// |
|
|
|
// |
|
|
|
// |
|
|
|
// |
|
|
|
// |
|
|
|
// String key = "shareId=" + member.getId(); |
|
|
|
// |
|
|
|
// param.put("path", xcxSharePage.getKeyValue() + "?" + key); //跳转页面 |
|
|
|
// String accessToken = this.getAccessToken(); |
|
|
|
// RestTemplate rest = new RestTemplate(); |
|
|
|
// InputStream inputStream = null; |
|
|
|
// OutputStream outputStream = null; |
|
|
|
// File file = null; |
|
|
|
// |
|
|
|
//// LambdaQueryWrapper<DbConf> configImg = new LambdaQueryWrapper<>(); |
|
|
|
//// configImg.eq(DbConf::getIsDel,0).eq(DbConf::getKeyValue,"codeImg"); |
|
|
|
//// DbConf oneImg = confService.getOne(configImg); |
|
|
|
// |
|
|
|
// CityConf oneImage = cityConfService.lambdaQuery() |
|
|
|
// .eq(CityConf::getKeyIcon, "codeImg") |
|
|
|
// .one(); |
|
|
|
// |
|
|
|
// |
|
|
|
// |
|
|
|
// |
|
|
|
// String codeImg = oneImage.getKeyValue(); |
|
|
|
// try{ |
|
|
|
// String url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + accessToken; |
|
|
|
// param.put("scene", member.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(this.uploadAliYunOss(mf)); |
|
|
|
// |
|
|
|
// |
|
|
|
// |
|
|
|
// |
|
|
|
// wxCodeVo.setName("瑶都万能墙欢迎您的加入"); |
|
|
|
// |
|
|
|
//// redisUtil.set("CodeImage::"+trial+member.getId(),wxCodeVo); |
|
|
|
// return Result.OK(wxCodeVo); |
|
|
|
HanHaiMember member = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
|
|
CommonConfig vsion = commonConfigService.lambdaQuery() |
|
|
|
.eq(CommonConfig::getKeyName, "v_sion") |
|
|
|
.one(); |
|
|
|
|
|
|
|
Integer vsionStr = Integer.parseInt(vsion.getKeyContent()); |
|
|
|
String trial = "release"; |
|
|
|
if(vsionStr == 0){ |
|
|
|
trial= "release"; |
|
|
|
}else if(vsionStr == 1){ |
|
|
|
trial= "trial"; |
|
|
|
}else{ |
|
|
|
trial= "develop"; |
|
|
|
} |
|
|
|
|
|
|
|
// WxQrCodeVo o = (WxQrCodeVo)redisUtil.get("CodeImage::" + trial+ member.getId()); |
|
|
|
// if(o!=null){ |
|
|
|
// |
|
|
|
// } 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(); |
|
|
|
// } |
|
|
|
// o.setName("瑶都万能墙欢迎您的加入"); |
|
|
|
// return Result.OK(o); |
|
|
|
// } |
|
|
|
// return null; |
|
|
|
|
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
CommonConfig xcxSharePage = commonConfigService.lambdaQuery() |
|
|
|
.eq(CommonConfig::getKeyName, "xcxSharePage") |
|
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String key = "shareId=" + member.getId(); |
|
|
|
|
|
|
|
param.put("path", xcxSharePage.getKeyContent() + "?" + key); //跳转页面 |
|
|
|
String accessToken = this.getAccessToken(); |
|
|
|
RestTemplate rest = new RestTemplate(); |
|
|
|
InputStream inputStream = null; |
|
|
|
OutputStream outputStream = null; |
|
|
|
File file = null; |
|
|
|
|
|
|
|
// LambdaQueryWrapper<DbConf> configImg = new LambdaQueryWrapper<>(); |
|
|
|
// configImg.eq(DbConf::getIsDel,0).eq(DbConf::getKeyValue,"codeImg"); |
|
|
|
// DbConf oneImg = confService.getOne(configImg); |
|
|
|
|
|
|
|
|
|
|
|
CommonConfig oneImage = commonConfigService.lambdaQuery() |
|
|
|
.eq(CommonConfig::getKeyName, "codeImg") |
|
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String codeImg = oneImage.getKeyValue(); |
|
|
|
try{ |
|
|
|
String url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + accessToken; |
|
|
|
param.put("scene", member.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(this.uploadAliYunOss(mf)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxCodeVo.setName("欢迎您的加入"); |
|
|
|
|
|
|
|
// redisUtil.set("CodeImage::"+trial+member.getId(),wxCodeVo); |
|
|
|
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 = "WxCodeFile"; |
|
|
|
// 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; |
|
|
|
// } |
|
|
|
// |
|
|
|
// |
|
|
|
/** |
|
|
|
* 获取令牌 |
|
|
|
* |
|
|
|
* @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 = "WxCodeFile"; |
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|