|
@@ -5,12 +5,15 @@ import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
|
import cn.hutool.extra.qrcode.QrConfig;
|
|
import cn.hutool.extra.qrcode.QrConfig;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.miaxis.common.constant.Constants;
|
|
import com.miaxis.common.utils.http.HttpUtils;
|
|
import com.miaxis.common.utils.http.HttpUtils;
|
|
-import com.miaxis.common.utils.wx.MessageUtil;
|
|
|
|
-import com.miaxis.feign.dto.WxTicket;
|
|
|
|
-import com.miaxis.feign.service.IWxMpService;
|
|
|
|
|
|
+import com.miaxis.feign.dto.WxQrTicket;
|
|
import com.miaxis.feign.service.IWxSendService;
|
|
import com.miaxis.feign.service.IWxSendService;
|
|
|
|
+import com.miaxis.spread.domain.WxSpreadRelation;
|
|
|
|
+import com.miaxis.spread.service.IWxSpreadRelationService;
|
|
import com.miaxis.wx.service.IWxMessageEvenService;
|
|
import com.miaxis.wx.service.IWxMessageEvenService;
|
|
|
|
+import com.miaxis.wx.service.IWxTicketService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -19,6 +22,8 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.awt.*;
|
|
import java.awt.*;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author wwl
|
|
* @author wwl
|
|
@@ -32,32 +37,56 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
|
|
|
|
|
|
private final RedisTemplate redisTemplate;
|
|
private final RedisTemplate redisTemplate;
|
|
|
|
|
|
- private final IWxMpService wxMpService;
|
|
|
|
-
|
|
|
|
private final IWxSendService wxSendService;
|
|
private final IWxSendService wxSendService;
|
|
|
|
|
|
|
|
+ private final IWxTicketService wxTicketService;
|
|
|
|
+
|
|
|
|
+ private final IWxSpreadRelationService wxSpreadRelationService;
|
|
|
|
+
|
|
@Value("${file.ticketPath}")
|
|
@Value("${file.ticketPath}")
|
|
private String ticketPath;
|
|
private String ticketPath;
|
|
|
|
|
|
@Value("${wxgzh.materialUrl}")
|
|
@Value("${wxgzh.materialUrl}")
|
|
private String materialUrl;
|
|
private String materialUrl;
|
|
|
|
|
|
|
|
+ @Value("${cos.bucketName}")
|
|
|
|
+ private String bucketName;
|
|
|
|
+
|
|
|
|
+ @Value("${cos.path}")
|
|
|
|
+ private String path;
|
|
|
|
+
|
|
|
|
+ @Value("${cos.preffix}")
|
|
|
|
+ private String preffix;
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 扫码关注事件
|
|
* 扫码关注事件
|
|
* @param fromUserName 发送方帐号(一个OpenID)
|
|
* @param fromUserName 发送方帐号(一个OpenID)
|
|
- * @param toUserName 开发者微信号
|
|
|
|
- * @param Ticket 二维码的ticket
|
|
|
|
|
|
+ * @param ticket 二维码的ticket
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public String scanSubscribeEvent(String fromUserName,String toUserName, String Ticket) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ public String scanSubscribeEvent(String fromUserName, String ticket) {
|
|
|
|
+
|
|
|
|
+ String message = "";
|
|
|
|
+ //判断是否存在父级推广关系
|
|
|
|
+ List<WxSpreadRelation> spreadRelations = wxSpreadRelationService.list(new QueryWrapper<WxSpreadRelation>().eq("openid", fromUserName));
|
|
|
|
+ if (spreadRelations.isEmpty()){
|
|
|
|
+ String openid = (String) redisTemplate.opsForValue().get(Constants.GZH_TICKET_KEY + ticket);
|
|
|
|
+ //保存推广关系表
|
|
|
|
+ WxSpreadRelation wxSpreadRelation = new WxSpreadRelation();
|
|
|
|
+ wxSpreadRelation.setOpenid(fromUserName);
|
|
|
|
+ wxSpreadRelation.setParentOpenid(openid);
|
|
|
|
+ message = "已成功绑定推广关系!";
|
|
|
|
+ }else {
|
|
|
|
+ message = "已存在推广关系!";
|
|
|
|
+ }
|
|
|
|
+ return message;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * click获取分销二维码事件
|
|
|
|
|
|
+ * click获取推广二维码事件
|
|
* @param fromUserName 发送方帐号(一个OpenID)
|
|
* @param fromUserName 发送方帐号(一个OpenID)
|
|
* @param token 凭证
|
|
* @param token 凭证
|
|
* @return
|
|
* @return
|
|
@@ -65,18 +94,24 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
|
|
@Override
|
|
@Override
|
|
public String gainTicketEvent(String fromUserName,String token) {
|
|
public String gainTicketEvent(String fromUserName,String token) {
|
|
|
|
|
|
- //生成带参数二维码ticket
|
|
|
|
- WxTicket wxTicket = new WxTicket();
|
|
|
|
- wxTicket.setExpire_seconds(2592000);//30天
|
|
|
|
- wxTicket.setAction_name("QR_SCENE");
|
|
|
|
|
|
+ // 根据fromUserName查询缓存 判断用户推广码是否过期
|
|
|
|
+ if (redisTemplate.hasKey(Constants.GZH_MATERIAL_KEY + fromUserName)){
|
|
|
|
+ String mediaId = (String) redisTemplate.opsForValue().get(Constants.GZH_MATERIAL_KEY + fromUserName);
|
|
|
|
+ return mediaId;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //生成带参数二维码ticket(永久)
|
|
|
|
+ WxQrTicket wxQrTicket = new WxQrTicket();
|
|
|
|
+ wxQrTicket.setExpire_seconds(259200);//3天
|
|
|
|
+ wxQrTicket.setAction_name("QR_SCENE");//临时
|
|
JSONObject jsonObject1 = new JSONObject();
|
|
JSONObject jsonObject1 = new JSONObject();
|
|
JSONObject jsonObject2 = new JSONObject();
|
|
JSONObject jsonObject2 = new JSONObject();
|
|
jsonObject1.put("scene_id","123");
|
|
jsonObject1.put("scene_id","123");
|
|
jsonObject2.put("scene",jsonObject1);
|
|
jsonObject2.put("scene",jsonObject1);
|
|
- wxTicket.setAction_info(jsonObject2);
|
|
|
|
- String wxTicketResult = wxSendService.generateTicket(token,wxTicket);
|
|
|
|
|
|
+ wxQrTicket.setAction_info(jsonObject2);
|
|
|
|
+ String wxTicketResult = wxSendService.generateTicket(token, wxQrTicket);
|
|
JSONObject jsonStr = JSONObject.parseObject(wxTicketResult);
|
|
JSONObject jsonStr = JSONObject.parseObject(wxTicketResult);
|
|
- log.info("---------ticket-------" + wxTicketResult);
|
|
|
|
|
|
+ log.info("---------ticket-------" + jsonStr);
|
|
|
|
|
|
//根据ticket生成二维码图片存储
|
|
//根据ticket生成二维码图片存储
|
|
File ticketFile = QrCodeUtil.generate(
|
|
File ticketFile = QrCodeUtil.generate(
|
|
@@ -114,7 +149,11 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
|
|
JSONObject resultJSON = JSONObject.parseObject(result);
|
|
JSONObject resultJSON = JSONObject.parseObject(result);
|
|
log.info("------result:" + resultJSON);
|
|
log.info("------result:" + resultJSON);
|
|
|
|
|
|
- //上传完成删除服务器文件
|
|
|
|
|
|
+ //缓存用户推广码相关信息
|
|
|
|
+ redisTemplate.opsForValue().set(Constants.GZH_TICKET_KEY+jsonStr.getString("ticket"),fromUserName,259200, TimeUnit.SECONDS);
|
|
|
|
+ redisTemplate.opsForValue().set(Constants.GZH_MATERIAL_KEY+fromUserName,resultJSON.getString("media_id"),259200, TimeUnit.SECONDS);
|
|
|
|
+
|
|
|
|
+ //删除服务器文件
|
|
File imgFile = new File(ticketPath + fromUserName+"_img.jpg");
|
|
File imgFile = new File(ticketPath + fromUserName+"_img.jpg");
|
|
if (ticketFile.exists() && imgFile.exists() && textFile.exists()) {
|
|
if (ticketFile.exists() && imgFile.exists() && textFile.exists()) {
|
|
if (ticketFile.delete()) {
|
|
if (ticketFile.delete()) {
|
|
@@ -136,7 +175,7 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
|
|
|
|
|
|
return resultJSON.getString("media_id");
|
|
return resultJSON.getString("media_id");
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.info("-----异常------click获取分销二维码事件");
|
|
|
|
|
|
+ log.info("-----异常------click获取推广二维码事件");
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|