no message
This commit is contained in:
63
unpackage/dist/dev/mp-alipay/utils/fun.js
vendored
Normal file
63
unpackage/dist/dev/mp-alipay/utils/fun.js
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../common/vendor.js");
|
||||
const api_api = require("../api/api.js");
|
||||
const lookImg = (e) => {
|
||||
common_vendor.index.previewImage({
|
||||
urls: e
|
||||
});
|
||||
};
|
||||
const call = (e) => common_vendor.index.makePhoneCall({
|
||||
phoneNumber: e
|
||||
});
|
||||
const copy = (e) => common_vendor.index.setClipboardData({
|
||||
data: e,
|
||||
success: function() {
|
||||
console.log("success");
|
||||
}
|
||||
});
|
||||
const urlQuery = (e) => {
|
||||
let search = e;
|
||||
search = search.split("?")[1];
|
||||
const pairs = search ? search.split("&") : [];
|
||||
const query = {};
|
||||
for (let i = 0; i < pairs.length; ++i) {
|
||||
const [key, value] = pairs[i].split("=");
|
||||
query[key] = query[key] || decodeURIComponent(value);
|
||||
}
|
||||
return query;
|
||||
};
|
||||
const uploadFiles = (urls) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let res = await api_api.getOssUploadParams();
|
||||
const fd = {
|
||||
policy: res.policy,
|
||||
OSSAccessKeyId: res.accessId,
|
||||
success_action_status: 200,
|
||||
signature: res.signature,
|
||||
key: res.dir + Date.now() + Math.floor(1e5 + Math.random() * 9e5) + "." + urls.substring(urls.lastIndexOf(".") + 1)
|
||||
};
|
||||
common_vendor.index.uploadFile({
|
||||
url: res.host,
|
||||
// Example, not a real endpoint
|
||||
filePath: urls,
|
||||
header: {
|
||||
"content-type": "multipart/form-data"
|
||||
},
|
||||
name: "file",
|
||||
formData: fd,
|
||||
success: (_res) => {
|
||||
resolve(fd.key);
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log(err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
console.log();
|
||||
});
|
||||
};
|
||||
exports.call = call;
|
||||
exports.copy = copy;
|
||||
exports.lookImg = lookImg;
|
||||
exports.uploadFiles = uploadFiles;
|
||||
exports.urlQuery = urlQuery;
|
||||
127
unpackage/dist/dev/mp-alipay/utils/sok.js
vendored
Normal file
127
unpackage/dist/dev/mp-alipay/utils/sok.js
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../common/vendor.js");
|
||||
const store_index = require("../store/index.js");
|
||||
const init = () => {
|
||||
console.log("sok-登录");
|
||||
var timeout = 1e4;
|
||||
var timeoutObj = null;
|
||||
var timeAnt = 0;
|
||||
setInterval(() => {
|
||||
timeAnt++;
|
||||
}, 1e3);
|
||||
openConnection();
|
||||
function checkOpenSocket() {
|
||||
common_vendor.index.sendSocketMessage({
|
||||
data: "ping",
|
||||
success: (res) => {
|
||||
timeAnt = 0;
|
||||
return;
|
||||
},
|
||||
fail: (err) => {
|
||||
openConnection();
|
||||
}
|
||||
});
|
||||
}
|
||||
function openConnection() {
|
||||
common_vendor.index.connectSocket({
|
||||
url: `wss://appapi.prod.zhongshuai2023.com/ws/deviceUpMessage?token=${common_vendor.index.getStorageSync("token")}`,
|
||||
success(res) {
|
||||
console.log("连接成功 connectSocket=", res);
|
||||
},
|
||||
fail(err) {
|
||||
console.log("连接失败 connectSocket=", err);
|
||||
}
|
||||
});
|
||||
common_vendor.index.onSocketOpen((res) => {
|
||||
checkOpenSocket();
|
||||
console.log("连接成功");
|
||||
});
|
||||
common_vendor.index.onSocketError((err) => {
|
||||
console.log("连接失败");
|
||||
});
|
||||
onSocketMessage();
|
||||
}
|
||||
function onSocketMessage() {
|
||||
timeout = 1e4;
|
||||
timeoutObj = null;
|
||||
common_vendor.index.onSocketMessage((res) => {
|
||||
timeAnt = 0;
|
||||
getSocketMsg(res.data);
|
||||
});
|
||||
}
|
||||
function getSocketMsg(data) {
|
||||
var obj;
|
||||
let pages = getCurrentPages();
|
||||
let currentPage = pages[pages.length - 1];
|
||||
let url = currentPage.route;
|
||||
if (data !== "pong") {
|
||||
store_index.store.commit("setSokStatus", 1);
|
||||
common_vendor.index.hideLoading();
|
||||
obj = JSON.parse(data);
|
||||
store_index.store.commit("setCommand", obj.command);
|
||||
store_index.store.commit("setDataObj", obj);
|
||||
if (obj.insertStatus || obj.insertStatus === 0) {
|
||||
store_index.store.commit("setInsertStatus", obj.insertStatus);
|
||||
}
|
||||
if (obj.command == "startResult" && obj.result == "-1") {
|
||||
common_vendor.index.showModal({
|
||||
title: "提示",
|
||||
content: "启动失败,请重试",
|
||||
showCancel: false,
|
||||
confirmText: "确认",
|
||||
success: () => {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (obj.command == "startResult" && obj.result == "-2") {
|
||||
common_vendor.index.showModal({
|
||||
title: "提示",
|
||||
content: "启动超时,请重试",
|
||||
showCancel: false,
|
||||
confirmText: "确认",
|
||||
success: () => {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (obj.command == "startResult" && obj.result == "01") {
|
||||
if (url != "pageOrder/recharge/recharge") {
|
||||
common_vendor.index.navigateTo({
|
||||
url: `/pageOrder/recharge/recharge?transactionNo=${obj.transactionNo}&type=order`
|
||||
});
|
||||
}
|
||||
}
|
||||
if (obj.command == "transactionResult") {
|
||||
if (url == "pageOrder/recharge/recharge") {
|
||||
common_vendor.index.navigateBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
timeAnt = 0;
|
||||
reset();
|
||||
}
|
||||
function reset() {
|
||||
clearInterval(timeoutObj);
|
||||
start();
|
||||
}
|
||||
function start() {
|
||||
timeoutObj = setInterval(function() {
|
||||
console.log(timeAnt);
|
||||
if (timeAnt > 10) {
|
||||
console.log("连接失败重新连接....");
|
||||
openConnection();
|
||||
return;
|
||||
}
|
||||
common_vendor.index.sendSocketMessage({
|
||||
data: "ping",
|
||||
success: (res) => {
|
||||
console.log(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("连接失败重新连接....");
|
||||
openConnection();
|
||||
}
|
||||
});
|
||||
}, timeout);
|
||||
}
|
||||
};
|
||||
exports.init = init;
|
||||
Reference in New Issue
Block a user