Jelajahi Sumber

检测文本和图像改为从后台调用

htc 5 bulan lalu
induk
melakukan
7482b47001
1 mengubah file dengan 19 tambahan dan 35 penghapusan
  1. 19 35
      http/index.js

+ 19 - 35
http/index.js

@@ -310,25 +310,23 @@ function del(url, data, json = true, isAuth = true, isBuffer = false) {
 }
 
 //检测文本和图像
+import { BaseApi } from './baseApi.js'
 async function detectionContent(content,type=1){
-	let ACCESS_TOKEN = await getStableAccessToken();
-	if(!ACCESS_TOKEN) return;
-	
 	if(type==1){
 		return new Promise((resolve,reject)=>{
 			wx.request({
 				method: 'POST',
-				url:`https://api.weixin.qq.com/wxa/msg_sec_check?access_token=${ACCESS_TOKEN}`,
+				url:`${BaseApi}/api/app/wx/secCheckMsg`,
 				dataType:'json',
 				data:{content},
 				success:res=>{
-					let result = {code:0};
-					if(res.statusCode===200){
-						result.code = res.data.errcode;
-						if(res.data.errcode==87014) result.msg = '内容包含敏感违规信息';
-						else if(res.data.errcode==40001) result.msg = 'token无效';
-						else if(res.data.errcode==40003) result.msg = 'openid无效';
-						else if(res.data.errcode==61010) result.msg = '用户访问记录超时';
+					let result = {code:999,msg:'数据错误'};
+					if(res.data.code===0){
+						result.code = res.data.data.errcode;
+						if(res.data.data.errcode==87014) result.msg = '内容包含敏感违规信息';
+						else if(res.data.data.errcode==40001) result.msg = 'token无效';
+						else if(res.data.data.errcode==40003) result.msg = 'openid无效';
+						else if(res.data.data.errcode==61010) result.msg = '用户访问记录超时';
 						else{
 							result.code = 0;
 							result.msg = '内容正常';
@@ -344,8 +342,8 @@ async function detectionContent(content,type=1){
 	}else if(type==2){
 		return new Promise((resolve,reject)=>{
 			wx.uploadFile({
-				url: `https://api.weixin.qq.com/wxa/img_sec_check?access_token=${ACCESS_TOKEN}`,
 				method:'POST',
+				url:`${BaseApi}/api/app/wx/secCheckImg`,
 				filePath: content,
 				name: 'file',
 				header: {
@@ -356,13 +354,15 @@ async function detectionContent(content,type=1){
 				},
 				success: res => {
 					let data = JSON.parse(res.data);
-					let result = {code:0};
-					if(data){
-						result.code = data.errcode;
-						if(data.errcode==87014) result.msg = '图片含有敏感违规信息';
-						else if(data.errcode==40001) result.msg = 'token无效';
-						else if(data.errcode==40003) result.msg = 'openid无效';
-						else if(data.errcode==61010) result.msg = '用户访问记录超时';
+					let result = {code:999,msg:'数据错误'};
+					if(data&&data.code===0){
+						let resu = JSON.parse(data.data);
+						if(!resu) return;
+						result.code = resu.errcode;
+						if(resu.errcode==87014) result.msg = '图片含有敏感违规信息';
+						else if(resu.errcode==40001) result.msg = 'token无效';
+						else if(resu.errcode==40003) result.msg = 'openid无效';
+						else if(resu.errcode==61010) result.msg = '用户访问记录超时';
 						else{
 							result.code = 0;
 							result.msg = '内容正常';
@@ -377,22 +377,6 @@ async function detectionContent(content,type=1){
 		})
 	} 
 }
-//获取AccessToken
-function getStableAccessToken(){
-	return new Promise((resolve,reject)=>{
-		// let sat = uni.getStorageSync('satInfo')?JSON.parse(uni.getStorageSync('satInfo')):'';
-		// if(sat){
-		// 	let now = Date.parse(new Date());
-		// 	if(now<sat.time) return resolve(sat.stableAccessToken)
-		// }
-		get('/merchant/app/wx/getStableAccessToken').then(res=>{
-			if(res.data.code===0){
-				// uni.setStorageSync('satInfo',JSON.stringify({stableAccessToken:res.data.data.accessToken,time:res.data.data.expiresIn}));
-				resolve(res.data.data.accessToken)
-			}
-		})
-	})
-}
 
 export default {
 	postJson,