Commit 1944fcde by 宋毅

tj

parent 120f9e9b
......@@ -135,12 +135,60 @@ class UtilsUserSve extends AppServiceBase {
* @param {*} url
*/
async getJsApiSingnature(pobj, ticket, nonce, timeStamp, url) {//获取JsApi鉴权签名信息----本类中调用
// public static String sign(String ticket, String nonceStr, long timeStamp, String url) throws OApiException {
// String plain = "jsapi_ticket=" + ticket + "&noncestr=" + nonceStr + "&timestamp=" + String.valueOf(timeStamp)
// + "&url=" + url;
// try {
// MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
// sha1.reset();
// sha1.update(plain.getBytes("UTF-8"));
// return byteToHex(sha1.digest());
// } catch (NoSuchAlgorithmException e) {
// throw new OApiResultException(e.getMessage());
// } catch (UnsupportedEncodingException e) {
// throw new OApiResultException(e.getMessage());
// }
// }
// // 字节数组转化成十六进制字符串
// private static String byteToHex(final byte[] hash) {
// Formatter formatter = new Formatter();
// for (byte b : hash) {
// formatter.format("%02x", b);
// }
// String result = formatter.toString();
// formatter.close();
// return result;
// }
let plainTex = "jsapi_ticket=" + ticket + "&noncestr=" + nonce + "&timestamp=" + timeStamp + "&url=" + url;
// var BufferList = new Buffer(plainTex).toString("UTF-8");
//1
var BufferList = new Buffer(plainTex, "UTF-8");
let signBufferList = cryptoJS.createHash('sha1').update(BufferList).digest();
let hexs = "";
for (let i = 0; i < signBufferList.length; i++) {
let hex = (signBufferList[i]).toString(16);
if (hex.length === 1) {
hexs = '0' + hex;
}
hexs += hex.toUpperCase();
}
const signature = hexs;
let signature = cryptoJS.createHash('sha1').update(plainTex).digest('hex').toUpperCase();
// 2
// let signature = cryptoJS.SHA1(plainTex).toString();
// 3
// let signature = cryptoJS.createHash('sha1').update(plainTex).digest('hex').toUpperCase();
this.logCtl.info({
appid: pobj.appInfo ? pobj.appInfo.uapp_id : "",
......@@ -152,7 +200,7 @@ class UtilsUserSve extends AppServiceBase {
// let signature = cryptoJS.SHA1(BufferList).digest().toString(cryptoJS.enc.Hex); //cryptoJS.SHA1(plainTex).toString();
return signature;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment