Commit d56cb3d4 authored by 郝增润's avatar 郝增润

兼容微信端

parent 54269720
......@@ -19,4 +19,19 @@ public class IndexController {
modelAndView.setViewName("autologin");
return modelAndView;
}
@GetMapping("/autologin2")
public ModelAndView autologin2() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("autologin2");
return modelAndView;
}
@GetMapping("/autologin3")
public ModelAndView autologin3() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("autologin3");
return modelAndView;
}
}
......@@ -230,6 +230,62 @@ public class Open2DuibaController {
}
}
@PostMapping("/autologin2")
public Result<String> autologin2(@RequestBody AutologinParam autologinParam) {
try {
LOGGER.info("autologin,autologinParam={}", JSON.toJSONString(autologinParam));
String token = autologinParam.getToken();
String source = Optional.ofNullable(autologinParam.getSource()).orElse(JdTokenSourceEnum.JD.getSource());
LOGGER.info("source,source={}", source);
String redirectUrl = autologinParam.getRedirectUrl();
String env = autologinParam.getEnv();
Long venderId = autologinParam.getVenderId();
Long shopId = autologinParam.getShopId();
if (venderId == null && shopId == null) {
//最开始波司登无这两个参数
venderId = JdShopEnum.BOSIDENG.getVenderId();
shopId = JdShopEnum.BOSIDENG.getShopId();
}
// 兑吧应用
DuibaAppEnum duibaApp = Optional
.ofNullable(DuibaAppEnum.getDuibaApp(autologinParam.getAppKey()))
.orElse(DuibaAppEnum.BOSIDENG_PROD);
TbShopAccessTokenDto accessToken = accessTokenUtils.getAccessTokenWithCache(venderId, shopId);
LOGGER.info("获取accessToken,结果={}", JSON.toJSONString(accessToken));
JdAppEnum appByAppKey = JdAppEnum.getAppByAppKey(accessToken.getAppKey());
Result<String> pinByToken = jdApiUtil.getPinByToken(appByAppKey, accessToken.getAccessToken(), source, token);
LOGGER.info("获取pin,结果={}", JSON.toJSONString(pinByToken));
Result<String> openIdByToken = jdApiUtil.getOpenIdByToken(appByAppKey, source, token);
LOGGER.info("获取openId,结果={}", JSON.toJSONString(openIdByToken));
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);
String nickName = userInfoByOpenId.getData().getNickName();
String avatar = userInfoByOpenId.getData().getImageUrl();
String credits = null;
if (StringUtils.equals(autologinParam.getNeedCredits(), "1")) {
Result<Long> customerPoints = jdApiUtil.getCustomerPoints(appByAppKey, pinByToken.getData(), accessToken.getAccessToken());
credits = String.valueOf(customerPoints.getData());
}
String autoLogin = autologin(duibaApp, uid, nickName, avatar, redirectUrl, env, credits);
LOGGER.info("autoLogin={}", autoLogin);
return ResultBuilder.success(autoLogin);
} catch (BizException e) {
return ResultBuilder.fail(e.getMessage());
} catch (Exception e) {
LOGGER.error("跳转异常", e);
return ResultBuilder.fail("跳转异常");
}
}
/**
* 生成免登url
*/
......
spring.application.name=jd-activity
spring.profiles.active=prod
#先排除一些autoconfigure
# 先排除一些autoconfigure
spring.autoconfigure.exclude=
# tomcat
server.port=8080
server.tomcat.accesslog.enabled=false
server.tomcat.uri-encoding=UTF-8
server.tomcat.threads.max=300
#服务器连接超时
# 服务器连接超时
server.tomcat.connection-timeout=8s
# logging
logging.file.path=${user.home}/logs/${spring.application.name}
......
<!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 () {
console.log(2)
openLoginPanel();
})()
function openLoginPanel() {
console.log("登录面板")
var isWechat = JSSDK.Client.isWeixin();
var isQQ = JSSDK.Client.isQQ();
if (isWechat || isQQ) {
var redirectUrlPrimary = window.location.href.replace('autologin2', 'autologin3') + '&source=02'
var url = 'https://wq.jd.com/pinbind/pintokenredirect?biz=jm-business-center&url=' + encodeURIComponent(redirectUrlPrimary)
window.location.href = url;
return;
}
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");
var needCredits = getUrlParam("needCredits");
$.ajax({
type: 'post',
url: `/open2Duiba/autologin`,
data: JSON.stringify({
token: token,
redirectUrl: redirect,
env: env,
shopId: shopId,
venderId: venderId,
appKey: appKey,
needCredits: needCredits
}),
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 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();
var token = getUrlParam("token");
autoLogin(token)
})()
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 source = getUrlParam("source");
var appKey = getUrlParam("appKey");
var needCredits = getUrlParam("needCredits");
$.ajax({
type: 'post',
url: `/open2Duiba/autologin2`,
data: JSON.stringify({
token: token,
redirectUrl: redirect,
source: source,
env: env,
shopId: shopId,
venderId: venderId,
appKey: appKey,
needCredits: needCredits
}),
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
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