易腾动力社区
标题:
微信分享网站链接时显示缩略图和描述的方法
[打印本页]
作者:
jaly
时间:
2018-4-25 17:43
标题:
微信分享网站链接时显示缩略图和描述的方法
微信分享方法一:【亲测有效】
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
wx.config({
debug: false,
appId: 'wxfb95e4025a5d4614',
timestamp: '1498633007',
nonceStr: 'tnZJBsdrUo88MFiB',
signature: 'cae67a0a883822e1087cba091321b14b73152210',
jsApiList: [
'onMenuShareTimeline',
'onMenuShareAppMessage'
]
});
wx.ready(function () {
var shareData = {
title: '这是分享的标题', // 标题
desc: '这是要分享的内容', // 描述
link: 'http://www.yidz.cn/', // 分享的URL,必须和当前打开的网页的URL是一样的
imgUrl: 'http://orange-web.uboxol.com/assets/img/vip/title.png' // 缩略图地址
};
wx.onMenuShareAppMessage(shareData);
wx.onMenuShareTimeline(shareData);
});
wx.error(function (res) {
//alert(res.errMsg);//错误提示
});
</script>
复制代码
微信分享方法二:
<meta itemprop="name" content="这是分享的标题"/>
<meta itemprop="image" content="http://orange-web.uboxol.com/assets/img/vip/title.png" />
<meta name="description" itemprop="description" content="这是要分享的内容" />
复制代码
微信分享方法三:
<div style="display:none;"><img src="http://orange-web.uboxol.com/assets/img/vip/title.png" alt=""></div>【亲测有效】
<div style="width:0px;height:0px;overflow:hidden;"><img src="http://ws234.com/content/templates/emlog_dux/images/fxlogo.png></div>
复制代码
作者:
jaly
时间:
2018-4-25 17:46
标题:
浏览器分享方法
浏览器分享方法一:
<meta property="og:type" content="website" />
<meta property="og:title" content="页面标题">
<meta property="og:description" content="页面描述">
<meta property="og:image" content="http://www.example.com/img/thumbnail.png">
<meta property="og:url" content="http://www.example.com/">
复制代码
作者:
jaly
时间:
2018-4-25 17:46
标题:
微信分享接口示例(设置标题、缩略图、连接、描述),附demo下载
微信分享方法四:[使用微信的分享接口JSSDK]
第一步:
先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”。
注:认证帐号才有分享权限
第二步
创建一个demo.php文件和wxshare.js
demo.php
<?php
// 步骤1.设置appid和appsecret
$appid = 'wxd75a2b20d3a54752';
$appsecret = '9b32270f32874ea7a7427f88ff770777';
// 步骤2.生成签名的随机串
function nonceStr($length){
$str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';//62个字符
$strlen = 62;
while($length > $strlen){
$str .= $str;
$strlen += 62;
}
$str = str_shuffle($str);
return substr($str,0,$length);
}
// 步骤3.获取access_token
$result = http_get('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret);
$json = json_decode($result,true);
$access_token = $json['access_token'];
function http_get($url){
$oCurl = curl_init();
if(stripos($url,"https://")!==FALSE){
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
}
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
if(intval($aStatus["http_code"])==200){
return $sContent;
}else{
return false;
}
}
// 步骤4.获取ticket
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$access_token";
$res = json_decode ( http_get ( $url ) );
$ticket = $res->ticket;
// 步骤5.生成wx.config需要的参数
$surl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$ws = getWxConfig( $ticket,$surl,time(),nonceStr(16) );
function getWxConfig($jsapiTicket,$url,$timestamp,$nonceStr) {
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
$signature = sha1 ( $string );
$WxConfig["appId"] = $appid;
$WxConfig["nonceStr"] = $nonceStr;
$WxConfig["timestamp"] = $timestamp;
$WxConfig["url"] = $url;
$WxConfig["signature"] = $signature;
$WxConfig["rawString"] = $string;
return $WxConfig;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Share Demo</title>
</head>
<body>
</body>
// 步骤6.调用JS接口
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
wx.config({
debug: false,
appId: '<?php echo $ws["appId"]; ?>',
timestamp: '<?php echo $ws["timestamp"]; ?>',
nonceStr: '<?php echo $ws["nonceStr"]; ?>',
signature: '<?php echo $ws["signature"]; ?>',
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'onMenuShareQZone',
]
});
var wstitle = "我是标题";
var wsdesc = "我是描述";
var wslink = "<?php echo $surl; ?>";
var wsimg = "http://fmwei.com/usr/uploads/2016/07/794257096.png";
</script>
<script src="wxshare.js"></script>
</html>
复制代码
wxshare.js
wx.ready(function () {
// 分享到朋友圈
wx.onMenuShareTimeline({
title: wstitle,
link: wslink,
imgUrl: wsimg,
success: function () {
alert('分享成功');
},
cancel: function () {
}
});
// 分享给朋友
wx.onMenuShareAppMessage({
title: wstitle,
desc: wsdesc,
link: wslink,
imgUrl: wsimg,
success: function () {
alert('分享成功');
},
cancel: function () {
}
});
// 分享到QQ
wx.onMenuShareQQ({
title: wstitle,
desc: wsdesc,
link: wslink,
imgUrl: wsimg,
success: function () {
alert('分享成功');
},
cancel: function () {
}
});
// 微信到腾讯微博
wx.onMenuShareWeibo({
title: wstitle,
desc: wsdesc,
link: wslink,
imgUrl: wsimg,
success: function () {
alert('分享成功');
},
cancel: function () {
}
});
// 分享到QQ空间
wx.onMenuShareQZone({
title: wstitle,
desc: wsdesc,
link: wslink,
imgUrl: wsimg,
success: function () {
alert('分享成功');
},
cancel: function () {
}
});
});
复制代码
欢迎光临 易腾动力社区 (http://bbs.yidz.cn/)
Powered by Discuz! X3