|
新的js SDK,其中有一接口函数onMenuShareTimeline便是针对朋友圈分享的监听,这将使得开发者更容易实现这种分享后可见的功能。
- <div style="font-size:60px;margin:20px;">提问:如何证明你妈是你妈?</div>
- <div id="status" style="font-size:60px;margin:20px;">(分享后见答案)</div>
- <script>
- function todoaftershare() {
- document.getElementById("status").innerHTML = "<font color='blue'>答案:......</font>";
- }
- function gettilte() {
- title = "测试专用";
- return title;
- }
- </script>
- /*******************/
- /* 下面的代码勿动 /
- /*******************/
- include_once(dirname(__FILE__).'/wxshare.php');
-
- $timestamp = time(); //获取时间戳
- $noncestr = rand(10000,99999); //随机验证码
- $jsapi = new website();
- $jsapi_ticket = $jsapi->GetToken(); //获取js的token
- $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; //当前页面URL
- $signature = getsignature($noncestr,$timestamp,$jsapi_ticket,$url); //获取签名
- //签名方法
- function getsignature($noncestr,$timestamp,$jsapi_ticket,$url) {
- $str = "jsapi_ticket=".$jsapi_ticket."&noncestr=".$noncestr."×tamp=".$timestamp."&url=".$url;
- //echo $str;
- return sha1($str);
- }
- ?>
- //加载官方JS包
- <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
- <script>
- wx.config({
- //debug: true, //调试模式,开启后则会在客户端直接alert结果
- appId: 公众号的appid,
- timestamp: "<?php echo $timestamp; ?>",
- nonceStr: "<?php echo $noncestr; ?>",
- signature: "<?php echo $signature; ?>",
- jsApiList: [ //需要调用的接口
- 'checkJsApi',
- 'onMenuShareTimeline'
- ]
- });
- wx.ready(function () {
- wx.onMenuShareTimeline({
- title: gettilte(), //分享后自定义标题
- link: 'https://bbs.weiwangvip.com', //分享后的URL
- imgUrl: 'https://bbs.weiwangvip.com/static/image/common/logo.png', //分享的LOGO
- trigger: function (res) {
-
- },
- success: function (res) {
- todoaftershare();
- },
- cancel: function (res) {
- },
- fail: function (res) {
- alert('wx.onMenuShareTimeline:fail: '+JSON.stringify(res));
- }
- });
- });
- wx.error(function (res) {
- alert('wx.error: '+JSON.stringify(res));
- });
- </script>
复制代码
|
|
共 3 个关于本帖的回复 最后回复于 2015-8-3 00:33