2025-09-24 00:55:36 +08:00
|
|
|
|
import { injectApp, waitLogin, gatewayHttpClient } from '@jdmini/api'
|
|
|
|
|
|
App(injectApp()({
|
|
|
|
|
|
globalData: {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
async onLaunch() {
|
2025-12-15 18:46:47 +08:00
|
|
|
|
if (wx.canIUse('getUpdateManager')) {
|
|
|
|
|
|
const updateManager = wx.getUpdateManager();
|
|
|
|
|
|
updateManager.onCheckForUpdate(function (res) {
|
|
|
|
|
|
if (res.hasUpdate) {
|
|
|
|
|
|
updateManager.onUpdateReady(function () {
|
|
|
|
|
|
wx.showModal({
|
|
|
|
|
|
title: '更新提示',
|
|
|
|
|
|
content: '新版本已经准备好,是否重启应用?',
|
|
|
|
|
|
success(res) {
|
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
|
updateManager.applyUpdate();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-09-24 00:55:36 +08:00
|
|
|
|
// 等待登陆完成以后请求自动携带token
|
|
|
|
|
|
await waitLogin()
|
|
|
|
|
|
// 三方登录本地缓存
|
|
|
|
|
|
console.log(wx.getStorageSync('jdwx-userinfo'))
|
|
|
|
|
|
},
|
2025-12-15 18:46:47 +08:00
|
|
|
|
|
|
|
|
|
|
//内容安全
|
|
|
|
|
|
async checkdata(txt = '', checkType, mediaUrl = '') {
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (!checkType || (checkType !== 2 && checkType !== 3)) {
|
|
|
|
|
|
throw new Error('checkType必须为2(图片检测)或3(文本检测)')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (checkType === 3 && !txt) {
|
|
|
|
|
|
throw new Error('文本检测时content不能为空')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (checkType === 2 && !mediaUrl) {
|
|
|
|
|
|
throw new Error('图片检测时mediaUrl不能为空')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const postdata = {
|
|
|
|
|
|
content: txt,
|
|
|
|
|
|
checkType: checkType,
|
|
|
|
|
|
mediaUrl: mediaUrl
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const data = await gatewayHttpClient.request('/wx/v1/api/app/content/check', 'post', postdata)
|
|
|
|
|
|
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
|
|
|
if (checkType == 3) {
|
|
|
|
|
|
return data.data.suggest === 'pass' ? 1 : 2
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (checkType == 2) {
|
|
|
|
|
|
return data.data.id || null
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.error('内容检测API调用失败:', data)
|
|
|
|
|
|
return 2
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('checkdata函数执行错误:', error)
|
|
|
|
|
|
return 2
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// 轮询检查图片是否合规
|
|
|
|
|
|
//imgurl 为本地图片地址
|
|
|
|
|
|
async checkimage(imgurl){
|
|
|
|
|
|
wx.showLoading({
|
|
|
|
|
|
title: '正在检查图片...',
|
|
|
|
|
|
mask: true
|
|
|
|
|
|
});
|
|
|
|
|
|
try{
|
|
|
|
|
|
const upfileData = await gatewayHttpClient.uploadFile(imgurl, 'image');
|
|
|
|
|
|
const checkid = await this.checkdata('',2,upfileData.data.url)
|
|
|
|
|
|
let retryCount = 0;
|
|
|
|
|
|
const maxRetries = 5;
|
|
|
|
|
|
while (retryCount < maxRetries) {
|
|
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 1000)); // 间隔1秒
|
|
|
|
|
|
|
|
|
|
|
|
const passcode = await this.checkSafetyResults(checkid);
|
|
|
|
|
|
|
|
|
|
|
|
// 检查具体的错误码
|
|
|
|
|
|
switch (passcode) {
|
|
|
|
|
|
case 100:
|
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
return upfileData.data;
|
|
|
|
|
|
case 20001:
|
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
await gatewayHttpClient.deleteFile(upfileData.data.id);
|
|
|
|
|
|
this.showwarning('图片时政内容,请重新选择');
|
|
|
|
|
|
return null;
|
|
|
|
|
|
case 20002:
|
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
await gatewayHttpClient.deleteFile(upfileData.data.id);
|
|
|
|
|
|
this.showwarning('图片含有色情内容,请重新选择');
|
|
|
|
|
|
return null;
|
|
|
|
|
|
case 20006:
|
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
await gatewayHttpClient.deleteFile(upfileData.data.id);
|
|
|
|
|
|
this.showwarning('图片含有违法犯罪内容,请重新选择');
|
|
|
|
|
|
return null;
|
|
|
|
|
|
case 21000:
|
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
await gatewayHttpClient.deleteFile(upfileData.data.id);
|
|
|
|
|
|
this.showwarning('图片非法内容,请重新选择');
|
|
|
|
|
|
return null;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
retryCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 5次超时,返回失败
|
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
await gatewayHttpClient.deleteFile(upfileData.data.id)//删除图片
|
|
|
|
|
|
wx.showToast({
|
|
|
|
|
|
title: '图片检查超时,请重试',
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
});
|
|
|
|
|
|
return null;
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
console.error('图片检查失败:', error);
|
|
|
|
|
|
wx.showToast({
|
|
|
|
|
|
title: '检查失败,请重试',
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
});
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
showwarning(txt){
|
|
|
|
|
|
wx.showModal({
|
|
|
|
|
|
title: '提示',
|
|
|
|
|
|
content: txt,
|
|
|
|
|
|
showCancel: false,
|
|
|
|
|
|
success: () => {
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-09-24 00:55:36 +08:00
|
|
|
|
}))
|