|
|
@ -2,7 +2,11 @@ package com.bsd.say.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.api.R;
|
|
|
|
import com.bsd.say.beans.AjaxResult;
|
|
|
|
import com.bsd.say.beans.AjaxResult;
|
|
|
|
|
|
|
|
import com.bsd.say.entities.Record;
|
|
|
|
|
|
|
|
import com.bsd.say.mapper.RecordMapper;
|
|
|
|
import com.bsd.say.service.WxOpenServiceDemo;
|
|
|
|
import com.bsd.say.service.WxOpenServiceDemo;
|
|
|
|
import com.bsd.say.service.impl.WeixinService;
|
|
|
|
import com.bsd.say.service.impl.WeixinService;
|
|
|
|
import com.bsd.say.util.AESWithJCEUtils;
|
|
|
|
import com.bsd.say.util.AESWithJCEUtils;
|
|
|
@ -24,6 +28,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("wechat")
|
|
|
|
@RequestMapping("wechat")
|
|
|
@ -45,6 +50,8 @@ public class WechatController {
|
|
|
|
Logger logger = LogUtils.getBussinessLogger();
|
|
|
|
Logger logger = LogUtils.getBussinessLogger();
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private WeixinService weixinService;
|
|
|
|
private WeixinService weixinService;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private RecordMapper recordMapper;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 接收component_verify_ticket 或 authorized事件
|
|
|
|
* 接收component_verify_ticket 或 authorized事件
|
|
|
@ -143,6 +150,31 @@ public class WechatController {
|
|
|
|
String decode = AESWithJCEUtils.aesDecode(result3, pubkey, iv);
|
|
|
|
String decode = AESWithJCEUtils.aesDecode(result3, pubkey, iv);
|
|
|
|
String resutl = HttpRequestUtils.sendGet("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + decode + "&openid=" + openId + "&lang=zh_CN");
|
|
|
|
String resutl = HttpRequestUtils.sendGet("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + decode + "&openid=" + openId + "&lang=zh_CN");
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(resutl);
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(resutl);
|
|
|
|
|
|
|
|
int subscribe = jsonObject.getInteger("subscribe");
|
|
|
|
|
|
|
|
Record recordByOpenId = recordMapper.selectOne(Wrappers.<Record>lambdaQuery().eq(Record::getOpenId,openId)
|
|
|
|
|
|
|
|
.and(queryWrapper1 -> queryWrapper1.eq(Record::getState,1)));
|
|
|
|
|
|
|
|
if (subscribe == 0){
|
|
|
|
|
|
|
|
//未关注公众号
|
|
|
|
|
|
|
|
if (recordByOpenId == null){
|
|
|
|
|
|
|
|
Record record = new Record();
|
|
|
|
|
|
|
|
record.setOpenId(openId);
|
|
|
|
|
|
|
|
record.setFan("新粉丝");
|
|
|
|
|
|
|
|
record.setCreateDateTime(new Date());
|
|
|
|
|
|
|
|
recordMapper.insert(record);
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
logger.info("游客访问过,但未关注");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
//关注过公众号
|
|
|
|
|
|
|
|
if (recordByOpenId == null){
|
|
|
|
|
|
|
|
Record record = new Record();
|
|
|
|
|
|
|
|
record.setOpenId(openId);
|
|
|
|
|
|
|
|
record.setFan("老粉丝");
|
|
|
|
|
|
|
|
record.setCreateDateTime(new Date());
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
logger.info("老粉丝访问过,已关注");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
AjaxResult ajaxResult = new AjaxResult();
|
|
|
|
AjaxResult ajaxResult = new AjaxResult();
|
|
|
|
ajaxResult.setData(jsonObject);
|
|
|
|
ajaxResult.setData(jsonObject);
|
|
|
|
return ajaxResult;
|
|
|
|
return ajaxResult;
|
|
|
|