|
@@ -5,7 +5,9 @@ import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei365.user.model.ResponseJson;
|
|
|
+import com.caimei365.user.utils.FastDfsUtil;
|
|
|
import com.caimei365.user.utils.RequestUtil;
|
|
|
+import com.sun.org.apache.regexp.internal.RE;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -14,18 +16,19 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.crypto.Cipher;
|
|
|
import javax.crypto.spec.IvParameterSpec;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.security.AlgorithmParameters;
|
|
|
import java.security.Security;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 微信 服务工具类
|
|
@@ -59,6 +62,11 @@ public class WeChatService {
|
|
|
private String mcareAppId;
|
|
|
@Value("${wx.mcare-app-secret}")
|
|
|
private String mcareAppSecret;
|
|
|
+ @Value("${spring.cloud.config.profile}")
|
|
|
+ private String active;
|
|
|
+ @Resource
|
|
|
+ private FastDfsUtil fastDfsUtil;
|
|
|
+
|
|
|
|
|
|
public void setRedirectUri(String redirectUri) {
|
|
|
redirectUri = redirectUri;
|
|
@@ -638,5 +646,53 @@ public class WeChatService {
|
|
|
return ResponseJson.success(result);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据accessToken生成小程序二维码
|
|
|
+ */
|
|
|
+ public ResponseJson<String> generateWxacode(String access_token,String params) throws Exception {
|
|
|
+ String requestUrl = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + access_token;
|
|
|
+ ByteArrayInputStream inputStream = RequestUtil.sendPost(requestUrl, params);
|
|
|
+ try {
|
|
|
+ String fileUrl = null;
|
|
|
+ String url = saveFile(inputStream);
|
|
|
+ fileUrl = "https://img-b.caimei365.com" + "/" + url;
|
|
|
+ log.info("【图片上传】>>>>>>>>>>>>>>>>上传成功:" + fileUrl);
|
|
|
+ return ResponseJson.success(fileUrl);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("【图片上传】>>>>>>>>>>>>>>>>上传失败:" + e);
|
|
|
+ return ResponseJson.error("图片上传失败", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存文件到FastDFS
|
|
|
+ */
|
|
|
+ private String saveFile(ByteArrayInputStream inputStream) throws IOException {
|
|
|
+ String randomStr = UUID.randomUUID().toString();
|
|
|
+ String name = ".jpeg";
|
|
|
+ // 图片暂存本地服务器路径
|
|
|
+ String filePath = "/mnt/newdatadrive/data/runtime/jar-instance/mall2c/tempImage/";
|
|
|
+ if ("dev".equals(active)){
|
|
|
+ filePath = "D:\\";
|
|
|
+ }
|
|
|
+ filePath += randomStr + name;
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(filePath);
|
|
|
+ int i = 0;
|
|
|
+ byte[] buffer = new byte[200];
|
|
|
+ while ((i = inputStream.read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, i);
|
|
|
+ }
|
|
|
+ outputStream.flush();
|
|
|
+ outputStream.close();
|
|
|
+ inputStream.close();
|
|
|
+ // 临时图片
|
|
|
+ File tempFile = new File(filePath);
|
|
|
+ log.info("【图片上传】>>>>>>>>>>>>>>>>图片临时路径:" + filePath);
|
|
|
+ String fileUrl = fastDfsUtil.uploadFile(filePath);
|
|
|
+ // 删除临时图片
|
|
|
+ boolean delete = tempFile.delete();
|
|
|
+ log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时图片:" + delete);
|
|
|
+ return fileUrl;
|
|
|
+ }
|
|
|
}
|