|
|
@@ -27,9 +27,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
import java.net.Proxy;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -99,83 +97,100 @@ public class SpotifyServiceImpl implements SpotifyService {
|
|
|
jsonObject.put("key","a1e486e2729f46d6bb368d6b2bcda326");
|
|
|
//creation_point=https://www.spotify.com/uk/
|
|
|
jsonObject.put("creation_point","https://www.spotify.com/us/");
|
|
|
- jsonObject.put("displayname",registerOrderDon.getNickname());
|
|
|
+ jsonObject.put("displayname",Optional.ofNullable(registerOrderDon.getNickname()).orElse(registerOrderDon.getEmail()));
|
|
|
jsonObject.put("password_repeat",registerOrderDon.getPassword());
|
|
|
jsonObject.put("password",registerOrderDon.getPassword());
|
|
|
- jsonObject.put("username",registerOrderDon.getUsername());
|
|
|
- jsonObject.put("birth_year",registerOrderDon.getBirthYear());
|
|
|
- jsonObject.put("birth_month",registerOrderDon.getBirthMonth());
|
|
|
- jsonObject.put("birth_day",registerOrderDon.getBirthDay());
|
|
|
+ jsonObject.put("username",Optional.ofNullable(registerOrderDon.getUsername()).orElse(registerOrderDon.getEmail()));
|
|
|
+ jsonObject.put("birth_year", Optional.ofNullable(registerOrderDon.getBirthYear()).orElse("1995"));
|
|
|
+ jsonObject.put("birth_month",Optional.ofNullable(registerOrderDon.getBirthMonth()).orElse("01"));
|
|
|
+ jsonObject.put("birth_day",Optional.ofNullable(registerOrderDon.getBirthDay()).orElse("01"));
|
|
|
jsonObject.put("gender",registerOrderDon.getGender());
|
|
|
jsonObject.put("email",registerOrderDon.getEmail());
|
|
|
jsonObject.put("iagree","1");
|
|
|
request.setMethod(Method.POST);
|
|
|
+ request.setConnectionTimeout(15 * 1000);
|
|
|
+ request.setReadTimeout(15 * 1000);
|
|
|
|
|
|
request.form(jsonObject);
|
|
|
|
|
|
- String proxyJson = HttpUtil.get("http://inside.sxfoundation.com:8899/api/v1/proxies");
|
|
|
- log.info(proxyJson);
|
|
|
- JSONArray array = JSONUtil.parseObj(proxyJson).getJSONArray("proxies");
|
|
|
- List<ProxyInfo> proxyInfos = array.toList(ProxyInfo.class);
|
|
|
- log.info("{}",proxyInfos);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
int start = 1;
|
|
|
int limit = 20;
|
|
|
boolean regFlag = false;
|
|
|
- while (true){
|
|
|
+ while (true) {
|
|
|
+
|
|
|
+ List<ProxyInfo> proxyInfos = new ArrayList<>();
|
|
|
+ List<Proxys> records = proxysMapper.selectPage(new Page<>(start, limit), Wrappers.lambdaQuery(Proxys.class).orderByDesc(Proxys::getId)).getRecords();
|
|
|
+ if (records.isEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ proxyInfos = records.stream().map((proxy) -> {
|
|
|
+ ProxyInfo proxyInfo = new ProxyInfo();
|
|
|
+ proxyInfo.setIp(proxy.getIp());
|
|
|
+ proxyInfo.setPort(proxy.getPort());
|
|
|
+ return proxyInfo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
for (ProxyInfo proxyInfo : proxyInfos) {
|
|
|
try {
|
|
|
- log.info("执行:info:{}",proxyInfo);
|
|
|
+ log.info("执行:info:{}", proxyInfo);
|
|
|
Proxy proxy = new Proxy(Proxy.Type.HTTP,
|
|
|
new InetSocketAddress(proxyInfo.getIp(), proxyInfo.getPort()));
|
|
|
request.setProxy(proxy);
|
|
|
HttpResponse response = request.execute();
|
|
|
String body = response.body();
|
|
|
- log.info("spotify 返回body:{}",body);
|
|
|
+ log.info("spotify 返回body:{}", body);
|
|
|
JSONObject resObj = JSONUtil.parseObj(body);
|
|
|
JSONObject errors = resObj.getJSONObject("errors");
|
|
|
- String errorMsg = errors.getStr("generic_error");
|
|
|
- if (!errors.isEmpty()) {
|
|
|
- if ("你似乎正在使用代理服务。请关闭此类服务,然后再试一次。如需更多帮助,请联系客服服务。".equals(errorMsg)) {
|
|
|
- log.info("spotify 注册 被监测出代理服务 。 删除该代理 ip:{}",proxyInfo.getIp());
|
|
|
- if(proxyInfo.getId() != null){
|
|
|
+
|
|
|
+ Integer status = resObj.getInt("status");
|
|
|
+ if (status == 320) {
|
|
|
+ String errorMsg = errors.getStr("generic_error");
|
|
|
+ if (StringUtils.isNotBlank(errorMsg) || "你似乎正在使用代理服务。请关闭此类服务,然后再试一次。如需更多帮助,请联系客户服务。".equals(errorMsg) || errorMsg.contains("代理")) {
|
|
|
+ log.info("spotify 注册 被监测出代理服务 。 删除该代理 ip:{}", proxyInfo.getIp());
|
|
|
+ if (proxyInfo.getId() != null) {
|
|
|
proxysMapper.deleteById(proxyInfo.getId());
|
|
|
}
|
|
|
continue;
|
|
|
- }else {
|
|
|
- registerOrderDon.setErrorMsg(errorMsg);
|
|
|
- registerOrderDon.setStatus(RegisterOrderDon.Status.error);
|
|
|
- registerOrderDonMapper.updateById(registerOrderDon);
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
- if(StringUtils.isNotBlank(resObj.getStr("login_token"))){
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(resObj.getStr("login_token"))) {
|
|
|
log.info("注册成功!");
|
|
|
registerOrderDon.setStatus(RegisterOrderDon.Status.complete);
|
|
|
registerOrderDonMapper.updateById(registerOrderDon);
|
|
|
regFlag = true;
|
|
|
break;
|
|
|
+ } else {
|
|
|
+ if (errors != null && !errors.isEmpty()) {
|
|
|
+ StringBuilder error = new StringBuilder();
|
|
|
+ for (String str : errors.keySet()) {
|
|
|
+ error.append(errors.getStr(str));
|
|
|
+ }
|
|
|
+ registerOrderDon.setErrorMsg(error.toString());
|
|
|
+ registerOrderDon.setStatus(RegisterOrderDon.Status.error);
|
|
|
+ registerOrderDonMapper.updateById(registerOrderDon);
|
|
|
+ regFlag = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (proxyInfo.getId() != null) {
|
|
|
+ proxysMapper.deleteById(proxyInfo.getId());
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
- log.error("错误 ip:{}",proxyInfo.getIp());
|
|
|
+ log.error("错误 ip:{}", proxyInfo.getIp());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(regFlag){
|
|
|
+ if (regFlag) {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- List<Proxys> records = proxysMapper.selectPage(new Page<>(start, limit), Wrappers.lambdaQuery(Proxys.class).orderByDesc(Proxys::getId)).getRecords();
|
|
|
- if(records.isEmpty()){
|
|
|
- break;
|
|
|
- }
|
|
|
- proxyInfos = records.stream().map((proxy)->{
|
|
|
- ProxyInfo proxyInfo = new ProxyInfo();
|
|
|
- proxyInfo.setIp(proxy.getIp());
|
|
|
- proxyInfo.setPort(proxy.getPort());
|
|
|
- return proxyInfo;
|
|
|
- }).collect(Collectors.toList());
|
|
|
}
|
|
|
}
|
|
|
|