javascript 微信分享,如何更改转发描述和缩略图?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22636071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 23:29:48  来源:igfitidea点击:

WeChat sharing, how to change re-share description and thumbnail?

javascripthtmlwechat

提问by davur

Question

问题

Is there a way to provide a custom title, description and thumbnail for when my website pages are shared from within WeChat?

当我的网站页面在微信中共享时,有没有办法提供自定义标题、描述和缩略图?

Background

背景

We have an iPhone app from which users can publish/share posts with their friends using WeChat (aka Weixin).

我们有一个 iPhone 应用程序,用户可以从中使用微信(又名微信)与他们的朋友发布/分享帖子。

When sharing from the app a title, a description and an image are posted via the API for the shared page (these display as desired when shared from the app). Once shared the friends open these pages in WeChat (and not our app).

从应用程序共享标题、描述和图像时,将通过共享页面的 API 发布(这些在从应用程序共享时根据需要显示)。一旦分享,朋友们就会在微信(而不是我们的应用程序)中打开这些页面。

The problem is that when the friends re-share our pages using WeChat's own share button it loses the description we provided. It will re-share with the HTML title tag, the first image on the page (stretched or squished to a square thumbnail) and where the description was originally it just shows the URL of the page.

问题是当朋友使用微信自己的分享按钮重新分享我们的页面时,它会丢失我们提供的描述。它将与 HTML 标题标签、页面上的第一张图像(拉伸或压缩为方形缩略图)以及描述最初的位置重新共享,它只显示页面的 URL。

I have tried providing descriptions in a description meta tag but to no luck. I have even tried Facebook style/open graph og:description meta tags.

我试过在描述元标签中提供描述,但没有运气。我什至尝试过 Facebook 风格/开放图 og:description 元标签。

Sidenote

边注

I have looked through the source on a Chinese site that seems to have overcome this issue. I think it's solved using a javascript plugin of some sort called WeixinJSBridge. Unfortunately I have been unable to uncover any documentation in English - My Chinese isn't great, and by not great I mean, I can't read a word.

我查看了一个中文网站上的来源,似乎已经解决了这个问题。我认为它是使用某种名为 WeixinJSBridge 的 javascript 插件解决的。不幸的是,我一直无法找到任何英文文档——我的中文不太好,我的意思是,我一个字都看不懂。

采纳答案by Wen

[Not working since WeChat published the new JS SDK] This is solution form WeChat: http://mp.weixin.qq.com/qa/index.php?qa=3163However, there are all Chinese. The code you could try is below:

【微信发布新的JS SDK后不能用】这是微信的解决方法:http://mp.weixin.qq.com/qa/index.php?qa= 3163但是全是中文的。您可以尝试的代码如下:


var imgUrl = 'http://xxx/your-share-icon.png';
var lineLink = 'http://xxx/your-share-link';
var descContent = "your-content-desc";
var shareTitle = 'you-share-title';
var appid = 'your-app-id (from WeChat)';

function shareFriend() {
    WeixinJSBridge.invoke('sendAppMessage',{
                            "appid": appid,
                            "img_url": imgUrl,
                            "img_width": "640",
                            "img_height": "640",
                            "link": lineLink,
                            "desc": descContent,
                            "title": shareTitle
                            }, function(res) {
                            _report('send_msg', res.err_msg);
                            })
}
function shareTimeline() {
    WeixinJSBridge.invoke('shareTimeline',{
                            "img_url": imgUrl,
                            "img_width": "640",
                            "img_height": "640",
                            "link": lineLink,
                            "desc": descContent,
                            "title": shareTitle
                            }, function(res) {
                            _report('timeline', res.err_msg);
                            });
}
function shareWeibo() {
    WeixinJSBridge.invoke('shareWeibo',{
                            "content": descContent,
                            "url": lineLink,
                            }, function(res) {
                            _report('weibo', res.err_msg);
                            });
}
// WeChat browser will initial by above function and trigger WeixinJSBridgeReady event.
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {

        // share to friend
        WeixinJSBridge.on('menu:share:appmessage', function(argv){
            shareFriend();
            });

        // share to timeline
        WeixinJSBridge.on('menu:share:timeline', function(argv){
            shareTimeline();
            });

        // share to weibo
        WeixinJSBridge.on('menu:share:weibo', function(argv){
            shareWeibo();
            });
        }, false);

回答by Taobility

Actually right now WeChat does provide iOS/Andriod SDK for share content in Moments or with friend, and here is the English documentation for that: http://dev.wechat.com/wechatapi/messages-moments

其实现在微信确实提供了iOS/​​Andriod SDK,可以在朋友圈或者朋友圈分享内容,英文文档如下:http: //dev.wechat.com/wechatapi/messages-moments