|
|
@@ -205,30 +205,9 @@ async function uploadFile(filename, filepath) {
|
|
205
|
205
|
export async function GetBaiduToken (ctx) {
|
|
206
|
206
|
const { Code, ProgramID } = ctx.query;
|
|
207
|
207
|
|
|
208
|
|
- let appid = '', secret = '';
|
|
209
|
|
-
|
|
210
|
|
- switch (ProgramID) {
|
|
211
|
|
- case '99':
|
|
212
|
|
- appid = config.wx.phonics_appid;
|
|
213
|
|
- secret = config.wx.phonics_appsecret;
|
|
214
|
|
- break;
|
|
215
|
|
- case '166':
|
|
216
|
|
- appid = config.wx.miaoguo_appid;
|
|
217
|
|
- secret = config.wx.miaoguo_appsecret;
|
|
218
|
|
- break;
|
|
219
|
|
- case '105':
|
|
220
|
|
- appid = config.wx.math_appid;
|
|
221
|
|
- secret = config.wx.math_appsecret;
|
|
222
|
|
- break;
|
|
223
|
|
- case '106':
|
|
224
|
|
- appid = config.wx.hanzi_appid;
|
|
225
|
|
- secret = config.wx.hanzi_appsecret;
|
|
226
|
|
- break;
|
|
227
|
|
- case '164':
|
|
228
|
|
- appid = config.wx.mathStar_appid;
|
|
229
|
|
- secret = config.wx.mathStar_appsecret;
|
|
230
|
|
- break;
|
|
231
|
|
- }
|
|
|
208
|
+ let appidObj=getAppIDAndSecret(ProgramID);
|
|
|
209
|
+ let appid = appidObj.appid;
|
|
|
210
|
+ let secret = appidObj.secret;
|
|
232
|
211
|
|
|
233
|
212
|
const url = `https://api.weixin.qq.com/sns/jscode2session?appid=${appid}&secret=${secret}&js_code=${Code}&grant_type=authorization_code`;
|
|
234
|
213
|
|
|
|
@@ -257,4 +236,97 @@ export async function GetBaiduToken (ctx) {
|
|
257
|
236
|
}
|
|
258
|
237
|
|
|
259
|
238
|
ctx.body = { errcode: 10000, result };
|
|
|
239
|
+}
|
|
|
240
|
+
|
|
|
241
|
+
|
|
|
242
|
+// 内容审核(1.4.0及以后使用)
|
|
|
243
|
+export const MsgSecCheck2 = async (ctx) => {
|
|
|
244
|
+ const param = ctx.request.body;
|
|
|
245
|
+ param.Content = param.Content || "";
|
|
|
246
|
+ let appidObj=getAppIDAndSecret(param.ProgramID);
|
|
|
247
|
+ let appid = appidObj.appid;
|
|
|
248
|
+ let secret = appidObj.secret;
|
|
|
249
|
+
|
|
|
250
|
+ let result = {};
|
|
|
251
|
+ if (param.Content) {
|
|
|
252
|
+ const tokenUrl = `https://api.weixin.qq.com/cgi-bin/token?appid=${config.wx.miaoguo_appid}&secret=${config.wx.miaoguo_appsecret}&grant_type=client_credential`;
|
|
|
253
|
+
|
|
|
254
|
+ try {
|
|
|
255
|
+ // 获取访问令牌
|
|
|
256
|
+ const tokenResponse = await axios.get(tokenUrl);
|
|
|
257
|
+ const tokenData = tokenResponse.data;
|
|
|
258
|
+
|
|
|
259
|
+ if (!tokenData || !tokenData.access_token) {
|
|
|
260
|
+ return { errcode: 103, errMsg: "获取访问令牌失败" };
|
|
|
261
|
+ }
|
|
|
262
|
+
|
|
|
263
|
+ param.access_token = tokenData.access_token;
|
|
|
264
|
+
|
|
|
265
|
+ // 内容安全检查
|
|
|
266
|
+ const checkUrl = `https://api.weixin.qq.com/wxa/msg_sec_check?access_token=${param.access_token}`;
|
|
|
267
|
+ const postData = {
|
|
|
268
|
+ content: param.Content
|
|
|
269
|
+ };
|
|
|
270
|
+
|
|
|
271
|
+ const checkResponse = await axios.post(checkUrl, postData);
|
|
|
272
|
+ const parsedBody = checkResponse.data;
|
|
|
273
|
+
|
|
|
274
|
+ if (parsedBody.errcode === 87014) {
|
|
|
275
|
+ parsedBody.errmsg = "内容涉及敏感词";
|
|
|
276
|
+ } else if (parsedBody.errcode !== 0) {
|
|
|
277
|
+ parsedBody.errmsg = "内容审核未过";
|
|
|
278
|
+ }
|
|
|
279
|
+
|
|
|
280
|
+ result = { errcode: 10000, result: parsedBody };
|
|
|
281
|
+
|
|
|
282
|
+ } catch (err) {
|
|
|
283
|
+ console.error("内容审核错误:", err);
|
|
|
284
|
+ result = { errcode: 102, errStr: err.message || "请求失败" };
|
|
|
285
|
+ }
|
|
|
286
|
+ }
|
|
|
287
|
+
|
|
|
288
|
+ ctx.body = result;
|
|
|
289
|
+};
|
|
|
290
|
+
|
|
|
291
|
+function getAppIDAndSecret(ProgramID){
|
|
|
292
|
+ let appid = '', secret = '';
|
|
|
293
|
+ switch (ProgramID) {
|
|
|
294
|
+ case '99':
|
|
|
295
|
+ appid = config.wx.phonics_appid;
|
|
|
296
|
+ secret = config.wx.phonics_appsecret;
|
|
|
297
|
+ break;
|
|
|
298
|
+ case '166':
|
|
|
299
|
+ appid = config.wx.miaoguo_appid;
|
|
|
300
|
+ secret = config.wx.miaoguo_appsecret;
|
|
|
301
|
+ break;
|
|
|
302
|
+ case '105':
|
|
|
303
|
+ appid = config.wx.math_appid;
|
|
|
304
|
+ secret = config.wx.math_appsecret;
|
|
|
305
|
+ break;
|
|
|
306
|
+ case '106':
|
|
|
307
|
+ appid = config.wx.hanzi_appid;
|
|
|
308
|
+ secret = config.wx.hanzi_appsecret;
|
|
|
309
|
+ break;
|
|
|
310
|
+ case '164':
|
|
|
311
|
+ appid = config.wx.mathStar_appid;
|
|
|
312
|
+ secret = config.wx.mathStar_appsecret;
|
|
|
313
|
+ break;
|
|
|
314
|
+ case '173':
|
|
|
315
|
+ appid = config.wx.mps_appid;
|
|
|
316
|
+ secret = config.wx.mps_appsecret;
|
|
|
317
|
+ break;
|
|
|
318
|
+ case '186':
|
|
|
319
|
+ appid = config.wx.yjbdc_appid;
|
|
|
320
|
+ secret = config.wx.yjbdc_appsecret;
|
|
|
321
|
+ break;
|
|
|
322
|
+ default:
|
|
|
323
|
+ appid = config.wx.miaoguo_appid;
|
|
|
324
|
+ secret = config.wx.miaoguo_appsecret;
|
|
|
325
|
+ break;
|
|
|
326
|
+ }
|
|
|
327
|
+ let result={
|
|
|
328
|
+ appid:appid,
|
|
|
329
|
+ secret:secret,
|
|
|
330
|
+ }
|
|
|
331
|
+ return result;
|
|
260
|
332
|
}
|