Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jd-activity
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
曾水平
jd-activity
Commits
a745a42d
Commit
a745a42d
authored
Jun 23, 2021
by
曾水平
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
078e52a4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
59 deletions
+120
-59
Open2DuibaController.java
...com/duiba/jdactivity/controller/Open2DuibaController.java
+2
-2
JdApiUtil.java
...cn/com/duiba/jdactivity/developer/jd/utils/JdApiUtil.java
+42
-42
JdApiUtilTest.java
...om/duiba/jdactivity/developer/jd/utils/JdApiUtilTest.java
+76
-15
No files found.
src/main/java/cn/com/duiba/jdactivity/controller/Open2DuibaController.java
View file @
a745a42d
...
@@ -392,7 +392,7 @@ public class Open2DuibaController {
...
@@ -392,7 +392,7 @@ public class Open2DuibaController {
}
catch
(
BizException
e
)
{
}
catch
(
BizException
e
)
{
return
ResultBuilder
.
fail
(
e
.
getMessage
());
return
ResultBuilder
.
fail
(
e
.
getMessage
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"
isMember
异常"
,
e
);
LOGGER
.
error
(
"
followShop
异常"
,
e
);
return
ResultBuilder
.
fail
(
"发生异常"
);
return
ResultBuilder
.
fail
(
"发生异常"
);
}
}
}
}
...
@@ -451,7 +451,7 @@ public class Open2DuibaController {
...
@@ -451,7 +451,7 @@ public class Open2DuibaController {
}
}
/**
/**
* 发放
优惠券
* 发放
店铺积分
*/
*/
@PostMapping
(
"/sendPoints"
)
@PostMapping
(
"/sendPoints"
)
public
Result
<
Boolean
>
sendPoints
(
@RequestBody
DuibaSendPointsParam
param
)
{
public
Result
<
Boolean
>
sendPoints
(
@RequestBody
DuibaSendPointsParam
param
)
{
...
...
src/main/java/cn/com/duiba/jdactivity/developer/jd/utils/JdApiUtil.java
View file @
a745a42d
...
@@ -46,6 +46,7 @@ import com.jd.open.api.sdk.response.user.PopCrmGetMemberInVenderResponse;
...
@@ -46,6 +46,7 @@ import com.jd.open.api.sdk.response.user.PopCrmGetMemberInVenderResponse;
import
com.jd.open.api.sdk.response.user.PopJmCenterUserGetEncryptPinNewResponse
;
import
com.jd.open.api.sdk.response.user.PopJmCenterUserGetEncryptPinNewResponse
;
import
com.jd.open.api.sdk.response.user.PopJmCenterUserGetOpenIdResponse
;
import
com.jd.open.api.sdk.response.user.PopJmCenterUserGetOpenIdResponse
;
import
com.jd.open.api.sdk.response.user.UserGetUserInfoByOpenIdResponse
;
import
com.jd.open.api.sdk.response.user.UserGetUserInfoByOpenIdResponse
;
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.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -264,47 +265,6 @@ public class JdApiUtil {
...
@@ -264,47 +265,6 @@ public class JdApiUtil {
}
}
}
}
/**
* 关注该店铺
* 如果已关注会返回false
*/
public
Result
<
Boolean
>
followByPinAndVid
(
JdAppEnum
jdAppEnum
,
String
pin
,
Long
shopId
,
String
accessToken
)
{
try
{
JdClient
client
=
getJdClient
(
jdAppEnum
,
accessToken
);
FollowVenderWriteFollowByPinAndVidRequest
request
=
new
FollowVenderWriteFollowByPinAndVidRequest
();
request
.
setPin
(
pin
);
request
.
setShopId
(
shopId
);
request
.
setOpenIdBuyer
(
pin
);
FollowVenderWriteFollowByPinAndVidResponse
response
=
client
.
execute
(
request
);
LOGGER
.
info
(
"关注该店铺,pin={},shopId={},response={}"
,
pin
,
shopId
,
JSON
.
toJSONString
(
response
));
return
Optional
.
ofNullable
(
response
)
.
map
(
FollowVenderWriteFollowByPinAndVidResponse:
:
getFollowbypinandvidResult
)
.
map
((
Function
<
com
.
jd
.
open
.
api
.
sdk
.
domain
.
user
.
FollowVenderWriteRpcService
.
response
.
followByPinAndVid
.
Result
,
Result
>)
result
->
{
Boolean
data
=
result
.
getData
();
String
code
=
result
.
getCode
();
String
msg
=
result
.
getMsg
();
if
(!
data
)
{
// 已关注情况,会返回false,要手动修复为true
if
(
Objects
.
equals
(
code
,
"F0402"
)
||
Objects
.
equals
(
msg
,
"已关注"
))
{
return
ResultBuilder
.
success
(
Boolean
.
TRUE
);
}
else
if
(
Objects
.
equals
(
code
,
"F0410"
))
{
return
ResultBuilder
.
fail
(
"用户关注店铺数量已达上限500"
);
}
else
{
return
ResultBuilder
.
fail
(
code
,
msg
);
}
}
else
{
return
ResultBuilder
.
success
(
Boolean
.
TRUE
);
}
})
.
orElse
(
ResultBuilder
.
fail
(
JSON
.
toJSONString
(
response
)));
}
catch
(
Exception
e
)
{
LOGGER
.
warn
(
"followByPinAndVid,exception"
,
e
);
return
ResultBuilder
.
fail
(
"发生异常"
);
}
}
private
static
Result
<
Boolean
>
sendPoints
(
JdAppEnum
jdAppEnum
,
String
pin
,
String
businessId
,
private
static
Result
<
Boolean
>
sendPoints
(
JdAppEnum
jdAppEnum
,
String
pin
,
String
businessId
,
short
sourceType
,
short
sourceType
,
Integer
points
,
String
desc
,
String
accessToken
)
{
Integer
points
,
String
desc
,
String
accessToken
)
{
...
@@ -331,7 +291,7 @@ public class JdApiUtil {
...
@@ -331,7 +291,7 @@ public class JdApiUtil {
*/
*/
request
.
setSourceType
(
sourceType
);
request
.
setSourceType
(
sourceType
);
request
.
setPoints
(
points
);
request
.
setPoints
(
points
);
request
.
setSourceComment
(
desc
.
substring
(
0
,
10
));
request
.
setSourceComment
(
StringUtils
.
substring
(
desc
,
0
,
10
));
PointsJosSendPointsResponse
response
=
client
.
execute
(
request
);
PointsJosSendPointsResponse
response
=
client
.
execute
(
request
);
LOGGER
.
info
(
"积分发放接口,request={},response={}"
,
LOGGER
.
info
(
"积分发放接口,request={},response={}"
,
JSON
.
toJSONString
(
request
),
JSON
.
toJSONString
(
response
));
JSON
.
toJSONString
(
request
),
JSON
.
toJSONString
(
response
));
...
@@ -345,6 +305,46 @@ public class JdApiUtil {
...
@@ -345,6 +305,46 @@ public class JdApiUtil {
}
}
}
}
/**
* 关注该店铺
* 如果已关注会返回false
*/
public
Result
<
Boolean
>
followByPinAndVid
(
JdAppEnum
jdAppEnum
,
String
pin
,
Long
shopId
,
String
accessToken
)
{
try
{
JdClient
client
=
getJdClient
(
jdAppEnum
,
accessToken
);
FollowVenderWriteFollowByPinAndVidRequest
request
=
new
FollowVenderWriteFollowByPinAndVidRequest
();
request
.
setPin
(
pin
);
request
.
setShopId
(
shopId
);
request
.
setOpenIdBuyer
(
pin
);
FollowVenderWriteFollowByPinAndVidResponse
response
=
client
.
execute
(
request
);
LOGGER
.
info
(
"关注该店铺,pin={},shopId={},response={}"
,
pin
,
shopId
,
JSON
.
toJSONString
(
response
));
return
Optional
.
ofNullable
(
response
)
.
map
(
FollowVenderWriteFollowByPinAndVidResponse:
:
getFollowbypinandvidResult
)
.
map
((
Function
<
com
.
jd
.
open
.
api
.
sdk
.
domain
.
user
.
FollowVenderWriteRpcService
.
response
.
followByPinAndVid
.
Result
,
Result
<
Boolean
>>)
result
->
{
Boolean
data
=
result
.
getData
();
String
code
=
result
.
getCode
();
String
msg
=
result
.
getMsg
();
if
(!
data
)
{
// 已关注情况,会返回false,要手动修复为true
if
(
Objects
.
equals
(
code
,
"F0402"
)
||
Objects
.
equals
(
msg
,
"已关注"
))
{
return
ResultBuilder
.
success
(
Boolean
.
TRUE
);
}
else
if
(
Objects
.
equals
(
code
,
"F0410"
))
{
return
ResultBuilder
.
fail
(
"用户关注店铺数量已达上限500"
);
}
else
{
return
ResultBuilder
.
fail
(
code
,
msg
);
}
}
else
{
return
ResultBuilder
.
success
(
Boolean
.
TRUE
);
}
})
.
orElse
(
ResultBuilder
.
fail
(
JSON
.
toJSONString
(
response
)));
}
catch
(
Exception
e
)
{
LOGGER
.
warn
(
"followByPinAndVid,exception"
,
e
);
return
ResultBuilder
.
fail
(
"发生异常"
);
}
}
/**
/**
* 通过用户pin加入购物车
* 通过用户pin加入购物车
*/
*/
...
...
src/test/java/cn/com/duiba/jdactivity/developer/jd/utils/JdApiUtilTest.java
View file @
a745a42d
package
cn
.
com
.
duiba
.
jdactivity
.
developer
.
jd
.
utils
;
package
cn
.
com
.
duiba
.
jdactivity
.
developer
.
jd
.
utils
;
import
cn.com.duiba.jdactivity.BaseTest
;
import
cn.com.duiba.jdactivity.BaseTest
;
import
cn.com.duiba.jdactivity.common.vo.Result
;
import
cn.com.duiba.jdactivity.developer.jd.constant.JdAppEnum
;
import
cn.com.duiba.jdactivity.developer.jd.constant.JdAppEnum
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.jd.open.api.sdk.domain.crm.VenderCustomerClientJsfService.response.getCustomer.EssentialCustomerInfo
;
import
com.jd.open.api.sdk.domain.market.PurchaseServiceProvider.response.getPurchaseInfo.PurchaseForJos
;
import
com.jd.open.api.sdk.domain.user.CrmCustomerService.response.getMemberInVender.CustomerInfoEs
;
import
com.jd.open.api.sdk.domain.user.UserRelatedRpcService.response.getUserInfoByOpenId.OAuthUserInfo
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.Order
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.List
;
/**
/**
* @author zsp (zengshuiping@duiba.com.cn)
* @author zsp (zengshuiping@duiba.com.cn)
...
@@ -13,10 +21,25 @@ import javax.annotation.Resource;
...
@@ -13,10 +21,25 @@ import javax.annotation.Resource;
*/
*/
class
JdApiUtilTest
extends
BaseTest
{
class
JdApiUtilTest
extends
BaseTest
{
private
static
final
String
accessToken
;
private
static
final
String
token
;
private
static
final
Long
shopId
;
private
static
final
Long
venderId
;
private
static
final
String
pin
;
static
{
accessToken
=
"51a1123d18064b969a2c773546998c12ntfh"
;
token
=
"AAFg0u4lADCOV4CmqwHEovuhnyxBLUdITuuMPAwXN5-LXc-Rptw86qHJyMSNeEitDca9ja88OtA"
;
shopId
=
0L
;
venderId
=
0L
;
pin
=
"yi皮仔"
;
}
@Resource
@Resource
private
JdApiUtil
jdApiUtil
;
private
JdApiUtil
jdApiUtil
;
@Test
@Test
@Order
(
0
)
void
venderShopQuery
()
{
void
venderShopQuery
()
{
// for (int i = 0; i < 1000; i++) {
// for (int i = 0; i < 1000; i++) {
// long now = System.currentTimeMillis();
// long now = System.currentTimeMillis();
...
@@ -24,29 +47,42 @@ class JdApiUtilTest extends BaseTest {
...
@@ -24,29 +47,42 @@ class JdApiUtilTest extends BaseTest {
// System.out.println("耗时" + (System.currentTimeMillis() - now));
// System.out.println("耗时" + (System.currentTimeMillis() - now));
// }
// }
System
.
out
.
println
(
JSON
.
toJSONString
(
jdApiUtil
.
venderShopQuery
(
JdAppEnum
.
DUIBA
,
"7ab5b3444e3e4c06ba06a8181133c8c7inwi"
)));
System
.
out
.
println
(
JSON
.
toJSONString
(
jdApiUtil
.
venderShopQuery
(
JdAppEnum
.
DUIBA
,
accessToken
)));
}
}
@Test
@Test
void
getPinByToken
()
{
void
getPinByToken
()
{
System
.
out
.
println
(
JSON
.
toJSONString
(
Result
<
String
>
result
=
jdApiUtil
.
getPinByToken
(
JdAppEnum
.
DUIBA
,
accessToken
,
"01"
,
token
);
jdApiUtil
.
getPinByToken
(
JdAppEnum
.
DUIBA
,
"dfef1ede28aa455999ddefe2944980cfzguy"
,
"01"
,
"AAFgpkP2ADCs9bF_MPObEd6CcwttmYLHfN69Yr8I8xmQA6CBleiqEh4X9mN6bfbjklo863VwWIk"
)));
System
.
out
.
println
(
JSON
.
toJSONString
(
result
));
Assertions
.
assertTrue
(
result
.
getSuccess
());
}
}
@Test
@Test
void
getEncryptPinNewByToken
()
{
void
getEncryptPinNewByToken
()
{
Result
<
String
>
result
=
jdApiUtil
.
getEncryptPinNewByToken
(
JdAppEnum
.
DUIBA
,
"1"
,
"01"
,
token
);
System
.
out
.
println
(
JSON
.
toJSONString
(
result
));
Assertions
.
assertTrue
(
result
.
getSuccess
());
}
}
@Test
@Test
void
getOpenIdByToken
()
{
void
OAuthUserInfo
()
{
}
Result
<
String
>
result
=
jdApiUtil
.
getOpenIdByToken
(
JdAppEnum
.
DUIBA
,
"01"
,
token
);
System
.
out
.
println
(
JSON
.
toJSONString
(
result
));
Assertions
.
assertTrue
(
result
.
getSuccess
());
@Test
Result
<
OAuthUserInfo
>
result2
=
jdApiUtil
.
getUserInfoByOpenId
(
JdAppEnum
.
DUIBA
,
accessToken
,
result
.
getData
());
void
getUserInfoByOpenId
()
{
System
.
out
.
println
(
JSON
.
toJSONString
(
result2
));
Assertions
.
assertTrue
(
result2
.
getSuccess
());
}
}
@Test
@Test
void
getCustomer
()
{
void
getCustomer
()
{
Result
<
EssentialCustomerInfo
>
result
=
jdApiUtil
.
getCustomer
(
JdAppEnum
.
DUIBA
,
"01"
,
token
);
System
.
out
.
println
(
JSON
.
toJSONString
(
result
));
Assertions
.
assertTrue
(
result
.
getSuccess
());
}
}
@Test
@Test
...
@@ -59,27 +95,52 @@ class JdApiUtilTest extends BaseTest {
...
@@ -59,27 +95,52 @@ class JdApiUtilTest extends BaseTest {
@Test
@Test
void
getMemberInVender
()
{
void
getMemberInVender
()
{
Result
<
CustomerInfoEs
>
result
=
jdApiUtil
.
getMemberInVender
(
JdAppEnum
.
DUIBA
,
"01"
,
token
);
System
.
out
.
println
(
JSON
.
toJSONString
(
result
));
Assertions
.
assertTrue
(
result
.
getSuccess
());
}
}
@Test
//
@Test
void
createCoupon
()
{
void
createCoupon
()
{
System
.
out
.
println
(
JSON
.
toJSONString
(
System
.
out
.
println
(
JSON
.
toJSONString
(
jdApiUtil
.
createCoupon
(
JdAppEnum
.
DUIBA
,
"dfef1ede28aa455999ddefe2944980cfzguy"
,
jdApiUtil
.
createCoupon
(
JdAppEnum
.
DUIBA
,
accessToken
,
"测试优惠券-排行榜-01"
,
50
)));
"测试优惠券-排行榜-01"
,
50
)));
}
}
@Test
//
@Test
void
lockCoupon
()
{
void
lockCoupon
()
{
System
.
out
.
println
(
JSON
.
toJSONString
(
System
.
out
.
println
(
JSON
.
toJSONString
(
jdApiUtil
.
lockCoupon
(
JdAppEnum
.
DUIBA
,
"dfef1ede28aa455999ddefe2944980cfzguy"
,
jdApiUtil
.
lockCoupon
(
JdAppEnum
.
DUIBA
,
accessToken
,
365488621L
)));
365488621L
)));
}
}
@Test
//
@Test
void
pushCoupon
()
{
void
pushCoupon
()
{
System
.
out
.
println
(
JSON
.
toJSONString
(
jdApiUtil
.
pushCoupon
(
JdAppEnum
.
DUIBA
,
accessToken
,
365488621L
,
pin
,
"1"
)));
}
@Test
void
sendPoints
()
{
Result
<
Boolean
>
result
=
jdApiUtil
.
sendPoints
(
JdAppEnum
.
DUIBA
,
pin
,
"businessId"
,
100
,
"给你100积分"
,
accessToken
);
System
.
out
.
println
(
JSON
.
toJSONString
(
result
));
Assertions
.
assertTrue
(
result
.
getSuccess
());
}
@Test
void
addCartItemByPin
()
{
Result
<
Boolean
>
result
=
jdApiUtil
.
addCartItemByPin
(
JdAppEnum
.
DUIBA
,
pin
,
"10021084856048"
,
101
,
accessToken
);
System
.
out
.
println
(
JSON
.
toJSONString
(
result
));
Assertions
.
assertTrue
(
result
.
getSuccess
());
}
@Test
@Order
(
0
)
void
getPurchaseInfo
()
{
Result
<
List
<
PurchaseForJos
>>
result
=
jdApiUtil
.
getPurchaseInfo
(
JdAppEnum
.
DUIBA
,
accessToken
);
System
.
out
.
println
(
JSON
.
toJSONString
(
System
.
out
.
println
(
JSON
.
toJSONString
(
jdApiUtil
.
pushCoupon
(
JdAppEnum
.
DUIBA
,
"dfef1ede28aa455999ddefe2944980cfzguy"
,
result
));
365488621L
,
"jd_7db1fb0992ce7"
,
"1"
)
));
Assertions
.
assertTrue
(
result
.
getSuccess
(
));
}
}
}
}
\ No newline at end of file
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