Article_show.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxb20d03be79354898&secret=4bb452da50dabcf862a5bad03004c827";
  3. $curl = curl_init();
  4. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  5. curl_setopt($curl, CURLOPT_TIMEOUT, 500);
  6. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  7. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  8. curl_setopt($curl, CURLOPT_URL, $url);
  9. $res = curl_exec($curl);
  10. curl_close($curl);
  11. $res = json_decode($res);
  12. $accessToken = $res->access_token;
  13. $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";
  14. $curl = curl_init();
  15. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  16. curl_setopt($curl, CURLOPT_TIMEOUT, 500);
  17. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  18. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  19. curl_setopt($curl, CURLOPT_URL, $url);
  20. $res = curl_exec($curl);
  21. curl_close($curl);
  22. $res = json_decode($res);
  23. $jsapiTicket = $res->ticket;
  24. $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
  25. $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  26. $timestamp = time();
  27. $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  28. $nonceStr = "";
  29. for ($i = 0; $i < 16; $i++) {
  30. $nonceStr .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
  31. }
  32. // 这里参数的顺序要按照 key 值 ASCII 码升序排序
  33. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  34. $signature = sha1($string);
  35. $signPackage = array(
  36. "appId" => 'wxb20d03be79354898',
  37. "nonceStr" => $nonceStr,
  38. "timestamp" => $timestamp,
  39. "url" => $url,
  40. "signature" => $signature,
  41. "rawString" => $string
  42. );
  43. ?>
  44. <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  45. <script type="text/javascript">
  46. wx.config({
  47. debug: false,
  48. appId: '{$signPackage.appId}',
  49. timestamp: '{$signPackage.timestamp}',
  50. nonceStr: '{$signPackage.nonceStr}',
  51. signature: '{$signPackage.signature}',
  52. jsApiList: [
  53. // 所有要调用的 API 都要加到这个列表中
  54. 'onMenuShareTimeline',
  55. 'onMenuShareAppMessage',
  56. 'updateTimelineShareData',
  57. 'updateAppMessageShareData'
  58. ]
  59. });
  60. //完成wx.config,执行这里
  61. wx.ready(function () {
  62. //分享到朋友圈
  63. wx.updateTimelineShareData({
  64. title: '{$title}-广州众炬科技', // 分享标题
  65. link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  66. imgUrl: 'https://www.zfire.top/.{$thumb}', // 分享图标
  67. success: function () {
  68. // 设置成功
  69. // alert('已分享');
  70. }
  71. });
  72. //分享给朋友
  73. wx.updateAppMessageShareData({
  74. title: '{$title}-广州众炬科技', // 分享标题
  75. desc: '{$des}', // 分享描述
  76. link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  77. imgUrl: 'https://www.zfire.top/.{$thumb}', // 分享图标
  78. success: function () {
  79. // 设置成功
  80. // alert('已分享');
  81. }
  82. })
  83. });
  84. </script>
  85. <div class="banner">
  86. <img src="wap/img/news_banner.jpg"/>
  87. </div>
  88. <!--新闻详情 开始-->
  89. <div class="news_detail bgfff mt10 padall">
  90. <div class="title">{$title}</div>
  91. <div class="date">{$createtime|toDate=###,"Y-m-d"}</div>
  92. <div class="content">{$content}</div>
  93. </div>
  94. <!--新闻详情 结束-->