06dcfb0b by simon

1、修改请求方式 (请求头加入env和moduleCode)

2、新增配置
1 parent 64abdf01
NODE_ENV = 'development'
VUE_APP_TITLE = 'development'
VUE_APP_PUBLIC_PATH = './'
VUE_APP_OUTPUT_DIR = 'dist'
\ No newline at end of file
VUE_APP_OUTPUT_DIR = 'dist'
VUE_APP_ENV = 'demo'
VUE_APP_MODULE_CODE = '6f9f27c42878499a965c94bc8f203b23'
VUE_APP_BASE_API = 'https://bizapi.kdao.xin'
VUE_APP_RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi7pNPRSc+87WEJxYnlMOzoDHBgMTmkQyVSMdYRi4tqcnqTibTqEB6xbL5S2w8kjq5ItMKjNcrFvdlh/oj+Qb2LtrHE/O6EOGQf58qH3kZmIhZ32tejJ57c67cXhqbaswUU8WhN4LkhdINrNcpKvnWBd6v2nmEUrmgvi/aL6DIG+OgUyFys0l5BQOeGqzEEYXQgR9ppwDl/QadKpIBgm87qPnhzR++EPKzScgqgqT8D8uw2A96Mj02HXS1n74eCViW+M04UiQ0p0Rq9RMs5EtVJMo2CuArHaPsvsjkUTVdsSROoRTvBzq+T1WmCZJzDvITPZ0hbpD5pTeaXHm7qItQIDAQAB'
VUE_APP_AES_IV = 'c5014a8dc3a341ac'
VUE_APP_TOKEN_KEY = 'kd_template_token'
VUE_APP_IS_POST_ENC = true
......
NODE_ENV = 'production'
VUE_APP_TITLE = 'production'
VUE_APP_PUBLIC_PATH = './'
VUE_APP_OUTPUT_DIR = 'dist'
\ No newline at end of file
VUE_APP_OUTPUT_DIR = 'dist'
VUE_APP_ENV = 'demo'
VUE_APP_MODULE_CODE = '6f9f27c42878499a965c94bc8f203b23'
VUE_APP_BASE_API = 'https://bizapi.kdao.xin'
VUE_APP_RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi7pNPRSc+87WEJxYnlMOzoDHBgMTmkQyVSMdYRi4tqcnqTibTqEB6xbL5S2w8kjq5ItMKjNcrFvdlh/oj+Qb2LtrHE/O6EOGQf58qH3kZmIhZ32tejJ57c67cXhqbaswUU8WhN4LkhdINrNcpKvnWBd6v2nmEUrmgvi/aL6DIG+OgUyFys0l5BQOeGqzEEYXQgR9ppwDl/QadKpIBgm87qPnhzR++EPKzScgqgqT8D8uw2A96Mj02HXS1n74eCViW+M04UiQ0p0Rq9RMs5EtVJMo2CuArHaPsvsjkUTVdsSROoRTvBzq+T1WmCZJzDvITPZ0hbpD5pTeaXHm7qItQIDAQAB'
VUE_APP_AES_IV = 'c5014a8dc3a341ac'
VUE_APP_TOKEN_KEY = 'kd_template_token'
VUE_APP_IS_POST_ENC = true
\ No newline at end of file
......
......@@ -2,3 +2,12 @@ NODE_ENV = 'production'
VUE_APP_TITLE = 'sandbox'
VUE_APP_PUBLIC_PATH = './'
VUE_APP_OUTPUT_DIR = 'sandbox'
VUE_APP_ENV = 'demo'
VUE_APP_MODULE_CODE = '6f9f27c42878499a965c94bc8f203b23'
VUE_APP_BASE_API = 'https://bizapi.kdao.xin'
VUE_APP_RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi7pNPRSc+87WEJxYnlMOzoDHBgMTmkQyVSMdYRi4tqcnqTibTqEB6xbL5S2w8kjq5ItMKjNcrFvdlh/oj+Qb2LtrHE/O6EOGQf58qH3kZmIhZ32tejJ57c67cXhqbaswUU8WhN4LkhdINrNcpKvnWBd6v2nmEUrmgvi/aL6DIG+OgUyFys0l5BQOeGqzEEYXQgR9ppwDl/QadKpIBgm87qPnhzR++EPKzScgqgqT8D8uw2A96Mj02HXS1n74eCViW+M04UiQ0p0Rq9RMs5EtVJMo2CuArHaPsvsjkUTVdsSROoRTvBzq+T1WmCZJzDvITPZ0hbpD5pTeaXHm7qItQIDAQAB'
VUE_APP_AES_IV = 'c5014a8dc3a341ac'
VUE_APP_TOKEN_KEY = 'kd_template_token'
VUE_APP_IS_POST_ENC = true
......
......@@ -7,7 +7,7 @@ npm install
### Compiles and hot-reloads for development
```
npm run serve
npm run dev
```
### Compiles and minifies for production
......@@ -25,5 +25,22 @@ npm run test
npm run lint
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
# 配置
## 环境配置
配置说明:
本地环境: .env.development
沙箱环境: .env.sandbox
正式环境: .env.development
## 配置项说明
```bash
# 接口环境
VUE_APP_ENV = 'demo' # 请求头环境参数:demo/prod,即开发/生产。不填写默认连接prod。
VUE_APP_MODULE_CODE = '' # 请求头module code,由后端提供。
VUE_APP_BASE_API = '' # api请求域名
VUE_APP_RSA_PUBLIC_KEY = '' # 加密公钥
VUE_APP_AES_IV = '' # 加密偏移量
VUE_APP_TOKEN_KEY = 'kd_template_token' # 埋cookies时,token以该值为key
VUE_APP_IS_POST_ENC = true # 该值为true所有post接口请求加密;为false不加密,但可配置opt.enc=true自定义接口加密
```
\ No newline at end of file
......
......@@ -17,15 +17,16 @@ import {
import api from '@/api/api';
// axios的默认url
// axios.defaults.baseURL = ""
let base = process.env.VUE_APP_BASE_API;
const ENV = process.env.VUE_APP_ENV;
const MODULE_CODE = process.env.VUE_APP_MODULE_CODE;
const IS_POST_ENC = process.env.VUE_APP_IS_POST_ENC;
// 默认超时
axios.defaults.timeout = 5000;
// 服务器地址
// let base = process.env.VUE_APP_API_HOST + "/jxMallApi";
let base = "https://ow.go.qudone.com";
if (location.href.indexOf("//k.wxpai.cn") > 0) {
base = "https://api.k.wxpai.cn/bizproxy"
}
// 请求拦截器
// axios.interceptors.request.use(
......@@ -98,28 +99,31 @@ axios.interceptors.response.use(
);
//formDataHeaders设置
let formDataHeaders = {
headers: {
"Content-Type": "multipart/form-data"
}
}
/**
* 封装get方法
* @param {*} params
*
* 分解参数&拦截请求
*/
export const httpGet = params => {
function analysisParams(params) {
let {
url,
data,
mode,
opt = Object.assign({}, params.opt),
sid = true
sid = true,
config,
method
} = params;
if (opt.enc) {
data = makeEncrypt(data);
if (IS_POST_ENC == 'true') {
if (method == 'post') {
data = makeEncrypt(data);
}
} else {
if (opt.enc) {
data = makeEncrypt(data);
}
}
if (opt.dec) {
data = makerypt(data);
}
let reqUrl = `${base}${url}`;
if (mode == "custom") {
......@@ -128,7 +132,32 @@ export const httpGet = params => {
let headers = {}
if (sid) {
headers.sessionId = getToken();
headers['-kd-platform-module'] = MODULE_CODE
headers['-kd-platform-env'] = ENV
}
return {
reqUrl,
data,
headers,
opt,
method,
config
}
}
/**
* 封装get方法
* @param {*} params
*/
export const httpGet = params => {
params.method = 'get';
let {
reqUrl,
data,
headers,
opt,
method
} = analysisParams(params);
return axios.get(reqUrl, {
params: data,
headers,
......@@ -138,27 +167,18 @@ export const httpGet = params => {
/**
* 封装post方法
* mode为custom时,忽略baseUrl
* @param {*} params
*/
export const httpPost = params => {
params.method = 'post';
let {
url,
reqUrl,
data,
mode,
opt = Object.assign({}, params.opt),
sid = true
} = params;
if (opt.enc) {
data = makeEncrypt(data);
}
let reqUrl = `${base}${url}`;
if (mode == "custom") {
reqUrl = `${url}`
}
let headers = {}
if (sid) {
headers.sessionId = getToken();
}
headers,
opt,
method
} = analysisParams(params);
return axios.post(reqUrl, data, {
headers,
opt
......@@ -186,7 +206,11 @@ export const formdata = params => {
for (let key in data) {
formData.append(key, data[key]);
}
return axios.post(`${base}${url}`, formData, formDataHeaders).then(res => res.data.content);
return axios.post(`${base}${url}`, formData, {
headers: {
"Content-Type": "multipart/form-data"
}
}).then(res => res.data.content);
}
......
import Cookies from 'js-cookie'
const TokenKey = 'temp-app-token'
const TokenKey = process.env.VUE_APP_TOKEN_KEY; // TokenKey 自行配置
export function getToken() {
return Cookies.get(TokenKey)
......
......@@ -11,8 +11,8 @@ let rsa = new JsEncrypt();
* iv 偏移量
*/
export function makeEncrypt(param) {
let key = "";
let iv = ""
let key = process.env.VUE_APP_RSA_PUBLIC_KEY; // process.env.AES_KEY
let iv = process.env.VUE_APP_AES_IV; // process.env.AES_IV
rsa.setPublicKey(key);
let chars = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z".split(",");
......