Commit 62494496 authored by renjie's avatar renjie

生产环境参数

parent bfee1df5
...@@ -93,11 +93,6 @@ ...@@ -93,11 +93,6 @@
<artifactId>aliyun-java-sdk-core</artifactId> <artifactId>aliyun-java-sdk-core</artifactId>
<version>4.1.0</version> <version>4.1.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency> <dependency>
<groupId>com.alipay.sdk</groupId> <groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId> <artifactId>alipay-sdk-java</artifactId>
......
...@@ -23,6 +23,9 @@ import org.apache.commons.lang3.StringUtils; ...@@ -23,6 +23,9 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties;
import org.springframework.core.env.Environment;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
...@@ -55,6 +58,9 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -55,6 +58,9 @@ public class IpResourceServiceImpl implements IpResourceService {
private static String startscript = ""; private static String startscript = "";
@Value("${spring.profiles.active}")
private String profiles;
@Autowired @Autowired
private AccountRepository accountRepository; private AccountRepository accountRepository;
...@@ -79,13 +85,19 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -79,13 +85,19 @@ public class IpResourceServiceImpl implements IpResourceService {
public HttpHeaders buildPostHeader() { public HttpHeaders buildPostHeader() {
HttpHeaders header = new HttpHeaders(); HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_JSON); header.setContentType(MediaType.APPLICATION_JSON);
header.setBearerAuth("oq5tg3gMsflHcK5iZ2741G5R30XYd9blyOqH9qeBItKtrzfTsGIoy8AsxqqNXdcm"); if (profiles.equals("dev"))
header.setBearerAuth("oq5tg3gMsflHcK5iZ2741G5R30XYd9blyOqH9qeBItKtrzfTsGIoy8AsxqqNXdcm");
else if (profiles.equals("prod"))
header.setBearerAuth("tKWsuHzcngf0RQPMss70f9jgymDIwgQ9zbLfESJdcou3pZSNWl7lNTzto8VQgwaO");
return header; return header;
} }
public HttpHeaders buildGetHeader() { public HttpHeaders buildGetHeader() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setBearerAuth("oq5tg3gMsflHcK5iZ2741G5R30XYd9blyOqH9qeBItKtrzfTsGIoy8AsxqqNXdcm"); if (profiles.equals("dev"))
headers.setBearerAuth("oq5tg3gMsflHcK5iZ2741G5R30XYd9blyOqH9qeBItKtrzfTsGIoy8AsxqqNXdcm");
else if (profiles.equals("prod"))
headers.setBearerAuth("tKWsuHzcngf0RQPMss70f9jgymDIwgQ9zbLfESJdcou3pZSNWl7lNTzto8VQgwaO");
return headers; return headers;
} }
...@@ -112,6 +124,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -112,6 +124,7 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override @Override
public List<IpResourceDto> buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception { public List<IpResourceDto> buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception {
String URL = (profiles.equals("dev") || profiles.equals("staging"))? TESTURL : CLOUDAMURL;
Account account = accountRepository.findByName(username); Account account = accountRepository.findByName(username);
if (account == null) if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST); throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
...@@ -156,7 +169,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -156,7 +169,7 @@ public class IpResourceServiceImpl implements IpResourceService {
HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(map, header); HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(map, header);
IpBuyResultDto ipBuyResultDto = null; IpBuyResultDto ipBuyResultDto = null;
try { try {
ipBuyResultDto = restTemplate.postForObject(TESTURL + "/intelligroup/ipresources?accountId=browser", httpEntity, IpBuyResultDto.class); ipBuyResultDto = restTemplate.postForObject(URL + "/intelligroup/ipresources?accountId=browser", httpEntity, IpBuyResultDto.class);
if (StringUtils.isNotBlank(ipBuyResultDto.getErrorCode())) if (StringUtils.isNotBlank(ipBuyResultDto.getErrorCode()))
throw new Exception(ipBuyResultDto.getErrorCode()); throw new Exception(ipBuyResultDto.getErrorCode());
} catch (Throwable e) { } catch (Throwable e) {
...@@ -213,6 +226,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -213,6 +226,7 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override @Override
public IpOperationResultDto renewIp(String username, IpResourceRequestDto ipResourceRequestDto) { public IpOperationResultDto renewIp(String username, IpResourceRequestDto ipResourceRequestDto) {
String URL = (profiles.equals("dev") || profiles.equals("staging"))? TESTURL : CLOUDAMURL;
Account account = accountRepository.findByName(username); Account account = accountRepository.findByName(username);
if (account == null) if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST); throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
...@@ -240,7 +254,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -240,7 +254,7 @@ public class IpResourceServiceImpl implements IpResourceService {
map.put("period", ipResourceRequestDto.getPeriod()); map.put("period", ipResourceRequestDto.getPeriod());
HttpHeaders headers = buildPostHeader(); HttpHeaders headers = buildPostHeader();
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(map, headers); HttpEntity<Map<String, Object>> entity = new HttpEntity<>(map, headers);
ResponseEntity<String> result = restTemplate.exchange(TESTURL + "/intelligroup/renewip?accountId=browser", HttpMethod.PUT, entity, String.class); ResponseEntity<String> result = restTemplate.exchange(URL + "/intelligroup/renewip?accountId=browser", HttpMethod.PUT, entity, String.class);
RenewIpResultDto renewIpResultDto = JSON.parseObject(result.getBody(), RenewIpResultDto.class); RenewIpResultDto renewIpResultDto = JSON.parseObject(result.getBody(), RenewIpResultDto.class);
if (StringUtils.isNotBlank(renewIpResultDto.getErrorCode())) { if (StringUtils.isNotBlank(renewIpResultDto.getErrorCode())) {
logger.error(renewIpResultDto.getErrorCode()); logger.error(renewIpResultDto.getErrorCode());
...@@ -272,6 +286,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -272,6 +286,7 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override @Override
public IpOperationResultDto deleteIp(String username, List<String> ipAddrs) { public IpOperationResultDto deleteIp(String username, List<String> ipAddrs) {
String URL = (profiles.equals("dev") || profiles.equals("staging"))? TESTURL : CLOUDAMURL;
Account account = accountRepository.findByName(username); Account account = accountRepository.findByName(username);
if (account == null) if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST); throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
...@@ -298,7 +313,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -298,7 +313,7 @@ public class IpResourceServiceImpl implements IpResourceService {
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
HttpEntity<Map<String, String>> httpEntity = new HttpEntity<>(params, headers); HttpEntity<Map<String, String>> httpEntity = new HttpEntity<>(params, headers);
try { try {
ResponseEntity<String> result = restTemplate.exchange(TESTURL + "/intelligroup/ipresources?accountId=browser&ip={ip}", HttpMethod.DELETE, httpEntity, String.class, ipAddr); ResponseEntity<String> result = restTemplate.exchange(URL + "/intelligroup/ipresources?accountId=browser&ip={ip}", HttpMethod.DELETE, httpEntity, String.class, ipAddr);
DeleteIpResultDto deleteIpResultDto = JSON.parseObject(result.getBody(), DeleteIpResultDto.class); DeleteIpResultDto deleteIpResultDto = JSON.parseObject(result.getBody(), DeleteIpResultDto.class);
if (StringUtils.isNotBlank(deleteIpResultDto.getErrorCode())) if (StringUtils.isNotBlank(deleteIpResultDto.getErrorCode()))
throw new Exception(deleteIpResultDto.getErrorCode()); throw new Exception(deleteIpResultDto.getErrorCode());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment