Skip to content

Utils


常用工具集

这里内置了一些常用的工具函数,如果不够你还可以在 utils 目录下继续扩展

时间处理

moment()
moment()

文档地址:https://momentjs.bootcss.com/

首字母大写

firstToUpper(str: string)
firstToUpper(str: string)

生成订单号

orderCode(num: number = 6)
orderCode(num: number = 6)

生成指定长度的随机数

getNonceStr(num: number = 6)
getNonceStr(num: number = 6)

sha1加密

sha1(str: string)
sha1(str: string)

RSA加密

rsaSign(content: string, privateKey: string, hash: string = 'SHA256withRSA')
rsaSign(content: string, privateKey: string, hash: string = 'SHA256withRSA')

对参数对象进行字典排序

raw(args: Record<string, any>)
raw(args: Record<string, any>)

获取IP地址

getIP()
getIP()

生成手机验证码

getValidateCode(num: number = 6)
getValidateCode(num: number = 6)

MD5加密

MD5(text: string)
MD5(text: string)

生成JWT TOKEN

createToken(obj: any = {}, jwt_key: string = getConfig().app.jwt_key, expiresIn: number = getConfig().app.expiresIn)
createToken(obj: any = {}, jwt_key: string = getConfig().app.jwt_key, expiresIn: number = getConfig().app.expiresIn)

校验并解析JWT TOKEN

validateToken(token: string)
validateToken(token: string)

微信支付

WxPay({ appid, mchid, private_key, serial_no, apiv3_private_key, notify_url }: WXPAY = {})
WxPay({ appid, mchid, private_key, serial_no, apiv3_private_key, notify_url }: WXPAY = {})

支付宝支付

AliPay({ appId, privateKey, encryptKey, alipayRootCertPath, alipayPublicCertPath, appCertPath }: ALIPAY = {})
AliPay({ appId, privateKey, encryptKey, alipayRootCertPath, alipayPublicCertPath, appCertPath }: ALIPAY = {})

阿里短信验证码下发业务

SMS({ accessKeyId, secretAccessKey }: SMSTYPE = {})
SMS({ accessKeyId, secretAccessKey }: SMSTYPE = {})

阿里OSS

OSS({ accessKeyId, accessKeySecret, region, bucket }: OSSTYPE = {})
OSS({ accessKeyId, accessKeySecret, region, bucket }: OSSTYPE = {})

备案号:冀ICP备20015584号-2