gzwnzss 發表於 2021-2-14 00:11:04

微信分享自定义标题、图片、链接的最新html代码

<br /><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">使用本文教程,必须满足几个条件:</font></font><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">1、项目域名必须备案(想要使用微信的接口都必须要域名是备案的)</font></font><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">2、认证过的公众号&nbsp; &nbsp; </font></font><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">3、能运行PHP文件的环境</font></font><br /><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">满足上面几个条件的话,请接着往下看:</font></font><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">教程</font></font><br /><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">第一步</font></font><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">下载相关代码文件&nbsp; &nbsp;网页调用微信js-sdk分享接口(1.4.0)&nbsp;&nbsp;</font></font><br /><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">第二步</font></font><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">将上步下载的accessToken文件夹上传网站目录中(路径自定义)</font></font><br /><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">第三步</font></font><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">登录微信公众号平台(需要有认证的公众号)</font></font><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">1、设置-公众号设置-功能设置-JS接口安全域名(域名需要备案的)</font></font><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">2、开发-基本设置-IP白名单(添加IP白名单后才能调用接口)</font></font><br /><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">第四步</font></font><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">进入accessToken文件夹,打开signPackage.php,将微信公众号的AppID、AppSecret填入对应的位置</font></font><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">示例代码:</font></font><br /><ol><li>&lt;?php<br /><li>// 实现微信分享功能<br /><li>// 通过script标签引入该文件,通过url参数传递原网页的完整url<br /><li>error_reporting(0);<br /><li>$queryString = $_SERVER[&quot;QUERY_STRING&quot;];// 获取PHP后的网址参数,格式为:originUrl=...<br /><li>$url = substr($queryString,10);// 截取原网页的完整url<br /><li>require_once &quot;jssdk.php&quot;;<br /><li>$jssdk = new JSSDK(&quot;AppID&quot;, &quot;AppSecret&quot;, $url);// 改为自己公众号的AppID、AppSecret<br /><li>$signPackage = $jssdk-&gt;GetSignPackage();<br /><li>echo &quot;var signPackage=&quot;;<br /><li> die(json_encode($signPackage));// 返回微信分享所需参数<br /><li> ?&gt;</ol><font face="Tahoma, &amp;quot;"><font style="font-size:15px">第五步</font></font><br /><font face="Tahoma, &amp;quot;"><font style="font-size:15px">在需要调用微信自定义分享接口的html页面添加如下代码</font></font><br /><ol><li>&lt;script src=&quot;https://res.wx.qq.com/open/js/jweixin-1.6.0.js&quot;&gt;&lt;/script&gt; <br /><li>&lt;script&gt;document.write(&quot;&lt;script src='accessToken/signPackage.php?originUrl=&quot; + window.location.href + &quot;' type='text/javascript'&gt;&lt;\/script&gt;&quot;);&lt;/script&gt;<br /><li>&lt;script&gt;<br /><li>&nbsp; &nbsp; var baseUrl = &quot;https://www.uw7.cn/&quot;;<br /><li>&nbsp; &nbsp; var wxData = {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;imgUrl&quot; : baseUrl + 'logo.png',//分享缩略图<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;link&quot;&nbsp; &nbsp;: baseUrl + 'welcome.html',//分享的链接<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;title&quot;&nbsp;&nbsp;: '接单:网站,公众号,小程序等业务',//分享朋友标题<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;title2&quot;&nbsp;&nbsp;: 'QQ:4175455',//分享朋友圈标题<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;desc&quot;&nbsp; &nbsp;: '价格美丽'//分享朋友的文案<br /><li>&nbsp; &nbsp; };<br /><li>&nbsp; &nbsp; wx.config({<br /><li>&nbsp; &nbsp; debug: false,<br /><li>&nbsp; &nbsp; appId: signPackage.appId,<br /><li>&nbsp; &nbsp; timestamp: parseInt(signPackage.timestamp),<br /><li>&nbsp; &nbsp; nonceStr: signPackage.nonceStr,<br /><li>&nbsp; &nbsp; signature: signPackage.signature,<br /><li>&nbsp; &nbsp; jsApiList: [<br /><li>&nbsp; &nbsp; 'updateAppMessageShareData',<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'updateTimelineShareData'<br /><li>&nbsp; &nbsp; ]<br /><li>&nbsp; &nbsp; });<br /><li>&nbsp; &nbsp; wx.ready(function () {<br /><li>&nbsp; &nbsp; wx.updateTimelineShareData({<br /><li>&nbsp; &nbsp; title: wxData.title2,<br /><li>&nbsp; &nbsp; link: wxData.link,<br /><li>&nbsp; &nbsp; imgUrl: wxData.imgUrl,<br /><li>&nbsp; &nbsp; success: function () {<br /><li>&nbsp; &nbsp; }<br /><li>&nbsp; &nbsp; });<br /><li>&nbsp; &nbsp; wx.updateAppMessageShareData({<br /><li>&nbsp; &nbsp; title: wxData.title,<br /><li>&nbsp; &nbsp; desc: wxData.desc,<br /><li>&nbsp; &nbsp; link: wxData.link,<br /><li>&nbsp; &nbsp; imgUrl: wxData.imgUrl,<br /><li>&nbsp; &nbsp; type: 'link',<br /><li>&nbsp; &nbsp; dataUrl: '',<br /><li>&nbsp; &nbsp; success: function () {<br /><li>&nbsp; &nbsp; }<br /><li>&nbsp; &nbsp; });<br /><li>&nbsp; &nbsp; });<br /><li>&lt;/script&gt;</ol><br /><br />Tahoma<em>, </em>15px<em>, </em>quot

gzwnzss 發表於 2021-2-14 23:57:14

可免费帮忙部署

sdlaobing 發表於 2021-2-15 12:28:02

支持学习了.只是觉得那个能够版更换图片吗?

panwf 發表於 2021-3-4 16:40:12

看看是不是需要的

老申的幸福生活 發表於 2021-6-25 12:50:18

事大是大是大阿萨顺丰到付

pcinstall 發表於 2021-6-28 12:17:57

kk

顽童不老 發表於 2021-7-4 11:00:08

支持一个。

sosoba 發表於 2021-7-16 13:59:38

我是来学习的

ywofs 發表於 2021-10-6 17:48:39

多谢分享

新化文印网 發表於 2021-10-19 10:19:28

学习一下,谢谢分享
頁: [1]
查看完整版本: 微信分享自定义标题、图片、链接的最新html代码