|
|
@@ -15,172 +15,23 @@ import aiController from './aiController.js';
|
|
15
|
15
|
|
|
16
|
16
|
import PDFDocument from 'pdfkit';
|
|
17
|
17
|
import tencentcloud from 'tencentcloud-sdk-nodejs-ocr';
|
|
18
|
|
-
|
|
19
|
|
-const ONE_DAY_MAX_BUILD_COUNT=12;//一天最大生成数
|
|
20
|
|
-
|
|
21
|
18
|
const OcrClient = tencentcloud.ocr.v20181119.Client;
|
|
|
19
|
+const ONE_DAY_MAX_BUILD_COUNT=12;//一天最大生成数
|
|
22
|
20
|
|
|
23
|
|
-//小程序登录
|
|
24
|
|
-export async function YJBDCLogin(ctx) {
|
|
25
|
|
- let param = ctx.request.body;
|
|
26
|
|
- if (param.param) {
|
|
27
|
|
- const paramStr = Decrypt(param.param, config.urlSecrets.aes_key, config.urlSecrets.aes_iv);
|
|
28
|
|
- //console.log("paramStr:"+paramStr);
|
|
29
|
|
- param = JSON.parse(paramStr);
|
|
30
|
|
- }
|
|
31
|
|
- const code = param.Code;
|
|
32
|
|
- //console.log("code:"+code);
|
|
33
|
|
- const url = `https://api.weixin.qq.com/sns/jscode2session?appid=${config.wx.yjbdc_appid}&secret=${config.wx.yjbdc_appsecret}&js_code=${code}&grant_type=authorization_code`;
|
|
34
|
|
-
|
|
35
|
|
- let result = await axios.get(url)
|
|
36
|
|
- .then(res => {
|
|
37
|
|
- const json = res.data;
|
|
38
|
|
- //console.log("json:"+json);
|
|
39
|
|
- if (json && json.openid) {
|
|
40
|
|
- param.OpenID = json.openid;
|
|
41
|
|
- param.sessionKey = json.session_key;
|
|
42
|
|
- if (json.unionid)
|
|
43
|
|
- param.UnionID = json.unionid;
|
|
44
|
|
- return {errcode: 10000};
|
|
45
|
|
- }
|
|
46
|
|
- else {
|
|
47
|
|
- return json;
|
|
48
|
|
- }
|
|
49
|
|
- })
|
|
50
|
|
- .catch(err => {
|
|
51
|
|
- return {errcode: 101, errStr: err};
|
|
52
|
|
- });
|
|
53
|
|
-
|
|
54
|
|
- if (result.errcode == 10000) {
|
|
55
|
|
- delete param.Code;
|
|
56
|
|
- if (param.sessionKey && param.iv && param.encryptedData){
|
|
57
|
|
- //console.log("param.sessionKey:"+param.sessionKey);
|
|
58
|
|
- const pc = new WXBizDataCrypt(config.wx.yjbdc_appid, param.sessionKey);
|
|
59
|
|
- const dataUnionID = pc.decryptData(param.encryptedData , param.iv);
|
|
60
|
|
- //console.log(dataUnionID);
|
|
61
|
|
- param.UnionID = dataUnionID.unionId;
|
|
62
|
|
- }
|
|
63
|
|
-
|
|
64
|
|
- delete param.sessionKey;
|
|
65
|
|
- delete param.iv;
|
|
66
|
|
- delete param.encryptedData;
|
|
67
|
|
-
|
|
68
|
|
- //todo
|
|
69
|
|
- //param.OpenID="o4UHq4gaNlHfdTWxgl3fTgC1mFsI";
|
|
70
|
|
-
|
|
71
|
|
- let userList = await yjbdc.GetUsersInfo(param);
|
|
72
|
|
- if (userList.length > 0) {
|
|
73
|
|
- param.LastLoginTime = new Date();
|
|
74
|
|
- const time1 = moment(userList[0].ProductServiceTime).format('YYYY-MM-DD HH:mm:ss');
|
|
75
|
|
- const time3 = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
76
|
|
- if (time1 < time3)
|
|
77
|
|
- param.IsMember = 0;
|
|
78
|
|
-
|
|
79
|
|
- delete param.Introducer;
|
|
80
|
|
- delete param.UserSource;
|
|
81
|
|
- delete param.SourceID;
|
|
82
|
|
- //console.log(param.NickName);
|
|
83
|
|
- if (param.NickName == "陌生用户") {
|
|
84
|
|
- delete param.NickName;
|
|
85
|
|
- delete param.AvatarUrl;
|
|
86
|
|
- delete param.Language;
|
|
87
|
|
- delete param.Gender;
|
|
88
|
|
- delete param.City;
|
|
89
|
|
- delete param.Province;
|
|
90
|
|
- delete param.Country;
|
|
91
|
|
- }
|
|
92
|
|
-
|
|
93
|
|
- await yjbdc.UpdateUsers(param);
|
|
94
|
|
- userList = await yjbdc.GetUsersInfo(param);
|
|
95
|
|
- }
|
|
96
|
|
- else {
|
|
97
|
|
- param.NickName = "陌生用户";
|
|
98
|
|
- param.AvatarUrl = "../images/userface_default.png";
|
|
99
|
|
- param.CreateTime = new Date();
|
|
100
|
|
- param.LastLoginTime = param.CreateTime;
|
|
101
|
|
- param.ProductServiceTime = param.CreateTime;
|
|
102
|
|
- const inseredID = await yjbdc.AddUsers(param);
|
|
103
|
|
- userList = await yjbdc.GetUsersInfo(param);
|
|
104
|
|
- }
|
|
105
|
|
-
|
|
106
|
|
- delete userList[0].OpenID;
|
|
107
|
|
- delete userList[0].UnionID;
|
|
108
|
|
-
|
|
109
|
|
- //产品支付是否显示
|
|
110
|
|
- if (param.ProgramVersion) {
|
|
111
|
|
- let param2 = {
|
|
112
|
|
- ProgramID: 186,
|
|
113
|
|
- Version: param.ProgramVersion,
|
|
114
|
|
- };
|
|
115
|
|
- let result3 = await commonModel.GetProductVersionList(param2);
|
|
116
|
|
- if (result3) {
|
|
117
|
|
- if ((param2.Version == result3[0].Version && result3[0].IsShowPay <= 0)
|
|
118
|
|
- || param2.Version > result3[0].Version) {
|
|
119
|
|
- userList[0].IsShow = result3[0].IsShowPay;
|
|
120
|
|
- }
|
|
121
|
|
- else {
|
|
122
|
|
- userList[0].IsShow = 1;
|
|
123
|
|
- }
|
|
124
|
|
-
|
|
125
|
|
- //针对iphone测试用户,永远是无支付状态
|
|
126
|
|
- if (userList[0].Brand == 'iPhone' && userList[0].WXLanguage == 'en-US'
|
|
127
|
|
- && userList[0].UserSource == '1001' && userList[0].IsPay == 0) {
|
|
128
|
|
- userList[0].IsShow = 0;
|
|
129
|
|
- }
|
|
130
|
|
-
|
|
131
|
|
- //针对微信测试用户,永远是无支付状态
|
|
132
|
|
- if ((userList[0].UserSource=='1001' && userList[0].System=="iOS 10.0.1")
|
|
133
|
|
- || (!userList[0].UserSource && (!userList[0].LastUserSource || userList[0].LastUserSource>10000))
|
|
134
|
|
- || userList[0].NickName.indexOf("dgztest")>=0){
|
|
135
|
|
- userList[0].IsShow=-1;
|
|
136
|
|
- }
|
|
137
|
|
-
|
|
138
|
|
- if (userList[0].IsMember===1)
|
|
139
|
|
- userList[0].IsShow=1;
|
|
140
|
|
- }
|
|
141
|
|
- }
|
|
142
|
|
-
|
|
143
|
|
- result = {errcode: 10000, result: userList[0]};
|
|
144
|
|
- }
|
|
145
|
|
-
|
|
146
|
|
- ctx.body = result;
|
|
147
|
|
-}
|
|
148
|
|
-
|
|
149
|
|
-//OCR获取单词
|
|
150
|
|
-export async function OCRImageData(ctx) {
|
|
151
|
|
- const params = ctx.request.body;
|
|
152
|
|
-
|
|
153
|
|
- const clientConfig = {
|
|
154
|
|
- credential: {
|
|
155
|
|
- secretId: config.tencentcloud.secretId,
|
|
156
|
|
- secretKey: config.tencentcloud.secretKey,
|
|
157
|
|
- },
|
|
158
|
|
- region: "ap-guangzhou",
|
|
159
|
|
- profile: {
|
|
160
|
|
- httpProfile: {
|
|
161
|
|
- endpoint: "ocr.tencentcloudapi.com",
|
|
162
|
|
- },
|
|
163
|
|
- },
|
|
164
|
|
- };
|
|
165
|
|
-
|
|
166
|
|
- // 实例化要请求产品的client对象,clientProfile是可选的
|
|
167
|
|
- const client = new OcrClient(clientConfig);
|
|
168
|
|
- const result = await client.GeneralBasicOCR(params);
|
|
169
|
21
|
|
|
170
|
|
- let param2={};
|
|
171
|
|
- param2.UserID=ctx.query.UserID;
|
|
172
|
|
- param2.CreateTime=moment().format('YYYY-MM-DD HH:mm:ss');
|
|
173
|
|
- param2.Params=JSON.stringify(params);
|
|
174
|
|
- param2.JSONString=JSON.stringify(result);
|
|
175
|
|
- await yjbdc.AddOCRInfo(param2);
|
|
176
|
|
- ctx.body = {"errcode": 10000, result};
|
|
177
|
|
-}
|
|
178
|
22
|
|
|
179
|
23
|
//AI生成文章
|
|
180
|
24
|
export async function GenerateArticle(ctx) {
|
|
181
|
25
|
|
|
182
|
26
|
const url='GenerateArticle?UserID='+ctx.query.UserID;
|
|
183
|
27
|
let result = globalCache.get(url);
|
|
|
28
|
+
|
|
|
29
|
+ // 检查是否是队列状态而不是正在处理状态
|
|
|
30
|
+ if (result && result.isQueued) {
|
|
|
31
|
+ // 如果是队列状态,继续处理
|
|
|
32
|
+ result = 0;
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
184
|
35
|
if (result === 0) {
|
|
185
|
36
|
const params = ctx.request.body;
|
|
186
|
37
|
const words = params.Words;
|
|
|
@@ -361,6 +212,162 @@ export async function GenerateArticle(ctx) {
|
|
361
|
212
|
ctx.body = result;
|
|
362
|
213
|
}
|
|
363
|
214
|
|
|
|
215
|
+//小程序登录
|
|
|
216
|
+export async function YJBDCLogin(ctx) {
|
|
|
217
|
+ let param = ctx.request.body;
|
|
|
218
|
+ if (param.param) {
|
|
|
219
|
+ const paramStr = Decrypt(param.param, config.urlSecrets.aes_key, config.urlSecrets.aes_iv);
|
|
|
220
|
+ //console.log("paramStr:"+paramStr);
|
|
|
221
|
+ param = JSON.parse(paramStr);
|
|
|
222
|
+ }
|
|
|
223
|
+ const code = param.Code;
|
|
|
224
|
+ //console.log("code:"+code);
|
|
|
225
|
+ const url = `https://api.weixin.qq.com/sns/jscode2session?appid=${config.wx.yjbdc_appid}&secret=${config.wx.yjbdc_appsecret}&js_code=${code}&grant_type=authorization_code`;
|
|
|
226
|
+
|
|
|
227
|
+ let result = await axios.get(url)
|
|
|
228
|
+ .then(res => {
|
|
|
229
|
+ const json = res.data;
|
|
|
230
|
+ //console.log("json:"+json);
|
|
|
231
|
+ if (json && json.openid) {
|
|
|
232
|
+ param.OpenID = json.openid;
|
|
|
233
|
+ param.sessionKey = json.session_key;
|
|
|
234
|
+ if (json.unionid)
|
|
|
235
|
+ param.UnionID = json.unionid;
|
|
|
236
|
+ return {errcode: 10000};
|
|
|
237
|
+ }
|
|
|
238
|
+ else {
|
|
|
239
|
+ return json;
|
|
|
240
|
+ }
|
|
|
241
|
+ })
|
|
|
242
|
+ .catch(err => {
|
|
|
243
|
+ return {errcode: 101, errStr: err};
|
|
|
244
|
+ });
|
|
|
245
|
+
|
|
|
246
|
+ if (result.errcode == 10000) {
|
|
|
247
|
+ delete param.Code;
|
|
|
248
|
+ if (param.sessionKey && param.iv && param.encryptedData){
|
|
|
249
|
+ //console.log("param.sessionKey:"+param.sessionKey);
|
|
|
250
|
+ const pc = new WXBizDataCrypt(config.wx.yjbdc_appid, param.sessionKey);
|
|
|
251
|
+ const dataUnionID = pc.decryptData(param.encryptedData , param.iv);
|
|
|
252
|
+ //console.log(dataUnionID);
|
|
|
253
|
+ param.UnionID = dataUnionID.unionId;
|
|
|
254
|
+ }
|
|
|
255
|
+
|
|
|
256
|
+ delete param.sessionKey;
|
|
|
257
|
+ delete param.iv;
|
|
|
258
|
+ delete param.encryptedData;
|
|
|
259
|
+
|
|
|
260
|
+ //todo
|
|
|
261
|
+ //param.OpenID="o4UHq4gaNlHfdTWxgl3fTgC1mFsI";
|
|
|
262
|
+
|
|
|
263
|
+ let userList = await yjbdc.GetUsersInfo(param);
|
|
|
264
|
+ if (userList.length > 0) {
|
|
|
265
|
+ param.LastLoginTime = new Date();
|
|
|
266
|
+ const time1 = moment(userList[0].ProductServiceTime).format('YYYY-MM-DD HH:mm:ss');
|
|
|
267
|
+ const time3 = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
268
|
+ if (time1 < time3)
|
|
|
269
|
+ param.IsMember = 0;
|
|
|
270
|
+
|
|
|
271
|
+ delete param.Introducer;
|
|
|
272
|
+ delete param.UserSource;
|
|
|
273
|
+ delete param.SourceID;
|
|
|
274
|
+ //console.log(param.NickName);
|
|
|
275
|
+ if (param.NickName == "陌生用户") {
|
|
|
276
|
+ delete param.NickName;
|
|
|
277
|
+ delete param.AvatarUrl;
|
|
|
278
|
+ delete param.Language;
|
|
|
279
|
+ delete param.Gender;
|
|
|
280
|
+ delete param.City;
|
|
|
281
|
+ delete param.Province;
|
|
|
282
|
+ delete param.Country;
|
|
|
283
|
+ }
|
|
|
284
|
+
|
|
|
285
|
+ await yjbdc.UpdateUsers(param);
|
|
|
286
|
+ userList = await yjbdc.GetUsersInfo(param);
|
|
|
287
|
+ }
|
|
|
288
|
+ else {
|
|
|
289
|
+ param.NickName = "陌生用户";
|
|
|
290
|
+ param.AvatarUrl = "../images/userface_default.png";
|
|
|
291
|
+ param.CreateTime = new Date();
|
|
|
292
|
+ param.LastLoginTime = param.CreateTime;
|
|
|
293
|
+ param.ProductServiceTime = param.CreateTime;
|
|
|
294
|
+ const inseredID = await yjbdc.AddUsers(param);
|
|
|
295
|
+ userList = await yjbdc.GetUsersInfo(param);
|
|
|
296
|
+ }
|
|
|
297
|
+
|
|
|
298
|
+ delete userList[0].OpenID;
|
|
|
299
|
+ delete userList[0].UnionID;
|
|
|
300
|
+
|
|
|
301
|
+ //产品支付是否显示
|
|
|
302
|
+ if (param.ProgramVersion) {
|
|
|
303
|
+ let param2 = {
|
|
|
304
|
+ ProgramID: 186,
|
|
|
305
|
+ Version: param.ProgramVersion,
|
|
|
306
|
+ };
|
|
|
307
|
+ let result3 = await commonModel.GetProductVersionList(param2);
|
|
|
308
|
+ if (result3) {
|
|
|
309
|
+ if ((param2.Version == result3[0].Version && result3[0].IsShowPay <= 0)
|
|
|
310
|
+ || param2.Version > result3[0].Version) {
|
|
|
311
|
+ userList[0].IsShow = result3[0].IsShowPay;
|
|
|
312
|
+ }
|
|
|
313
|
+ else {
|
|
|
314
|
+ userList[0].IsShow = 1;
|
|
|
315
|
+ }
|
|
|
316
|
+
|
|
|
317
|
+ //针对iphone测试用户,永远是无支付状态
|
|
|
318
|
+ if (userList[0].Brand == 'iPhone' && userList[0].WXLanguage == 'en-US'
|
|
|
319
|
+ && userList[0].UserSource == '1001' && userList[0].IsPay == 0) {
|
|
|
320
|
+ userList[0].IsShow = 0;
|
|
|
321
|
+ }
|
|
|
322
|
+
|
|
|
323
|
+ //针对微信测试用户,永远是无支付状态
|
|
|
324
|
+ if ((userList[0].UserSource=='1001' && userList[0].System=="iOS 10.0.1")
|
|
|
325
|
+ || (!userList[0].UserSource && (!userList[0].LastUserSource || userList[0].LastUserSource>10000))
|
|
|
326
|
+ || userList[0].NickName.indexOf("dgztest")>=0){
|
|
|
327
|
+ userList[0].IsShow=-1;
|
|
|
328
|
+ }
|
|
|
329
|
+
|
|
|
330
|
+ if (userList[0].IsMember===1)
|
|
|
331
|
+ userList[0].IsShow=1;
|
|
|
332
|
+ }
|
|
|
333
|
+ }
|
|
|
334
|
+
|
|
|
335
|
+ result = {errcode: 10000, result: userList[0]};
|
|
|
336
|
+ }
|
|
|
337
|
+
|
|
|
338
|
+ ctx.body = result;
|
|
|
339
|
+}
|
|
|
340
|
+
|
|
|
341
|
+//OCR获取单词
|
|
|
342
|
+export async function OCRImageData(ctx) {
|
|
|
343
|
+ const params = ctx.request.body;
|
|
|
344
|
+
|
|
|
345
|
+ const clientConfig = {
|
|
|
346
|
+ credential: {
|
|
|
347
|
+ secretId: config.tencentcloud.secretId,
|
|
|
348
|
+ secretKey: config.tencentcloud.secretKey,
|
|
|
349
|
+ },
|
|
|
350
|
+ region: "ap-guangzhou",
|
|
|
351
|
+ profile: {
|
|
|
352
|
+ httpProfile: {
|
|
|
353
|
+ endpoint: "ocr.tencentcloudapi.com",
|
|
|
354
|
+ },
|
|
|
355
|
+ },
|
|
|
356
|
+ };
|
|
|
357
|
+
|
|
|
358
|
+ // 实例化要请求产品的client对象,clientProfile是可选的
|
|
|
359
|
+ const client = new OcrClient(clientConfig);
|
|
|
360
|
+ const result = await client.GeneralBasicOCR(params);
|
|
|
361
|
+
|
|
|
362
|
+ let param2={};
|
|
|
363
|
+ param2.UserID=ctx.query.UserID;
|
|
|
364
|
+ param2.CreateTime=moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
365
|
+ param2.Params=JSON.stringify(params);
|
|
|
366
|
+ param2.JSONString=JSON.stringify(result);
|
|
|
367
|
+ await yjbdc.AddOCRInfo(param2);
|
|
|
368
|
+ ctx.body = {"errcode": 10000, result};
|
|
|
369
|
+}
|
|
|
370
|
+
|
|
364
|
371
|
export async function GetYJBDCGenerateConfig(ctx) {
|
|
365
|
372
|
const param = {
|
|
366
|
373
|
UserID: ctx.query.UserID || 0,
|