Edit D:\xinhaisoft\crisis_new\api\controllers\uic.js
/** * ?????????-?????????????????? * ?????????????????????????????????????? */ const util = require('../utils') const db = require('../data') const dayjs = require('dayjs') const axios = require('axios') const cache = new (require('node-cache'))() const EnDeNum = require('../utils/encrypt-decrypt-number') const Token = require('../token') let [sql, rs] = ['', null] const appId = 100032 const appSecret = 'c414a54b-766e-4274-88e7-b4bab3738cd9' const Key = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9ol3laUK7u9C8j2w1I1FX7rm3zSMkpeZi2fqBNwj1gDAxNOPoMAB6vJRDsCfzvAVJBNX6QHru5elC577VVMb7tRrUlsL2VLNG2HdcSx62OLtdr5bfIBmwXmSIEyr6W2zcSFCFENbcvuwLloE/iaML17gV1gAMIgQivJiHRwastwIDAQAB' axios.defaults.baseURL = 'http://dgv2.uic.edu.cn:8080' axios.defaults.timeout = 30000 axios.defaults.decompress = false /** * Token???????????? */ const GetToken = async () => { const token = cache.get('uic-token') if (token) { return token } else { return await axios.post('/api/token/get', { appId, appSecret }).then(res => { const json = res.data if (json.success) { const token = json.item.token cache.set('uic-token', token, json.item.expires - 60) return token } }) } } /** * ??????????????D????????? */ const GetType = async (yx, zy) => { let type = 0 const parent = await db.select(`select top 1 id,path from member_type where name='${yx}' and parid=1`) if (parent) { const child = await db.select(`select top 1 id from member_type where name='${zy}' and parid=${parent.id}`) if (child) { type = child.id } else { type = await db.newid('member_type') sql = 'insert into member_type(id,parid,path,topid,name,sort) values(' + type + ',' + parent.id + `,'${parent.path + ',' + type}'` + ',1' + `,'${zy}'` + ',' + type + ')' db.execute(sql) } } else { const maxid = await db.scalar('select top 1 id from member_type order by id desc') const yxid = maxid + 1 const zyid = maxid + 2 sql = 'insert into member_type(id,parid,path,topid,name,sort) values(' + yxid + ',1' + `,'${'0,2,1,' + yxid}'` + ',1' + `,'${yx}'` + ',' + yxid + ');' + 'insert into member_type(id,parid,path,topid,name,sort) values(' + zyid + ',' + yxid + `,'${'0,2,1,' + yxid + ',' + zyid}'` + ',1' + `,'${zy}'` + ',' + zyid + ')' db.execute(sql) type = zyid } return type } /** * ??????ID????????? */ const GetGrade = async nj => { let grade = 0 rs = await db.select(`select top 1 id from member_grade where name='${nj}'`) if (rs) { grade = rs.id } else { grade = await db.newid('member_grade') sql = 'insert into member_grade(id,name,sort,membertype) values(' + grade + `,'${nj}'` + ',' + grade + ',1' + ')' db.execute(sql) } return grade } /** * ??????????????? * post: /uic/user-transfer */ exports.UserTransfer = async ctx => { const Member = require('./member') const body = ctx.request.body let number = body.number let secret = body.secret let timestamp = body.timestamp if (number && /^[a-f0-9]{32}$/.test(secret) && /^1\d{12}$/.test(timestamp)) { number = Buffer.from(number, 'base64').toString('utf-8') if (Date.now() - 60 * 1000 > Number(timestamp)) { throw { code: 2, message: '????????' } } if (util.MD5(number + '{' + Key + '}{' + timestamp + '}') !== secret) { throw { code: 3, message: '?????????' } } // ?????? let id let password const fields = 'id,number,realname,sex,birthday,age,password,mobile,email,qq,type,balance,face,bind_consultant_id,zx_times,[right],isSchoolAdmin,isconsultant,weixin_openid,member_type_path,member_type_top,address,[group]' rs = await db.select(`select top 1 ${fields} from v_member where number='${number}'`) if (rs) { // ??? db.execute(`update member set lasttime=getdate(),lastip='${util.GuestIP(ctx)}',logtimes=logtimes+1 where id=${id}`) id = rs.id password = rs.password const data = Object.assign(rs, { token: Token.Sign({ id }), cookie: Member.MemberCookie(id, password), key: EnDeNum.encrypt(id) }) ctx.body = { code: 0, data } } else { // ????? const token = await GetToken() await axios.post('/api/uc/student/get', { number }, { params: { accessToken: token } }).then(async res => { const json = res.data if (json.success) { const item = json.item const type = await GetType(item.division, item.programme) const grade = await GetGrade(item.ucUserType.name + '-' + item.cohort) const birthday = dayjs(Number(item.birthday)).format('YYYY-MM-DD') id = await db.newid('member', 10001) password = util.MD5(number.slice(-6)) sql = 'insert into member(id,number,password,realname,type,grade,[state],[group],sex,birthday,isstudent,mobile,email) values(' + id + `,'${number}'` + `,'${password}'` + `,'${item.userName.cn}'` + ',' + type + ',' + grade + ',5' + ',1' + ',' + (item.gender === 'MALE' ? 1 : 0) + `,'${birthday}'` + ',1' + `,'${item.mobile}'` + `,'${item.email}'` + ')' await db.execute(sql) // ????????? rs = await db.select('select top 1 * from v_member with (nolock) where id=' + id) if (rs) { const data = Object.assign(rs, { token: Token.Sign({ id }), cookie: Member.MemberCookie(id, password), key: EnDeNum.encrypt(id) }) ctx.body = { code: 0, data } } else { throw { code: 2, message: '??????????????' } } } else { ctx.body = { code: 1, message: json.msg } } }) } } else { throw { code: -2 } } } /** * ?????? * get: /uic/user-notify */ exports.UserNotify = async ctx => { const type = ctx.query.type if (type === 'student') { if (ctx.query.token === util.MD5(ctx.query.time + String(appId) + appSecret).toUpperCase()) { // const number = ctx.query.number ctx.body = { success: true } } else { ctx.body = { code: 1, success: false, message: 'Token??????' } } } else { ctx.body = { success: true } } } /** * ???????????????????? * post: /uic/import */ exports.Import = async ctx => { const grade = ctx.query.grade if (grade) { // const token = await GetToken() await axios('/api/uc/student/list', { params: { cohort: grade, pageNo: 0, pageSize: 50 } }).then(async res => { const json = res.data const list = json.result.data if (list.length) { let i = 0 for (i = 0; i < list.length; i++) { const row = list[i] rs = await db.select(`select top 1 id from member where number='${row.uid}'`) if (rs) { sql = 'update member set' + ` mobile='${row.mobile}'` + `,email='${row.email}'` + ',sex=' + (row.gender === 'MALE' ? 1 : 0) + ' where id=' + rs.id db.execute(sql) } } } }) } else { throw { code: -2 } } } /** * ?????????????????? * get: /uic/user-transfer-link */ exports.UserTransferLink = ctx => { const number = ctx.query.number const number_encrypt = Buffer.from(number).toString('base64') const timestamp = Date.now() const data = 'http://113.31.18.30:8090/school/sso/uic.htm' + '?number=' + number_encrypt + '&secret=' + util.MD5(number + '{' + Key + '}{' + timestamp + '}') + '×tamp=' + timestamp ctx.body = { code: 0, data } }
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de