Files
oil-client-wechat/README.md
2025-12-19 11:20:59 +08:00

231 lines
5.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// var devUrl = "http://192.168.0.166:8080"
var devUrl = "https://kyb.sxlyb.com";
// var devUrl = "http://192.168.0.194:8080";
// var kamo56Url = "http://101.201.181.3:8131";
const app = getApp()
function getCode(phone) {
var md4 = "appkeyandroid_ea031a3f-f130-43c4-8c95-6897d8a03697phone" + phone + "role1timestamp" + getTimestamp() +
"type3version2.0"
var md5 = require("../utils/md5.js");
var md5 = md5.hex_md5(md4).toUpperCase();
return md5;
}
function getTimestamp() {
var myDate = new Date();
var timestamp = formatTime(myDate.getTime(), "YMDHMS");
return timestamp;
}
function formatTime(value, type) {
var dataTime = "";
var data = new Date();
data.setTime(value);
var year = data.getFullYear();
var month = addZero(data.getMonth() + 1);
var day = addZero(data.getDate());
var hour = addZero(data.getHours());
var minute = addZero(data.getMinutes());
var second = addZero(data.getSeconds());
if (type == "YMD") {
dataTime = year + "-" + month + "-" + day;
} else if (type == "YMDHMS") {
dataTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
} else if (type == "MDHMS") {
dataTime = month + "-" + day + " " + hour + ":" + minute + ":" + second;
// dataTime =123;
} else if (type == "HMS") {
dataTime = hour + ":" + minute + ":" + second;
} else if (type == "YM") {
dataTime = year + "-" + month;
}
return dataTime; //灏嗘牸寮忓寲鍚庣殑瀛楃涓茶緭鍑哄埌鍓嶇鏄剧ず
};
function addZero(val) {
if (val < 10) {
return "0" + val;
} else {
return val;
}
};
function maskFlag(that) {
if (that.data.maskFlag == true) {
that.setData({
maskFlag: false,
})
} else {
that.setData({
maskFlag: true,
boxDetail: true,
payBox: true,
showNotice: true,
})
}
};
function weChat(that) {
// 登录
wx.login({
success: function (res) {
if (res.code) {
//发起网络请求
wx.request({
url: devUrl + '/api/v1/cooperation/openId',
data: {
code: res.code
},
success: function (res) {
if (res.data.code == 0) {
wx.setStorageSync('sessionKey', res.data.data.sessionKey);
if (res.data.data.state == 1) {
wx.setStorageSync('cooperation', res.data.data.cooperation);
wx.navigateTo({
url: '/pages/oilManage/oilManage',
})
} else if(res.data.data.state == 0) {
wx.setStorageSync('weChatId', res.data.data.weChatId);
// wx.navigateTo({
// url: '/pages/login-wx/login-wx?weChatId=' + res.data.data.weChatId,
// })
}
}
},
error: function (res) {
console.log(res.data)
},
fail: function (data) {
wx.showModal({
title: '提示',
content: '网络传输异常',
showCancel: false,
})
}
})
} else {
wx.redirectTo({
url: '../login/login',
})
}
},
fail: function () {
// wx.showModal({
// title: '警告通知',
// content: '您点击了拒绝授权,将无法正常显示个人信息,点击确定重新获取授权。',
// })
wx.navigateTo({
url: '../login/login'
})
}
});
};
function findId(that) {
wx.setStorageSync('name', "")
wx.setStorageSync('number', "")
// var that = this;
wx.request({
url: devUrl + '/api/v1/supply/detail/info',
data: {
phone: wx.getStorageSync("phone")
},
success: function(res) {
if (res.data.code == 0) {
wx.setStorageSync('id', res.data.data.id)
// wx.setStorageSync('payPassword', res.data.object.user.payPassword)
wx.setStorageSync('name', res.data.data.name)
if (res.data.data.vehicle) {
wx.setStorageSync('number', res.data.data.vehicle)
}
// var state = res.data.object.user.state;
// 1 "审核状态审核中"
// 2 "审核状态审核失败认证通过即可发货"
// 3 "审核状态已认证"
// 4 "审核状态未认证认证通过即可发货
// if (state == 1) {
// state = "审核中"
// } else if (state == 2) {
// state = "审核失败"
// } else if (state == 3) {
// state = "已认证"
// } else if (state == 4) {
// state = "未认证"
// }
// wx.setStorageSync('state', state)
}
},
error: function() {
wx.hideLoading()
console.log(res)
},
fail: function (data) {
wx.showModal({
title: '提示',
content: '网络传输异常',
showCancel: false,
})
}
})
}
function showMsg(msg){
wx.showModal({
title: '提示',
content: msg,
showCancel: false,
})
}
function ifNull(str){
if(str==null){
str=""
}
return str;
}
function ifNullMoney(str) {
if (str == null) {
str = ""
}else{
str = str+"元"
}
return str;
}
function renderTime(date) {
var dateee = new Date(date).toJSON();
return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '').replace(/-/g, "/")
}
module.exports = {
devUrl: devUrl,
formatTime: formatTime,
maskFlag: maskFlag,
weChat: weChat,
findId: findId,
showMsg: showMsg,
ifNull: ifNull,
ifNullMoney: ifNullMoney,
renderTime: renderTime
}