Commit 7cecbdee by 李嘉林

feat: jwt生成token

parent 0ef543c0
......@@ -2342,6 +2342,11 @@
"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": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/css/-/css-2.2.4.tgz",
......
......@@ -27,6 +27,7 @@
"build:my": "node build/build.js my"
},
"dependencies": {
"crypto-js": "^4.2.0",
"hashids": "^2.2.8",
"mayi-analytics": "^1.1.47",
"mayi-front-tools": "^1.0.1",
......
......@@ -11,6 +11,26 @@ import cartApi from './api/cart'
import classificationApi from "./api/classification";
import spokesmanApi from './api/spokesman'
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工具类
import tool from "@/utils/tool";
var log = require('./utils/log')
......@@ -104,6 +124,7 @@ mpApp.openSelectGoods = function () { }
mpApp.openTwoBAddCart = function () { }
// 动态设置首页背景图片
mpApp.setHomeBgImg = function () {}
mpApp.generateToken = generateToken;
/**
* 组件点击行为收集
......
......@@ -36,7 +36,7 @@ Component({
WaterfallFlowListL : [],
WaterfallFlowListR : []
},
ready(){
ready() {
if (this.data.datas.componentData.paddingList){
this.setData({
getPaddingList: this.data.datas.componentData.paddingList
......@@ -86,6 +86,17 @@ Component({
methods: {
itemClick(e){
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.$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