当前位置:网站首页>Using baijiafan to automatically generate API calls: progress in JS (II)
Using baijiafan to automatically generate API calls: progress in JS (II)
2022-06-26 10:50:00 【InfoQ】
Generate logic description
Entry script
const axios = require("axios");
const config = require("./config.js");
const instance = axios.create(config);
const sso_servlet_organduser = require("./api-sso_servlet_organduser.js");
sso_servlet_organduser.injure(instance);
module.exports = instance;
const axios = require("./axios");
axios.getSsoServletOrganduser().then(res=>{
console.log(res);
}).catch(err=>{
console.log(err);
})
Global configuration script
module.exports = {
// Certification services
baseURL: 'https://puser.zjzwfw.gov.cn/',
// Open the next line , Modify request timeout , The current example is 10s
// timeout: 10 * 1000
}
Interface script
const { verify, timestr,md5 } = require("./functions.js");
const injure = (instance)=>{
var config = {params:{}};
// route :sso/servlet/organduser, Calling method GET
//params The following attributes are required to be transferred , There is no sign ' Have default values ' The arguments to are passed by the caller
//-method( Have default values ): Calling method
//-servicecode: The access resources are SSO Business code after successful registration , from 【SSO Administrators 】 Provide .
//-time( Have default values ): Time stamp , current time Mm / DD / yyyy HHM / S example :2009 year 10 month 10 Japan 12 when 12 branch 12 The second format is 20091010121212
//-sign( Have default values ):MD5(servicecode+servicepwd+time), Put the business code 、 Business key 、 The sending time is connected in sequence and md5 encryption . notes :1、 Parameters servicepwd from 【SSO Administrators 】 Provide ;2、MD5 The algorithm is the standard algorithm , You can use java Internal implementation ;3、MD5 The value after is 32 Bit and lowercase .
//-userid: The user is in SSO Unique identification of
//-datatype( Have default values ): data format xml json. Default xml
//-servicepwd: Assigned password , Be careful , This parameter is only used for sign Calculation
instance.getSsoServletOrganduser = (params = {}) => {
var verify_err = null ||
verify(params.servicecode,"servicecode",{"required":true}) ||
verify(params.userid,"userid",{"required":true}) ||
verify(params.servicepwd,"servicepwd",{"required":true});
if ( verify_err !=null){
return verify_err;
}
var defaultParam = {
datatype: "json",
method: "getUserInfoById",
};
params = Object.assign(defaultParam,params);
if (params.time == undefined){
params.time= timestr("YYYYMMDDHHmmss");
}
if (params.sign == undefined){
params.sign= md5(params.servicecode+params.servicepwd+params.time);
}
return instance.get("sso/servlet/organduser",{params});
}
}
module.exports = {
injure
}
- Input verification , It is defined as mandatory in the interface definition , However, the parameters that do not contain default values are used for judgment , If there is a problem with the inspection , Go straight back to reject Of Promise.
- The default value fills in , The default values are included in the interface definition , And the default value is not a parameter of the computable attribute , Build a default parameter object , Merge with the passed in parameters .
- No value passed in , But in the parameter definition , Defined as a computed property ( Is the default value in ‘=’ The properties of the beginning , for example
timestr("YYYYMMDDHHmmss")), Translate the calculation expression into the actual js Code .
- call axios The original function of , Such as get,post etc. .
Auxiliary function
const dayjs = require("dayjs");
const md5 = require("md5");
module.exports = {
timestr: (fmt) => {
return dayjs().format(fmt);
},
md5: (str) => {
return md5(str);
},
verify: (par, name, option) =>{
if (option.required && par == undefined){
return Promise.reject(" Parameters "+name+" The request must be transmitted , But not into ");
}
}
}
Progress description
Welcome to try , Provide your valuable advice
边栏推荐
- Global and Chinese market for baked potato chips 2022-2028: Research Report on technology, participants, trends, market size and share
- 栖霞市住建局和消防救援大队开展消防安全培训
- Matrix fast power notes
- Write data to local file
- Progressive web application PWA is the future of application development
- Redis (IV) redis association table caching
- See how I store integer data in the map < string, string > set
- 六月集训(第26天) —— 并查集
- 8- creating leecode algorithm with pictures and texts - algorithm solution of minimum stack and LRU caching mechanism
- 2021 Q3-Q4 Kotlin Multiplatform 使用现状 | 调查报告
猜你喜欢

Using reflection to export entity data to excel

Basic MySQL

AdaptiveAvgPool2D 不支持 onnx 导出,自定义一个类代替 AdaptiveAvgPool2D

Développeur, quelle est l'architecture des microservices?
![[echart] II. User manual and configuration item reading notes](/img/03/fa87e5b8f8d23381ea6923d507f250.jpg)
[echart] II. User manual and configuration item reading notes

JS take the date of the previous month 【 pit filling 】

Easyexcel - Excel read / write tool

MySQL第八次作业

Flutter and native communication (Part 1)

2021 Q3-Q4 Kotlin Multiplatform 使用现状 | 调查报告
随机推荐
consul微服务治理中心踩坑
Redis中执行Lua脚本
How QT uses quazip to compress and decompress files
jwt认证协议阐述之——我开了一家怡红院
Global and Chinese markets of children's electronic thermometers 2022-2028: Research Report on technology, participants, trends, market size and share
Oracle sqlplus query result display optimization
Idea remote debugger
基础-MySQL
Global and Chinese market of cryogenic bulk tanks 2022-2028: Research Report on technology, participants, trends, market size and share
April 13, 2021 interview with beaver family
Redis (basic) - learning notes
Express (I) - easy to get started
Matrix fast power notes
[work details] March 18, 2020
Global and Chinese market of amateur football helmets 2022-2028: Research Report on technology, participants, trends, market size and share
SQL index learning notes
MySQL Chapter 5 Summary
OpenCV图像处理-灰度处理
Server single and two-way adjustable one key mutual trust script!
Nuxt. JS - learning notes