zoukankan      html  css  js  c++  java
  • 微信分享朋友圈监听(PHP)

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script language="javascript" type="text/javascript">
    wx.config({
        debug: false,//这里是开启测试,如果设置为true,则打开每个步骤,都会有提示,是否成功或者失败
        appId: '你的appid',
        timestamp: '14999923234',//这个一定要与上面的php代码里的一样。
        nonceStr: '14999923234',//这个一定要与上面的php代码里的一样。
        signature: '<?=jssdk();?>',
        jsApiList: [
          // 所有要调用的 API 都要加到这个列表中
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo'
        ]
    });
    wx.ready(function(){
        wx.onMenuShareTimeline({
            title: "这里是草果网", // 分享标题
            link: "http://www.icaoguo.com/", // 分享链接
            imgUrl: "http://icaoguo.com/upfile/banner1.png", // 分享图标
            success: function () { 
                alert('成功');
                // 用户确认分享后执行的回调函数
            },
            cancel: function () { 
                alert('取消');
                // 用户取消分享后执行的回调函数
            }
        });
        wx.onMenuShareAppMessage({
            title: "<?=$act['act_name']?>", // 分享标题
            desc: "<?=substr($act['act_stime'],0,10)?><?=$act['act_place']?>", // 分享描述
            link: "http://www.brandhd.com/v/events/view/<?=$act['act_id']?>", // 分享链接
            imgUrl: "http://www.brandhd.com<?=$act['act_poster_small']?>", // 分享图标
            type: '', // 分享类型,music、video或link,不填默认为link
            dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
            success: function () { 
                // 用户确认分享后执行的回调函数
            },
            cancel: function () { 
                // 用户取消分享后执行的回调函数
            }
        });
        wx.onMenuShareQQ({
            title: "<?=$act['act_name']?>", // 分享标题
            desc: "<?=substr($act['act_stime'],0,10)?>
    <?=$act['act_place']?>", // 分享描述
            link: "http://www.brandhd.com/v/events/view/<?=$act['act_id']?>", // 分享链接
            imgUrl: "http://www.brandhd.com<?=$act['act_poster_small']?>", // 分享图标
            success: function () { 
               // 用户确认分享后执行的回调函数
            },
            cancel: function () { 
               // 用户取消分享后执行的回调函数
            }
        });
        wx.onMenuShareWeibo({
            title: "<?=$act['act_name']?>", // 分享标题
            desc: "<?=substr($act['act_stime'],0,10)?>
    <?=$act['act_place']?>", // 分享描述
            link: "http://www.brandhd.com/v/events/view/<?=$act['act_id']?>", // 分享链接
            imgUrl: "http://www.brandhd.com<?=$act['act_poster_small']?>", // 分享图标
            success: function () { 
               // 用户确认分享后执行的回调函数
            },
            cancel: function () { 
                // 用户取消分享后执行的回调函数
            }
        });
    });
    </script>
    </body>
    </html>
    
    <?php
    function jssdk(){
            $appid = '你的appid';
            $secret = '你的secret';
            $_title = '微信';$accesstoken = file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."");//获取access_token
            $token = json_decode($accesstoken); //对JSON格式的字符串进行编码
            $t = get_object_vars($token);//转换成数组
            $access_token = $t['access_token'];//输出access_token
             
            $jsapi = file_get_contents("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi");
            $jsapi = json_decode($jsapi);
            $j = get_object_vars($jsapi);
            $jsapi = $j['ticket'];//get JSAPI
             
            $time = 14999923234;
            $noncestr= $time;
            $jsapi_ticket= $jsapi;
            $timestamp=$time;
            $url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
            $and = "jsapi_ticket=".$jsapi_ticket."&noncestr=".$noncestr."&timestamp=".$timestamp."&url=".$url."";
            $signature = sha1($and);
            return $signature;
        }
    
    ?>

    不生效的话,要去微信公众号平台设置JS安全域名。

  • 相关阅读:
    python基础 条件和循环
    git基本使用(搭建Git服务器)
    面试题整理
    node nvm npm nrm 安装
    onmouse事件
    webpack
    web前端UI框架
    javascript cookie
    三大家族,offset,scroll,client
    clientTop,scrollTop,兼容
  • 原文地址:https://www.cnblogs.com/jh1994/p/5217315.html
Copyright © 2011-2022 走看看