-
Creator 版本:cocoscreator3.8
-
目标平台:安卓
-
重现方式:服务器将微信头像url用Base64加密之后再到客户端解密,除了oppo手机外的安卓手机都可以正常加载,到oppo手机上解密后不能加载,也不能直接在后面拼接"?aa=aa.jpg",先在加密url后加上加密的"?aa=aa.jpg",再解密替换就可以形成带"?aa==aa.jpg"的url,但是这样就不能在除oppo手机外的其他手机上加载 ,加载不到的assetManager.loadRemote都没有回调
-
手机型号: oppo A93
-
重现概率: 必现
这是oppo手机上的方式
const httpParts = _faceUrl.split(’:’);
_faceUrl += Base64.encode("?aa=aa.jpg");
console.log("头像url: "+_faceUrl)
if (httpParts[0] !== "http" && httpParts[0] !== "https") {
// 假设 url 是 Base64 编码的,尝试解码
try {
_faceUrl = Base64.decode(_faceUrl);
_faceUrl = _faceUrl.replace(/öÖæ§p/g,"?aa=aa.jpg")
} catch (error) {
console.error('解码 Base64 字符串时出错:', error);
}
}
console.log("加载头像url55555555555: "+_faceUrl)
assetManager.loadRemote<ImageAsset>(_faceUrl, function (err, asset: ImageAsset) {
if (err) {
let expath = _faceID;//"img_head_" + _faceID
Res.loadBundleRes(BundleName.res, AtlasPath.HeadImgsPath + expath + "/spriteFrame", SpriteFrame, (res) => {
imgTx.spriteFrame = res;
});
console.log("加载头像失败: "+err);
} else {
console.log("加载头像成功: ");
// let headsprite = new SpriteFrame()
// let _txture = new Texture2D()
// _txture.image = asset
// headsprite.texture = _txture
// imgTx.spriteFrame = headsprite;
imgTx.spriteFrame = SpriteFrame.createWithImage(asset);
}
});
这是其他安卓手机上的方式
const httpParts = _faceUrl.split(’:’);
//_faceUrl += Base64.encode("?aa=aa.jpg");
console.log("头像url: "+_faceUrl)
if (httpParts[0] !== "http" && httpParts[0] !== "https") {
// 假设 url 是 Base64 编码的,尝试解码
try {
_faceUrl = Base64.decode(_faceUrl);
// _faceUrl = _faceUrl.replace(/öÖæ§p/g,"?aa=aa.jpg")
} catch (error) {
console.error('解码 Base64 字符串时出错:', error);
}
}
console.log("加载头像url55555555555: "+_faceUrl)
assetManager.loadRemote<ImageAsset>(_faceUrl,{ext:".jpg"}, function (err, asset: ImageAsset) {
if (err) {
let expath = _faceID;//"img_head_" + _faceID
Res.loadBundleRes(BundleName.res, AtlasPath.HeadImgsPath + expath + "/spriteFrame", SpriteFrame, (res) => {
imgTx.spriteFrame = res;
});
console.log("加载头像失败: "+err);
} else {
console.log("加载头像成功: ");
// let headsprite = new SpriteFrame()
// let _txture = new Texture2D()
// _txture.image = asset
// headsprite.texture = _txture
// imgTx.spriteFrame = headsprite;
imgTx.spriteFrame = SpriteFrame.createWithImage(asset);
}
});