瀏覽代碼

优化代码

ms
zhoujie 2 年之前
父節點
當前提交
2aa2417f90
共有 5 個檔案被更改,包括 75 行新增63 行删除
  1. 35
    47
      pages/payment/payment.vue
  2. 9
    3
      pages/userInfoUploading/userInfoUploading.vue
  3. 10
    0
      utils/network/encryption.js
  4. 1
    2
      utils/network/request.js
  5. 20
    11
      utils/storage.ts

+ 35
- 47
pages/payment/payment.vue 查看文件

@@ -130,58 +130,46 @@
let {
jumpPage
} = config.value
setTimeout(() => {
uni.hideLoading()
contractTesting(qdOrderVal.value.qdOrderNo, jumpPage)
// uni.navigateTo({
// url: '/' + jumpPage,
// animationType: 'pop-in',
// animationDuration: 500
// })
}, 1000)
// setTimeout(() => {
// uni.hideLoading()
// contractTesting(qdOrderVal.value.qdOrderNo, jumpPage)
// uni.navigateTo({
// url: '/' + jumpPage,
// animationType: 'pop-in',
// animationDuration: 500
// })
// }, 1000)

// 根据公网ip获取支付地址
myJsonp({
url: 'https://www.taobao.com/help/getip.php',
success(res) {
console.log(res)
const data = {
fee: 1,
spbillCreateIp: res.ip,
}
OrdinaryRequest({
data,
}).then(res => {
if (res.code === 200) {
console.log(res.data)
// window.location.href = res.data.h5Url
window.open(res.data.h5Url, '_blank')
// 在当前窗口中打开一个新窗口
// const newWindow = window.open('', '_self'); // 给 URL 添加自定义请求头信息
// const url = res.data.h5Url;
// const headers = {
// 'Referer': 'www.aaa.com'
// };
// const params = new URLSearchParams(headers).toString();
// const urlWithHeader = `${url}?${params}`; // 设置新窗口的 URL
// newWindow.location.href = urlWithHeader;
// const h5Url = res.data.h5Url.substring(21)

// toWeixin(h5Url)
url: 'https://www.taobao.com/help/getip.php',
success(res) {
console.log(res)
const data = {
fee: 1,
spbillCreateIp: res.ip,
}
})
}
})


// const data = {
// fee: 1,
// spbillCreateIp: '',
// }
// OrdinaryRequest({
// data,
// })
OrdinaryRequest({
data,
}).then(res => {
if (res.code === 200) {
console.log(res.data)
// window.location.href = res.data.h5Url
window.open(res.data.h5Url, '_blank')
}
}).finally(() => {
uni.hideLoading()
})
// request('fdfbdddba6ec49f8b451cf2e299b4feb', {
// data,
// }).then((res) => {
// if (res.statusCode === 0) {
// console.log(res);

// }
})
}
})
}
// 签约检测
function contractTesting(qdOrderNo, jumpPage) {

+ 9
- 3
pages/userInfoUploading/userInfoUploading.vue 查看文件

@@ -30,8 +30,11 @@
import fromData from './fromData'
import ocrHandle from './ocrHandle'
import {
userInfoFormData
} from '@/utils/formDataHandle'
setToken,
} from '@/utils/storage'
// import {
// userInfoFormData
// } from '@/utils/formDataHandle'
let config = ref < any > ({
hasReturn: 'true',
submitName: '下一步',
@@ -201,7 +204,10 @@
data: params,
}).then((res) => {
if (res.statusCode === 0) {
return JSON.parse(res.bizContent).openId
let bizContent = JSON.parse(res.bizContent)
// 保存token
setToken(bizContent.accessToken)
return bizContent.openId
}
})
}

+ 10
- 0
utils/network/encryption.js 查看文件

@@ -17,6 +17,9 @@ import {
import {
sm3
} from '../util/SM3.js'
import {
getToken
} from '@/utils/storage'
const s4 = new SM4Util()

const _signCode = "etc123456"; //签名码
@@ -161,8 +164,10 @@ function textToBase64(text, key, iv) {

//调用中台参数
export function encryption(ifCode, subdata, type) {

let requestData = new Array();
requestData["ifCode"] = ifCode;
requestData["ifCode"] = ifCode;
// requestData["appId"] = "52030131"; // || "admin001"
requestData["appId"] = "admin001"; // || "admin001"

@@ -176,6 +181,7 @@ export function encryption(ifCode, subdata, type) {

if (import.meta.env.MODE === 'production') {
// 生产环境
let token = getToken()
requestData['signType'] = 'SM3';
let sm3Data = 'appId=' + requestData['appId'] +
'&bizContent=' + requestData['bizContent'] +
@@ -184,6 +190,10 @@ export function encryption(ifCode, subdata, type) {
'&timestamp=' + requestData['timestamp'] +
'&ifCode=' + ifCode +
'&reqId=' + requestData['reqId']
if (token) {
requestData['accessToken'] = token
sm3Data += `&accessToken=${token}`
}
requestData['sign'] = sm3(sm3Data, sm3Key);
} else {
requestData['signType'] = 'MD5';

+ 1
- 2
utils/network/request.js 查看文件

@@ -10,7 +10,7 @@ export function request(code, options = {}) {
// console.log('接口请求参数:', options)
//公参
const Common = {
loginSource: '69af303ba2eb4608a099163f0d2a5dbd',
// loginSource: '69af303ba2eb4608a099163f0d2a5dbd',
orderSource: 'H5'
}
//Url 地址
@@ -133,7 +133,6 @@ export function OrdinaryRequest(options = {}) {
xhr.open("POST", "/wxpay/apply");
xhr.send(data);
})

}
// jsonp请求-用于获取公网地址
export function myJsonp(options) {

+ 20
- 11
utils/storage.ts 查看文件

@@ -3,36 +3,45 @@
//*******************************************************//

export enum StorageKeys {
Token = "token", //登录token
OpenId = "openId", //openId
Key = "key"//字典key
Token = "token", //登录token
OpenId = "openId", //openId
Key = "key"//字典key
}

//存储
export const setItem = (key:string,data:any) =>{
if(typeof data === "object"){
export const setItem = (key : string, data : any) => {
if (typeof data === "object") {
data = JSON.stringify(data);
}
uni.setStorageSync(key,data);
uni.setStorageSync(key, data);
}


//获取
export const getItem = (key:string) =>{
export const getItem = (key : string) => {
const data = uni.getStorageSync(key);
try{
try {
return JSON.parse(data);
}catch(e){
} catch (e) {
return data;
}
}

//移除
export const removeItem = (key) => {
uni.removeStorageSync(key);
uni.removeStorageSync(key);
};

//清空存储
export const cleanStorage = () => {
uni.clearStorageSync();
uni.clearStorageSync();
};
// 获取token
let token = 'cacheToken'
export const getToken = () => {
return getItem(token)
}
// 设置token
export const setToken = (key : any) => {
return setItem(token, key)
}

Loading…
取消
儲存