|
@@ -1,11 +1,17 @@
|
|
|
package com.zbkj.front.service.impl;
|
|
|
|
|
|
|
|
|
+import com.zbkj.common.model.cat.Cart;
|
|
|
+import com.zbkj.common.model.cat.CartShare;
|
|
|
import com.zbkj.common.request.GetwxacodeRequest;
|
|
|
import com.zbkj.common.request.SmsPayRequest;
|
|
|
import com.zbkj.common.utils.RedisUtil;
|
|
|
import com.zbkj.front.service.AAAService;
|
|
|
+import com.zbkj.service.service.CartService;
|
|
|
+import com.zbkj.service.service.CartShareService;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.poi.ss.formula.functions.IDStarAlgorithm;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
@@ -26,7 +32,8 @@ import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.time.Instant;
|
|
|
-
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
|
@Service
|
|
@@ -34,6 +41,10 @@ public class AAAServiceImpl implements AAAService {
|
|
|
|
|
|
@Autowired
|
|
|
private RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ private CartService cartService;
|
|
|
+ @Autowired
|
|
|
+ private CartShareService cartShareService;
|
|
|
|
|
|
private static final String APP_ID = "wx2198b51c8406aed0";
|
|
|
|
|
@@ -43,15 +54,28 @@ public class AAAServiceImpl implements AAAService {
|
|
|
private static Instant accessTokenExpiry;
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public String getImage(GetwxacodeRequest getwxacodeRequest) {
|
|
|
String scene = getwxacodeRequest.getScene();
|
|
|
String page = getwxacodeRequest.getPath();
|
|
|
String env_version = getwxacodeRequest.getEnvVersion();
|
|
|
- String fileNmae = "/crmebimage/public/miniprogrampic/"+System.currentTimeMillis()+".png";
|
|
|
+ String fileNmae = "/crmebimage/public/miniprogrampic/" + System.currentTimeMillis() + ".png";
|
|
|
// String fileNmaes = "C:\\Users\\ASUS\\Desktop\\mer_java\\crmebimage\\public\\miniprogrampic\\"+fileNmae;
|
|
|
- String fileNmaes = "/usr/java/AimagePath"+fileNmae;
|
|
|
+ String fileNmaes = "/usr/java/AimagePath" + fileNmae;
|
|
|
+ //将分享的购物车数据存入新表,以便后期查看数据保证分享数据不发生变化
|
|
|
+ String cartIdString = scene.substring(0, scene.indexOf("&"));
|
|
|
+ String substring = cartIdString.substring(cartIdString.indexOf("=")+1);
|
|
|
+ String[] cartIds = substring.split(",");
|
|
|
+ List<Cart> cartList = cartService.getListByid(cartIds);
|
|
|
+ ArrayList<CartShare> cartShares = new ArrayList<>();
|
|
|
+ for (Cart cart:cartList){
|
|
|
+ CartShare cartShare = new CartShare();
|
|
|
+ BeanUtils.copyProperties(cart,cartShare);
|
|
|
+ cartShares.add(cartShare);
|
|
|
+ }
|
|
|
+ cartShareService.saveBatch(cartShares);
|
|
|
+
|
|
|
+
|
|
|
File outputFile = new File(fileNmaes);
|
|
|
|
|
|
// if (!isValidAccessToken()) {
|
|
@@ -60,15 +84,15 @@ public class AAAServiceImpl implements AAAService {
|
|
|
//// return null;
|
|
|
//// }
|
|
|
//// }
|
|
|
- if (!redisUtil.exists( "wxaccessToken" )){
|
|
|
+ if (!redisUtil.exists("wxaccessToken")) {
|
|
|
// if (!updateAccessToken()) {
|
|
|
// System.err.println("Failed to update access token.");
|
|
|
// return null;
|
|
|
// }
|
|
|
updateAccessToken();
|
|
|
- redisUtil.set( "wxaccessToken",accessToken,6000L );
|
|
|
+ redisUtil.set("wxaccessToken", accessToken, 6000L);
|
|
|
}
|
|
|
- String accessToken2 = redisUtil.get( "wxaccessToken" );
|
|
|
+ String accessToken2 = redisUtil.get("wxaccessToken");
|
|
|
try {
|
|
|
String urlStr = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken2;
|
|
|
URL url = new URL(urlStr);
|
|
@@ -78,7 +102,7 @@ public class AAAServiceImpl implements AAAService {
|
|
|
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
|
|
|
|
|
// 构造请求体
|
|
|
- String jsonRequest ="{\"scene\":\"" + scene + "\",\"env_version\":\"" + env_version + "\", \"page\":\"" + page + "\"}";
|
|
|
+ String jsonRequest = "{\"scene\":\"" + scene + "\",\"env_version\":\"" + env_version + "\", \"page\":\"" + page + "\"}";
|
|
|
|
|
|
OutputStream output = conn.getOutputStream();
|
|
|
output.write(jsonRequest.getBytes("UTF-8"));
|