Commit 16ed34cb authored by 曾水平's avatar 曾水平

POST避免+变成空格

parent 0b25eb0b
......@@ -66,7 +66,7 @@ public class AESCS7Util {
加密字段:uid
*/
String key = "JuGi3FCECD1dA2BPL1lCWC==";
String test = AESEncrypt("test", key);
String test = AESEncrypt("jd_6bdf29cf7cf49", key);
System.out.println(test);
System.out.println(AES256Decrypt(test, key));
}
......
......@@ -2,6 +2,7 @@ package cn.com.duiba.jdactivity.controller;
import cn.com.duiba.credits.sdk.CreditTool;
import cn.com.duiba.credits.sdk.SignTool;
import cn.com.duiba.jdactivity.common.utils.AESCS7Util;
import cn.com.duiba.jdactivity.common.utils.RequestTool;
import cn.com.duiba.jdactivity.common.utils.UrlUtils;
import cn.com.duiba.jdactivity.common.vo.Result;
......@@ -11,7 +12,6 @@ import cn.com.duiba.jdactivity.developer.jd.constant.JdAppEnum;
import cn.com.duiba.jdactivity.developer.jd.constant.JdShopEnum;
import cn.com.duiba.jdactivity.developer.jd.constant.JdTokenSourceEnum;
import cn.com.duiba.jdactivity.developer.jd.utils.AccessTokenUtils;
import cn.com.duiba.jdactivity.developer.jd.utils.EncryptUtil;
import cn.com.duiba.jdactivity.developer.jd.utils.JdApiUtil;
import cn.com.duiba.jdactivity.dto.AutologinParam;
import cn.com.duiba.jdactivity.dto.TbShopAccessTokenDto;
......@@ -22,10 +22,10 @@ import com.jd.open.api.sdk.domain.user.UserRelatedRpcService.response.getUserInf
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
......@@ -48,14 +48,13 @@ import java.util.stream.Collectors;
@RequestMapping("/open2Duiba")
public class Open2DuibaController {
public static final Logger LOGGER = LoggerFactory.getLogger(Open2DuibaController.class);
//默认超时或提前2分钟
private static long defaultTime = 5 * 60 * 1000L;
@Resource
private EncryptUtil encryptUtil;
public static final String ENCRYPT_KEY = "JuGi3FCECD1dA2BPL1lCWC==";
@Resource
private JdApiUtil jdApiUtil;
@Resource
private AccessTokenUtils accessTokenUtils;
//默认超时或提前5分钟
private static final long DEFAULT_EXPIRE_TIME = 5 * 60 * 1000L;
/**
* 根据环境获取不同的免登录地址
......@@ -116,7 +115,7 @@ public class Open2DuibaController {
Result<OAuthUserInfo> userInfoByOpenId = jdApiUtil.getUserInfoByOpenId(appByAppKey, accessToken.getAccessToken(), openIdByToken.getData());
LOGGER.info("获取userInfo,结果={}", JSON.toJSONString(userInfoByOpenId));
String uid = convert2Uid(appByAppKey, accessToken.getAccessToken(), pinByToken.getData());
LOGGER.info("加密pin,pin{},uid={}", pinByToken.getData(), uid);
LOGGER.info("加密pin,pin={},uid={}", pinByToken.getData(), uid);
String nickName = userInfoByOpenId.getData().getNickName();
String avatar = userInfoByOpenId.getData().getImageUrl();
......@@ -179,9 +178,10 @@ public class Open2DuibaController {
/**
* 是否关注店铺
*/
@GetMapping("/isFollowShop")
public Result<Boolean> isFollowShop(String uid, Long shopId, Long venderId) {
@PostMapping("/isFollowShop")
public Result<Boolean> isFollowShop(@RequestParam String uid, @RequestParam Long shopId, @RequestParam Long venderId) {
try {
uid = uid.replaceAll(" ", "+");
signVerify("是否关注店铺");
TbShopAccessTokenDto accessToken = accessTokenUtils.getAccessToken(venderId, shopId);
......@@ -199,9 +199,10 @@ public class Open2DuibaController {
/**
* 关注店铺
*/
@GetMapping("/followShop")
public Result<Boolean> followShop(String uid, Long shopId, Long venderId) {
@PostMapping("/followShop")
public Result<Boolean> followShop(@RequestParam String uid, @RequestParam Long shopId, @RequestParam Long venderId) {
try {
uid = uid.replaceAll(" ", "+");
signVerify("关注店铺");
TbShopAccessTokenDto accessToken = accessTokenUtils.getAccessToken(venderId, shopId);
......@@ -226,20 +227,19 @@ public class Open2DuibaController {
LOGGER.info(method + "参数:" + JSON.toJSONString(parameterMap));
//前后5分钟内有效
String timestampObj = request.getParameter("timestamp");
String timestamp = request.getParameter("timestamp");
String appKey = request.getParameter("appKey");
String sign = request.getParameter("sign");
DuibaAppEnum duibaAppEnum = DuibaAppEnum.getDuibaApp(appKey);
if (duibaAppEnum == null) {
throw new BizException("appKey不存在");
}
long clientTimestamp = timestampObj == null ? 0L : Long.parseLong(timestampObj);
long clientTimestamp = timestamp == null ? 0L : Long.parseLong(timestamp);
long now = System.currentTimeMillis();
if (Math.abs(now - clientTimestamp) > defaultTime) {
throw new BizException("请同步服务器与客户端时间为5分钟之内");
if (Math.abs(now - clientTimestamp) > DEFAULT_EXPIRE_TIME) {
throw new BizException(String.format("请同步服务器与客户端时间为%s分钟之内", DEFAULT_EXPIRE_TIME));
}
//验签sign
Map<String, String> signMap = new HashMap<>(parameterMap);
signMap.remove("sign");
......@@ -259,9 +259,10 @@ public class Open2DuibaController {
/**
* 是否是会员
*/
@GetMapping("/isMember")
public Result<Boolean> isMember(String uid, Long shopId, Long venderId) {
@PostMapping("/isMember")
public Result<Boolean> isMember(@RequestParam String uid, @RequestParam Long shopId, @RequestParam Long venderId) {
try {
uid = uid.replaceAll(" ", "+");
signVerify("是否是会员");
TbShopAccessTokenDto accessToken = accessTokenUtils.getAccessToken(venderId, shopId);
......@@ -281,13 +282,14 @@ public class Open2DuibaController {
/**
* 发放优惠券
*/
@GetMapping("/sendCouponId")
public Result<Boolean> sendCouponId(String uid,
Long couponId,
String uuid,
Long shopId,
Long venderId) {
@PostMapping("/sendCouponId")
public Result<Boolean> sendCouponId(@RequestParam String uid,
@RequestParam Long couponId,
@RequestParam String uuid,
@RequestParam Long shopId,
@RequestParam Long venderId) {
try {
uid = uid.replaceAll(" ", "+");
signVerify("发放优惠券");
TbShopAccessTokenDto accessToken = accessTokenUtils.getAccessToken(venderId, shopId);
......@@ -313,11 +315,22 @@ public class Open2DuibaController {
}
public String convert2Pin(JdAppEnum appByAppKey, String accessToken, String uid) {
return encryptUtil.decryptString(appByAppKey, accessToken, uid);
public String convert2Pin(JdAppEnum appByAppKey, String accessToken, String uid) throws BizException {
try {
return AESCS7Util.AES256Decrypt(uid, ENCRYPT_KEY);
} catch (Exception e) {
LOGGER.error("uid解密失败,uid={}", uid, e);
throw new BizException("uid解密失败");
}
}
public String convert2Uid(JdAppEnum appByAppKey, String accessToken, String pin) {
return encryptUtil.encryptString(appByAppKey, accessToken, pin);
public String convert2Uid(JdAppEnum appByAppKey, String accessToken, String pin) throws BizException {
try {
return AESCS7Util.AESEncrypt(pin, ENCRYPT_KEY);
} catch (Exception e) {
LOGGER.error("pin加密失败,uid={}", pin, e);
throw new BizException("pin加密失败");
}
}
}
......@@ -2,6 +2,7 @@ package cn.com.duiba.jdactivity.controller;
import cn.com.duiba.jdactivity.ControllerTest;
import cn.com.duiba.jdactivity.developer.jd.constant.JdAppEnum;
import cn.com.duiba.jdactivity.exception.BizException;
import org.junit.jupiter.api.Test;
import javax.annotation.Resource;
......@@ -40,7 +41,11 @@ class Open2DuibaControllerTest extends ControllerTest {
void convert2Uid() {
String accessToken = "dfef1ede28aa455999ddefe2944980cfzguy";
String pin = "yi皮仔";
System.out.println(open2DuibaController.convert2Uid(JdAppEnum.DUIBA, accessToken, pin));
try {
System.out.println(open2DuibaController.convert2Uid(JdAppEnum.DUIBA, accessToken, pin));
} catch (BizException e) {
e.printStackTrace();
}
;
}
......
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