cocoscreator3.X加载微信头像在oppo手机上和其他安卓手机上要不同的写法才能显示

  • 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);

                }

            });

你可以用同一个头像,把不同手机的收到的url以及其解码结果打出来对比。
如果url本身就不一样,那么说明服务器(或微信平台)本身的问题,那就只能用条件判断。
如果url一样,解码结果不一样,那就是base64的decode实现有问题,建议是换一套base64 decode的实现,最好是找用js写的。