|
|
@@ -81,6 +81,62 @@ function parseCookies(cookieString) {
|
|
|
return dict;
|
|
|
}
|
|
|
|
|
|
+// 系列化为cookie字符串
|
|
|
+function serializeCookies(cookieData) {
|
|
|
+ const parts = [];
|
|
|
+ for(let key in cookieData){
|
|
|
+ let value = cookieData[key];
|
|
|
+ let cookiePart = `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
|
+ parts.push(cookiePart);
|
|
|
+ }
|
|
|
+ return parts.join('; ');
|
|
|
+}
|
|
|
+
|
|
|
+function parseSetCookies(cookieString) {
|
|
|
+ const attribKeys = ['Expires', 'Max-Age', 'Domain', 'Path', 'HttpOnly', 'SameSite'];
|
|
|
+ const parts = cookieString.split(';');
|
|
|
+ let mainKey = null;
|
|
|
+ const retDict = {};
|
|
|
+ const retData = [];
|
|
|
+ parts.forEach(part => {
|
|
|
+ let pstr = part.trim();
|
|
|
+ let aKey = null;
|
|
|
+ let aValue = true;
|
|
|
+
|
|
|
+ if (pstr.includes('=')) {
|
|
|
+ [aKey, aValue] = pstr.split('=').map(item => item.trim());
|
|
|
+ } else {
|
|
|
+ aKey = pstr;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (attribKeys.includes(aKey)) {
|
|
|
+ if (retDict[mainKey]) {
|
|
|
+ retDict[mainKey][aKey] = aValue;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let attribs = {};
|
|
|
+ if (pstr.includes(',')) {
|
|
|
+ const keys = pstr.split(',');
|
|
|
+
|
|
|
+ keys.forEach(key => {
|
|
|
+ const k = key.trim();
|
|
|
+ if (attribKeys.includes(k)) {
|
|
|
+ attribs[k] = true;
|
|
|
+ } else {
|
|
|
+ mainKey = k;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ mainKey = aKey;
|
|
|
+ }
|
|
|
+
|
|
|
+ retDict[mainKey] = { name: mainKey, value: aValue, attribs: attribs };
|
|
|
+ retData.push(retDict[mainKey]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return retData;
|
|
|
+}
|
|
|
+
|
|
|
function parseBase64(base64Str){
|
|
|
let CryptoJS = createCryptoJS();
|
|
|
let words = CryptoJS.enc.Base64.parse(base64Str);
|
|
|
@@ -126,10 +182,10 @@ function checkHandleRequest() {
|
|
|
if(!lk.isEmpty(headers.Cookie)){
|
|
|
gCookie = handleCookie(headers.Cookie);
|
|
|
}
|
|
|
- if(path.match(/\/h5\/union\/market\/indexConfigAll/)){
|
|
|
+ if(path.match(/\/h5\/union\/interactiveIGoChoose\/index/)){
|
|
|
+ handleIndexLogin();
|
|
|
+ } else if(path.match(/\/h5\/union\/market\/indexConfigAll/)){
|
|
|
handleIndexConfigAll();
|
|
|
- } else if(path.match(/\/h5\/union\/interactiveIGoChoose\/index/)){
|
|
|
-
|
|
|
} else if(path.match(/\/h5\/union\/api\/interactiveIGoChoose\/indexConfigRebuild/)){
|
|
|
// 获取商品列表-首单享好礼(活动1)
|
|
|
handleMarketGoodsList(1);
|
|
|
@@ -208,6 +264,31 @@ function updateMarketInfoByUrlParams(){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function handleIndexLogin(){
|
|
|
+ let urlParams = lk.parseQueryStr($request.url);
|
|
|
+ let loginParams = urlParams.loginParams;
|
|
|
+ let headers = $response.headers;
|
|
|
+ let newAuthorization = null;
|
|
|
+ if(headers['Set-Cookie']){
|
|
|
+ lk.log(headers['Set-Cookie']);
|
|
|
+ let cookieData = parseSetCookies(headers['Set-Cookie']);
|
|
|
+ for(let i=0; i < cookieData.length; i++){
|
|
|
+ let info = cookieData[i];
|
|
|
+ let name = info.name;
|
|
|
+ let value = info.value;
|
|
|
+ gCookie[name] = value;
|
|
|
+ if(name == 'unionToken_interactiveIGoChoose'){
|
|
|
+ newAuthorization = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(newAuthorization){
|
|
|
+ lk.log('刷新token');
|
|
|
+ let cookieStr = serializeCookies(gCookie);
|
|
|
+ lk.setVal(OfPayConstKey.cookie, cookieStr);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
function handleIndexConfigAll(){
|
|
|
updateMarketInfoByUrlParams();
|
|
|
}
|