<?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; 微信</title>
	<atom:link href="https://www.yunda51.com/?feed=rss2&#038;tag=%E5%BE%AE%E4%BF%A1" 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>
		<item>
		<title>CURL模拟进行微信接口的GET与POST</title>
		<link>https://www.yunda51.com/?p=1475</link>
		<comments>https://www.yunda51.com/?p=1475#comments</comments>
		<pubDate>Wed, 31 Dec 2014 06:38:16 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[php技术]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[Post]]></category>
		<category><![CDATA[微信]]></category>
		<category><![CDATA[接口]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1475</guid>
		<description><![CDATA[Get提交获取数据 /** * @desc 获取access_token * @return String a<a href="https://www.yunda51.com/?p=1475" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p><strong>Get提交获取数据</strong></p>
<pre class="wp-code-highlight prettyprint">
           /** 
            * @desc 获取access_token 
            * @return String access_token 
            */  
           function getAccessToken(){  
               $AppId = &#039;1232assad13213123&#039;;  
               $AppSecret = &#039;2312312321adss3123213&#039;;  
               $getUrl = &#039;https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&amp;appid=&#039;.$AppId.&#039;&amp;secret=&#039;.$AppSecret;  
               $ch = curl_init();  
               curl_setopt($ch, CURLOPT_URL, $getUrl);  
               curl_setopt($ch, CURLOPT_HEADER, 0);  
               curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
               curl_setopt($ch, CURL_SSLVERSION_SSL, 2);  
               curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  
               curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  
               $data = curl_exec($ch);  
               $response = json_decode($data);  
               return $response-&gt;access_token;  
           }  
</pre>
<p><strong>Post提交获取数据</strong></p>
<pre class="wp-code-highlight prettyprint">
            /** 
             * @desc 实现天气内容回复 
             */  
            public function testWeixin(){  
                $access_token = $this-&gt;getAccessToken();  
                $customMessageSendUrl = &#039;https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=&#039;.$access_token;  
                $description = &#039;今天天气的详细信息（从第三方获取）。&#039;;  
                $url = &#039;http://weather.com/&#039;;  
                $picurl = &#039;http://weather.com/&#039;;  
                $postDataArr = array(  
                    &#039;touser&#039;=&gt;&#039;OPENID&#039;,  
                    &#039;msgtype&#039;=&gt;&#039;news&#039;,  
                    &#039;news&#039;=&gt;array(  
                        &#039;articles&#039;=&gt;array(  
                            &#039;title&#039;=&gt;&#039;当天天气&#039;,  
                            &#039;description&#039;=&gt;$description,  
                            &#039;url&#039;=&gt;$url,  
                            &#039;picurl&#039;=&gt;$picurl,  
                        ),  
                    ),  
                );  
                $postJosnData = json_encode($postDataArr);  
                $ch = curl_init($customMessageSendUrl);      
                curl_setopt($ch, CURLOPT_HEADER, 0);      
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);      
                curl_setopt($ch, CURLOPT_POST, 1);      
                curl_setopt($ch, CURLOPT_POSTFIELDS, $postJosnData);    
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  
                $data = curl_exec($ch);      
                var_dump($data);  
            }  
</pre>
<p>转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a>  原文地址：<a href="http://www.yunda51.com/1475.html">http://www.yunda51.com/1475.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1475</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
