Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
browser-backend
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
browser-backend
Commits
9efa15c5
Commit
9efa15c5
authored
Oct 21, 2024
by
chenchao.deng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接入 ipv
parent
0e980068
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
129 additions
and
44 deletions
+129
-44
CloudPlatformOrder.java
...gec/browserbackend/browser/domain/CloudPlatformOrder.java
+2
-0
IpResourceServiceImpl.java
...erbackend/browser/service/Impl/IpResourceServiceImpl.java
+23
-3
BrowserTask.java
...va/com/edgec/browserbackend/browser/task/BrowserTask.java
+33
-11
IpvClient.java
...gec/browserbackend/common/client/ipvClient/IpvClient.java
+50
-11
RegionMappingEnum.java
.../edgec/browserbackend/common/enums/RegionMappingEnum.java
+10
-10
IpvCliestTest.java
src/test/java/com/edgec/browserbackend/IpvCliestTest.java
+11
-9
No files found.
src/main/java/com/edgec/browserbackend/browser/domain/CloudPlatformOrder.java
View file @
9efa15c5
...
...
@@ -31,6 +31,8 @@ public class CloudPlatformOrder {
private
String
platformOrderId
;
//云平台订单id
private
String
platformInstanceNo
;
//云平台服务器No(住宅ip释放用)
private
String
platformType
;
//云平台类型
private
Integer
retryCount
;
//重试次数
...
...
src/main/java/com/edgec/browserbackend/browser/service/Impl/IpResourceServiceImpl.java
View file @
9efa15c5
...
...
@@ -23,6 +23,9 @@ import com.edgec.browserbackend.browser.service.IpAndShopService;
import
com.edgec.browserbackend.browser.service.IpResourceService
;
import
com.edgec.browserbackend.common.client.AliEcsClient
;
import
com.edgec.browserbackend.common.client.TenCentEcsClient
;
import
com.edgec.browserbackend.common.client.ipvClient.IpvClient
;
import
com.edgec.browserbackend.common.client.ipvClient.dto.AppInstanceReleaseResp
;
import
com.edgec.browserbackend.common.client.ipvClient.dto.AppOrderResp
;
import
com.edgec.browserbackend.common.commons.error.ClientRequestException
;
import
com.edgec.browserbackend.common.commons.utils.NotifyUtils
;
import
com.edgec.browserbackend.common.utils.FileUtil
;
...
...
@@ -277,6 +280,9 @@ public class IpResourceServiceImpl implements IpResourceService {
case
"tencent"
:
ipResource
.
setVendorCn
(
"腾讯云"
);
break
;
case
"isp"
:
ipResource
.
setVendorCn
(
"住宅"
);
break
;
case
"aws"
:
ipResource
.
setVendorCn
(
"亚马逊云"
);
break
;
...
...
@@ -611,6 +617,10 @@ public class IpResourceServiceImpl implements IpResourceService {
cloudPlatformOrder
.
getPlatformOrderId
(),
cloudPlatformOrder
.
getRegionId
());
}
}
else
if
(
"isp"
.
equals
(
cloudPlatformOrder
.
getPlatformType
())){
IpvClient
.
instanceRelease
(
cloudPlatformOrder
.
getPlatformOrderId
(),
cloudPlatformOrder
.
getPlatformInstanceNo
());
}
}
ipResource
.
setShopIds
(
null
);
...
...
@@ -1223,12 +1233,22 @@ public class IpResourceServiceImpl implements IpResourceService {
IPData
ipData
=
new
IPData
();
ipData
.
setIp
(
ipResource
.
getAddr
());
ipDataList
.
add
(
ipData
);
}
}
}
else
if
(
"isp"
.
equals
(
cloudPlatformOrder
.
getPlatformType
())){
AppOrderResp
response
=
IpvClient
.
instanceRenew
(
ipResource
.
getOwner
(),
cloudPlatformOrder
.
getOrderNo
(),
cloudPlatformOrder
.
getPlatformInstanceNo
(),
period
);
if
(
null
==
response
)
{
logger
.
error
(
"fail to renew ip : {}"
,
JSON
.
toJSON
(
response
));
}
else
if
(
Objects
.
nonNull
(
response
.
getAppOrderNo
())){
cloudPlatformOrder
.
setPlatformOrderId
(
response
.
getOrderNo
());
cloudPlatformOrderRepository
.
save
(
cloudPlatformOrder
);
IPData
ipData
=
new
IPData
();
ipData
.
setIp
(
ipResource
.
getAddr
());
ipDataList
.
add
(
ipData
);
}
}
}
if
(
CollectionUtils
.
isNotEmpty
(
ipDataList
))
{
...
...
src/main/java/com/edgec/browserbackend/browser/task/BrowserTask.java
View file @
9efa15c5
...
...
@@ -48,6 +48,7 @@ import com.tencentcloudapi.lighthouse.v20200324.models.CreateInstancesResponse;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.ZoneOffset
;
import
java.time.format.DateTimeFormatter
;
import
java.time.temporal.ChronoUnit
;
import
javax.annotation.Resource
;
...
...
@@ -514,7 +515,8 @@ public class BrowserTask {
ipResource
.
setStatus
(
0
);
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ISO_INSTANT
;
Instant
instant
=
Instant
.
from
(
formatter
.
parse
(
instance
.
getExpiredTime
()));
formatter
.
parse
(
instance
.
getExpiredTime
())).
atZone
(
ZoneOffset
.
UTC
).
toInstant
();
ipResource
.
setValidTime
(
instant
.
toEpochMilli
());
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
()))
{
...
...
@@ -585,6 +587,8 @@ public class BrowserTask {
}
else
if
(
"isp"
.
equals
(
cloudPlatformOrder
.
getPlatformType
())){
AppOrderResp
order
=
IpvClient
.
getOrder
(
cloudPlatformOrder
.
getPlatformOrderId
());
log
.
info
(
"调用ipv查询实例,响应参数:owner:{},response:{}"
,
ipResource
.
getOwner
(),
JSON
.
toJSON
(
order
));
if
(
order
.
getStatus
()
!=
3
)
{
//订单还没有处理完成
return
;
...
...
@@ -600,15 +604,10 @@ public class BrowserTask {
ipResource
.
setStatus
(
0
);
ipResource
.
setPort
(
Collections
.
singletonList
(
String
.
valueOf
(
appInstanceResp
.
getPort
())));
ipResource
.
set
Proxy
Username
(
appInstanceResp
.
getUsername
());
ipResource
.
setUsername
(
appInstanceResp
.
getUsername
());
ipResource
.
setPassword
(
appInstanceResp
.
getPwd
());
ipResource
.
setValidTime
(
appInstanceResp
.
getUserExpired
());
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
()))
{
ipResource
.
setProxyUsername
(
ipResource
.
getAddr
());
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
ipResource
.
setSpecialLine
(
true
);
}
//以秒为单位的时间戳需要 *1000转为毫秒级
ipResource
.
setValidTime
(
appInstanceResp
.
getUserExpired
()*
1000L
);
ipResourceRepository
.
save
(
ipResource
);
IpHistory
ipHistory
=
new
IpHistory
();
ipHistory
.
setIpNo
(
ipResource
.
getAddr
());
...
...
@@ -616,6 +615,9 @@ public class BrowserTask {
cloudPlatformOrder
.
getPlatformType
());
ipHistory
.
setPurchasedTime
(
Instant
.
now
().
toEpochMilli
());
ipHistoryRepository
.
save
(
ipHistory
);
cloudPlatformOrder
.
setPlatformInstanceNo
(
appInstanceResp
.
getInstanceNo
());
cloudPlatformOrderRepository
.
save
(
cloudPlatformOrder
);
return
;
}
}
...
...
@@ -703,7 +705,7 @@ public class BrowserTask {
ipResource
.
setStatus
(
0
);
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ISO_INSTANT
;
Instant
instant
=
Instant
.
from
(
formatter
.
parse
(
instance
.
getExpiredTime
()));
formatter
.
parse
(
instance
.
getExpiredTime
()))
.
atZone
(
ZoneOffset
.
UTC
).
toInstant
()
;
ipResource
.
setValidTime
(
instant
.
toEpochMilli
());
ipResourceRepository
.
save
(
ipResource
);
}
...
...
@@ -725,11 +727,31 @@ public class BrowserTask {
ipResource
.
setStatus
(
0
);
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ISO_INSTANT
;
Instant
instant
=
Instant
.
from
(
formatter
.
parse
(
instance
.
getExpiredTime
()));
formatter
.
parse
(
instance
.
getExpiredTime
()))
.
atZone
(
ZoneOffset
.
UTC
).
toInstant
()
;
ipResource
.
setValidTime
(
instant
.
toEpochMilli
());
ipResourceRepository
.
save
(
ipResource
);
}
}
}
else
if
(
"isp"
.
equals
(
cloudPlatformOrder
.
getPlatformType
()))
{
AppOrderResp
order
=
IpvClient
.
getOrder
(
cloudPlatformOrder
.
getPlatformOrderId
());
log
.
info
(
"调用ipv查询实例,响应参数:owner:{},response:{}"
,
ipResource
.
getOwner
(),
JSON
.
toJSON
(
order
));
if
(
order
.
getStatus
()
!=
3
)
{
//订单还没有处理完成
return
;
}
if
(
Objects
.
nonNull
(
order
.
getInstances
()))
{
//判断是否重复购买
AppInstanceResp
appInstanceResp
=
order
.
getInstances
().
get
(
0
);
if
(
appInstanceResp
.
getStatus
()
==
3
)
{
//包年包月 更新ip状态
ipResource
.
setStatus
(
0
);
ipResource
.
setValidTime
(
appInstanceResp
.
getUserExpired
()*
1000L
);
ipResourceRepository
.
save
(
ipResource
);
}
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
...
...
src/main/java/com/edgec/browserbackend/common/client/ipvClient/IpvClient.java
View file @
9efa15c5
...
...
@@ -47,9 +47,9 @@ public class IpvClient {
public
static
final
String
ENCRYPT_AES
=
"AES"
;
private
static
String
endPoint
=
"https://
sandbox
.ipipv.com"
;
private
static
String
appKey
=
"AK2024
0923090940
"
;
private
static
String
appSecret
=
"
zd7js60suebep2hkiane59g6v9j8jezv
"
;
private
static
String
endPoint
=
"https://
api
.ipipv.com"
;
private
static
String
appKey
=
"AK2024
1021180017
"
;
private
static
String
appSecret
=
"
khjqqk7eytc8otdnteuugccng69y56as
"
;
public
AppInfoResp
getAppInfo
()
throws
Exception
{
byte
[]
res
=
post
(
GET_APP_INFO_URI
,
null
);
...
...
@@ -131,8 +131,11 @@ public class IpvClient {
params
.
add
(
param
);
req
.
setParams
(
params
);
byte
[]
params1
=
JSON
.
toJSONBytes
(
req
);
log
.
info
(
"调用ipv购买实例,入参:owner:{},regionId:{},req:{}"
,
owner
,
productNo
,
JSON
.
toJSONBytes
(
req
));
byte
[]
res
=
post
(
INSTANCE_OPEN_URI
,
params1
);
resp
=
JSON
.
parseObject
(
new
String
(
res
),
AppOrderResp
.
class
);
log
.
info
(
"调用ipv购买实例,响应参数:owner:{},response:{}"
,
owner
,
JSON
.
toJSON
(
resp
));
}
catch
(
Exception
e
){
log
.
error
(
"fail to ipipv instanceOpen {}"
,
e
.
getMessage
());
}
...
...
@@ -154,17 +157,53 @@ public class IpvClient {
return
resp
;
}
public
AppOrderResp
instanceRenew
(
AppInstanceRenewReq
req
)
throws
Exception
{
byte
[]
params
=
JSON
.
toJSONBytes
(
req
);
byte
[]
res
=
post
(
INSTANCE_RENEW_URI
,
params
);
AppOrderResp
resp
=
JSON
.
parseObject
(
new
String
(
res
),
AppOrderResp
.
class
);
/**
* @author Chen
* @description 续费
* @date 2024/10/21 21:02
*/
public
static
AppOrderResp
instanceRenew
(
String
owner
,
String
orderNo
,
String
instanceNo
,
int
duration
)
{
AppOrderResp
resp
=
null
;
try
{
AppInstanceRenewReq
req
=
new
AppInstanceRenewReq
();
req
.
setAppOrderNo
(
orderNo
);
Instance
instance
=
new
Instance
();
instance
.
setInstanceNo
(
instanceNo
);
instance
.
setDuration
(
duration
);
List
<
Instance
>
list
=
new
ArrayList
<>();
list
.
add
(
instance
);
req
.
setInstances
(
list
);
byte
[]
params
=
JSON
.
toJSONBytes
(
req
);
log
.
info
(
"调用ipv续费实例,入参:owner:{},req:{}"
,
owner
,
JSON
.
toJSON
(
req
));
byte
[]
res
=
post
(
INSTANCE_RENEW_URI
,
params
);
resp
=
JSON
.
parseObject
(
new
String
(
res
),
AppOrderResp
.
class
);
log
.
info
(
"调用ipv续费实例,响应参数:owner:{},req:{}"
,
owner
,
JSON
.
toJSON
(
resp
));
}
catch
(
Exception
e
){
log
.
error
(
"fail to ipipv instanceRenew {}"
,
e
.
getMessage
());
}
return
resp
;
}
/**
* @author Chen
* @description 释放ip
* @date 2024/10/21 21:43
*/
public
static
AppInstanceReleaseResp
instanceRelease
(
String
orderNo
,
String
instanceNo
)
{
AppInstanceReleaseResp
resp
=
null
;
try
{
AppInstanceReleaseReq
req
=
new
AppInstanceReleaseReq
();
req
.
setOrderNo
(
orderNo
);
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
instanceNo
);
req
.
setInstances
(
list
);
byte
[]
params
=
JSON
.
toJSONBytes
(
req
);
byte
[]
res
=
post
(
INSTANCE_RELEASE_URI
,
params
);
resp
=
JSON
.
parseObject
(
new
String
(
res
),
AppInstanceReleaseResp
.
class
);
log
.
info
(
"调用Ipv删除ECS实例,响应参数response:{}"
,
JSON
.
toJSON
(
resp
));
}
catch
(
Exception
e
){
log
.
error
(
"fail to ipipv instanceRelease {}"
,
e
.
getMessage
());
}
public
AppInstanceReleaseResp
instanceRelease
(
AppInstanceReleaseReq
req
)
throws
Exception
{
byte
[]
params
=
JSON
.
toJSONBytes
(
req
);
byte
[]
res
=
post
(
INSTANCE_RELEASE_URI
,
params
);
AppInstanceReleaseResp
resp
=
JSON
.
parseObject
(
new
String
(
res
),
AppInstanceReleaseResp
.
class
);
return
resp
;
}
...
...
src/main/java/com/edgec/browserbackend/common/enums/RegionMappingEnum.java
View file @
9efa15c5
...
...
@@ -28,17 +28,17 @@ public enum RegionMappingEnum {
CN_HHHT
(
"huhehaote"
,
"呼和浩特"
,
"cn-huhehaote"
,
""
,
""
),
CN_CD
(
"chengdu"
,
"成都"
,
"cn-chengdu"
,
""
,
""
),
CN_HY
(
"heyuan"
,
"河源"
,
"cn-heyuan"
,
""
,
""
),
CN_HK
(
"hongkong"
,
"中国香港"
,
"cn-hongkong"
,
""
,
"
ipideash_594
"
),
CN_HK
(
"hongkong"
,
"中国香港"
,
"cn-hongkong"
,
""
,
"
mb_gmhd5exet
"
),
US
(
"us"
,
"美国随机"
,
""
,
""
,
""
),
US_CALIFORNIA
(
"california"
,
"加利福尼亚"
,
""
,
""
,
""
),
//待确认
US_VIRGINIA
(
"virginia"
,
"弗吉尼亚"
,
"us-east-1"
,
""
,
"ipideash_589"
),
EU_UK
(
"uk"
,
"英国-伦敦"
,
"eu-west-1"
,
""
,
"
ipideash_591
"
),
EU_UK
(
"uk"
,
"英国-伦敦"
,
"eu-west-1"
,
""
,
"
mb_gmh92exc3
"
),
EU_CENTRAL
(
"germany"
,
"德国-法兰克福"
,
"eu-central-1"
,
"eu-frankfurt"
,
""
),
JAPAN
(
"japan"
,
"日本-东京"
,
"ap-northeast-1"
,
"ap-tokyo"
,
""
),
SINGAPORE
(
"singapore"
,
"新加坡"
,
"ap-southeast-1"
,
"ap-singapore"
,
"
ipideash_599
"
),
SINGAPORE
(
"singapore"
,
"新加坡"
,
"ap-southeast-1"
,
"ap-singapore"
,
"
mb_gmyqad4b8
"
),
AUSTRALIA
(
"australia"
,
"澳大利亚-悉尼"
,
""
,
""
,
""
),
//待确认
MALAYSIA
(
"malaysia"
,
"马来西亚-吉隆坡"
,
"ap-southeast-3"
,
""
,
"
ipideash_604
"
),
YAJIADA
(
"yajiada"
,
"印度尼西亚-雅加达"
,
"ap-southeast-5"
,
"ap-jakarta"
,
"
ipideash_608
"
),
MALAYSIA
(
"malaysia"
,
"马来西亚-吉隆坡"
,
"ap-southeast-3"
,
""
,
"
mb_gmh92ex56
"
),
YAJIADA
(
"yajiada"
,
"印度尼西亚-雅加达"
,
"ap-southeast-5"
,
"ap-jakarta"
,
"
mb_gmh92exuc
"
),
INDIA
(
"india"
,
"孟买"
,
""
,
"ap-mumbai"
,
""
),
//待确认
MEAST
(
"meast"
,
"迪拜"
,
"me-east-1"
,
""
,
""
),
BRAZIL
(
"brazil"
,
"巴西-圣保罗"
,
""
,
"sa-saopaulo"
,
""
),
...
...
@@ -46,17 +46,17 @@ public enum RegionMappingEnum {
SILICON
(
"silicon"
,
"美国(硅谷)"
,
"us-west-1"
,
"na-siliconvalley"
,
""
),
NANJING
(
"nanjing"
,
"南京"
,
""
,
"ap-nanjing"
,
""
),
BANGKOK
(
"bangkok"
,
"泰国(曼谷)"
,
"ap-southeast-7"
,
""
,
"
ipideash_607
"
),
BANGKOK
(
"bangkok"
,
"泰国(曼谷)"
,
"ap-southeast-7"
,
""
,
"
mb_gmh92ex88
"
),
MANILA
(
"manila"
,
"菲律宾-马尼拉"
,
"ap-southeast-6"
,
""
,
"ipideash_606"
),
SEOUL
(
"seoul"
,
"韩国-首尔"
,
"ap-northeast-2"
,
"ap-seoul"
,
"ipideash_621"
),
TW
(
"taiwan"
,
"中国-台湾"
,
""
,
""
,
"
ipideash_592
"
),
TW
(
"taiwan"
,
"中国-台湾"
,
""
,
""
,
"
mb_gmhd5exem
"
),
LSWJS
(
"lasvegas"
,
"美国-拉斯维加斯"
,
""
,
""
,
"ipideash_592"
),
NY
(
"newyork"
,
"美国-纽约"
,
""
,
""
,
"ipideash_590"
),
LSG
(
"losangeles"
,
"美国-洛杉矶"
,
""
,
""
,
"ipideash_615"
),
MAM
(
"miami"
,
"美国-迈阿密"
,
""
,
""
,
"ipideash_595"
),
HSD
(
"washington"
,
"美国-华盛顿"
,
""
,
""
,
"
ipideash_613
"
),
CAN
(
"canada"
,
"加拿大"
,
""
,
""
,
"
ipideash_603
"
),
YN
(
"vietnam"
,
"越南"
,
""
,
""
,
"
ipideash_619
"
),
HSD
(
"washington"
,
"美国-华盛顿"
,
""
,
""
,
"
mb_gmxaa44sn
"
),
CAN
(
"canada"
,
"加拿大"
,
""
,
""
,
"
mb_gmhd5exdf
"
),
YN
(
"vietnam"
,
"越南"
,
""
,
""
,
"
mb_gmhd5extm
"
),
;
...
...
src/test/java/com/edgec/browserbackend/IpvCliestTest.java
View file @
9efa15c5
...
...
@@ -72,25 +72,27 @@ public class IpvCliestTest {
params
.
add
(
param
);
req
.
setParams
(
params
);
AppOrderResp
appOrderResp
=
IpvClient
.
instanceOpen
(
"test00012213"
,
"111223"
,
4
,
2
,
"ipideash_619
"
);
"111223"
,
1
,
1
,
"mb_gmhd5exet
"
);
System
.
out
.
println
(
JSON
.
toJSONString
(
appOrderResp
));
}
@Test
void
testGetOrder
()
throws
Exception
{
AppGetOrderReq
req
=
new
AppGetOrderReq
();
req
.
setOrderNo
(
"
D20241009112841659606
"
);
AppOrderResp
resp
=
IpvClient
.
getOrder
(
"C202410
08141433048384
"
);
req
.
setOrderNo
(
"
C20241021222705135265
"
);
AppOrderResp
resp
=
IpvClient
.
getOrder
(
"C202410
21222705135265
"
);
System
.
out
.
println
(
JSON
.
toJSONString
(
resp
));
}
@Test
void
testinstanceRelease
()
throws
Exception
{
AppInstanceReleaseReq
req
=
new
AppInstanceReleaseReq
();
req
.
setOrderNo
(
"R20241009112657386808"
);
req
.
setInstances
(
Lists
.
newArrayList
(
"c_gz7bdmvrvns6qea"
));
AppInstanceReleaseResp
resp
=
ipv
.
instanceRelease
(
req
);
System
.
out
.
println
(
JSON
.
toJSONString
(
resp
));
req
.
setOrderNo
(
"C20241021212430166572"
);
req
.
setInstances
(
Lists
.
newArrayList
(
"c_gtpb9mkn953dp34"
));
AppInstanceReleaseResp
appInstanceReleaseResp
=
IpvClient
.
instanceRelease
(
"C20241021212430166572"
,
"c_gtpb9mkn953dp34"
);
//AppInstanceReleaseResp resp = ipv.instanceRelease(req);
System
.
out
.
println
(
JSON
.
toJSONString
(
appInstanceReleaseResp
));
}
@Test
...
...
@@ -101,8 +103,8 @@ public class IpvCliestTest {
instance
.
setInstanceNo
(
"c_gz7bdmvrvns6qea"
);
instance
.
setDuration
(
1
);
req
.
setInstances
(
Lists
.
newArrayList
(
instance
));
AppOrderResp
resp
=
ipv
.
instanceRenew
(
req
);
System
.
out
.
println
(
JSON
.
toJSONString
(
resp
));
//
AppOrderResp resp = ipv.instanceRenew(req);
//
System.out.println(JSON.toJSONString(resp));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment