|
|
@@ -5,8 +5,10 @@ import config from '../../config/index.js';
|
|
5
|
5
|
import _ from 'lodash';
|
|
6
|
6
|
import path from 'path';
|
|
7
|
7
|
import gm from 'gm';
|
|
|
8
|
+import axios from 'axios';
|
|
8
|
9
|
import COS from 'cos-nodejs-sdk-v5';
|
|
9
|
10
|
import { uploadSingle } from '../../middleware/upload.js';
|
|
|
11
|
+import { globalState } from '../../util/globalState.js';
|
|
10
|
12
|
|
|
11
|
13
|
const imageMagick = gm.subClass({ imageMagick: true });
|
|
12
|
14
|
|
|
|
@@ -191,4 +193,55 @@ async function uploadFile(filename, filepath) {
|
|
191
|
193
|
});
|
|
192
|
194
|
}
|
|
193
|
195
|
|
|
|
196
|
+export async function GetBaiduToken (ctx) {
|
|
|
197
|
+ const { Code, ProgramID } = ctx.query;
|
|
|
198
|
+
|
|
|
199
|
+ let appid = '', secret = '';
|
|
|
200
|
+
|
|
|
201
|
+ switch (ProgramID) {
|
|
|
202
|
+ case '99':
|
|
|
203
|
+ appid = config.wx.phonics_appid;
|
|
|
204
|
+ secret = config.wx.phonics_appsecret;
|
|
|
205
|
+ break;
|
|
|
206
|
+ case '166':
|
|
|
207
|
+ appid = config.wx.miaoguo_appid;
|
|
|
208
|
+ secret = config.wx.miaoguo_appsecret;
|
|
|
209
|
+ break;
|
|
|
210
|
+ case '105':
|
|
|
211
|
+ appid = config.wx.math_appid;
|
|
|
212
|
+ secret = config.wx.math_appsecret;
|
|
|
213
|
+ break;
|
|
|
214
|
+ case '164':
|
|
|
215
|
+ appid = config.wx.mathStar_appid;
|
|
|
216
|
+ secret = config.wx.mathStar_appsecret;
|
|
|
217
|
+ break;
|
|
|
218
|
+ }
|
|
|
219
|
+
|
|
|
220
|
+ const url = `https://api.weixin.qq.com/sns/jscode2session?appid=${appid}&secret=${secret}&js_code=${Code}&grant_type=authorization_code`;
|
|
|
221
|
+
|
|
|
222
|
+ const resultLogin = await axios.get(url)
|
|
|
223
|
+ .then(response => {
|
|
|
224
|
+ const json = response.data;
|
|
|
225
|
+ return json.openid ? { errcode: 10000 } : { errcode: 102 };
|
|
|
226
|
+ })
|
|
|
227
|
+ .catch(err => ({ errcode: 101, errStr: err }));
|
|
|
228
|
+
|
|
|
229
|
+ let result = 0;
|
|
|
230
|
+ if (resultLogin.errcode === 10000) {
|
|
|
231
|
+ result = globalState.getBufferMemory('BaiduToken');
|
|
|
232
|
+ if (result === 0) {
|
|
|
233
|
+ const baiduUrl = 'https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=9r1Idx1mgMONvElxU3KGE5Gi&client_secret=f4f606f1a5c0b4eaf800e1e046802d81';
|
|
|
234
|
+ result = await axios.get(baiduUrl)
|
|
|
235
|
+ .then(response => {
|
|
|
236
|
+ const json = response.data;
|
|
|
237
|
+ if (json.access_token) {
|
|
|
238
|
+ globalState.SetBufferMemory('BaiduToken', json.access_token, config.BufferMemoryTimeHigh);
|
|
|
239
|
+ return json.access_token;
|
|
|
240
|
+ }
|
|
|
241
|
+ return 0;
|
|
|
242
|
+ });
|
|
|
243
|
+ }
|
|
|
244
|
+ }
|
|
194
|
245
|
|
|
|
246
|
+ ctx.body = { errcode: 10000, result };
|
|
|
247
|
+}
|