Althars123 3 jaren geleden
bovenliggende
commit
90e2b3a3d9

+ 2 - 2
twzd-service/src/main/java/com/miaxis/wx/service/IWxMessageEvenService.java

@@ -14,12 +14,12 @@ public interface IWxMessageEvenService {
     /**
      * 扫码关注事件
      * @param fromUserName 发送方帐号(一个OpenID)
-     * @param ticket 二维码的ticket
+     * @param openid 推荐人openid
      * @param token 凭证
      * @param userName 微信名称
      * @return
      */
-    String scanSubscribeEvent(String fromUserName,String ticket,String token,String userName);
+    String scanSubscribeEvent(String fromUserName,String openid,String token,String userName);
 
     /**
      * click获取分销二维码事件

+ 1 - 1
twzd-service/src/main/java/com/miaxis/wx/service/impl/WxGzhServiceImpl.java

@@ -144,7 +144,7 @@ public class WxGzhServiceImpl implements IWxGzhService {
                     if (org.apache.commons.lang3.StringUtils.isNotEmpty(jsonObjectData.getStr("Ticket"))){
                         log.info("3.1.2..");
                         //根据Ticket  绑定信息到上级用户
-                        String subscribeEvent = wxMessageEvenService.scanSubscribeEvent(fromUserName, jsonObjectData.getStr("Ticket"),this.getGzhToken(),userInfo.getNickName());
+                        String subscribeEvent = wxMessageEvenService.scanSubscribeEvent(fromUserName, jsonObjectData.getStr("EventKey"),this.getGzhToken(),userInfo.getNickName());
                         return MessageUtil.initText(fromUserName,toUserName,subscribeEvent);
 
                     }else {

+ 26 - 21
twzd-service/src/main/java/com/miaxis/wx/service/impl/WxMessageEvenServiceImpl.java

@@ -8,7 +8,6 @@ import cn.hutool.extra.qrcode.QrCodeUtil;
 import cn.hutool.extra.qrcode.QrConfig;
 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.feign.dto.WxGzhMini;
 import com.miaxis.feign.dto.WxMessageCusom;
@@ -30,7 +29,6 @@ import java.io.File;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
-import java.util.concurrent.TimeUnit;
 
 /**
  * @author wwl
@@ -42,6 +40,8 @@ import java.util.concurrent.TimeUnit;
 @RequiredArgsConstructor
 public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
 
+    private final static Integer expireTime = 2592000;//30天
+
     private final RedisTemplate redisTemplate;
 
     private final IWxSendService wxSendService;
@@ -69,19 +69,19 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
     /**
      * 扫码关注事件
      * @param fromUserName 发送方帐号(一个OpenID)
-     * @param ticket 二维码的ticket
+     * @param openid 推荐人openid
      * @param token 凭证
      * @param userName 微信名称
      * @return
      */
     @Override
-    public String scanSubscribeEvent(String fromUserName, String ticket,String token,String userName) {
+    public String scanSubscribeEvent(String fromUserName, String openid,String token,String userName) {
 
         String message = "";
         //判断是否存在父、子级推广关系
         List<WxSpreadRelation> spreadRelations = wxSpreadRelationService.list(new QueryWrapper<WxSpreadRelation>().eq("openid", fromUserName));
         List<WxSpreadRelation> spreads = wxSpreadRelationService.list(new QueryWrapper<WxSpreadRelation>().eq("parent_openid", fromUserName));
-        String openid = (String) redisTemplate.opsForValue().get(Constants.GZH_TICKET_KEY + ticket);
+        //String openid = (String) redisTemplate.opsForValue().get(Constants.GZH_TICKET_KEY + ticket);
 
         if (spreadRelations.isEmpty() && spreads.isEmpty()){
             //保存推广关系表
@@ -116,20 +116,13 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
         messageCustomSend(fromUserName,token);
 
         // 根据fromUserName查询缓存 判断用户推广码是否过期
-        if (redisTemplate.hasKey(Constants.GZH_MATERIAL_KEY + fromUserName)){
-            String mediaId = (String) redisTemplate.opsForValue().get(Constants.GZH_MATERIAL_KEY + fromUserName);
-            return mediaId;
-        }
+//        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(2592000);//30天
-        wxQrTicket.setAction_name("QR_SCENE");//临时
-        JSONObject jsonObject1 = new JSONObject();
-        JSONObject jsonObject2 = new JSONObject();
-        jsonObject1.put("scene_id","123");
-        jsonObject2.put("scene",jsonObject1);
-        wxQrTicket.setAction_info(jsonObject2);
+        //生成带参数临时二维码ticket
+        WxQrTicket wxQrTicket = createShortTimeTicket(fromUserName);
         String wxTicketResult = wxSendService.generateTicket(token, wxQrTicket);
         JSONObject jsonStr = JSONObject.parseObject(wxTicketResult);
         log.info("---------ticket-------" + jsonStr);
@@ -166,7 +159,7 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
         );
 
         DateTime date = DateUtil.date();
-        Date newDate = DateUtil.offsetDay(date, 3);
+        Date newDate = DateUtil.offsetDay(date, 30);
         String dateStr = DateUtil.format(newDate, "yyyy-MM-dd");
         log.info(dateStr);
 
@@ -191,8 +184,8 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
             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);
+//            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");
@@ -227,6 +220,18 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
         return null;
     }
 
+    private WxQrTicket createShortTimeTicket(String fromUserName) {
+        WxQrTicket wxQrTicket = new WxQrTicket();
+        wxQrTicket.setExpire_seconds(expireTime);
+        wxQrTicket.setAction_name("QR_STR_SCENE");//临时字符串参数
+        JSONObject jsonObject1 = new JSONObject();
+        JSONObject jsonObject2 = new JSONObject();
+        jsonObject1.put("scene_str",fromUserName);
+        jsonObject2.put("scene",jsonObject1);
+        wxQrTicket.setAction_info(jsonObject2);
+        return wxQrTicket;
+    }
+
 
     /**
      * 发送客服消息