| | |
| | | import java.io.FileInputStream;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.util.Date;
|
| | | import java.util.UUID;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.QRCodeUtil;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.share.ShareMapper;
|
| | | import com.yeshi.fanli.service.inter.user.QrCodeService;
|
| | |
| | | import com.yeshi.fanli.util.FileUtil;
|
| | | import com.yeshi.fanli.util.ImageUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.QRCodeUtil;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
|
| | | @Service
|
| | | public class QrCodeServiceImpl implements QrCodeService {
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public String drawInviteQrCode(String url, Long uid, String portrait) throws IOException {
|
| | | public String drawInviteQrCode(String url, Long uid, String portrait, String inviteCode) throws IOException {
|
| | | if (url != null && !url.equals("")) {
|
| | | String targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | | String erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | |
| | | InputStream erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 二维码
|
| | |
|
| | | // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片
|
| | | ImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath);
|
| | | ImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, inviteCode);
|
| | |
|
| | | if (new File(targetPath).exists() && new File(targetPath).length() > 0) {
|
| | | // 上传文件
|
| | |
| | |
|
| | | @Override
|
| | | public String drawInviteQrCode(String url, Long uid, String portrait, int erCodePostionX, int erCodePostionY,
|
| | | int erCodeSize) throws IOException {
|
| | | int erCodeSize, String inviteCode) throws IOException {
|
| | | if (!StringUtil.isNullOrEmpty(url)) {
|
| | | String targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | | String erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | |
| | |
|
| | | // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片
|
| | | ImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath,
|
| | | erCodePostionX, erCodePostionY, erCodeSize);
|
| | | erCodePostionX, erCodePostionY, erCodeSize, inviteCode);
|
| | |
|
| | | if (new File(targetPath).exists() && new File(targetPath).length() > 0) {
|
| | | // 上传文件
|
| | |
| | | }
|
| | | return null;
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public String drawInviteQrCodeNew(String url, Long uid, String portrait, Integer pX, Integer pY, Integer size, String inviteCode) throws IOException {
|
| | | |
| | | if (StringUtil.isNullOrEmpty(url)) {
|
| | | return null;
|
| | | }
|
| | | |
| | | String targetPath = null;
|
| | | String erCodeTempPath = null;
|
| | | InputStream erCodeInputStream = null; // 二维码
|
| | | InputStream portraitInputStream = null; // 头像
|
| | | InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 背景
|
| | | |
| | | String uuid = UUID.randomUUID().toString().replace("-", "");
|
| | | if (uid == null) {
|
| | | targetPath = FileUtil.getCacheDir() + "/share_" + uuid + "_" + System.currentTimeMillis() + ".jpg";
|
| | | // 官方 邀请码(无效的)
|
| | | inviteCode = "FLQAPP";
|
| | | // 官方二维码
|
| | | erCodeInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official.png");
|
| | | // 官方默认头像
|
| | | portraitInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_icon.png");
|
| | | |
| | | } else {
|
| | | |
| | | targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | | erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | | |
| | | String erCode = HttpUtil.getShortLink("http://" + Constant.wxGZConfig.getLoginHost() + "/"
|
| | | + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid);
|
| | | // 生成
|
| | | try {
|
| | | QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | | urlInputStream = HttpUtil.getAsInputStream(url); // 背景
|
| | | portraitInputStream = HttpUtil.getAsInputStream(portrait); // 头像
|
| | | erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 二维码
|
| | | }
|
| | | |
| | | // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片
|
| | | ImageUtil.inviteFriendImgWhitecustom(urlInputStream, portraitInputStream, erCodeInputStream, targetPath,
|
| | | pX, pY, size, inviteCode);
|
| | | |
| | | // 删除二维码文件
|
| | | if(erCodeInputStream != null) {
|
| | | erCodeInputStream.close();
|
| | | }
|
| | | if (erCodeTempPath != null && new File(erCodeTempPath).exists()) {
|
| | | new File(erCodeTempPath).delete();
|
| | | }
|
| | | |
| | | // 上传文件相对位置
|
| | | if (new File(targetPath).exists() && new File(targetPath).length() > 0) {
|
| | | int index = url.lastIndexOf("/");
|
| | | String newUrl = url.substring(index + 1);
|
| | | String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf("."));
|
| | | String fileUrl= null;
|
| | | if (uid == null) {
|
| | | fileUrl = "ercode/" + "ercode_" + uuid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg";
|
| | | } else {
|
| | | fileUrl = "ercode/" + "ercode_" + uid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg";
|
| | | }
|
| | |
|
| | | // 上传文件
|
| | | String imgUrl = COSManager.getInstance().uploadFile(new File(targetPath), fileUrl).getUrl();
|
| | | |
| | | // 删除本地缓存文件
|
| | | new File(targetPath).delete();
|
| | |
|
| | | return imgUrl;
|
| | | }
|
| | | return null;
|
| | | }
|
| | | |
| | | @Override
|
| | | public String drawInviteToGreet(String url, Long uid, String portrait, String inviteCode, String content, |
| | | Date date) throws IOException {
|
| | | |
| | | if (StringUtil.isNullOrEmpty(url)) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | String targetPath = null;
|
| | | String erCodeTempPath = null;
|
| | | InputStream erCodeInputStream = null; // 二维码
|
| | | InputStream portraitInputStream = null; // 头像
|
| | | InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 背景
|
| | | |
| | | String uuid = UUID.randomUUID().toString().replace("-", "");
|
| | | if (uid == null) {
|
| | | targetPath = FileUtil.getCacheDir() + "/share_" + uuid + "_" + System.currentTimeMillis() + ".jpg";
|
| | | // 官方 邀请码(无效的)
|
| | | inviteCode = "FLQAPP";
|
| | | // 官方二维码
|
| | | erCodeInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official.png");
|
| | | // 官方默认头像
|
| | | portraitInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_icon.png");
|
| | | |
| | | } else {
|
| | | targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | | erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | | String erCode = HttpUtil.getShortLink("http://" + Constant.wxGZConfig.getLoginHost() + "/"
|
| | | + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid);
|
| | | // 生成
|
| | | try {
|
| | | QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); |
| | | portraitInputStream = HttpUtil.getAsInputStream(portrait); // 头像
|
| | | }
|
| | | |
| | | |
| | | // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片
|
| | | ImageUtil.drawInviteToGreet(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, inviteCode, content, date);
|
| | |
|
| | | |
| | | // 删除二维码文件
|
| | | if(erCodeInputStream != null) {
|
| | | erCodeInputStream.close();
|
| | | }
|
| | | if (erCodeTempPath != null && new File(erCodeTempPath).exists()) {
|
| | | new File(erCodeTempPath).delete();
|
| | | }
|
| | | |
| | | // 上传文件
|
| | | if (new File(targetPath).exists() && new File(targetPath).length() > 0) {
|
| | | int index = url.lastIndexOf("/");
|
| | | String newUrl = url.substring(index + 1);
|
| | | String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf("."));
|
| | |
|
| | | // 上传文件相对位置
|
| | | String fileUrl= null;
|
| | | if (uid == null) {
|
| | | fileUrl = "ercode/" + "ercode_" + uuid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg";
|
| | | } else {
|
| | | fileUrl = "ercode/" + "ercode_" + uid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg";
|
| | | }
|
| | |
|
| | | // 上传
|
| | | String imgUrl = COSManager.getInstance().uploadFile(new File(targetPath), fileUrl).getUrl();
|
| | | // 删除缓存文件
|
| | | new File(targetPath).delete();
|
| | |
|
| | | return imgUrl;
|
| | | } |
| | | return null;
|
| | | }
|
| | |
|
| | | }
|