|
|
@@ -1,18 +1,13 @@
|
|
|
package com.cyksj.service.register.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.lang.UUID;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
-import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
-import cn.hutool.http.Method;
|
|
|
-import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.cyksj.common.EnvCommonService;
|
|
|
import com.cyksj.common.constant.TemplateEnum;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
@@ -22,7 +17,10 @@ import com.cyksj.mapper.RegisterOrderDonMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponMapper;
|
|
|
import com.cyksj.model.dto.WxMpTemplateData;
|
|
|
import com.cyksj.model.dto.WxMpTemplateMessage;
|
|
|
-import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.entity.Coupon;
|
|
|
+import com.cyksj.model.entity.CouponUser;
|
|
|
+import com.cyksj.model.entity.RegisterOrderDon;
|
|
|
+import com.cyksj.model.entity.SysConfig;
|
|
|
import com.cyksj.model.request.SpotifyRegisterReq;
|
|
|
import com.cyksj.model.response.ProxyInfo;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
@@ -32,16 +30,16 @@ import com.cyksj.service.sys.SysConfigService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import okhttp3.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
import java.net.InetSocketAddress;
|
|
|
import java.net.Proxy;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
|
|
/**
|
|
|
* @author chan
|
|
|
@@ -139,34 +137,67 @@ public class SpotifyServiceImpl implements SpotifyService {
|
|
|
map.put("Sec-Fetch-Mode", "cors");
|
|
|
map.put("Sec-Fetch-Site", "same-site");
|
|
|
map.put("referrer-policy", "strict-origin-when-cross-origin");
|
|
|
- List<ProxyInfo> proxyInfos = (List<ProxyInfo>) redisService.get(RedisKey.IP_LIST);
|
|
|
+ CopyOnWriteArrayList<ProxyInfo> proxyInfos = (CopyOnWriteArrayList<ProxyInfo>) redisService.get(RedisKey.IP_LIST);
|
|
|
if (proxyInfos == null || proxyInfos.size() == 0) {
|
|
|
- String res = HttpUtil.get("http://api.proxy.ipidea.io/getProxyIp?num=10&return_type=json&lb=1&sb=0&flow=1®ions=jp&protocol=http");
|
|
|
- JSONObject jsonObject = JSONUtil.parseObj(res);
|
|
|
- JSONArray data = jsonObject.getJSONArray("data");
|
|
|
- proxyInfos = data.toList(ProxyInfo.class);
|
|
|
+ //String res = HttpUtil.get("http://api.proxy.ipidea.io/getProxyIp?num=30&return_type=json&lb=1&sb=0&flow=1®ions=&protocol=http");
|
|
|
+ //JSONObject jsonObject = JSONUtil.parseObj(res);
|
|
|
+ //JSONArray data = jsonObject.getJSONArray("data");
|
|
|
+ //proxyInfos = new CopyOnWriteArrayList<>(data.toList(ProxyInfo.class));
|
|
|
+
|
|
|
+ String result = HttpUtil.get("https://dvapi.doveip.com/cmapi.php?rq=distribute&user=1031494735&token=ckc1MUFURnk3bi80MXVxeUFTZUh0Zz09&auth=0&geo=tr&agreement=0&timeout=10&num=1&type_ip=1&repeat=0");
|
|
|
+ log.info("付费ip 请求返回 res:{}",result);
|
|
|
+ /*
|
|
|
+ * {
|
|
|
+ * "errno": 200,
|
|
|
+ * "msg": "Success",
|
|
|
+ * "data": {
|
|
|
+ * "geo": "mx", //国家
|
|
|
+ * "ip": "47.253.12.97", //代理ip
|
|
|
+ * "port": 40076, //代理端口
|
|
|
+ * "d_ip": "201.162.169.86" //目标ip
|
|
|
+ * "timeout": 600 //有效时间(秒)
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ */
|
|
|
+ JSONObject resObj = JSONUtil.parseObj(result);
|
|
|
+ if (200 == resObj.getInt("errno")) {
|
|
|
+ JSONObject data = resObj.getJSONObject("data");
|
|
|
+ ProxyInfo proxyInfo = new ProxyInfo();
|
|
|
+ proxyInfo.setPort(data.getInt("port"));
|
|
|
+ proxyInfo.setIp(data.getStr("ip"));
|
|
|
+ log.info("----------付费IP地址----------\n ip:{}",proxyInfo);
|
|
|
+ proxyInfos = new CopyOnWriteArrayList<>();
|
|
|
+ proxyInfos.add(proxyInfo);
|
|
|
+ }else {
|
|
|
+ log.error("----------获取 付费IP 错误 停止循环----------");
|
|
|
+ }
|
|
|
}
|
|
|
int count = 1;
|
|
|
while (count <= 10) {
|
|
|
+ boolean flag = false;
|
|
|
for (ProxyInfo proxyInfo : proxyInfos) {
|
|
|
try {
|
|
|
log.info("执行:info:{}", proxyInfo);
|
|
|
|
|
|
- Proxy proxy = new Proxy(Proxy.Type.HTTP,
|
|
|
+ Proxy proxy = new Proxy(Proxy.Type.SOCKS,
|
|
|
new InetSocketAddress(proxyInfo.getIp(), proxyInfo.getPort()));
|
|
|
- OkHttpClient client = new OkHttpClient().newBuilder().proxy(proxy).build();
|
|
|
- RequestBody requestBody = FormBody.create(JSONUtil.toJsonStr(registerReq).getBytes(StandardCharsets.UTF_8),MediaType.parse("application/json; charset=utf-8"));
|
|
|
-
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url("https://spclient.wg.spotify.com/signup/public/v2/account/create")
|
|
|
- .post(requestBody)
|
|
|
- .headers(Headers.of(map))
|
|
|
- .build();
|
|
|
-
|
|
|
- okhttp3.Response response = client.newCall(request).execute();
|
|
|
- ResponseBody body = response.body();
|
|
|
-
|
|
|
- String spotifyBody = body.string();
|
|
|
+ //OkHttpClient client = new OkHttpClient().newBuilder().proxy(proxy).build();
|
|
|
+ //log.info("spotify request body :{}",JSONUtil.toJsonStr(registerReq));
|
|
|
+ //RequestBody requestBody = FormBody.create(JSONUtil.toJsonStr(registerReq),MediaType.parse("application/json; charset=utf-8"));
|
|
|
+ //
|
|
|
+ //Request request = new Request.Builder()
|
|
|
+ // .url("https://spclient.wg.spotify.com/signup/public/v2/account/create")
|
|
|
+ // .post(requestBody)
|
|
|
+ // .headers(Headers.of(map))
|
|
|
+ // .build();
|
|
|
+ //
|
|
|
+ //okhttp3.Response response = client.newCall(request).execute();
|
|
|
+ //ResponseBody body = response.body();
|
|
|
+ HttpRequest request = new HttpRequest("https://spclient.wg.spotify.com/signup/public/v2/account/create");
|
|
|
+ request.setProxy(proxy);
|
|
|
+ request.body(JSONUtil.toJsonStr(registerReq));
|
|
|
+ request.addHeaders(map);
|
|
|
+ String spotifyBody = request.execute().body();
|
|
|
|
|
|
log.info("spotify 返回body:{}", spotifyBody);
|
|
|
/*
|
|
|
@@ -192,9 +223,9 @@ public class SpotifyServiceImpl implements SpotifyService {
|
|
|
}
|
|
|
*/
|
|
|
JSONObject resObj = JSONUtil.parseObj(spotifyBody);
|
|
|
- JSONObject error_details = resObj.getJSONObject("error").getJSONObject("error_details");
|
|
|
-
|
|
|
- if (error_details == null) {
|
|
|
+ log.info("spotify 返回:{}",resObj);
|
|
|
+ JSONObject error = resObj.getJSONObject("error");
|
|
|
+ if (error.isEmpty()) {
|
|
|
JSONObject success = resObj.getJSONObject("success");
|
|
|
if (StringUtils.isNotBlank(success.getStr("login_token")) || StringUtils.isNotBlank("username")) {
|
|
|
log.info("注册成功!");
|
|
|
@@ -204,11 +235,17 @@ public class SpotifyServiceImpl implements SpotifyService {
|
|
|
spotifyTemplateMsg(registerOrderDon, String.format("%s%s", envCommonService.getDomain(), "yinhe/web/sign/list"), true);
|
|
|
//注册成功发放声破天优惠券
|
|
|
sendSpotifyCoupon(registerOrderDon);
|
|
|
+ flag = true;
|
|
|
break;
|
|
|
+ }else if(!resObj.getJSONObject("challenge").isEmpty()) {
|
|
|
+ log.info("spotify 注册 被监测出代理服务 。 删除该代理 ip:{}", proxyInfo.getIp());
|
|
|
+ proxyInfos.remove(proxyInfo);
|
|
|
}
|
|
|
}else {
|
|
|
+ JSONObject error_details = error.getJSONObject("error_details");
|
|
|
String errorMsg = error_details.getStr("body");
|
|
|
- if (errorMsg.equals("4") ||StringUtils.isNotBlank(errorMsg) || "你的设备似乎已连接至代理或 VPN 服务。请关闭此类服务,然后再试一次。".equals(errorMsg) || errorMsg.contains("代理")) {
|
|
|
+ Integer code = error_details.getInt("code");
|
|
|
+ if (code.equals(4) || "你的设备似乎已连接至代理或 VPN 服务。请关闭此类服务,然后再试一次。".equals(errorMsg) || errorMsg.contains("代理")) {
|
|
|
log.info("spotify 注册 被监测出代理服务 。 删除该代理 ip:{}", proxyInfo.getIp());
|
|
|
proxyInfos.remove(proxyInfo);
|
|
|
continue;
|
|
|
@@ -220,18 +257,22 @@ public class SpotifyServiceImpl implements SpotifyService {
|
|
|
|
|
|
//注册失败发放模板消息
|
|
|
spotifyTemplateMsg(registerOrderDon, String.format("%s%s", envCommonService.getDomain(), "yinhe/web/sign/list"), false);
|
|
|
+ flag = true;
|
|
|
break;
|
|
|
-
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
proxyInfos.remove(proxyInfo);
|
|
|
log.error("错误 ip:{}", proxyInfo.getIp());
|
|
|
+ e.printStackTrace();
|
|
|
count++;
|
|
|
}
|
|
|
}
|
|
|
+ if(flag){
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- redisService.set(RedisKey.IP_LIST,proxyInfos,600L);
|
|
|
+ redisService.set(RedisKey.IP_LIST,proxyInfos,360L);
|
|
|
}
|
|
|
|
|
|
private void sendSpotifyCoupon(RegisterOrderDon registerOrderDon) {
|
|
|
@@ -252,7 +293,7 @@ public class SpotifyServiceImpl implements SpotifyService {
|
|
|
private void spotifyTemplateMsg(RegisterOrderDon registerOrderDon, String url, Boolean isSuccess) throws Exception {
|
|
|
TemplateEnum templateEnum = null;
|
|
|
if (EnvCommonService.active.equals(envCommonService.getEnv())) {
|
|
|
- templateEnum = TemplateEnum.SPOTIFY_ENV_TEMPLATE;
|
|
|
+ return;
|
|
|
}else {
|
|
|
templateEnum = TemplateEnum.SPOTIFY_PRD_TEMPLATE;
|
|
|
}
|