Commit 7cecbdee by 李嘉林

feat: jwt生成token

parent 0ef543c0
...@@ -2342,6 +2342,11 @@ ...@@ -2342,6 +2342,11 @@
"randomfill": "^1.0.3" "randomfill": "^1.0.3"
} }
}, },
"crypto-js": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz",
"integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q=="
},
"css": { "css": {
"version": "2.2.4", "version": "2.2.4",
"resolved": "https://registry.npmjs.org/css/-/css-2.2.4.tgz", "resolved": "https://registry.npmjs.org/css/-/css-2.2.4.tgz",
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
"build:my": "node build/build.js my" "build:my": "node build/build.js my"
}, },
"dependencies": { "dependencies": {
"crypto-js": "^4.2.0",
"hashids": "^2.2.8", "hashids": "^2.2.8",
"mayi-analytics": "^1.1.47", "mayi-analytics": "^1.1.47",
"mayi-front-tools": "^1.0.1", "mayi-front-tools": "^1.0.1",
......
...@@ -11,6 +11,26 @@ import cartApi from './api/cart' ...@@ -11,6 +11,26 @@ import cartApi from './api/cart'
import classificationApi from "./api/classification"; import classificationApi from "./api/classification";
import spokesmanApi from './api/spokesman' import spokesmanApi from './api/spokesman'
import { DFSImg, concatUrl, serialize } from "@/utils/index"; import { DFSImg, concatUrl, serialize } from "@/utils/index";
import CryptoJS from 'crypto-js';
const secretKey = 'efa1e9fd-d48c-413b-9e29-d91429373956'; // 秘钥
function base64UrlEncode(str) {
var encodedSource = CryptoJS.enc.Base64.stringify(str);
var reg = new RegExp('/', 'g');
encodedSource = encodedSource.replace(/=+$/,'').replace(/\+/g,'-').replace(reg,'_');
return encodedSource;
};
function generateToken(payload) {
let header = JSON.stringify({
"alg": "HS256",
"typ": "JWT"
})
let payloadStr =JSON.stringify(payload)
let before_sign = base64UrlEncode(CryptoJS.enc.Utf8.parse(header)) + '.' + base64UrlEncode(CryptoJS.enc.Utf8.parse(payloadStr));
let signature =CryptoJS.HmacSHA256(before_sign, secretKey);
signature = base64UrlEncode(signature);
let final_sign = before_sign + '.' + signature;
return final_sign;
};
//一些js工具类 //一些js工具类
import tool from "@/utils/tool"; import tool from "@/utils/tool";
var log = require('./utils/log') var log = require('./utils/log')
...@@ -104,6 +124,7 @@ mpApp.openSelectGoods = function () { } ...@@ -104,6 +124,7 @@ mpApp.openSelectGoods = function () { }
mpApp.openTwoBAddCart = function () { } mpApp.openTwoBAddCart = function () { }
// 动态设置首页背景图片 // 动态设置首页背景图片
mpApp.setHomeBgImg = function () {} mpApp.setHomeBgImg = function () {}
mpApp.generateToken = generateToken;
/** /**
* 组件点击行为收集 * 组件点击行为收集
......
...@@ -36,7 +36,7 @@ Component({ ...@@ -36,7 +36,7 @@ Component({
WaterfallFlowListL : [], WaterfallFlowListL : [],
WaterfallFlowListR : [] WaterfallFlowListR : []
}, },
ready(){ ready() {
if (this.data.datas.componentData.paddingList){ if (this.data.datas.componentData.paddingList){
this.setData({ this.setData({
getPaddingList: this.data.datas.componentData.paddingList getPaddingList: this.data.datas.componentData.paddingList
...@@ -48,7 +48,7 @@ Component({ ...@@ -48,7 +48,7 @@ Component({
let list = this.data.datas.componentData.imgList let list = this.data.datas.componentData.imgList
let WaterfallFlowListL = [] let WaterfallFlowListL = []
let WaterfallFlowListR = [] let WaterfallFlowListR = []
this.setData({ this.setData({
WaterfallFlowListL: [], WaterfallFlowListL: [],
WaterfallFlowListR: [] WaterfallFlowListR: []
...@@ -86,6 +86,17 @@ Component({ ...@@ -86,6 +86,17 @@ Component({
methods: { methods: {
itemClick(e){ itemClick(e){
let item = e.currentTarget.dataset.item let item = e.currentTarget.dataset.item
if (item && item.link.link.includes('/pages/wlForYourPerusal/index')) {
let loginUserInfo = wx.getStorageSync("loginUserInfo") || null;
if (loginUserInfo) {
const user = { phone: loginUserInfo.mobilephone, uid: `C${loginUserInfo.userId}`, timestamp: new Date().getTime() };
let token = app.generateToken(user);
console.log('token->', token);
item.link.link = `http://trip.wuliangye.com.cn:8000/app/?token=${token}`;
item.link.name = item.link.link;
}
}
console.log('itemClick->', e, item);
app.trackCpn(e, this.data.datas.componentName, item) app.trackCpn(e, this.data.datas.componentName, item)
app.$themeToLink(item.link) app.$themeToLink(item.link)
}, },
......
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