<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>运达&#039;s  blog &#187; H5</title>
	<atom:link href="https://www.yunda51.com/?feed=rss2&#038;tag=h5" rel="self" type="application/rss+xml" />
	<link>https://www.yunda51.com</link>
	<description>运达的博客</description>
	<lastBuildDate>Wed, 12 Nov 2025 07:58:26 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0.19</generator>
	<item>
		<title>手机端的H5页面自定义分享到微信朋友、朋友圈</title>
		<link>https://www.yunda51.com/?p=1966</link>
		<comments>https://www.yunda51.com/?p=1966#comments</comments>
		<pubDate>Sun, 26 Nov 2023 14:53:17 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[php技术]]></category>
		<category><![CDATA[H5]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[微信]]></category>
		<category><![CDATA[朋友圈]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1966</guid>
		<description><![CDATA[最近在工作中遇到了一个功能，需要将我们手机端的H5页面自定义分享到微信朋友、朋友圈、QQ和QQ空间。 下面是我<a href="https://www.yunda51.com/?p=1966" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p>最近在工作中遇到了一个功能，需要将我们手机端的H5页面自定义分享到微信朋友、朋友圈、QQ和QQ空间。<br />
下面是我自己百度，然后自己亲身测试得到的一个方法；下面分享给大家，相互学习。<br />
实现原理：H5的自定义分享需要用到微信公众平台的分享接口，也就是微信网页开发中的JSSDK,【具体的说明文档：https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html】使用微信的SDK中的分享接<br />
示例：https://m.php.cn/faq/538242.html<br />
获取流程：<br />
1、获取 access_token<br />
2、通过access_token换取 jsapi_ticket<br />
3、签名算法<br />
签名生成规则如下：参与签名的字段包括noncestr（随机字符串）, 有效的jsapi_ticket, timestamp（时间戳）, url（当前网页的URL，不包含#及其后面部分） 。对所有待签名参数按照字段名的ASCII 码从小到大排序（字典序）后，使用URL键值对的格式（即key1=value1&#038;key2=value2…）拼接成字符串string1。这里需要注意的是所有参数名均为小写字符。对string1作sha1加密，字段名和字段值都采用原始值，不进行URL 转义。<br />
因为获取access_token不能请求，请求次数过多微信会把IP禁用，所以需要把access_token缓存起来，要不存到数据库里，两种方法，看自己选择。<br />
<strong>二、在数据库中添加access_token表：</strong></p>
<pre class="wp-code-highlight prettyprint">
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for access_token
-- ----------------------------
DROP TABLE IF EXISTS access_token;
CREATE TABLE access_token (
id int(11) NOT NULL AUTO_INCREMENT,
access_token char(64) NOT NULL COMMENT &#039;令牌-唯一标识&#039;,
expires_time varchar(64) DEFAULT NULL COMMENT &#039;过期时间&#039;,
ticket char(64) NOT NULL COMMENT &#039;临时票据&#039;,
ticket_expires_time varchar(64) DEFAULT NULL COMMENT &#039;过期的票据时间&#039;,
PRIMARY KEY (id)
</pre>
<p><strong>三、具体实现方式</strong><br />
1、获取access_token（access_token 的有效时间是7200s，故可以采用文件存储的方法进行保存，避免多次请求；）</p>
<pre class="wp-code-highlight prettyprint">
/**
* 添加微信分享接口
* 第一步：获取access token
*/
public function getAccessToken(){
$appid = &#039;wx207546bd5b43c838&#039;;
$secret = &#039;0ea9ee069f0dee52861aa460bed26452&#039;; //用户唯一凭证密钥
$time = time()+7000; //当前时间+2小时等于过期时间
$res = file_get_contents(&#039;https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&amp;appid=&#039; .$appid.&#039;&amp;secret=&#039;. $secret);
$res = json_decode($res, true);
$token = $res[&#039;access_token&#039;];
if($token){
$insert_data[&#039;access_token&#039;] = $token;
$insert_data[&#039;expires_time&#039;] = $time;
//把获得的token存储到数据库中
$model = Db::table(&quot;access_token&quot;)-&gt;insert($insert_data);
}
return $token;
</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1966</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
