正式版2.5 中对问题分享时缺少图片的现象修改建议,可能是我闲得蛋疼,老是纠结为什么在微信中分享问题的时候没图片,于是我就写了把views/default/m/footer.tpl.htm 这个文件里的JS给改了,可以成功分享的时候带图片显示了。默认显示问题中的第一张图
<script type="text/javascript">
$(function()
{
if ($('.aw-mod-body img').first().attr('src') == ''){
var weixin_img_url =location.protocol+'//'+location.host+'/static/common/weixin_default_logo.jpg';
}else{
var weixin_img_url = $('.aw-mod-body img').first().attr('src'),
weixin_img_first = $('.aw-mod-body img').first().attr('src').replace(/(.[i]\/){0,}([^\.]+.[/i])/ig, "$2");
var weixin_img_url = weixin_img_url.replace(weixin_img_first,'90x90_'+weixin_img_first);
}
// 判断是否微信打开
if (typeof G_IN_WEIXIN != 'undefined' && G_IN_WEIXIN == true)
{
$('header, nav, footer').hide();
var weixin_handler = setInterval(function()
{
if (typeof G_IN_WEIXIN != 'undefined' && G_IN_WEIXIN == true)
{
if (WEIXIN_APP_ID == ''){ //不支持开放平台
WeixinJSBridge.on('menu:share:appmessage', function(argv) {
WeixinJSBridge.invoke('sendAppMessage', {
"img_url":weixin_img_url,
"title" : document.title,
"link" : location.href,
"desc" : ($('#weixin-desc').text()=='')?document.description:$('#weixin-desc').text()
});
});
WeixinJSBridge.on('menu:share:timeline', function(argv) {
WeixinJSBridge.invoke('shareTimeline', {
"img_url":weixin_img_url,
"title" : document.title,
"link" :location.href,
"desc" :($('#weixin-desc').text()=='')?document.description:$('#weixin-desc').text()
});
});
}else{ //支持开放平台
WeixinJSBridge.on('menu:share:timeline', function(argv) {
WeixinJSBridge.invoke('shareTimeline', {
"title" : document.title,
"link" : 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + WEIXIN_APP_ID + '&redirect_uri=' + encodeURIComponent(G_BASE_URL + '/m/weixin/redirect/?redirect=' + $.base64.encode(location.href)) + '&response_type=code&scope=snsapi_userinfo&state=OAUTH#wechat_redirect',
"description" : document.description
});
});
WeixinJSBridge.on('menu:share:appmessage', function(argv) {
WeixinJSBridge.invoke('sendAppMessage', {
"title" : document.title,
"link" : 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + WEIXIN_APP_ID + '&redirect_uri=' + encodeURIComponent(G_BASE_URL + '/m/weixin/redirect/?redirect=' + $.base64.encode(location.href)) + '&response_type=code&scope=snsapi_userinfo&state=OAUTH#wechat_redirect',
"description" : document.description
});
});
}
clearInterval(weixin_handler);
}
}, 500);
}
});
</script>
阅读全文
收起全文