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
9c3e6072
Commit
9c3e6072
authored
Oct 23, 2024
by
chenchao.deng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接入住宅ip
parent
0674a60e
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
134 additions
and
17 deletions
+134
-17
IpController.java
...edgec/browserbackend/browser/controller/IpController.java
+15
-0
IpResourceServiceImpl.java
...erbackend/browser/service/Impl/IpResourceServiceImpl.java
+26
-1
IpResourceService.java
...gec/browserbackend/browser/service/IpResourceService.java
+2
-0
BrowserTask.java
...va/com/edgec/browserbackend/browser/task/BrowserTask.java
+56
-9
IpvClient.java
...gec/browserbackend/common/client/ipvClient/IpvClient.java
+10
-4
AppProductSyncReq.java
...ackend/common/client/ipvClient/dto/AppProductSyncReq.java
+20
-0
RegionMappingEnum.java
.../edgec/browserbackend/common/enums/RegionMappingEnum.java
+3
-3
IpvCliestTest.java
src/test/java/com/edgec/browserbackend/IpvCliestTest.java
+2
-0
No files found.
src/main/java/com/edgec/browserbackend/browser/controller/IpController.java
View file @
9c3e6072
...
...
@@ -56,6 +56,21 @@ public class IpController {
}
}
@RequestMapping
(
value
=
"/queryinventory"
,
method
=
RequestMethod
.
POST
)
public
ResultDto
queryinventory
(
Principal
principal
,
@RequestBody
IpResourceRequestDto
ipResourceRequestDto
)
{
String
logs
=
"【buyIp】 "
;
log
.
info
(
"{}, params : {}"
,
logs
,
principal
.
getName
());
try
{
return
ResponseUtil
.
success
(
ipResourceService
.
queryInventory
(
principal
.
getName
(),
ipResourceRequestDto
));
}
catch
(
ClientRequestException
e
)
{
log
.
warn
(
"{}, ClientRequestException : {}"
,
logs
,
e
.
getErrorCode
().
getReason
());
return
ResponseUtil
.
error
(
e
.
getErrorCode
());
}
catch
(
Exception
e
)
{
log
.
error
(
"{}, Exception : {}"
,
logs
,
e
.
getMessage
(),
e
);
return
ResponseUtil
.
error
(
e
.
getMessage
());
}
}
/**
* 续费IP资源
*
...
...
src/main/java/com/edgec/browserbackend/browser/service/Impl/IpResourceServiceImpl.java
View file @
9c3e6072
...
...
@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
import
com.alibaba.fastjson.JSONObject
;
import
com.aliyun.sdk.service.ecs20140526.models.DeleteInstanceResponse
;
import
com.aliyun.sdk.service.ecs20140526.models.DescribeInstancesResponse
;
import
com.aliyun.sdk.service.ecs20140526.models.DescribeInstancesResponseBody.Instance
;
import
com.aliyun.sdk.service.ecs20140526.models.RenewInstanceResponse
;
import
com.edgec.browserbackend.account.controller.LimitedUsers
;
import
com.edgec.browserbackend.account.domain.Account
;
...
...
@@ -26,8 +25,12 @@ 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.client.ipvClient.dto.AppProductSyncReq
;
import
com.edgec.browserbackend.common.client.ipvClient.dto.AppProductSyncResp
;
import
com.edgec.browserbackend.common.client.ipvClient.dto.Instance
;
import
com.edgec.browserbackend.common.commons.error.ClientRequestException
;
import
com.edgec.browserbackend.common.commons.utils.NotifyUtils
;
import
com.edgec.browserbackend.common.enums.RegionMappingEnum
;
import
com.edgec.browserbackend.common.utils.FileUtil
;
import
com.tencentcloudapi.cvm.v20170312.models.RenewInstancesResponse
;
import
com.tencentcloudapi.cvm.v20170312.models.TerminateInstancesResponse
;
...
...
@@ -1007,6 +1010,28 @@ public class IpResourceServiceImpl implements IpResourceService {
shopSecretRepository
.
save
(
shopSecret
);
}
@Override
public
Integer
queryInventory
(
String
name
,
IpResourceRequestDto
dto
)
{
RegionMappingEnum
byRegion
=
RegionMappingEnum
.
getByRegion
(
dto
.
getRegion
());
if
(
Objects
.
isNull
(
byRegion
))
{
return
0
;
}
AppProductSyncReq
req
=
new
AppProductSyncReq
();
List
<
Integer
>
list
=
new
ArrayList
<>();
list
.
add
(
103
);
req
.
setProxyType
(
list
);
req
.
setProductNo
(
byRegion
.
getIspRegionApi
());
//req.setCountryCode("USA");
List
<
AppProductSyncResp
>
resp
=
IpvClient
.
getProductStock
(
req
);
logger
.
info
(
"调用ipv查询产品库存结果:{}"
,
JSON
.
toJSONString
(
resp
));
if
(
CollectionUtils
.
isEmpty
(
resp
)){
return
null
;
}
return
resp
.
get
(
0
).
getInventory
();
}
private
IpChargeRequestDto
buildIpChargeRequestDto
(
IpResourceRequestDto
request
,
int
chargeType
,
int
payMethod
)
{
IpChargeRequestDto
ipChargeRequestDto
=
new
IpChargeRequestDto
();
...
...
src/main/java/com/edgec/browserbackend/browser/service/IpResourceService.java
View file @
9c3e6072
...
...
@@ -58,4 +58,6 @@ public interface IpResourceService {
String
getShop32Secret
(
String
shopId
);
void
saveShopSecret
(
String
shopId
,
String
sercret
);
Integer
queryInventory
(
String
name
,
IpResourceRequestDto
ipResourceRequestDto
);
}
src/main/java/com/edgec/browserbackend/browser/task/BrowserTask.java
View file @
9c3e6072
...
...
@@ -562,7 +562,6 @@ public class BrowserTask {
Objects
.
isNull
(
cloudPlatformOrder
.
getRetryCount
())
?
0
:
cloudPlatformOrder
.
getRetryCount
();
cloudPlatformOrder
.
setRetryCount
(
oldRetryCount
+
1
);
cloudPlatformOrderRepository
.
save
(
cloudPlatformOrder
);
String
instanceId
=
response1
.
getInstanceIdSet
()[
0
];
cloudPlatformOrder
.
setPlatformOrderId
(
instanceId
);
ipResource
.
setStatus
(
3
);
...
...
@@ -589,15 +588,44 @@ public class BrowserTask {
cloudPlatformOrder
.
getPlatformOrderId
());
log
.
info
(
"调用ipv查询实例,响应参数:owner:{},response:{}"
,
ipResource
.
getOwner
(),
JSON
.
toJSON
(
order
));
if
(
order
.
getStatus
()
!=
3
)
{
if
(
order
.
getStatus
()
!=
3
&&
order
.
getStatus
()
!=
4
)
{
//订单还没有处理完成
return
;
}
AppInstanceResp
appInstanceResp
=
order
.
getInstances
().
get
(
0
);
if
(
order
.
getStatus
()
==
3
&&
appInstanceResp
.
getStatus
()
==
3
)
{
//查询是否为重复ip
String
ipNo
=
appInstanceResp
.
getIp
();
LocalDateTime
localDateTime
=
LocalDateTime
.
now
()
.
minus
(
3
,
ChronoUnit
.
MONTHS
);
Instant
instant
=
localDateTime
.
atZone
(
ZoneId
.
systemDefault
())
.
toInstant
();
List
<
IpHistory
>
ipHistoryList
=
ipHistoryRepository
.
findByIpNoAndPurchasedTimeAfter
(
ipNo
,
instant
.
toEpochMilli
());
if
(
CollectionUtils
.
isNotEmpty
(
ipHistoryList
)
&&
(
Objects
.
isNull
(
cloudPlatformOrder
.
getRetryCount
())
||
cloudPlatformOrder
.
getRetryCount
()
<
5
))
{
//重新分配ip(删除旧的 购买新的)
IpvClient
.
instanceRelease
(
cloudPlatformOrder
.
getPlatformOrderId
(),
cloudPlatformOrder
.
getPlatformInstanceNo
());
int
unit
=
ipResource
.
getUnit
().
equals
(
"week"
)
?
2
:
3
;
String
ispRegion
=
RegionMappingEnum
.
getIspRegion
(
ipResource
.
getRegion
());
AppOrderResp
appOrderResp
=
IpvClient
.
instanceOpen
(
cloudPlatformOrder
.
getOrderNo
(),
ipResource
.
getOwner
(),
unit
,
ipResource
.
getPeriod
(),
ispRegion
);
if
(
Objects
.
nonNull
(
appOrderResp
)
&&
StringUtils
.
isNotEmpty
(
appOrderResp
.
getOrderNo
()))
{
int
oldRetryCount
=
Objects
.
isNull
(
cloudPlatformOrder
.
getRetryCount
())
?
0
:
cloudPlatformOrder
.
getRetryCount
();
cloudPlatformOrder
.
setRetryCount
(
oldRetryCount
+
1
);
cloudPlatformOrder
.
setPlatformOrderId
(
appOrderResp
.
getOrderNo
());
ipResource
.
setStatus
(
3
);
ipResourceRepository
.
save
(
ipResource
);
cloudPlatformOrderRepository
.
save
(
cloudPlatformOrder
);
}
if
(
Objects
.
nonNull
(
order
.
getInstances
()))
{
//判断是否重复购买
AppInstanceResp
appInstanceResp
=
order
.
getInstances
().
get
(
0
);
if
(
appInstanceResp
.
getStatus
()
==
3
)
{
}
else
{
//包年包月 更新ip状态
ipResource
.
setAddr
(
appInstanceResp
.
getIp
());
...
...
@@ -610,19 +638,38 @@ public class BrowserTask {
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
ipResource
.
setSpecialLine
(
true
);
//以秒为单位的时间戳需要 *1000转为毫秒级
ipResource
.
setValidTime
(
appInstanceResp
.
getUserExpired
()*
1000L
);
ipResource
.
setValidTime
(
appInstanceResp
.
getUserExpired
()
*
1000L
);
ipResourceRepository
.
save
(
ipResource
);
IpHistory
ipHistory
=
new
IpHistory
();
ipHistory
.
setIpNo
(
ipResource
.
getAddr
());
ipHistory
.
setPlatformType
(
cloudPlatformOrder
.
getPlatformType
());
ipHistory
.
setPurchasedTime
(
Instant
.
now
().
toEpochMilli
());
ipHistory
.
setPurchasedTime
(
Instant
.
now
().
toEpochMilli
());
ipHistoryRepository
.
save
(
ipHistory
);
cloudPlatformOrder
.
setPlatformInstanceNo
(
appInstanceResp
.
getInstanceNo
());
cloudPlatformOrder
.
setPlatformInstanceNo
(
appInstanceResp
.
getInstanceNo
());
cloudPlatformOrderRepository
.
save
(
cloudPlatformOrder
);
return
;
}
}
else
if
(
order
.
getStatus
()
==
4
)
{
//处理失败 释放退款
IpChargeRequestDto
ipChargeRequestDto
=
buildIpChargeRequestDto
(
ipResource
,
3
,
0
);
accountService
.
chargeByMoney
(
ipResource
.
getOwner
(),
-
ipResource
.
getPrice
(),
ipChargeRequestDto
);
if
(
ipResource
.
getShopIds
()
!=
null
&&
ipResource
.
getShopIds
().
size
()
>
0
)
{
ShopRequestDto
shopRequestDto
=
new
ShopRequestDto
();
shopRequestDto
.
setIpId
(
ipResource
.
getId
());
shopRequestDto
.
setShopIds
(
ipResource
.
getShopIds
());
ipAndShopService
.
unBindShops
(
ipResource
.
getUsername
(),
shopRequestDto
);
}
ipResourceRepository
.
deleteById
(
ipResource
.
getId
());
}
}
}
catch
(
Exception
e
)
{
...
...
src/main/java/com/edgec/browserbackend/common/client/ipvClient/IpvClient.java
View file @
9c3e6072
...
...
@@ -57,10 +57,16 @@ public class IpvClient {
return
list
;
}
public
List
<
AppProductSyncResp
>
getProductStock
(
AppProductSyncReq
req
)
throws
Exception
{
byte
[]
params
=
JSON
.
toJSONBytes
(
req
);
byte
[]
res
=
post
(
GET_PRODUCT_STOCK_URI
,
params
);
List
<
AppProductSyncResp
>
list
=
JSON
.
parseArray
(
new
String
(
res
),
AppProductSyncResp
.
class
);
public
static
List
<
AppProductSyncResp
>
getProductStock
(
AppProductSyncReq
req
)
{
List
<
AppProductSyncResp
>
list
=
null
;
try
{
byte
[]
params
=
JSON
.
toJSONBytes
(
req
);
byte
[]
res
=
post
(
GET_PRODUCT_STOCK_URI
,
params
);
list
=
JSON
.
parseArray
(
new
String
(
res
),
AppProductSyncResp
.
class
);
}
catch
(
Exception
e
){
log
.
error
(
"fail to ipipv getProductStock {}"
,
e
.
getMessage
());
}
return
list
;
}
...
...
src/main/java/com/edgec/browserbackend/common/client/ipvClient/dto/AppProductSyncReq.java
View file @
9c3e6072
...
...
@@ -5,6 +5,26 @@ import java.util.List;
public
class
AppProductSyncReq
{
private
List
<
Integer
>
proxyType
;
//代理类型 101=静态云平台 102=静态国内家庭 103=静态国外家庭 104=动态国外 105=动态国内 201=whatsapp
private
String
countryCode
;
private
String
productNo
;
public
String
getProductNo
()
{
return
productNo
;
}
public
void
setProductNo
(
String
productNo
)
{
this
.
productNo
=
productNo
;
}
public
String
getCountryCode
()
{
return
countryCode
;
}
public
void
setCountryCode
(
String
countryCode
)
{
this
.
countryCode
=
countryCode
;
}
public
List
<
Integer
>
getProxyType
()
{
return
proxyType
;
}
...
...
src/main/java/com/edgec/browserbackend/common/enums/RegionMappingEnum.java
View file @
9c3e6072
...
...
@@ -31,7 +31,7 @@ public enum RegionMappingEnum {
CN_HK
(
"hongkong"
,
"中国香港"
,
"cn-hongkong"
,
""
,
"mb_gmhd5exet"
),
US
(
"us"
,
"美国随机"
,
""
,
""
,
""
),
US_CALIFORNIA
(
"california"
,
"加利福尼亚"
,
""
,
""
,
""
),
//待确认
US_VIRGINIA
(
"virginia"
,
"弗吉尼亚"
,
"us-east-1"
,
""
,
"
ipideash_589
"
),
US_VIRGINIA
(
"virginia"
,
"弗吉尼亚"
,
"us-east-1"
,
""
,
"
mb_gmhd5ex97
"
),
EU_UK
(
"uk"
,
"英国-伦敦"
,
"eu-west-1"
,
""
,
"mb_gmh92exc3"
),
EU_CENTRAL
(
"germany"
,
"德国-法兰克福"
,
"eu-central-1"
,
"eu-frankfurt"
,
""
),
JAPAN
(
"japan"
,
"日本-东京"
,
"ap-northeast-1"
,
"ap-tokyo"
,
""
),
...
...
@@ -47,10 +47,10 @@ public enum RegionMappingEnum {
NANJING
(
"nanjing"
,
"南京"
,
""
,
"ap-nanjing"
,
""
),
BANGKOK
(
"bangkok"
,
"泰国(曼谷)"
,
"ap-southeast-7"
,
""
,
"mb_gmh92ex88"
),
MANILA
(
"manila"
,
"菲律宾-马尼拉"
,
"ap-southeast-6"
,
""
,
"
ipideash_606
"
),
MANILA
(
"manila"
,
"菲律宾-马尼拉"
,
"ap-southeast-6"
,
""
,
"
mb_gmh92ex8p
"
),
SEOUL
(
"seoul"
,
"韩国-首尔"
,
"ap-northeast-2"
,
"ap-seoul"
,
"ipideash_621"
),
TW
(
"taiwan"
,
"中国-台湾"
,
""
,
""
,
"mb_gmhd5exem"
),
LSWJS
(
"lasvegas"
,
"美国-拉斯维加斯"
,
""
,
""
,
"ipideash_59
2
"
),
LSWJS
(
"lasvegas"
,
"美国-拉斯维加斯"
,
""
,
""
,
"ipideash_59
3
"
),
NY
(
"newyork"
,
"美国-纽约"
,
""
,
""
,
"ipideash_590"
),
LSG
(
"losangeles"
,
"美国-洛杉矶"
,
""
,
""
,
"ipideash_615"
),
MAM
(
"miami"
,
"美国-迈阿密"
,
""
,
""
,
"ipideash_595"
),
...
...
src/test/java/com/edgec/browserbackend/IpvCliestTest.java
View file @
9c3e6072
...
...
@@ -43,6 +43,8 @@ public class IpvCliestTest {
void
testGetProductStock
()
throws
Exception
{
AppProductSyncReq
req
=
new
AppProductSyncReq
();
req
.
setProxyType
(
Lists
.
newArrayList
(
103
));
req
.
setProductNo
(
"ipideash_593"
);
//req.setCountryCode("USA");
List
<
AppProductSyncResp
>
resp
=
ipv
.
getProductStock
(
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