Commit 585358a5 authored by muhong's avatar muhong

修改 藏品详情和用户登录

parent a15a183b
......@@ -3,6 +3,7 @@ package com.wwdz.ch.wx.entity.vo;
import com.xxdxxs.entity.Entity;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
......@@ -26,4 +27,6 @@ public class ItemResponseVo implements Entity {
private Boolean isDeleted;
private String itemNickname;
private Integer timeType;
private List<Map<String, Object>> imagesList;
private List<Map<String, Object>> videosList;
}
......@@ -455,7 +455,7 @@ public class FavoritesServiceImpl implements FavoritesService {
String[] image = item.getImages().split(";");
homePageMap.put("url", image[0]);
if (image[0].contains("_")) {
homePageMap = getImageMap(image[0]);
homePageMap = getAspect(image[0]);
homePageMap.put("url", image[0]);
homePageMap.put("type", 2);
}
......@@ -464,7 +464,7 @@ public class FavoritesServiceImpl implements FavoritesService {
String[] vedioImage = item.getVideos().split(";");
if (vedioImage[0].contains(",")) {
String[] video = vedioImage[0].split(",");
homePageMap = getImageMap(video[1]);
homePageMap = getAspect(video[1]);
homePageMap.put("url", video[1]);
homePageMap.put("type", 1);
}
......@@ -478,7 +478,7 @@ public class FavoritesServiceImpl implements FavoritesService {
* @param image
* @return
*/
private Map<String, Object> getImageMap(String image) {
private Map<String, Object> getAspect(String image) {
Map<String, Object> map = new HashMap<>();
String[] _image = image.split("_");
String[] infoImage = _image[1].split("\\.");
......
......@@ -153,7 +153,7 @@ public class FootPrintServiceImpl implements FootPrintService {
String[] image = item.getImages().split(";");
homePageMap.put("url", image[0]);
if (image[0].contains("_")) {
homePageMap = getImageMap(image[0]);
homePageMap = getAspect(image[0]);
homePageMap.put("url", image[0]);
homePageMap.put("type", 2);
}
......@@ -162,7 +162,7 @@ public class FootPrintServiceImpl implements FootPrintService {
String[] vedioImage = item.getVideos().split(";");
if (vedioImage[0].contains(",")) {
String[] video = vedioImage[0].split(",");
homePageMap = getImageMap(video[1]);
homePageMap = getAspect(video[1]);
homePageMap.put("url", video[1]);
homePageMap.put("type", 1);
}
......@@ -176,7 +176,7 @@ public class FootPrintServiceImpl implements FootPrintService {
* @param image
* @return
*/
private Map<String, Object> getImageMap(String image) {
private Map<String, Object> getAspect(String image) {
Map<String, Object> map = new HashMap<>();
String[] _image = image.split("_");
String[] infoImage = _image[1].split("\\.");
......
......@@ -15,8 +15,8 @@ import com.wwdz.ch.db.es.ItemEsDao;
import com.wwdz.ch.wx.entity.request.ItemRequestDto;
import com.wwdz.ch.wx.entity.vo.AgentTranceResponseVo;
import com.wwdz.ch.wx.entity.vo.ItemResponseVo;
import com.wwdz.ch.wx.manager.WxLoginManager;
import com.wwdz.ch.wx.service.ItemService;
import com.wwdz.ch.wx.service.WxLoginService;
import com.wwdz.ch.wx.util.StringUtil;
import com.xxdxxs.utils.CommonUtils;
import com.xxdxxs.utils.DateUtils;
......@@ -57,7 +57,7 @@ public class ItemServiceImpl implements ItemService {
@Autowired
private FavoritesDao favoritesDao;
@Autowired
private WxLoginService wxLoginService;
private WxLoginManager wxLoginManager;
@Autowired
private QiniuStorage qiniuStorage;
@Autowired
......@@ -178,7 +178,7 @@ public class ItemServiceImpl implements ItemService {
item.setSort(100);
item.setImages(dto.getImages());
if (StringUtils.isNotBlank(dto.getVideos())) {
item.setVideos(getVediosImage(dto.getVideos()));
item.setVideos(getVideosImage(dto.getVideos()));
}
item.setPrice(Long.parseLong(dto.getPrice()) * 100);
item.setDetail(dto.getDetail());
......@@ -266,6 +266,10 @@ public class ItemServiceImpl implements ItemService {
}
itemResponseVo.setVideos(stringBuilder.substring(0, stringBuilder.length() - 1));
}
// 设置图片列表
itemResponseVo.setImagesList(getImagesMapList(item.getImages()));
// 设置视频列表
itemResponseVo.setVideosList(StringUtils.isNotBlank(item.getVideos()) ? getVideosMapList(item.getVideos()) : new ArrayList<>());
// 设置分类id和名称
itemResponseVo.setCid(item.getCid());
Category category = categoryDao.findById(item.getCid());
......@@ -415,7 +419,7 @@ public class ItemServiceImpl implements ItemService {
item.setImages(dto.getImages());
item.setVideos("");
if (StringUtils.isNotBlank(dto.getVideos())) {
item.setVideos(getVediosImage(dto.getVideos()));
item.setVideos(getVideosImage(dto.getVideos()));
}
item.setPrice(Long.parseLong(dto.getPrice()) * 100);
item.setDetail(dto.getDetail());
......@@ -460,7 +464,7 @@ public class ItemServiceImpl implements ItemService {
String keyName = CommConsts.UPLOAD_PRE_WXACODE_DIRECTORY + page + "/" + scene + "." + MediaTypeEnum.IMAGE_JPG.getExt();
FileInfo fileInfo = (FileInfo) qiniuStorage.checkFile(keyName);
if (Objects.isNull(fileInfo)) {
InputStream inputStream = wxLoginService.getWxacodeStream(page, scene);
InputStream inputStream = wxLoginManager.getWxacodeStream(page, scene);
if (Objects.isNull(inputStream)) {
return Result.failed("获取微信小程序流失败");
}
......@@ -482,7 +486,7 @@ public class ItemServiceImpl implements ItemService {
@Override
public Result getWxLink(String pageUrl) {
try {
String link = wxLoginService.getLink(pageUrl);
String link = wxLoginManager.getLink(pageUrl);
if (StringUtils.isBlank(link)) {
return Result.failed("获取微信小程序链接失败");
}
......@@ -537,8 +541,8 @@ public class ItemServiceImpl implements ItemService {
}
}
private String getVediosImage(String vedios) {
String vedio = "";
private String getVideosImage(String vedios) {
String video = "";
String[] images = vedios.split(";");
StringBuffer stringBuffer = new StringBuffer();
Arrays.stream(images).parallel().forEach(image -> {
......@@ -560,8 +564,8 @@ public class ItemServiceImpl implements ItemService {
logger.error("视频图片上传失败", e);
}
});
vedio = stringBuffer.toString();
return vedio;
video = stringBuffer.toString();
return video;
}
/**
......@@ -597,7 +601,7 @@ public class ItemServiceImpl implements ItemService {
String[] image = es.getImages().split(";");
homePageMap.put("url", image[0]);
if (image[0].contains("_")) {
homePageMap = getImageMap(image[0]);
homePageMap = getAspect(image[0]);
homePageMap.put("url", image[0]);
homePageMap.put("type", 2);
}
......@@ -606,7 +610,7 @@ public class ItemServiceImpl implements ItemService {
String[] vedioImage = es.getVideos().split(";");
if (vedioImage[0].contains(",")) {
String[] video = vedioImage[0].split(",");
homePageMap = getImageMap(video[1]);
homePageMap = getAspect(video[1]);
homePageMap.put("url", video[1]);
homePageMap.put("type", 1);
}
......@@ -614,13 +618,63 @@ public class ItemServiceImpl implements ItemService {
return homePageMap;
}
/**
* 获取图片对象列表
*
* @param images
* @return
*/
private List<Map<String, Object>> getImagesMapList(String images) {
List<Map<String, Object>> list = new ArrayList<>();
String[] image = images.split(";");
for (int i = 0; i < image.length; i++) {
Map<String, Object> map = new HashMap<>();
if (image[i].contains("_")) {
map = getAspect(image[i]);
} else {
map.put("width", "0");
map.put("type", "0");
}
map.put("url", image[i]);
map.put("type", 2);
list.add(map);
}
return list;
}
/**
* 获取视频对象列表
*
* @param videos
* @return
*/
private List<Map<String, Object>> getVideosMapList(String videos) {
List<Map<String, Object>> list = new ArrayList<>();
String[] video = videos.split(";");
for (int i = 0; i < video.length; i++) {
Map<String, Object> map = new HashMap<>();
if (video[i].contains(",")) {
String[] image = video[i].split(",");
map = getAspect(image[1]);
map.put("url", image[0]);
} else {
map.put("width", "0");
map.put("type", "0");
map.put("url", video[i]);
}
map.put("type", 1);
list.add(map);
}
return list;
}
/**
* 获取图片的长宽
*
* @param image
* @return
*/
private Map<String, Object> getImageMap(String image) {
private Map<String, Object> getAspect(String image) {
Map<String, Object> map = new HashMap<>();
String[] _image = image.split("_");
String[] infoImage = _image[1].split("\\.");
......
package com.wwdz.ch.wx.impl;
package com.wwdz.ch.wx.manager;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
......@@ -7,8 +7,6 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.alibaba.fastjson.JSON;
import com.wwdz.ch.core.util.OkHttpUtil;
import com.wwdz.ch.wx.entity.request.UserRequestDto;
import com.wwdz.ch.wx.service.WxLoginService;
import com.wwdz.ch.wx.util.RedisUtil;
import com.xxdxxs.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -21,7 +19,7 @@ import java.util.HashMap;
import java.util.Map;
@Service
public class WxLoginServiceImpl implements WxLoginService {
public class WxLoginManager {
private static final Logger logger = LoggerFactory.getLogger(WxMaServiceImpl.class);
private static final String appid = "wx5b4409448bf2c72b";
......@@ -33,11 +31,8 @@ public class WxLoginServiceImpl implements WxLoginService {
@Autowired
private WxMaService wxMaService;
@Autowired
private RedisUtil redisUtil;
@Override
public String getPhone(UserRequestDto dto) {
String phone = "";
if (dto.getType() == 1) {
......@@ -88,27 +83,9 @@ public class WxLoginServiceImpl implements WxLoginService {
return phone;
}
@Override
public String getAccessToken() {
logger.info("开始获取access_token----------------");
try {
// if (redisUtil.hasKey(CacheCodeConstants.WX_ACCESS_TOKEN)) {
// logger.info("从redis获取access_token成功");
// return redisUtil.get(CacheCodeConstants.WX_ACCESS_TOKEN).toString();
// } else {
// String accessTokenUrl = String.format(GET_ACCESS_TOKEN_URL, appid, secret);
// String res = OkHttpUtil.builder().url(accessTokenUrl)
// .get().sync();
// logger.info("获取access_token结果:" + res);
// if (!res.contains("access_token")) {
// logger.error("获取accessToken出错,返回结果是:" + res);
// return null;
// }
// String accessToken = JsonUtils.getValueByPath(res, "access_token");
// String expiresIn = JsonUtils.getValueByPath(res, "expires_in");
// redisUtil.set(CacheCodeConstants.WX_ACCESS_TOKEN, accessToken, Long.parseLong(expiresIn));
// return accessToken;
// }
String accessTokenUrl = String.format(GET_ACCESS_TOKEN_URL, appid, secret);
String res = OkHttpUtil.builder().url(accessTokenUrl)
.get().sync();
......@@ -124,7 +101,6 @@ public class WxLoginServiceImpl implements WxLoginService {
}
}
@Override
public InputStream getWxacodeStream(String page, String scene) {
try {
String accessToken = getAccessToken();
......@@ -141,7 +117,6 @@ public class WxLoginServiceImpl implements WxLoginService {
}
}
@Override
public String getLink (String pageUrl) {
try {
String accessToken = getAccessToken();
......
package com.wwdz.ch.wx.service;
import com.wwdz.ch.wx.entity.request.UserRequestDto;
import java.io.InputStream;
public interface WxLoginService {
/**
* 获取微信用户手机号
*
* @param dto
* @return
*/
String getPhone(UserRequestDto dto);
/**
* 获取微信用户授权access_token
*
* @return
*/
String getAccessToken();
/**
* 获取微信小程序小程序码图片流
*
* @param path
* @param scene
* @return
*/
InputStream getWxacodeStream(String path, String scene);
/**
* 获取微信小程序短链接
*
* @param pageUrl
* @return
*/
String getLink (String pageUrl);
}
......@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.wx.entity.request.ItemRequestDto;
import com.wwdz.ch.wx.service.ItemService;
import com.wwdz.ch.wx.service.WxLoginService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -15,8 +14,6 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@RestController
......@@ -26,8 +23,6 @@ public class WxItemController {
@Autowired
private ItemService itemService;
@Autowired
private WxLoginService wxLoginService;
@ApiOperation(value = "藏品名称联想")
@PostMapping("/findNames")
......@@ -139,18 +134,6 @@ public class WxItemController {
return itemService.cancel(dto);
}
@ApiOperation(value = "小程序授权码")
@PostMapping("/getAccessToken")
public Result getAccessToken() {
String accessToken = wxLoginService.getAccessToken();
if (StringUtils.isBlank(accessToken)) {
return Result.failed("获取access_token失败");
}
Map<String, Object> map = new HashMap<>();
map.put("access_token", accessToken);
return Result.success(map);
}
@ApiOperation(value = "小程序码")
@GetMapping("/getWxacode")
public Result getWxacode(String page, String scene, HttpServletResponse response) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment