apicloud解决安卓微信分享缩略图一直读取第一张问题。

下面是实现代码。
var sdhimg = Math.ceil(Math.random()*1000); //获取0~1000的随机数
api.download({
url: goods_img,
savePath: ‘fs://ceshi’+sdhimg+’.jpg’, //这里要兼容安卓不获取重复图片,必须带上这个随机数参数。ios随意。
report: true,
cache: false,
allowResume: true
}, function(ret, err) {
// console.log(JSON.stringify(ret.savePath));
if (ret.state == 1) {
aurl = ret.savePath
}
});

下面是微信和其他方式分享。
var dialogBox = api.require(‘dialogBox’);
dialogBox.actionMenu({
rect: {
h: 180
},
texts: {
cancel: ‘取消’
},
items: [{
text: ‘微信好友’,
icon: ‘widget://image/home/share_friends.png’
}, {
text: ‘朋友圈’,
icon: ‘widget://image/home/share_pyq.png’
}, {
text: ‘其他’,
icon: ‘widget://image/home/share_more.png’
}],
styles: {
bg: ‘#FFF’,
column: 3,
itemText: {
color: ‘#000’,
size: 11,
marginT: 10
},
itemIcon: {
size: 35
},
cancel: {
bg: ‘fs://icon.png’,
color: ‘#000’,
h: 44,
size: 13
}
}
}, function(ret) {
//console.log(JSON.stringify(ret));
if (ret.index == 0) { //分享到微信
var data = {
product: obj.commodity_id,
sharepath: “/about_shoppings.html”
};

                    ajaxRequest('/v2/ecapi.product.get', 'post', data, true, function(ret) {
                        if (ret.error_code == 0) {
                            var fx_url = ret.product.share_url; //生成专属分享链接
                            //console.log(fx_url);
                            var wx = api.require('wx');

                            wx.shareWebpage({
                                apiKey: '',
                                scene: 'session',
                                title: sharename,
                                description: sharename,
                                thumb:"fs://"+aurl,
                                contentUrl: fx_url
                            }, function(ret, err) {
                                if (ret.status) {

                                } else {
                                  //  console.log(JSON.stringify(err));
                                }
                            });

                        } else {
                            toast(ret.error_desc);
                        }
                    });
                    dialogBox.close({
                        dialogName: 'actionMenu'
                    });

                } else if (ret.index == 1) { //分享到其他
                    var data = {
                        product: obj.commodity_id,
                        sharepath: "/about_shoppings.html"
                    };
                    ajaxRequest('/v2/ecapi.product.get', 'post', data, true, function(ret) {
                        if (ret.error_code == 0) {
                            var fx_url = ret.product.share_url; //生成专属分享链接
                            //console.log(aimg);
                            var wx = api.require('wx');

                            wx.shareWebpage({
                                apiKey: '',
                                scene: 'timeline',
                                title: sharename,
                                description: sharename,
                                thumb:"fs://"+aurl,
                                contentUrl: fx_url
                            }, function(ret, err) {
                                if (ret.status) {} else {
                                    //console.log(JSON.stringify(err))
                                }
                            });



                        } else {
                            toast(ret.error_desc);
                        }
                    });
                    dialogBox.close({
                        dialogName: 'actionMenu'
                    });
                } else if (ret.index == 2) { //分享到其他
                    var data = {
                        product: obj.commodity_id,
                        sharepath: "/about_shoppings.html"
                    };
                    ajaxRequest('/v2/ecapi.product.get', 'post', data, true, function(ret) {
                        if (ret.error_code == 0) {
                            var fx_url = ret.product.share_url; //生成专属分享链接
                            //console.log(fx_url);
                            sharedModule.share({
                                path: fx_url,
                                type: 'url'
                            });
                        } else {
                            toast(ret.error_desc);
                            return;
                        }
                    });
                    dialogBox.close({
                        dialogName: 'actionMenu'
                    });
                } else if (ret.eventType == "cancel") {
                    dialogBox.close({
                        dialogName: 'actionMenu'
                    });
                }
            });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值