caipin 4 éve
szülő
commit
6eba7bdd21
1 módosított fájl, 83 hozzáadás és 0 törlés
  1. 83 0
      app/lib/jl.js

+ 83 - 0
app/lib/jl.js

@@ -0,0 +1,83 @@
+/*
+ * @description: 计量支付相关
+ * @Author: CP
+ * @Date: 2020-08-27 15:09:55
+ * @FilePath: \construction_management_backstage\app\lib\jl.js
+ */
+'use strict';
+
+// 加密类
+const crypto = require('crypto');
+class Jl {
+
+    /**
+     * 构造函数
+     *
+     * @param {Object} ctx - egg全局变量
+     * @return {void}
+     */
+    constructor(ctx) {
+        this.authUrl = 'http://cld.smartcost.com.cn/api/auth';
+        this.getDataUrl = 'http://cld.smartcost.com.cn/api/getData';
+        this.app = 'scConstruct';
+        this.token = 'sc@ConS!tru@ct*88';
+        this.ctx = ctx;
+    }
+
+    /**
+     * 获得计量支付项目管理员相关信息
+     * @param {*} code 
+     */
+    async getJlProjectAccountData(code) {
+        let result = {};
+        return result={
+            account:"caipin",
+            password:"JL Password",
+            is_admin:1,
+        }
+        try {
+            if (code === '' ) {
+                throw '项目编号错误';
+            }
+            // 生成加密token
+            //const [encryptToken, postTime] = this.generateCLDToken();
+            const postData = {
+                code,
+                //time: postTime,
+                //token: encryptToken,
+                app: this.app,
+            };
+
+            const responseData = await this.ctx.helper.sendRequest(this.getDataUrl, postData);
+            if (responseData.err !== 0) {
+                throw '接口返回错误:' + responseData.err;
+            }
+            result = responseData;
+        } catch (error) {
+            console.log('cld:' + error);
+            result = {};
+        }
+
+        return result;
+    }
+
+   
+
+    /**
+     * 生成CLD Token
+     *
+     * @return {Array} - 生成的token,当前生成的时间
+     */
+    generateCLDToken() {
+        let currentTime = new Date().getTime();
+        currentTime = parseFloat(currentTime / 1000).toFixed(0);
+
+        const encryptToken = crypto.createHmac('sha1', this.token).update(this.token + currentTime)
+            .digest().toString('base64');
+
+        return [encryptToken, currentTime];
+    }
+
+}
+
+module.exports = Jl;