添加微信接口二进制转base64

master
吴顺杰 2 years ago
parent 9a200012a0
commit 0d689924dd

@ -1,6 +1,8 @@
package com.ruoyi.system.service.impl; package com.ruoyi.system.service.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
@ -14,6 +16,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Arrays; import java.util.Arrays;
@ -153,8 +156,11 @@ public class WeChatServiceImpl implements WeChatService {
} }
map.put("path", req.getPath() + "?shanghuId=" + req.getShanghuId()); map.put("path", req.getPath() + "?shanghuId=" + req.getShanghuId());
String jsonStr = JSONUtil.toJsonStr(map); String jsonStr = JSONUtil.toJsonStr(map);
String body = HttpUtil.post("https://api.weixin.qq.com/wxa/getwxacode?access_token=" + accessToken, jsonStr); byte[] qrCode = HttpRequest.post("https://api.weixin.qq.com/wxa/getwxacode?access_token=" + accessToken)
// return Base64.getEncoder().encodeToString(body.getBytes()); .body(jsonStr)
return body.getBytes(); .execute().bodyBytes();
String filePath = "../classes/data/uploads/"+"vx图片"+".jpg";
File file = FileUtil.writeBytes(qrCode, filePath);
return qrCode;
} }
} }

Loading…
Cancel
Save