|
|
@@ -0,0 +1,236 @@
|
|
|
+package com.mokamrp.privates.tast.pangu;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.mokamrp.privates.constant.RedisKey;
|
|
|
+import com.mokamrp.privates.mapper.pangu.pojo.DomainFirst;
|
|
|
+import com.mokamrp.privates.mapper.pangu.pojo.DomainSecond;
|
|
|
+import com.mokamrp.privates.service.pangu.DomainFirstService;
|
|
|
+import com.mokamrp.privates.service.pangu.DomainSecondService;
|
|
|
+import com.mokamrp.privates.service.pangu.PlaybillService;
|
|
|
+import com.mokamrp.privates.service.pangu.PromoteCodeService;
|
|
|
+import com.mokamrp.privates.utils.Cmd;
|
|
|
+import com.mokamrp.privates.utils.http.HttpResponsePojo;
|
|
|
+import com.mokamrp.privates.utils.http.HttpUtils;
|
|
|
+import lombok.Data;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.autoconfigure.cache.CacheProperties;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.net.ConnectException;
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class CheckWxDomainStatus {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public DomainFirstService domainFirstService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public DomainSecondService domainSecondService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public StringRedisTemplate stringRedisTemplate;
|
|
|
+
|
|
|
+ private final String domain = "open.weixin.qq.com";
|
|
|
+ private final String homepageurl = "https://open.weixin.qq.com/";
|
|
|
+ private final String loginurl = "https://open.weixin.qq.com/cgi-bin/login";
|
|
|
+ private final String checkdomianurl = "https://open.weixin.qq.com/cgi-bin/component_acct";
|
|
|
+ private final String feishu = "https://open.feishu.cn/open-apis/bot/v2/hook/d2b5556d-30fb-400e-b10f-cb9310dbc705";
|
|
|
+
|
|
|
+ private final String account = "kaifa01@hzlomo.cn";
|
|
|
+ private final String passwd = "b95495d2b655e0cd832244427261b76a";
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(HttpUtils.class);
|
|
|
+
|
|
|
+ @Scheduled(fixedDelay = 300 * 1000) //.间隔 半小时
|
|
|
+ public void execute() {
|
|
|
+ System.out.println("[cronjob]:检测域名微信内封禁状态");
|
|
|
+ List<DomainFirst> domainFirstList = domainFirstService.list(new QueryWrapper<DomainFirst>().ne("status",3));
|
|
|
+ List<DomainSecond> domainSecondList = domainSecondService.list(new QueryWrapper<DomainSecond>().ne("status",2));
|
|
|
+ for (DomainFirst domainFirst : domainFirstList){
|
|
|
+ Boolean res = this.checkDomain(domainFirst.getDomain());
|
|
|
+ if (res == false){
|
|
|
+ //.更新状态为域名封禁
|
|
|
+ DomainFirst save = new DomainFirst();
|
|
|
+ save.setStatus(3);
|
|
|
+ save.setForbbidenAt(LocalDateTime.now());
|
|
|
+ domainFirstService.update(save,new QueryWrapper<DomainFirst>().eq("id",domainFirst.getId()));
|
|
|
+ Cmd.sendFeishuMsg(feishu,"[警告]:一级域名"+domainFirst.getDomain()+"被封禁");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (DomainSecond domainSecond : domainSecondList){
|
|
|
+ Boolean res = this.checkDomain(domainSecond.getDomain());
|
|
|
+ if (res == false){
|
|
|
+ //.更新状态 同时去除redis
|
|
|
+ stringRedisTemplate.opsForZSet().remove(RedisKey.PanSecondDomainList,domainSecond.getDomain());
|
|
|
+ DomainSecond save = new DomainSecond();
|
|
|
+ save.setStatus(2);
|
|
|
+ save.setForbbidenAt(LocalDateTime.now());
|
|
|
+ domainSecondService.update(save,new QueryWrapper<DomainSecond>().eq("id",domainSecond.getId()));
|
|
|
+ Cmd.sendFeishuMsg(feishu,"[警告]:二级域名"+domainSecond.getDomain()+"被封禁");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean checkDomain(String domain){
|
|
|
+ String checkDomain = domain;
|
|
|
+ Map<String, Object> tokenRes = this.getToken();
|
|
|
+ if (tokenRes.get("token") == null) {
|
|
|
+ //.登录失败
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ String cookie = "data_bizuin=" + tokenRes.get("dataBizuin") +
|
|
|
+ ";data_ticket=" + tokenRes.get("dataTicket") +
|
|
|
+ ";ticket=ab8b1f3f74f3594bc7541689dd673ec452e0b3a6;cert=pp3fphHQZw07bwrLrnebTgMiciggnp0d" +
|
|
|
+ ";fake_id=" + tokenRes.get("fakeId") +
|
|
|
+ ";master_sid=" + tokenRes.get("masterSid");
|
|
|
+ Map<String, String> header = this.buildHeader();
|
|
|
+ header.put("Cookie", cookie);
|
|
|
+ String params = "wxa_server_domain=&" +
|
|
|
+ "jump_h5_domain=&" +
|
|
|
+ "appid=wx5bafb2538d3d9402&" +
|
|
|
+ "action=check_domain_by_scene&" +
|
|
|
+ "key=check_domain_by_scene&" +
|
|
|
+ "lang=zh_CN&" +
|
|
|
+ "f=json&" +
|
|
|
+ "token=" + tokenRes.get("token") + "&" +
|
|
|
+ "sns_domain=" + checkDomain;
|
|
|
+ HttpResponsePojo checkRes = sendPost(this.checkdomianurl, header, params);
|
|
|
+ JSONObject body = JSON.parseObject(checkRes.getBody());
|
|
|
+ JSONObject baseResp = JSON.parseObject(body.getJSONObject("base_resp").toString());
|
|
|
+ if (Integer.parseInt(baseResp.get("ret").toString()) == 1053) {
|
|
|
+ //.域名封禁
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取登录token
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Object> getToken() {
|
|
|
+ Map<String, Object> res = new HashMap<>();
|
|
|
+ String jsonStr = stringRedisTemplate.opsForValue().get(RedisKey.CheckWxDomainToken);
|
|
|
+ if (jsonStr != null && !jsonStr.isEmpty()){
|
|
|
+ res = JSON.parseObject(jsonStr,Map.class);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ Map<String, String> header = this.buildHeader();
|
|
|
+ String params = "token=&" +
|
|
|
+ "lang=zh_CN&" +
|
|
|
+ "f=json&" +
|
|
|
+ "ajax=1&" +
|
|
|
+ "key=1&" +
|
|
|
+ "account=" + account + "&" +
|
|
|
+ "passwd=" + passwd + "&";
|
|
|
+ HttpResponsePojo httpResponsePojo = this.sendPost(this.loginurl, header, params);
|
|
|
+ List<String> setCookie = httpResponsePojo.getResponseHeader().get("Set-Cookie");
|
|
|
+ List<String> cookies = new ArrayList<>(setCookie);
|
|
|
+ for (int i = 0; i < cookies.size(); i++) {
|
|
|
+ cookies.set(i, cookies.get(i).split(";")[0]);
|
|
|
+ cookies.set(i, cookies.get(i).split("=")[1]);
|
|
|
+ }
|
|
|
+ JSONObject body = JSON.parseObject(httpResponsePojo.getBody());
|
|
|
+ JSONObject baseResp = JSON.parseObject(body.getJSONObject("base_resp").toString());
|
|
|
+ if (Integer.parseInt(baseResp.get("ret").toString()) == 0) {
|
|
|
+ res.put("token", baseResp.get("token").toString());
|
|
|
+ res.put("dataBizuin", cookies.get(3));
|
|
|
+ res.put("dataTicket", cookies.get(2));
|
|
|
+ res.put("fakeId", cookies.get(1));
|
|
|
+ res.put("masterSid", cookies.get(0));
|
|
|
+ stringRedisTemplate.opsForValue().set(RedisKey.CheckWxDomainToken,JSON.toJSONString(res));
|
|
|
+ stringRedisTemplate.expire(RedisKey.CheckWxDomainToken,3600, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> buildHeader() {
|
|
|
+ Map<String, String> header = new HashMap<>();
|
|
|
+ header.put("Referer", "https://open.weixin.qq.com/cgi-bin/frame?t=home/mp_tmpl&lang=zh_CN");
|
|
|
+ header.put("Host", "open.weixin.qq.com");
|
|
|
+ header.put("Origin", "https://mp.weixin.qq.com");
|
|
|
+ header.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36");
|
|
|
+ header.put("X-Requested-With", "XMLHttpRequest");
|
|
|
+ header.put("Connection","keep-alive");
|
|
|
+ header.put("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
|
+ header.put("Accept-Encoding", "gzip, deflate, br");
|
|
|
+ header.put("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
|
|
|
+ header.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
|
+ header.put("Cookie", "pgv_pvi=2698027008; ptui_loginuin=1935951743; pt2gguin=o1935951743; RK=tmwoZCHVY0; ptcz=0323743c131b12434561be1c3136cd79bf79d526ac7f6e0dd935c6e73e74013f; pgv_pvid=6597685168; data_bizuin=3508179233; _qpsvr_localtk=1533696622886; data_ticket=i/mHR9mcpIYcoKi37t5TbUz3IrlSD25lQ8SFa7fp27rAL0w7xNxgvQsvUfvt1w6r; ticket_id=0; ticket=a88ec404a133959fc82c23293d077b843c43f9de; cert=pc9NWFBxXQWyb3Ih8s0Zy1Z4Fo2on3DD");
|
|
|
+ return header;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static HttpResponsePojo sendPost(String url, Map<String, String> header, String param) {
|
|
|
+ PrintWriter out = null;
|
|
|
+ BufferedReader in = null;
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
+ Map<String, List<String>> responseHeader = new HashMap<>();
|
|
|
+ try {
|
|
|
+ String urlNameString = url;
|
|
|
+ URL realUrl = new URL(urlNameString);
|
|
|
+ URLConnection conn = realUrl.openConnection();
|
|
|
+ for (Map.Entry<String, String> entry : header.entrySet()) {
|
|
|
+ conn.setRequestProperty(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+// conn.setRequestProperty("accept", "*/*");
|
|
|
+// conn.setRequestProperty("connection", "Keep-Alive");
|
|
|
+// conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
|
|
+// conn.setRequestProperty("Accept-Charset", "utf-8");
|
|
|
+// conn.setRequestProperty("contentType", "utf-8");
|
|
|
+ conn.setDoOutput(true);
|
|
|
+ conn.setDoInput(true);
|
|
|
+ out = new PrintWriter(conn.getOutputStream());
|
|
|
+ out.print(param);
|
|
|
+ out.flush();
|
|
|
+ in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
|
|
|
+ String line;
|
|
|
+ responseHeader = conn.getHeaderFields();
|
|
|
+ while ((line = in.readLine()) != null) {
|
|
|
+ result.append(line);
|
|
|
+ }
|
|
|
+ log.info("recv - {}", result);
|
|
|
+ } catch (ConnectException e) {
|
|
|
+ log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
|
|
|
+ } catch (SocketTimeoutException e) {
|
|
|
+ log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (out != null) {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ if (in != null) {
|
|
|
+ in.close();
|
|
|
+ }
|
|
|
+ } catch (IOException ex) {
|
|
|
+ log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ HttpResponsePojo httpResponsePojo = new HttpResponsePojo();
|
|
|
+ httpResponsePojo.setBody(result.toString());
|
|
|
+ httpResponsePojo.setResponseHeader(responseHeader);
|
|
|
+ return httpResponsePojo;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|