// 将其转成 base64
// var base64={
var utf16toEntities=function(str) {
var patt = /[\ud800-\udbff][\udc00-\udfff]/g; // 检测utf16字符正则
str = str.replace(patt, function (char) {
var H, L, code;
if (char.length === 2) {
H = char.charCodeAt(0); // 取出高位
L = char.charCodeAt(1); // 取出低位
code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00; // 转换算法
return "&#" + code + ";";
} else {
return char;
}
});
return str;
}
var uncodeUtf16=function(str) {
var reg = /\&#.*?;/g;
var result = str.replace(reg, function (char) {
var H, L, code;
if (char.length == 9) {
code = parseInt(char.match(/[0-9]+/g));
H = Math.floor((code - 0x10000) / 0x400) + 0xD800;
L = (code - 0x10000) % 0x400 + 0xDC00;
return unescape("%u" + H.toString(16) + "%u" + L.toString(16));
} else {
return char;
}
});
return result;
}
// }
module.exports={
utf16toEntities,
uncodeUtf16
}
小程序调用
var base64=require("../../../../utils/base64.js")
GetCommand () {
util.loading();//加载中
let that = this;
//参数
var data = {
UserID:wx.getStorageSync("userId"),//用户ID
NetWorkID:that.data.netWorkId, //网点ID
}
console.log('口令参数',data);
util.ajaxRequest('Advertisement/GetAdvertisingCommand', 'POST', data,
// 成功回调
function (res) {
console.log(res)
if(res.data.ERROR_CODE == -1){
wx.setClipboardData({
data: base64.uncodeUtf16(res.data.DATA.command) ,
success: function () {
wx.showToast({
title: '复制成功',
duration:10,
icon:"none"
})
}
})
}
})
//隐藏-加载中
wx.hideLoading();
},
将其转成 base64
最新推荐文章于 2024-05-20 22:28:51 发布