123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxb20d03be79354898&secret=4bb452da50dabcf862a5bad03004c827";
-
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_TIMEOUT, 500);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_URL, $url);
-
- $res = curl_exec($curl);
- curl_close($curl);
-
- $res = json_decode($res);
- $accessToken = $res->access_token;
-
- $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";
-
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_TIMEOUT, 500);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_URL, $url);
-
- $res = curl_exec($curl);
- curl_close($curl);
-
- $res = json_decode($res);
-
- $jsapiTicket = $res->ticket;
-
- $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
- $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
-
- $timestamp = time();
-
- $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- $nonceStr = "";
- for ($i = 0; $i < 16; $i++) {
- $nonceStr .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
- }
-
- // 这里参数的顺序要按照 key 值 ASCII 码升序排序
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
-
- $signature = sha1($string);
-
- $signPackage = array(
- "appId" => 'wxb20d03be79354898',
- "nonceStr" => $nonceStr,
- "timestamp" => $timestamp,
- "url" => $url,
- "signature" => $signature,
- "rawString" => $string
- );
- ?>
- <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
- <script type="text/javascript">
- wx.config({
- debug: false,
- appId: '{$signPackage.appId}',
- timestamp: '{$signPackage.timestamp}',
- nonceStr: '{$signPackage.nonceStr}',
- signature: '{$signPackage.signature}',
- jsApiList: [
- // 所有要调用的 API 都要加到这个列表中
- 'onMenuShareTimeline',
- 'onMenuShareAppMessage',
- 'updateTimelineShareData',
- 'updateAppMessageShareData'
- ]
- });
- //完成wx.config,执行这里
- wx.ready(function () {
- //分享到朋友圈
- wx.updateTimelineShareData({
- title: '{$title}-广州众炬科技', // 分享标题
- link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
- imgUrl: 'https://www.zfire.top/.{$thumb}', // 分享图标
- success: function () {
- // 设置成功
- // alert('已分享');
- }
- });
-
- //分享给朋友
- wx.updateAppMessageShareData({
- title: '{$title}-广州众炬科技', // 分享标题
- desc: '{$des}', // 分享描述
- link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
- imgUrl: 'https://www.zfire.top/.{$thumb}', // 分享图标
- success: function () {
- // 设置成功
- // alert('已分享');
- }
- })
-
- });
- </script>
- <div class="banner">
- <img src="wap/img/news_banner.jpg"/>
- </div>
- <!--新闻详情 开始-->
- <div class="news_detail bgfff mt10 padall">
- <div class="title">{$title}</div>
- <div class="date">{$createtime|toDate=###,"Y-m-d"}</div>
- <div class="content">{$content}</div>
- </div>
- <!--新闻详情 结束-->
|