Commit 6a86bd6d authored by 曾水平's avatar 曾水平

Merge branch 'hotfix/20210519-zsp' into 'master'

Hotfix/20210519 zsp

See merge request !3
parents b69a61a6 b48c5e90
...@@ -48,6 +48,7 @@ dependencies { ...@@ -48,6 +48,7 @@ dependencies {
compile("org.aspectj:aspectjweaver:1.8.11") compile("org.aspectj:aspectjweaver:1.8.11")
//http //http
compile 'cn.com.duiba.credits:duiba-java-sdk:0.0.23' compile 'cn.com.duiba.credits:duiba-java-sdk:0.0.23'
compile('com.github.ben-manes.caffeine:caffeine:2.3.5')
} }
......
...@@ -23,10 +23,10 @@ public class AESCS7Util { ...@@ -23,10 +23,10 @@ public class AESCS7Util {
static final String AES_PADDING = "AES/ECB/PKCS7Padding"; static final String AES_PADDING = "AES/ECB/PKCS7Padding";
static { static {
if (Security.getProvider("BC") == null) { if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
} else { } else {
Security.removeProvider("BC"); Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
} }
} }
...@@ -66,7 +66,7 @@ public class AESCS7Util { ...@@ -66,7 +66,7 @@ public class AESCS7Util {
加密字段:uid 加密字段:uid
*/ */
String key = "JuGi3FCECD1dA2BPL1lCWC=="; String key = "JuGi3FCECD1dA2BPL1lCWC==";
String test = AESEncrypt("test", key); String test = AESEncrypt("jd_6bdf29cf7cf49", key);
System.out.println(test); System.out.println(test);
System.out.println(AES256Decrypt(test, key)); System.out.println(AES256Decrypt(test, key));
} }
......
package cn.com.duiba.jdactivity.common.utils; package cn.com.duiba.jdactivity.common.utils;
import cn.com.duiba.jdactivity.common.utils.user.ShopUserCookieDto;
/** /**
* @author zsp (zengshuiping@duiba.com.cn) * @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/17 18:44 * @date 2021/5/17 18:44
*/ */
public class RequestLocal { public class RequestLocal {
private static final ThreadLocal<Object> USER = new ThreadLocal<>(); private static final ThreadLocal<ShopUserCookieDto> USER = new ThreadLocal<>();
public static ShopUserCookieDto getUser() {
return USER.get();
}
public static void setUser(Object dto) { public static void setUser(ShopUserCookieDto dto) {
USER.set(dto); USER.set(dto);
} }
......
package cn.com.duiba.jdactivity.common.utils; package cn.com.duiba.jdactivity.common.utils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collection; import java.util.Collection;
...@@ -136,6 +139,18 @@ public final class UrlUtils { ...@@ -136,6 +139,18 @@ public final class UrlUtils {
} }
} }
public static String urlDecode(String url) {
if (StringUtils.isBlank(url)) {
return "";
}
try {
return URLDecoder.decode(StringEscapeUtils.unescapeHtml3(url), "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return url;
}
public static Map<String, String> explainURLParams(String params) { public static Map<String, String> explainURLParams(String params) {
Map<String, String> mapRequest = new HashMap<>(); Map<String, String> mapRequest = new HashMap<>();
String[] arrSplit; String[] arrSplit;
......
package cn.com.duiba.jdactivity.common.utils.user;
/**
* @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/17 18:52
*/
public class ShopUserCookieDto {
/**
* 登录时间
*/
private long loginTime;
/**
* 店铺信息
*/
private Long venderId;
private Long shopId;
private String shopName;
/**
* 当前用户信息
*/
private String openId;
private String uid;
public long getLoginTime() {
return loginTime;
}
public void setLoginTime(long loginTime) {
this.loginTime = loginTime;
}
public Long getVenderId() {
return venderId;
}
public void setVenderId(Long venderId) {
this.venderId = venderId;
}
public Long getShopId() {
return shopId;
}
public void setShopId(Long shopId) {
this.shopId = shopId;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public String getOpenId() {
return openId;
}
public void setOpenId(String openId) {
this.openId = openId;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
}
package cn.com.duiba.jdactivity.common.utils.user;
/**
* @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/17 18:52
*/
public class UserCookieDto {
/**
* 登录时间
*/
private long time;
private String userId;
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
}
package cn.com.duiba.jdactivity.common.utils.user; package cn.com.duiba.jdactivity.common.utils.user;
import cn.com.duiba.jdactivity.common.utils.AESCS7Util; import cn.com.duiba.jdactivity.common.utils.AESCS7Util;
import cn.com.duiba.jdactivity.common.utils.RequestLocal;
import cn.com.duiba.jdactivity.common.utils.RequestTool; import cn.com.duiba.jdactivity.common.utils.RequestTool;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -26,8 +27,15 @@ public class UserUtils { ...@@ -26,8 +27,15 @@ public class UserUtils {
return loginTime > now - 86400000 && loginTime < now + 300000; return loginTime > now - 86400000 && loginTime < now + 300000;
} }
void injectConsumerInfoIntoCookie(UserCookieDto userCookieDto, HttpServletRequest request, HttpServletResponse response) { /**
String userJson = JSONObject.toJSONString(userCookieDto); * 注入cookies
*/
public static void injectConsumerInfoIntoCookie(ShopUserCookieDto shopUserCookieDto) {
RequestLocal.setUser(shopUserCookieDto);
HttpServletRequest request = RequestTool.getHttpServletRequest();
HttpServletResponse response = RequestTool.getHttpServletResponse();
String userJson = JSONObject.toJSONString(shopUserCookieDto);
String userCookieVal = null; String userCookieVal = null;
try { try {
...@@ -39,17 +47,16 @@ public class UserUtils { ...@@ -39,17 +47,16 @@ public class UserUtils {
String reqDomain = getRequestDomain(request); String reqDomain = getRequestDomain(request);
if (reqDomain != null) { if (reqDomain != null) {
Cookie reqUserCookie = new Cookie(USER_COOKIE, userCookieVal); Cookie reqUserCookie = new Cookie(USER_COOKIE, userCookieVal);
reqUserCookie.setHttpOnly(true);//防止被js获得 //防止被js获得
reqUserCookie.setHttpOnly(true);
reqUserCookie.setDomain(reqDomain); reqUserCookie.setDomain(reqDomain);
reqUserCookie.setPath("/"); reqUserCookie.setPath("/");
response.addCookie(reqUserCookie); response.addCookie(reqUserCookie);
} }
} }
public static UserCookieDto getUserCookieDto(HttpServletRequest request) { public static ShopUserCookieDto getUserCookieDto(HttpServletRequest request) {
String cookie = RequestTool.getCookie(request, USER_COOKIE); String cookie = RequestTool.getCookie(request, USER_COOKIE);
if (cookie == null || cookie.isEmpty()) { if (cookie == null || cookie.isEmpty()) {
return null; return null;
...@@ -60,8 +67,8 @@ public class UserUtils { ...@@ -60,8 +67,8 @@ public class UserUtils {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
UserCookieDto c = JSONObject.parseObject(userJson, UserCookieDto.class); ShopUserCookieDto c = JSONObject.parseObject(userJson, ShopUserCookieDto.class);
if (!isValidTime(c.getTime())) { if (!isValidTime(c.getLoginTime())) {
return null; return null;
} }
return c; return c;
...@@ -73,7 +80,7 @@ public class UserUtils { ...@@ -73,7 +80,7 @@ public class UserUtils {
* @param request 请求对象 * @param request 请求对象
* @return * @return
*/ */
public String getRequestDomain(HttpServletRequest request) { public static String getRequestDomain(HttpServletRequest request) {
String domainName = request.getServerName(); String domainName = request.getServerName();
if (domainName == null || "".equals(domainName)) { if (domainName == null || "".equals(domainName)) {
return null; return null;
......
...@@ -2,15 +2,13 @@ package cn.com.duiba.jdactivity.controller; ...@@ -2,15 +2,13 @@ package cn.com.duiba.jdactivity.controller;
import cn.com.duiba.jdactivity.common.vo.Result; import cn.com.duiba.jdactivity.common.vo.Result;
import cn.com.duiba.jdactivity.common.vo.ResultBuilder; import cn.com.duiba.jdactivity.common.vo.ResultBuilder;
import cn.com.duiba.jdactivity.developer.jd.JdAppEnum; import cn.com.duiba.jdactivity.developer.jd.constant.JdAppEnum;
import cn.com.duiba.jdactivity.developer.jd.domain.AccessTokenResponse; import cn.com.duiba.jdactivity.developer.jd.domain.AccessTokenResponse;
import cn.com.duiba.jdactivity.developer.jd.domain.JosParameters; import cn.com.duiba.jdactivity.developer.jd.domain.JosParameters;
import cn.com.duiba.jdactivity.developer.jd.utils.AccessTokenUtils; import cn.com.duiba.jdactivity.developer.jd.utils.AccessTokenUtils;
import cn.com.duiba.jdactivity.developer.jd.utils.JdApiUtil; import cn.com.duiba.jdactivity.developer.jd.utils.JdApiUtil;
import cn.com.duiba.jdactivity.developer.jd.utils.LoginUtils; import cn.com.duiba.jdactivity.developer.jd.utils.LoginUtils;
import cn.com.duiba.jdactivity.dto.TbShopAccessTokenDto;
import cn.com.duiba.jdactivity.exception.BizException; import cn.com.duiba.jdactivity.exception.BizException;
import com.alibaba.fastjson.JSONObject;
import com.jd.open.api.sdk.domain.seller.ShopSafService.response.query.ShopJosResult; import com.jd.open.api.sdk.domain.seller.ShopSafService.response.query.ShopJosResult;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -18,7 +16,6 @@ import org.slf4j.LoggerFactory; ...@@ -18,7 +16,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.view.RedirectView;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -35,17 +32,15 @@ public class AppController { ...@@ -35,17 +32,15 @@ public class AppController {
@Resource @Resource
private AccessTokenUtils accessTokenUtils; private AccessTokenUtils accessTokenUtils;
@Resource @Resource
private JdApiUtil jdApiUtil; private JdApiUtil jdApiUtil;
/** /**
* 应用插件启动唤起页 * 应用插件启动唤起页
*/ */
@RequestMapping("/login") @RequestMapping("/login")
public Result<JSONObject> login( public Result<String> login(String code, @RequestParam(required = false) String state) {
String code,
@RequestParam(required = false) String state) {
try { try {
LOGGER.info("login,code={},state={}", code, state); LOGGER.info("login,code={},state={}", code, state);
if (StringUtils.isAnyBlank(code)) { if (StringUtils.isAnyBlank(code)) {
...@@ -66,57 +61,64 @@ public class AppController { ...@@ -66,57 +61,64 @@ public class AppController {
return ResultBuilder.fail("appKey参数不合法"); return ResultBuilder.fail("appKey参数不合法");
} }
JSONObject object = new JSONObject();
AccessTokenResponse accessTokenByCode = accessTokenUtils.getAccessTokenByCode(jdAppEnum, code); AccessTokenResponse accessTokenByCode = accessTokenUtils.getAccessTokenByCode(jdAppEnum, code);
if (accessTokenByCode != null && accessTokenByCode.isOk()) { if (accessTokenByCode != null && accessTokenByCode.isOk()) {
object.put("accessToken", accessTokenByCode); LOGGER.info("login,获取AccessToken成功");
object.put("msg", "授权成功");
Result<ShopJosResult> shopJosResultResult = jdApiUtil.venderShopQuery(jdAppEnum, accessTokenByCode.getAccess_token()); Result<ShopJosResult> shopJosResultResult = jdApiUtil.venderShopQuery(jdAppEnum, accessTokenByCode.getAccess_token());
if (shopJosResultResult.getSuccess()) { if (shopJosResultResult.getSuccess()) {
LOGGER.info("login,获取ShopJosResult成功");
ShopJosResult shopJosResult = shopJosResultResult.getData(); ShopJosResult shopJosResult = shopJosResultResult.getData();
object.put("shop", shopJosResult);
// 保存入库 // 保存入库
Long id = accessTokenUtils.saveAccessToken(jdAppEnum, accessTokenByCode, shopJosResult); Long id = accessTokenUtils.saveAccessToken(jdAppEnum, accessTokenByCode, shopJosResult);
object.put("save", id); LOGGER.info("login,保存AccessToken成功");
if (id != null && id > 0) { if (id != null && id > 0) {
object.put("id", accessTokenUtils.getAccessToken(shopJosResult.getVenderId(), shopJosResult.getShopId()).getShopId()); Long shopId = accessTokenUtils.getAccessTokenWithCache(shopJosResult.getVenderId(), shopJosResult.getShopId()).getShopId();
LOGGER.info("login,保存AccessToken成功,shopId={}", shopId);
} }
// ShopUserCookieDto shopUserCookieDto = new ShopUserCookieDto();
// shopUserCookieDto.setLoginTime(System.currentTimeMillis());
// shopUserCookieDto.setVenderId(shopJosResult.getVenderId());
// shopUserCookieDto.setShopId(shopJosResult.getShopId());
// shopUserCookieDto.setShopName(shopJosResult.getShopName());
// shopUserCookieDto.setOpenId(accessTokenByCode.getOpen_id());
// shopUserCookieDto.setUid(accessTokenByCode.getUid());
//
// UserUtils.injectConsumerInfoIntoCookie(shopUserCookieDto);
} else {
LOGGER.error("login,获取ShopJosResult失败");
} }
} }
return ResultBuilder.success(object); return ResultBuilder.success(accessTokenByCode.getMsg());
} catch (BizException e) {
return ResultBuilder.fail(e.getMessage());
}
}
/**
* 获取店铺信息
*/
@RequestMapping("/getShopInfoVO")
public Result<JSONObject> getShopInfoVO(Long venderId, Long shopId) {
try {
TbShopAccessTokenDto accessToken = accessTokenUtils.getAccessToken(venderId, shopId);
JdAppEnum jdAppEnum = JdAppEnum.getAppByAppKey(accessToken.getAppKey());
Result<ShopJosResult> shopJosResultResult = jdApiUtil.venderShopQuery(jdAppEnum, accessToken.getAccessToken());
JSONObject jsonObject = new JSONObject();
jsonObject.put("shop", shopJosResultResult.getData());
return ResultBuilder.success(jsonObject);
} catch (BizException e) { } catch (BizException e) {
return ResultBuilder.fail(e.getMessage()); return ResultBuilder.fail(e.getMessage());
} catch (Exception e) {
LOGGER.error("店铺授权异常", e);
return ResultBuilder.fail("店铺授权失败");
} }
} }
// /**
/** // * 获取店铺信息
* 应用插件启动唤起页 // */
*/ // @RequestMapping("/getShopInfoVO")
@RequestMapping("/redirect") // public Result<JSONObject> getShopInfoVO() {
public RedirectView login(@RequestParam(required = false) String url) { // try {
if (StringUtils.isBlank(url)) { // ShopUserCookieDto user = RequestLocal.getUser();
url = "https://79476.activity-1.m.duiba.com.cn/projectx/p77f9040a/pageshare.html?appKey=2Rwdy9oVkZM8D4ngh3JTMutPZezt&openBs=openbs&inviteCode=5541398"; // if (user == null) {
} // return ResultBuilder.fail("未登录");
return new RedirectView(url); // }
} // TbShopAccessTokenDto accessToken = accessTokenUtils.getAccessTokenWithCache(user.getVenderId(), user.getShopId());
// JdAppEnum jdAppEnum = JdAppEnum.getAppByAppKey(accessToken.getAppKey());
// Result<ShopJosResult> shopJosResultResult = jdApiUtil.venderShopQuery(jdAppEnum, accessToken.getAccessToken());
// JSONObject jsonObject = new JSONObject();
// jsonObject.put("shop", shopJosResultResult.getData());
// return ResultBuilder.success(jsonObject);
// } catch (BizException e) {
// return ResultBuilder.fail(e.getMessage());
// }
// }
} }
package cn.com.duiba.jdactivity.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 心跳
*
* @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/12 15:26
*/
@RestController
@RequestMapping("/heart")
public class HeartController {
@RequestMapping("")
public String heart() {
return "success";
}
}
\ No newline at end of file
package cn.com.duiba.jdactivity.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
/**
* @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/12 15:26
*/
@Controller
@RequestMapping("/hello")
public class HelloController {
public static final Logger LOGGER = LoggerFactory.getLogger(HelloController.class);
@Resource(name = "stringRedisTemplate")
private StringRedisTemplate stringRedisTemplate;
@RequestMapping("/testRedis")
@ResponseBody
public String testRedis(String value) {
LOGGER.info("testRedis");
stringRedisTemplate.opsForValue().set("test_key", value);
return stringRedisTemplate.opsForValue().get("test_key");
}
}
\ No newline at end of file
...@@ -13,18 +13,10 @@ import org.springframework.web.servlet.ModelAndView; ...@@ -13,18 +13,10 @@ import org.springframework.web.servlet.ModelAndView;
@RequestMapping("/") @RequestMapping("/")
public class IndexController { public class IndexController {
@RequestMapping(value = {"", "index"}) @GetMapping("/autologin")
public ModelAndView index() { public ModelAndView autologin() {
ModelAndView modelAndView = new ModelAndView(); ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("index"); modelAndView.setViewName("autologin");
return modelAndView;
}
@GetMapping("/share")
public ModelAndView share() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("share");
return modelAndView; return modelAndView;
} }
} }
package cn.com.duiba.jdactivity.developer.duiba; package cn.com.duiba.jdactivity.developer.duiba;
import org.apache.commons.lang3.StringUtils;
import java.util.Objects;
/** /**
* @author zsp (zengshuiping@duiba.com.cn) * @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/18 15:58 * @date 2021/5/18 15:58
*/ */
public enum DuibaAppEnum { public enum DuibaAppEnum {
WX("微信公众号测试", "3bRVpGghtsQXXeZpVH4VGi92Nr7V", "28Ujh91mWeKSCZ4ndDyLWf527TN1"),
TEST_4_27("4-27测试", "22KCCnB22yZihPnuB8gpqZhtdAka", "ct8j6grNJ5cCqQcN1c8sTdSEdcK"),
BOSIDENG_PROD("波司登线上", "4EBS3taRKgKpKKSVg4xv4UnfEESh", "2hMzuvExEE7XzfThv2fbnUKxRsXA"),
;
private final String appName;
private final String appKey;
private final String appSecret;
DuibaAppEnum(String appName, String appKey, String appSecret) {
this.appName = appName;
this.appKey = appKey;
this.appSecret = appSecret;
}
public String getAppName() {
return appName;
}
public String getAppKey() {
return appKey;
}
public String getAppSecret() {
return appSecret;
}
public static DuibaAppEnum getDuibaApp(String appKey) {
if (StringUtils.isBlank(appKey)) {
return null;
}
for (DuibaAppEnum value : values()) {
if (Objects.equals(value.getAppKey(), appKey)) {
return value;
}
}
return null;
}
} }
...@@ -19,7 +19,7 @@ public class Main { ...@@ -19,7 +19,7 @@ public class Main {
public static final String appKey = "B0F491866BC8C8BA5954B4DFCCF283CC"; public static final String appKey = "B0F491866BC8C8BA5954B4DFCCF283CC";
public static final String appSecret = "571df532d10c4c1e839cef1f1a9a2113"; public static final String appSecret = "571df532d10c4c1e839cef1f1a9a2113";
public static final String accessToken = "35d57da4101d498b99e2963302d5e112ntdk"; public static final String accessToken = "dfef1ede28aa455999ddefe2944980cfzguy";
public static void main(String[] args) { public static void main(String[] args) {
testDataEncryptOrDecrypt(); testDataEncryptOrDecrypt();
......
package cn.com.duiba.jdactivity.developer.jd;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/13 15:05
*/
@Configuration
@ConfigurationProperties(prefix = "jd.url")
public class UrlConstants {
private String oauthUrl = "https://open-oauth.jd.com/oauth2";
private String apiServerUrl = "https://api.jd.com/routerjson";
private String logServerUrl = "https://api-log.jd.com/routerjson";
public String getOauthUrl() {
return oauthUrl;
}
public void setOauthUrl(String oauthUrl) {
this.oauthUrl = oauthUrl;
}
public String getApiServerUrl() {
return apiServerUrl;
}
public void setApiServerUrl(String apiServerUrl) {
this.apiServerUrl = apiServerUrl;
}
public String getLogServerUrl() {
return logServerUrl;
}
public void setLogServerUrl(String logServerUrl) {
this.logServerUrl = logServerUrl;
}
}
package cn.com.duiba.jdactivity.developer.jd; package cn.com.duiba.jdactivity.developer.jd.constant;
import java.util.Objects; import java.util.Objects;
...@@ -50,9 +50,4 @@ public enum JdAppEnum { ...@@ -50,9 +50,4 @@ public enum JdAppEnum {
} }
return null; return null;
} }
public static JdAppEnum getDefault() {
return JdAppEnum.DUIBA;
}
} }
package cn.com.duiba.jdactivity.developer.jd.constant;
public enum JdServerUrlEnum {
OAUTH_URL("https://open-oauth.jd.com/oauth2"),
API_URL("https://api.jd.com/routerjson"),
LOG_URL("https://api-log.jd.com/routerjson"),
;
private final String url;
JdServerUrlEnum(String url) {
this.url = url;
}
public String getUrl() {
return url;
}
}
package cn.com.duiba.jdactivity.developer.jd.constant;
import java.util.Objects;
public enum JdShopEnum {
TEST_01("开放运营部测试店铺一号", 10276497L, 10139787L),
BOSIDENG("波司登官方旗舰店", 48034L, 44892L);
private final String shopName;
/**
* 商家Id
*/
private final Long venderId;
/**
* 店铺Id
*/
private final Long shopId;
JdShopEnum(String shopName, Long venderId, Long shopId) {
this.shopName = shopName;
this.shopId = shopId;
this.venderId = venderId;
}
public String getShopName() {
return shopName;
}
public Long getShopId() {
return shopId;
}
public Long getVenderId() {
return venderId;
}
public static JdShopEnum getJdShop(Long venderId, Long shopId) {
if (venderId == null || shopId == null || venderId == 0L || shopId == 0L) {
return null;
}
for (JdShopEnum value : values()) {
if (Objects.equals(value.getVenderId(), venderId) && Objects.equals(value.getShopId(), shopId)) {
return value;
}
}
return null;
}
}
package cn.com.duiba.jdactivity.developer.jd.constant;
/**
* 01: 京东 App,02:微信
*/
public enum JdTokenSourceEnum {
JD("01"),
WX("02");
private final String source;
JdTokenSourceEnum(String source) {
this.source = source;
}
public String getSource() {
return source;
}
}
...@@ -2,8 +2,8 @@ package cn.com.duiba.jdactivity.developer.jd.utils; ...@@ -2,8 +2,8 @@ package cn.com.duiba.jdactivity.developer.jd.utils;
import cn.com.duiba.jdactivity.common.utils.HttpClientUtil; import cn.com.duiba.jdactivity.common.utils.HttpClientUtil;
import cn.com.duiba.jdactivity.common.utils.UrlUtils; import cn.com.duiba.jdactivity.common.utils.UrlUtils;
import cn.com.duiba.jdactivity.developer.jd.JdAppEnum; import cn.com.duiba.jdactivity.developer.jd.constant.JdAppEnum;
import cn.com.duiba.jdactivity.developer.jd.UrlConstants; import cn.com.duiba.jdactivity.developer.jd.constant.JdServerUrlEnum;
import cn.com.duiba.jdactivity.developer.jd.domain.AccessTokenResponse; import cn.com.duiba.jdactivity.developer.jd.domain.AccessTokenResponse;
import cn.com.duiba.jdactivity.dto.TbShopAccessTokenDto; import cn.com.duiba.jdactivity.dto.TbShopAccessTokenDto;
import cn.com.duiba.jdactivity.exception.BizException; import cn.com.duiba.jdactivity.exception.BizException;
...@@ -11,9 +11,12 @@ import cn.com.duiba.jdactivity.service.TbShopAccessTokenService; ...@@ -11,9 +11,12 @@ import cn.com.duiba.jdactivity.service.TbShopAccessTokenService;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONValidator; import com.alibaba.fastjson.JSONValidator;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.jd.open.api.sdk.domain.seller.ShopSafService.response.query.ShopJosResult; import com.jd.open.api.sdk.domain.seller.ShopSafService.response.query.ShopJosResult;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
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;
...@@ -24,8 +27,11 @@ import java.util.Date; ...@@ -24,8 +27,11 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
/** /**
* // TODO 定时刷新
*
* @author zsp (zengshuiping@duiba.com.cn) * @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/11 15:00 * @date 2021/5/11 15:00
*/ */
...@@ -37,13 +43,20 @@ public class AccessTokenUtils { ...@@ -37,13 +43,20 @@ public class AccessTokenUtils {
private static final String ACCESS_TOKEN_SUFFIX = "/access_token"; private static final String ACCESS_TOKEN_SUFFIX = "/access_token";
private static final String NULL = "null"; private static final String NULL = "null";
@Resource
private UrlConstants urlConstants;
@Resource @Resource
private HttpClientUtil httpClientUtil; private HttpClientUtil httpClientUtil;
@Resource @Resource
private TbShopAccessTokenService tbShopAccessTokenService; private TbShopAccessTokenService tbShopAccessTokenService;
private static final Cache<String, TbShopAccessTokenDto> ACCESS_TOKEN_CACHE = Caffeine.newBuilder()
// 缓存一天,不考虑过期时间
.expireAfterWrite(1, TimeUnit.DAYS)
.initialCapacity(10)
.maximumSize(100)
.recordStats()
.build();
public String generateAuthUrl(JdAppEnum appKey, String state) { public String generateAuthUrl(JdAppEnum appKey, String state) {
Map<String, String> param = new TreeMap<>(); Map<String, String> param = new TreeMap<>();
param.put("app_key", appKey.getAppKey()); param.put("app_key", appKey.getAppKey());
...@@ -51,7 +64,7 @@ public class AccessTokenUtils { ...@@ -51,7 +64,7 @@ public class AccessTokenUtils {
param.put("redirect_uri", appKey.getUrl()); param.put("redirect_uri", appKey.getUrl());
param.put("scope", "snsapi_base"); param.put("scope", "snsapi_base");
param.put("state", state); param.put("state", state);
return UrlUtils.assembleUrl(urlConstants.getOauthUrl() + TO_LOGIN_SUFFIX, param); return UrlUtils.assembleUrl(JdServerUrlEnum.OAUTH_URL.getUrl() + TO_LOGIN_SUFFIX, param);
} }
...@@ -61,7 +74,7 @@ public class AccessTokenUtils { ...@@ -61,7 +74,7 @@ public class AccessTokenUtils {
param.put("app_secret", appKey.getAppSecret()); param.put("app_secret", appKey.getAppSecret());
param.put("grant_type", "authorization_code"); param.put("grant_type", "authorization_code");
param.put("code", code); param.put("code", code);
String url = UrlUtils.assembleUrl(urlConstants.getOauthUrl() + ACCESS_TOKEN_SUFFIX, param); String url = UrlUtils.assembleUrl(JdServerUrlEnum.OAUTH_URL.getUrl() + ACCESS_TOKEN_SUFFIX, param);
String s = httpClientUtil.sendGet(url); String s = httpClientUtil.sendGet(url);
LOGGER.info("getAccessTokenByCode,code={},url={},s={}", code, url, s); LOGGER.info("getAccessTokenByCode,code={},url={},s={}", code, url, s);
...@@ -75,10 +88,8 @@ public class AccessTokenUtils { ...@@ -75,10 +88,8 @@ public class AccessTokenUtils {
return null; return null;
} }
private static String getCacheKey(Long venderId, Long shopId) {
public Long saveAccessToken(JdAppEnum jdAppEnum, AccessTokenResponse accessTokenByCode, ShopJosResult data) { return String.format("%s_%s", venderId, shopId);
TbShopAccessTokenDto tbShopAccessTokenDto = assembleTbShopAccessTokenDto(jdAppEnum, accessTokenByCode, data);
return tbShopAccessTokenService.insert(tbShopAccessTokenDto);
} }
private TbShopAccessTokenDto assembleTbShopAccessTokenDto(JdAppEnum jdAppEnum, AccessTokenResponse accessTokenByCode, ShopJosResult data) { private TbShopAccessTokenDto assembleTbShopAccessTokenDto(JdAppEnum jdAppEnum, AccessTokenResponse accessTokenByCode, ShopJosResult data) {
...@@ -99,8 +110,54 @@ public class AccessTokenUtils { ...@@ -99,8 +110,54 @@ public class AccessTokenUtils {
return tbShopAccessTokenDto; return tbShopAccessTokenDto;
} }
private static Pair<String, String> splitCacheKey(String key) throws BizException {
String[] split = key.split("_");
if (split.length != 2) {
throw new BizException("key不合法" + key);
}
return Pair.of(split[0], split[1]);
}
public Long saveAccessToken(JdAppEnum jdAppEnum, AccessTokenResponse accessTokenByCode, ShopJosResult data) {
ACCESS_TOKEN_CACHE.invalidate(getCacheKey(data.getVenderId(), data.getShopId()));
TbShopAccessTokenDto tbShopAccessTokenDto = assembleTbShopAccessTokenDto(jdAppEnum, accessTokenByCode, data);
return tbShopAccessTokenService.insert(tbShopAccessTokenDto);
}
public TbShopAccessTokenDto getAccessToken(Long venderId, Long shopId) throws BizException { public TbShopAccessTokenDto getAccessTokenWithCache(Long venderId, Long shopId) throws BizException {
if (venderId == null || shopId == null || venderId == 0L || shopId == 0L) {
throw new BizException("店铺参数不存在");
}
String key = getCacheKey(venderId, shopId);
TbShopAccessTokenDto tbShopAccessTokenDto = ACCESS_TOKEN_CACHE.get(key, s -> {
try {
LOGGER.info("开始加载缓存,venderId={},shopId={}", venderId, shopId);
return getAccessTokenWithoutCache(venderId, shopId);
} catch (BizException e) {
LOGGER.warn("加载缓存失败", e);
return null;
}
});
LOGGER.info("获取缓存结果,venderId={},shopId={},tbShopAccessTokenDto={}", venderId, shopId, tbShopAccessTokenDto != null);
if (tbShopAccessTokenDto == null) {
throw new BizException("店铺授权获取失败" + shopId);
}
if (tbShopAccessTokenDto.getExpiresTime().before(new Date())) {
ACCESS_TOKEN_CACHE.invalidate(key);
throw new BizException("店铺授权获取失败" + shopId);
}
return tbShopAccessTokenDto;
}
private TbShopAccessTokenDto getAccessTokenWithoutCache(Long venderId, Long shopId) throws BizException {
if (venderId == null || shopId == null || venderId == 0L || shopId == 0L) {
throw new BizException("店铺参数不存在");
}
Date now = new Date(); Date now = new Date();
List<TbShopAccessTokenDto> tbShopAccessTokenDtos = tbShopAccessTokenService.queryByVenderIdShopId(venderId, shopId); List<TbShopAccessTokenDto> tbShopAccessTokenDtos = tbShopAccessTokenService.queryByVenderIdShopId(venderId, shopId);
if (CollectionUtils.isEmpty(tbShopAccessTokenDtos)) { if (CollectionUtils.isEmpty(tbShopAccessTokenDtos)) {
......
package cn.com.duiba.jdactivity.developer.jd.utils; package cn.com.duiba.jdactivity.developer.jd.utils;
import cn.com.duiba.jdactivity.developer.jd.JdAppEnum; import cn.com.duiba.jdactivity.developer.jd.constant.JdAppEnum;
import cn.com.duiba.jdactivity.developer.jd.UrlConstants; import cn.com.duiba.jdactivity.developer.jd.constant.JdServerUrlEnum;
import com.jd.security.tdeclient.SecretJdClient; import com.jd.security.tdeclient.SecretJdClient;
import com.jd.security.tdeclient.TDEClient; import com.jd.security.tdeclient.TDEClient;
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;
import javax.annotation.Resource;
/** /**
* @author zsp (zengshuiping@duiba.com.cn) * @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/18 16:04 * @date 2021/5/18 16:04
...@@ -18,10 +16,6 @@ import javax.annotation.Resource; ...@@ -18,10 +16,6 @@ import javax.annotation.Resource;
public class EncryptUtil { public class EncryptUtil {
public static final Logger LOGGER = LoggerFactory.getLogger(EncryptUtil.class); public static final Logger LOGGER = LoggerFactory.getLogger(EncryptUtil.class);
@Resource
private UrlConstants urlConstants;
public String encryptString(JdAppEnum jdAppEnum, String accessToken, String plaintext) { public String encryptString(JdAppEnum jdAppEnum, String accessToken, String plaintext) {
try { try {
TDEClient tdeClient = getClient(jdAppEnum, accessToken); TDEClient tdeClient = getClient(jdAppEnum, accessToken);
...@@ -44,6 +38,6 @@ public class EncryptUtil { ...@@ -44,6 +38,6 @@ public class EncryptUtil {
} }
private TDEClient getClient(JdAppEnum jdAppEnum, String accessToken) throws Exception { private TDEClient getClient(JdAppEnum jdAppEnum, String accessToken) throws Exception {
return SecretJdClient.getInstance(urlConstants.getApiServerUrl(), accessToken, jdAppEnum.getAppKey(), jdAppEnum.getAppSecret()); return SecretJdClient.getInstance(JdServerUrlEnum.API_URL.getUrl(), accessToken, jdAppEnum.getAppKey(), jdAppEnum.getAppSecret());
} }
} }
package cn.com.duiba.jdactivity.developer.jd.utils; package cn.com.duiba.jdactivity.developer.jd.utils;
import cn.com.duiba.jdactivity.common.utils.RequestTool; import cn.com.duiba.jdactivity.common.utils.RequestTool;
import cn.com.duiba.jdactivity.developer.jd.JdAppEnum; import cn.com.duiba.jdactivity.developer.jd.constant.JdAppEnum;
import cn.com.duiba.jdactivity.developer.jd.UrlConstants; import cn.com.duiba.jdactivity.developer.jd.constant.JdServerUrlEnum;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.jd.open.api.sdk.DefaultJdClient; import com.jd.open.api.sdk.DefaultJdClient;
import com.jd.open.api.sdk.JdClient; import com.jd.open.api.sdk.JdClient;
...@@ -15,7 +15,6 @@ import org.slf4j.Logger; ...@@ -15,7 +15,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Objects; import java.util.Objects;
...@@ -28,11 +27,13 @@ import java.util.Objects; ...@@ -28,11 +27,13 @@ import java.util.Objects;
@Component @Component
public class LogUtil { public class LogUtil {
public static final Logger LOGGER = LoggerFactory.getLogger(LogUtil.class); public static final Logger LOGGER = LoggerFactory.getLogger(LogUtil.class);
@Resource
private UrlConstants urlConstants;
public void logLogin(JdAppEnum jdAppEnum, boolean loginSuccess, String deviceId) { private static String getDeviceId() {
return RequestTool.getHttpServletRequest().getHeader("device_id");
}
public void logLogin(JdAppEnum jdAppEnum, boolean loginSuccess, String jdId, String userId) {
try { try {
JdClient client = getClient(jdAppEnum); JdClient client = getClient(jdAppEnum);
IsvUploadLoginLogRequest request = new IsvUploadLoginLogRequest(); IsvUploadLoginLogRequest request = new IsvUploadLoginLogRequest();
...@@ -40,9 +41,9 @@ public class LogUtil { ...@@ -40,9 +41,9 @@ public class LogUtil {
request.setUserIp(getClientIp()); request.setUserIp(getClientIp());
request.setAppName(jdAppEnum.getAppName()); request.setAppName(jdAppEnum.getAppName());
request.setJosAppKey(jdAppEnum.getAppKey()); request.setJosAppKey(jdAppEnum.getAppKey());
request.setJdId("123"); request.setJdId(jdId);
request.setDeviceId(deviceId); request.setDeviceId(getDeviceId());
request.setUserId("adsf1234sg23"); request.setUserId(userId);
request.setMessage(loginSuccess ? "登录成功" : "登陆失败"); request.setMessage(loginSuccess ? "登录成功" : "登陆失败");
request.setTimeStamp(System.currentTimeMillis()); request.setTimeStamp(System.currentTimeMillis());
IsvUploadLoginLogResponse response = client.execute(request); IsvUploadLoginLogResponse response = client.execute(request);
...@@ -56,21 +57,21 @@ public class LogUtil { ...@@ -56,21 +57,21 @@ public class LogUtil {
} catch (Exception e) { } catch (Exception e) {
LOGGER.info("logLogin,exception", e); LOGGER.info("logLogin,exception", e);
} }
} }
public void logDBOperation(JdAppEnum jdAppEnum, String jdId, String db, String sql) {
public void logDBOperation(JdAppEnum jdAppEnum, String deviceId, String db, String sql) {
try { try {
JdClient client = getClient(jdAppEnum); JdClient client = getClient(jdAppEnum);
IsvUploadDBOperationLogRequest request = new IsvUploadDBOperationLogRequest(); IsvUploadDBOperationLogRequest request = new IsvUploadDBOperationLogRequest();
request.setUserIp(getClientIp()); request.setUserIp(getClientIp());
request.setAppName("日志应用"); request.setAppName(jdAppEnum.getAppName());
request.setJosAppKey(jdAppEnum.getAppKey()); request.setJosAppKey(jdAppEnum.getAppKey());
request.setDeviceId(deviceId); request.setDeviceId(getDeviceId());
request.setUserId("1111"); request.setUserId(jdId);
request.setUrl(RequestTool.getRequestUrl(RequestTool.getHttpServletRequest())); request.setUrl(RequestTool.getRequestUrl(RequestTool.getHttpServletRequest()));
if (StringUtils.isBlank(db)) {
db = "custom";
}
request.setDb(db); request.setDb(db);
request.setSql(sql); request.setSql(sql);
request.setTimeStamp(System.currentTimeMillis()); request.setTimeStamp(System.currentTimeMillis());
...@@ -109,6 +110,6 @@ public class LogUtil { ...@@ -109,6 +110,6 @@ public class LogUtil {
} }
private DefaultJdClient getClient(JdAppEnum jdAppEnum) { private DefaultJdClient getClient(JdAppEnum jdAppEnum) {
return new DefaultJdClient(urlConstants.getLogServerUrl(), "", jdAppEnum.getAppKey(), jdAppEnum.getAppSecret()); return new DefaultJdClient(JdServerUrlEnum.LOG_URL.getUrl(), "", jdAppEnum.getAppKey(), jdAppEnum.getAppSecret());
} }
} }
package cn.com.duiba.jdactivity.dto;
import java.io.Serializable;
/**
* 免登录参数
*
* @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/20 15:40
*/
public class AutologinParam implements Serializable {
private static final long serialVersionUID = -2744319658331307681L;
private Long venderId;
private Long shopId;
private String token;
private String source;
private String redirectUrl;
/**
* 兑吧环境
*/
private String env;
/**
* 兑吧appKey
*/
private String appKey;
public Long getVenderId() {
return venderId;
}
public void setVenderId(Long venderId) {
this.venderId = venderId;
}
public Long getShopId() {
return shopId;
}
public void setShopId(Long shopId) {
this.shopId = shopId;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getRedirectUrl() {
return redirectUrl;
}
public void setRedirectUrl(String redirectUrl) {
this.redirectUrl = redirectUrl;
}
public String getEnv() {
return env;
}
public void setEnv(String env) {
this.env = env;
}
public String getAppKey() {
return appKey;
}
public void setAppKey(String appKey) {
this.appKey = appKey;
}
}
package cn.com.duiba.jdactivity.interceptor; package cn.com.duiba.jdactivity.interceptor;
import cn.com.duiba.jdactivity.common.utils.RequestLocal; import cn.com.duiba.jdactivity.common.utils.RequestLocal;
import cn.com.duiba.jdactivity.common.utils.user.UserCookieDto; import cn.com.duiba.jdactivity.common.utils.user.ShopUserCookieDto;
import cn.com.duiba.jdactivity.common.utils.user.UserUtils; import cn.com.duiba.jdactivity.common.utils.user.UserUtils;
import cn.com.duiba.jdactivity.common.vo.ResultBuilder; import cn.com.duiba.jdactivity.common.vo.ResultBuilder;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
...@@ -18,7 +17,7 @@ import java.io.PrintWriter; ...@@ -18,7 +17,7 @@ import java.io.PrintWriter;
* @author zsp (zengshuiping@duiba.com.cn) * @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/17 18:41 * @date 2021/5/17 18:41
*/ */
@Component // @Component
public class LoginInterceptor implements HandlerInterceptor { public class LoginInterceptor implements HandlerInterceptor {
@Override @Override
...@@ -33,8 +32,8 @@ public class LoginInterceptor implements HandlerInterceptor { ...@@ -33,8 +32,8 @@ public class LoginInterceptor implements HandlerInterceptor {
} }
} }
try { try {
UserCookieDto userCookieDto = UserUtils.getUserCookieDto(request); ShopUserCookieDto shopUserCookieDto = UserUtils.getUserCookieDto(request);
RequestLocal.setUser(userCookieDto); RequestLocal.setUser(shopUserCookieDto);
} catch (Exception e) { } catch (Exception e) {
String message = JSONObject.toJSONString(ResultBuilder.fail(e.getMessage())); String message = JSONObject.toJSONString(ResultBuilder.fail(e.getMessage()));
writeResult(response, message); writeResult(response, message);
......
#MySQL配置 注意这是内网地址 #MySQL配置 注意这是内网地址
spring.datasource.url=jdbc:mysql://mysql-cn-north-1-5321aee1b70d421c.rds.jdcloud.com:3306/custom?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true spring.datasource.url=jdbc:mysql://mysql-cn-north-1-5321aee1b70d421c.rds.jdcloud.com:3306/custom?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&connectTimeout=5000&socketTimeout=60000
spring.datasource.username=jd_activity spring.datasource.username=jd_activity
spring.datasource.password=kP6oWdeYU78tHee70bcs spring.datasource.password=kP6oWdeYU78tHee70bcs
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
......
...@@ -7,6 +7,8 @@ server.port=8080 ...@@ -7,6 +7,8 @@ server.port=8080
server.tomcat.accesslog.enabled=false server.tomcat.accesslog.enabled=false
server.tomcat.uri-encoding=UTF-8 server.tomcat.uri-encoding=UTF-8
server.tomcat.threads.max=300 server.tomcat.threads.max=300
#服务器连接超时
server.tomcat.connection-timeout=8s
# logging # logging
logging.file.path=${user.home}/logs/${spring.application.name} logging.file.path=${user.home}/logs/${spring.application.name}
# MyBatis 配置 # MyBatis 配置
...@@ -17,10 +19,16 @@ spring.thymeleaf.prefix=classpath:templates/ ...@@ -17,10 +19,16 @@ spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.suffix=.html spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML spring.thymeleaf.mode=HTML
spring.thymeleaf.cache=false spring.thymeleaf.cache=false
#连接池最大连接数
spring.datasource.tomcat.max-active=8
#连接池的初始化连接数
spring.datasource.tomcat.initial-size=3
#连接池最大空闲链接数
spring.datasource.tomcat.max-idle=8
#连接池最小空闲连接数
spring.datasource.tomcat.min-idle=0
#等待连接池的最大时间
spring.datasource.tomcat.max-wait=3000
#连接最大存活时间
spring.datasource.tomcat.max-age=1800000
jd.bosideng.appKey=jlg88lyxz7siqtmr
jd.bosideng.appSecret=1x0eap95f4xfi77uaptrnwh9ewzvlm
jd.bosideng.autoUrl=http://activity.m.duibatest.com.cn?
#需要encode
jd.bosideng.defIndexUrl=http%3A%2F%2Factivity.m.duibatest.com.cn%2Fhdtool%2Findex%3Fid%3D163505506037221%26dbnewopen
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>正在加载..</title>
<meta content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"
name="viewport"/>
<meta content="yes" name="apple-mobile-web-app-capable"/>
<meta content="true" name="full-screen"/>
<meta content="portrait" name="screen-orientation"/>
<!-- <meta name="x5-fullscreen" content="true"/> -->
<!-- <meta name="360-fullscreen" content="true"/> -->
<!-- <script src="./jssdk.min.js"></script> -->
<script src="//yun.duiba.com.cn/aurora/assets/4c37d75a75d8e7534d9e3b056911ba06ac5bf8f8.js"></script>
<script src="//yun.duiba.com.cn/js-libs/vConsole/3.3.4/vconsole.min.js"></script>
<!-- <script src="http://wechatfe.github.io/vconsole/lib/vconsole.min.js?v=3.2.0"></script> -->
<script>
new VConsole();
</script>
<style>
.box {
width: 100%;
height: 100vh;
}
.box > div {
width: 100%;
height: 30px;
line-height: 30px;
text-align: center;
border: 2px solid #ccc;
margin: 5px 0;
}
</style>
</head>
<body>
<div class="box">
<div onclick="login()">是否登录</div>
<div onclick="openLoginPanel()">登录面板</div>
<div onclick="shareConfig()">分享设置</div>
<div onclick="getToken()">获取混淆token</div>
<div onclick="isInJd()">是否在京东APP内</div>
<div onclick="isInWx()">是否在微信内</div>
</div>
<script language="javascript">
console.log("JSSDK", JSSDK)
function login() {
JSSDK.Login.isLogin({
from: window.location.host
}, isLogin);
}
function isLogin(res) {
console.log(res)
setTimeout(function () {
console.log(res.data)
}, 0);
}
function openLoginPanel() {
console.log("登录面板")
JSSDK.Isv.isAppLogin(callback);
}
function callback(res) {
console.log("登录面板返回", res)
}
function shareConfig() {
console.log("分享配置")
JSSDK.WebView.callHeaderSharePanel({
title: "京东超值购",
content: "来京东,更超值",
shareUrl: window.location.href,
channel: "",
iconUrl: ""
});
}
function getToken() {
console.log("获取token", window.location.href)
JSSDK.Isv.requestIsvToken({
url: window.location.href
}, callBackToken);
}
function callBackToken(res) {
console.log("获取token的返回", res)
}
function isInJd() {
var inJd = JSSDK.Client.isJDApp();
console.log("是否在京东内", inJd)
}
function isInWx() {
var inWx = JSSDK.Client.isWeixin();
console.log("是否在微信内", inWx)
}
</script>
</body>
</html>
\ No newline at end of file
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1,shrink-to-fit=no" name="viewport">
<meta content="#000000" name="theme-color">
<title>活动标题</title>
<script src="//yun.duiba.com.cn/js-libs/rem/1.1.3/rem.min.js"></script>
<script src="//yun.duiba.com.cn/h5/lib/zepto.min.js"></script>
<script src="//yun.duiba.com.cn/aurora/assets/4c37d75a75d8e7534d9e3b056911ba06ac5bf8f8.js"></script>
<script src="//yun.duiba.com.cn/js-libs/vConsole/3.3.4/vconsole.min.js"></script>
<script src="//yun.duiba.com.cn/aurora/assets/06d225d08a7cb9f924c7d2563361c6d64be08f47.js"></script>
<script>"use strict";
new VConsole();</script>
<script>"use strict";
function getApp() {
return {
cloud: {},
cloudName: "clientTemplate2C",
requestType: "mock"
};
}
var CFG = CFG || {};
CFG.projectId = location.pathname.split('/')[2] || '1';
function getUrlParam(name) {
var search = window.location.search;
var matched = search.slice(1).match(new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'));
return search.length ? matched && matched[2] : null;
}
CFG.appID = '${APPID}';
if (!getUrlParam("appID")) {// alert("【警告】检测到活动url中没有appID参数\n缺少该参数会导致埋点、分享、app信息获取错误。")
}
console.log(jdshare);
jdshare.setShareInfo({
title: '京东无线',
content: '每日京喜好货,都在京东 APP!',
url: 'https://m.jd.com',
img: 'https://m.360buyimg.com/n1/s120x120_jfs/t2566/341/1119128176/23675/6356333 b/568e3d86Naa36a750.jpg',
/**
* 以下非必填
*/
channel: 'Wxfriends,Wxmoments,Sinaweibo',
callback: null,
clickcallback: null,
qrparam: null,
timeline_title: '',
keyparam: {
url: "https://79476.activity-1.m.duiba.com.cn/projectx/p77f9040a/pageshare.html?appKey=2Rwdy9oVkZM8D4ngh3JTMutPZezt&openBs=openbs&inviteCode=5541398",
keyEndTime: "1673267745000",
keyChannel: "Wxfriends,QQfriends,Wxmoments,QQzone,Sinaweibo",
sourceCode: "babel",
keyImg: "https://yun.duiba.com.cn/spark/assets/628a094f3755370025e75b12fdbec774b80fc23c.png",
keyId: "11",
//活动标识传参规则,详情查看京口令使用规范&调用方式
keyTitle: "我是一条小青龙,我有许多小秘密",
keyContent: "我就是内容,就不告诉你"
}
});</script>
<link href="//yun.duiba.com.cn/spark/v2/sparkproject-1621392784078/1621403771417/styles/main.c4ec6aaf352f9224af6d.css"
rel="stylesheet">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script src="//yun.duiba.com.cn/spark/v2/sparkproject-1621392784078/1621403771417/js/runtime-main.51b70ba8.js"></script>
<script src="//yun.duiba.com.cn/spark/v2/sparkproject-1621392784078/1621403771417/js/vendors.c34d460b.js"></script>
<script src="//yun.duiba.com.cn/spark/v2/sparkproject-1621392784078/1621403771417/js/main.159515e7.js"></script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>正在加载..</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<script src="//yun.duiba.com.cn/aurora/assets/4c37d75a75d8e7534d9e3b056911ba06ac5bf8f8.js"></script>
<!-- <script src="//yun.duiba.com.cn/js-libs/vConsole/3.3.4/vconsole.min.js"></script> -->
<!-- jquery.min.js -->
<script src="//h5static.m.jd.com/act/jm-jdshare/2.0.0/jm-jdshare.js"></script>
<script src="//s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js"></script>
<script>
// new VConsole();
</script>
<style>
.box {
width: 100%;
height: 100vh;
}
.box > div {
width: 100%;
height: 30px;
line-height: 30px;
text-align: center;
border: 2px solid #ccc;
margin: 5px 0;
}
</style>
</head>
<body>
<div class="box">
<!-- <div onclick="openLoginPanel()">唤起登录面板</div> -->
<!-- <div onclick="jumpToPage()">跳转</div> -->
</div>
<script language="javascript">
(function () {
openLoginPanel();
})()
function openLoginPanel() {
console.log("登录面板")
JSSDK.Isv.requestLogin(isLogin);
}
function isLogin(res) {
console.log("login回调/打开登录面板的回调", res)
setTimeout(function () {
console.log(res.data)
if (res.data == 1) {
// 已登录
getToken();
} else {
// 未登录
}
}, 0);
}
function getToken() {
console.log("进入获取token方法", window.location.href)
JSSDK.Isv.requestIsvToken({
url: window.location.href
}, callBackToken);
}
function callBackToken(res) {
console.log("获取token的返回", res)
autoLogin(res.data);
}
var pageUrl = "";
function autoLogin(token) {
var redirect = getUrlParam("redirect");
var env = getUrlParam("env");
var shopId = getUrlParam("shopId");
var venderId = getUrlParam("venderId");
var appKey = getUrlParam("appKey");
$.ajax({
type: 'post',
url: `/open2Duiba/autologin`,
data: JSON.stringify({
token: token,
redirectUrl: redirect,
env: env,
shopId: shopId,
venderId: venderId,
appKey: appKey
}),
async: false,
contentType: 'application/json',
dataType: 'json', //返回 JSON 数据
beforeSend: function () {
},
success: function (data, status) {
console.log("autoLogin返回参数:", data)
pageUrl = data.data;
console.log(pageUrl)
window.location.href = pageUrl;
},
complete: function () {
},
error: function (data, status, e) {
console.log("接口调用错误", e)
}
});
}
function jumpToPage() {
console.log(pageUrl)
window.location.href = pageUrl;
}
function getUrlParam(name) {
var search = window.location.search;
var matched = search
.slice(1)
.match(new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'));
return search.length ? matched && matched[2] : null;
}
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>正在加载..</title>
<meta content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"
name="viewport"/>
<meta content="yes" name="apple-mobile-web-app-capable"/>
<meta content="true" name="full-screen"/>
<meta content="portrait" name="screen-orientation"/>
<!-- <meta name="x5-fullscreen" content="true"/> -->
<!-- <meta name="360-fullscreen" content="true"/> -->
<!-- <script src="./jssdk.min.js"></script> -->
<script src="//yun.duiba.com.cn/aurora/assets/4c37d75a75d8e7534d9e3b056911ba06ac5bf8f8.js"></script>
<script src="//yun.duiba.com.cn/js-libs/vConsole/3.3.4/vconsole.min.js"></script>
<!-- <script src="http://wechatfe.github.io/vconsole/lib/vconsole.min.js?v=3.2.0"></script> -->
<script>
new VConsole();
</script>
<style>
.box {
width: 100%;
height: 100vh;
}
.box > div {
width: 100%;
height: 30px;
line-height: 30px;
text-align: center;
border: 2px solid #ccc;
margin: 5px 0;
}
</style>
</head>
<body>
<div class="box">
<div onclick="login()">是否登录</div>
<div onclick="openLoginPanel()">登录面板</div>
<div onclick="shareConfig()">分享设置</div>
<div onclick="getToken()">获取混淆token</div>
<div onclick="isInJd()">是否在京东APP内</div>
<div onclick="isInWx()">是否在微信内</div>
</div>
<script language="javascript">
console.log("JSSDK", JSSDK)
function login() {
JSSDK.Login.isLogin({
from: window.location.host
}, isLogin);
}
function isLogin(res) {
console.log(res)
setTimeout(function () {
console.log(res.data)
}, 0);
}
function openLoginPanel() {
console.log("登录面板")
JSSDK.Isv.isAppLogin(callback);
}
function callback(res) {
console.log("登录面板返回", res)
}
function shareConfig() {
console.log("分享配置")
JSSDK.WebView.callHeaderSharePanel({
title: "京东超值购",
content: "来京东,更超值",
shareUrl: window.location.href,
channel: "",
iconUrl: ""
});
}
function getToken() {
console.log("获取token", window.location.href)
JSSDK.Isv.requestIsvToken({
url: window.location.href
}, callBackToken);
}
function callBackToken(res) {
console.log("获取token的返回", res)
}
function isInJd() {
var inJd = JSSDK.Client.isJDApp();
console.log("是否在京东内", inJd)
}
function isInWx() {
var inWx = JSSDK.Client.isWeixin();
console.log("是否在微信内", inWx)
}
</script>
</body>
</html>
\ No newline at end of file
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1,shrink-to-fit=no" name="viewport">
<meta content="#000000" name="theme-color">
<title>活动标题</title>
<script src="//yun.duiba.com.cn/js-libs/rem/1.1.3/rem.min.js"></script>
<script src="//yun.duiba.com.cn/h5/lib/zepto.min.js"></script>
<script src="//yun.duiba.com.cn/aurora/assets/4c37d75a75d8e7534d9e3b056911ba06ac5bf8f8.js"></script>
<script src="//yun.duiba.com.cn/js-libs/vConsole/3.3.4/vconsole.min.js"></script>
<script src="//yun.duiba.com.cn/aurora/assets/06d225d08a7cb9f924c7d2563361c6d64be08f47.js"></script>
<script>"use strict";
new VConsole();</script>
<script>"use strict";
function getApp() {
return {
cloud: {},
cloudName: "clientTemplate2C",
requestType: "mock"
};
}
var CFG = CFG || {};
CFG.projectId = location.pathname.split('/')[2] || '1';
function getUrlParam(name) {
var search = window.location.search;
var matched = search.slice(1).match(new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'));
return search.length ? matched && matched[2] : null;
}
CFG.appID = '${APPID}';
if (!getUrlParam("appID")) {// alert("【警告】检测到活动url中没有appID参数\n缺少该参数会导致埋点、分享、app信息获取错误。")
}
console.log(jdshare);
jdshare.setShareInfo({
title: '京东无线',
content: '每日京喜好货,都在京东 APP!',
url: 'https://m.jd.com',
img: 'https://m.360buyimg.com/n1/s120x120_jfs/t2566/341/1119128176/23675/6356333 b/568e3d86Naa36a750.jpg',
/**
* 以下非必填
*/
channel: 'Wxfriends,Wxmoments,Sinaweibo',
callback: null,
clickcallback: null,
qrparam: null,
timeline_title: '',
keyparam: {
url: "https://79476.activity-1.m.duiba.com.cn/projectx/p77f9040a/pageshare.html?appKey=2Rwdy9oVkZM8D4ngh3JTMutPZezt&openBs=openbs&inviteCode=5541398",
keyEndTime: "1673267745000",
keyChannel: "Wxfriends,QQfriends,Wxmoments,QQzone,Sinaweibo",
sourceCode: "babel",
keyImg: "https://yun.duiba.com.cn/spark/assets/628a094f3755370025e75b12fdbec774b80fc23c.png",
keyId: "11",
//活动标识传参规则,详情查看京口令使用规范&调用方式
keyTitle: "我是一条小青龙,我有许多小秘密",
keyContent: "我就是内容,就不告诉你"
}
});</script>
<link href="//yun.duiba.com.cn/spark/v2/sparkproject-1621392784078/1621403771417/styles/main.c4ec6aaf352f9224af6d.css"
rel="stylesheet">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script src="//yun.duiba.com.cn/spark/v2/sparkproject-1621392784078/1621403771417/js/runtime-main.51b70ba8.js"></script>
<script src="//yun.duiba.com.cn/spark/v2/sparkproject-1621392784078/1621403771417/js/vendors.c34d460b.js"></script>
<script src="//yun.duiba.com.cn/spark/v2/sparkproject-1621392784078/1621403771417/js/main.159515e7.js"></script>
</body>
</html>
\ No newline at end of file
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;
class Open2DuibaControllerTest extends ControllerTest {
@Resource
private Open2DuibaController open2DuibaController;
@Test
void autologin() {
}
@Test
void isFollowShop() {
}
@Test
void followShop() {
}
@Test
void isMember() {
}
@Test
void sendCouponId() {
}
@Test
void convert2Pin() {
}
@Test
void convert2Uid() {
String accessToken = "dfef1ede28aa455999ddefe2944980cfzguy";
String pin = "yi皮仔";
try {
System.out.println(open2DuibaController.convert2Uid(JdAppEnum.DUIBA, accessToken, pin));
} catch (BizException e) {
e.printStackTrace();
}
;
}
}
\ No newline at end of file
package cn.com.duiba.jdactivity.developer.jd; package cn.com.duiba.jdactivity.developer.jd;
import cn.com.duiba.jdactivity.BaseTest; import cn.com.duiba.jdactivity.BaseTest;
import cn.com.duiba.jdactivity.developer.jd.constant.JdAppEnum;
import cn.com.duiba.jdactivity.developer.jd.domain.AccessTokenResponse; import cn.com.duiba.jdactivity.developer.jd.domain.AccessTokenResponse;
import cn.com.duiba.jdactivity.developer.jd.utils.AccessTokenUtils; import cn.com.duiba.jdactivity.developer.jd.utils.AccessTokenUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
......
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.developer.jd.JdAppEnum; import cn.com.duiba.jdactivity.developer.jd.constant.JdAppEnum;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -17,12 +18,23 @@ class EncryptUtilTest extends BaseTest { ...@@ -17,12 +18,23 @@ class EncryptUtilTest extends BaseTest {
@Test @Test
void test() { void test() {
String plaintext = "16612341234"; String plaintext = "yi皮仔";
testEncryptString(plaintext, "dfef1ede28aa455999ddefe2944980cfzguy");
String encryptString = encryptUtil.encryptString(JdAppEnum.DUIBA, "7ab5b3444e3e4c06ba06a8181133c8c7inwi", plaintext); // for (int i = 0; i < 10000; i++) {
// testEncryptString(plaintext + i);
// }
}
boolean equals = Objects.equals(plaintext, encryptUtil.decryptString(JdAppEnum.DUIBA, "7ab5b3444e3e4c06ba06a8181133c8c7inwi", encryptString)); private void testEncryptString(String plaintext, String accessToken) {
System.out.println(equals); long l = System.currentTimeMillis();
String encryptString = encryptUtil.encryptString(JdAppEnum.DUIBA, accessToken, plaintext);
System.out.println("加密耗时" + (System.currentTimeMillis() - l));
System.out.println(encryptString);
l = System.currentTimeMillis();
String decryptString = encryptUtil.decryptString(JdAppEnum.DUIBA, accessToken, encryptString);
System.out.println("解密耗时" + (System.currentTimeMillis() - l));
boolean equals = Objects.equals(plaintext, decryptString);
Assertions.assertTrue(equals);
} }
......
package cn.com.duiba.jdactivity.developer.jd.utils;
import cn.com.duiba.jdactivity.BaseTest;
import cn.com.duiba.jdactivity.developer.jd.constant.JdAppEnum;
import com.alibaba.fastjson.JSON;
import org.junit.jupiter.api.Test;
import javax.annotation.Resource;
/**
* @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/19 18:09
*/
class JdApiUtilTest extends BaseTest {
@Resource
private JdApiUtil jdApiUtil;
@Test
void venderShopQuery() {
// for (int i = 0; i < 1000; i++) {
// long now = System.currentTimeMillis();
// Result<ShopJosResult> shopJosResultResult = jdApiUtil.venderShopQuery(JdAppEnum.DUIBA, "7ab5b3444e3e4c06ba06a8181133c8c7inwi");
// System.out.println("耗时" + (System.currentTimeMillis() - now));
// }
System.out.println(JSON.toJSONString(jdApiUtil.venderShopQuery(JdAppEnum.DUIBA, "7ab5b3444e3e4c06ba06a8181133c8c7inwi")));
}
@Test
void getPinByToken() {
System.out.println(JSON.toJSONString(
jdApiUtil.getPinByToken(JdAppEnum.DUIBA, "dfef1ede28aa455999ddefe2944980cfzguy", "01", "AAFgpkP2ADCs9bF_MPObEd6CcwttmYLHfN69Yr8I8xmQA6CBleiqEh4X9mN6bfbjklo863VwWIk")));
}
@Test
void getEncryptPinNewByToken() {
}
@Test
void getOpenIdByToken() {
}
@Test
void getUserInfoByOpenId() {
}
@Test
void getCustomer() {
}
@Test
void isFollowByPinAndVid() {
}
@Test
void followByPinAndVid() {
}
@Test
void getMemberInVender() {
}
@Test
void createCoupon() {
System.out.println(JSON.toJSONString(
jdApiUtil.createCoupon(JdAppEnum.DUIBA, "dfef1ede28aa455999ddefe2944980cfzguy",
"测试优惠券-排行榜-01", 50)));
}
@Test
void lockCoupon() {
System.out.println(JSON.toJSONString(
jdApiUtil.lockCoupon(JdAppEnum.DUIBA, "dfef1ede28aa455999ddefe2944980cfzguy",
365488621L)));
}
@Test
void pushCoupon() {
System.out.println(JSON.toJSONString(
jdApiUtil.pushCoupon(JdAppEnum.DUIBA, "dfef1ede28aa455999ddefe2944980cfzguy",
365488621L, "jd_7db1fb0992ce7", "1")));
}
}
\ No newline at end of file
package cn.com.duiba.jdactivity.service; package cn.com.duiba.jdactivity.service;
import cn.com.duiba.jdactivity.BaseTest; import cn.com.duiba.jdactivity.BaseTest;
import cn.com.duiba.jdactivity.developer.jd.JdAppEnum; import cn.com.duiba.jdactivity.developer.jd.constant.JdAppEnum;
import cn.com.duiba.jdactivity.dto.TbShopAccessTokenDto; import cn.com.duiba.jdactivity.dto.TbShopAccessTokenDto;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
......
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