|
|
@@ -1,4 +1,4 @@
|
|
|
-package com.cyksj.web.controller.manage.spotify;
|
|
|
+package com.cyksj.service.register.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
@@ -14,18 +14,16 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.ProxysMapper;
|
|
|
-import com.cyksj.mapper.SpotifyRegisterMapper;
|
|
|
+import com.cyksj.mapper.RegisterOrderDonMapper;
|
|
|
import com.cyksj.model.entity.Proxys;
|
|
|
+import com.cyksj.model.entity.RegisterOrderDon;
|
|
|
import com.cyksj.model.entity.SpotifyRegister;
|
|
|
-import com.cyksj.model.manage.request.SpotifyRegisterReq;
|
|
|
import com.cyksj.model.response.ProxyInfo;
|
|
|
+import com.cyksj.service.register.SpotifyService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
import java.net.Proxy;
|
|
|
@@ -36,17 +34,16 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author chan
|
|
|
- * @date 2022/11/3 3:50 PM
|
|
|
+ * @date 2022/11/7 1:54 PM
|
|
|
*/
|
|
|
-@RequestMapping("/spotify")
|
|
|
-@RestController
|
|
|
+@Service
|
|
|
@Slf4j
|
|
|
@RequiredArgsConstructor
|
|
|
-public class SpotifyController {
|
|
|
+public class SpotifyServiceImpl implements SpotifyService {
|
|
|
|
|
|
private final ProxysMapper proxysMapper;
|
|
|
|
|
|
- private final SpotifyRegisterMapper spotifyRegisterMapper;
|
|
|
+ private final RegisterOrderDonMapper registerOrderDonMapper;
|
|
|
|
|
|
private static final List<String> User_Agent_LIST = List.of(
|
|
|
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
|
|
|
@@ -84,9 +81,10 @@ public class SpotifyController {
|
|
|
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11",
|
|
|
"Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10");
|
|
|
|
|
|
- @PostMapping("/register")
|
|
|
- public Result<String> register(@RequestBody SpotifyRegisterReq registerReq){
|
|
|
- log.info("spotify 请求 params:{}",registerReq);
|
|
|
+ @Override
|
|
|
+ public void register(Long registerOrderId){
|
|
|
+ log.info("spotify 注册 orderId:{}",registerOrderId);
|
|
|
+ RegisterOrderDon registerOrderDon = registerOrderDonMapper.selectById(registerOrderId);
|
|
|
HttpRequest request = new HttpRequest("https://spclient.wg.spotify.com/signup/public/v1/account");
|
|
|
|
|
|
request.header("User-Agent", User_Agent_LIST.get(RandomUtil.randomInt(User_Agent_LIST.size())));
|
|
|
@@ -101,16 +99,16 @@ public class SpotifyController {
|
|
|
jsonObject.put("key","a1e486e2729f46d6bb368d6b2bcda326");
|
|
|
//creation_point=https://www.spotify.com/uk/
|
|
|
jsonObject.put("creation_point","https://www.spotify.com/us/");
|
|
|
- jsonObject.put("displayname",registerReq.getDisplayname());
|
|
|
- jsonObject.put("password_repeat",registerReq.getPasswordRepeat());
|
|
|
- jsonObject.put("password",registerReq.getPassword());
|
|
|
- jsonObject.put("username",registerReq.getUsername());
|
|
|
- jsonObject.put("birth_year",registerReq.getBirthYear());
|
|
|
- jsonObject.put("birth_month",registerReq.getBirthMonth());
|
|
|
- jsonObject.put("birth_day",registerReq.getBirthDay());
|
|
|
- jsonObject.put("gender",registerReq.getGender());
|
|
|
- jsonObject.put("email",registerReq.getEmail());
|
|
|
- jsonObject.put("iagree",registerReq.getIagree());
|
|
|
+ jsonObject.put("displayname",registerOrderDon.getNickname());
|
|
|
+ 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("gender",registerOrderDon.getGender());
|
|
|
+ jsonObject.put("email",registerOrderDon.getEmail());
|
|
|
+ jsonObject.put("iagree","1");
|
|
|
request.setMethod(Method.POST);
|
|
|
|
|
|
request.form(jsonObject);
|
|
|
@@ -123,7 +121,7 @@ public class SpotifyController {
|
|
|
|
|
|
int start = 1;
|
|
|
int limit = 20;
|
|
|
-
|
|
|
+ boolean regFlag = false;
|
|
|
while (true){
|
|
|
for (ProxyInfo proxyInfo : proxyInfos) {
|
|
|
try {
|
|
|
@@ -135,20 +133,39 @@ public class SpotifyController {
|
|
|
String body = response.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){
|
|
|
+ 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"))){
|
|
|
log.info("注册成功!");
|
|
|
- SpotifyRegister spotifyRegister = new SpotifyRegister();
|
|
|
- BeanUtil.copyProperties(registerReq,spotifyRegister);
|
|
|
- spotifyRegisterMapper.insert(spotifyRegister);
|
|
|
+ registerOrderDon.setStatus(RegisterOrderDon.Status.complete);
|
|
|
+ registerOrderDonMapper.updateById(registerOrderDon);
|
|
|
+ regFlag = true;
|
|
|
break;
|
|
|
}
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("注册成功!");
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
log.error("错误 ip:{}",proxyInfo.getIp());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if(regFlag){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
List<Proxys> records = proxysMapper.selectPage(new Page<>(start, limit), Wrappers.lambdaQuery(Proxys.class).orderByDesc(Proxys::getId)).getRecords();
|
|
|
if(records.isEmpty()){
|
|
|
break;
|
|
|
@@ -160,10 +177,7 @@ public class SpotifyController {
|
|
|
return proxyInfo;
|
|
|
}).collect(Collectors.toList());
|
|
|
}
|
|
|
-
|
|
|
- return GatewayResponse.FAIL.newBuilder().toResult("注册失败!");
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
-
|