Skip to content

Commit 3c9699a

Browse files
committed
feat(jsSdk): Add jsSdk Function
1 parent 552e9fb commit 3c9699a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/utile/wechat.util.ts

+38
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,42 @@ export class WeChatUtil {
5757
return accessToken;
5858
}
5959
}
60+
61+
/**
62+
* 生成随机字符串
63+
* @returns {Promise<any>}
64+
*/
65+
async generatingRandomNumbers() {
66+
return Math.random().toString(36).substr(2, 15);
67+
}
68+
69+
/**
70+
* 生成时间戳
71+
* @returns {Promise<string>}
72+
*/
73+
async generationTimestamp() {
74+
return '' + Math.floor(Date.now() / 1000);
75+
}
76+
77+
/**
78+
* 排序查询字符串
79+
* @param args
80+
* @returns {Promise<any>}
81+
*/
82+
async sortQuery(args: any) {
83+
let keys = Object.keys(args);
84+
keys = keys.sort();
85+
const newArgs = {};
86+
for (let i = 0; i < keys.length; i++) {
87+
const key = keys[i];
88+
newArgs[key.toLowerCase()] = args[key];
89+
}
90+
let str = '';
91+
const newKeys = Object.keys(newArgs);
92+
for (let j = 0; j < newKeys.length; j++) {
93+
const k = newKeys[j];
94+
str += '&' + k + '=' + newArgs[k];
95+
}
96+
return str.substr(1);
97+
}
6098
}

0 commit comments

Comments
 (0)