鍍金池/ 問答/PHP  網(wǎng)絡(luò)安全/ 求助:微信jssdk分享配置完沒有任何反應(yīng),跟沒配置一樣...

求助:微信jssdk分享配置完沒有任何反應(yīng),跟沒配置一樣...

按照教程做了配置,比較直接選擇直接獲取access_token和jsapi_tikcet沒有緩存,但是返回值都是ok的,不知道為什么這樣配置之后,選擇分享給朋友或者朋友圈,都沒有任何反應(yīng),也沒有看到api返回的值,有好心人能幫我看一下哪兒有問題嗎?

<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
        <title>測試</title>
        <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    </head>

<body>    
    <div class="page-content">
        
        <?php
            //獲取access_token
            $appid = "";//填了appid
            $secret = ""; //填了secret    
            $request_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret;
            $ch=curl_init();
            curl_setopt($ch,CURLOPT_URL,$request_url);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 從證書中檢查SSL加密算法是否存在   
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//返回文本流,
            $data=curl_exec($ch);
            curl_close($ch);
            $result=json_decode($data,true);
            $access_token = $result['access_token'];
            
            //獲取jsapi_ticket
            $request_url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
            $ch=curl_init();
            curl_setopt($ch,CURLOPT_URL,$request_url);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 從證書中檢查SSL加密算法是否存在   
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//返回文本流,
            $data=curl_exec($ch);
            curl_close($ch);
            $result=json_decode($data,true);
            $jsapi_ticket = $result['ticket'];
            
            //生成16位字符串
            function generate_noncestr($length = 16){
                $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; 
                $noncestr = "";
                for ( $i = 0; $i < $length; $i++ ){
                    $noncestr .= $chars[ mt_rand(0, strlen($chars) - 1) ]; 
                }
                return $noncestr;
            }
            $noncestr = generate_noncestr();
                
            //生成簽名
            $timestamp = time();
            $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
            $string1 = "jsapi_ticket=".$jsapi_ticket."&noncestr=".$noncestr."&timestamp=".$timestamp."&url=".$url;
            $signature = sha1($string1);
        ?>
        
        <script type="text/javascript">
            
            wx.config({
                debug: true, // 開啟調(diào)試模式,調(diào)用的所有api的返回值會在客戶端alert出來,若要查看傳入的參數(shù),可以在pc端打開,參數(shù)信息會通過log打出,僅在pc端時才會打印。
                appId: '<?php echo $appid; ?>', // 必填,公眾號的唯一標(biāo)識
                timestamp: '<?php echo $timestamp; ?>', // 必填,生成簽名的時間戳
                nonceStr: '<?php echo $noncestr; ?>', // 必填,生成簽名的隨機串
                signature: '<?php echo $signature; ?>',// 必填,簽名
                jsApiList: [
                    'onMenuShareTimeline',
                    'onMenuShareAppMessage',
                ] // 必填,需要使用的JS接口列表
            });
            
            wx.ready(function(){
                
                wx.onMenuShareTimeline({
                    title: 'test1', // 分享標(biāo)題
                    link: 'http://baidu.com', // 分享鏈接,該鏈接域名或路徑必須與當(dāng)前頁面對應(yīng)的公眾號JS安全域名一致
                    imgUrl: 'https://www.baidu.com/img/baidu_jgylogo3.gif', // 分享圖標(biāo)
                    success: function () {
                    // 用戶點擊了分享后執(zhí)行的回調(diào)函數(shù)
                        alert('成功');
                    },
                    cancel: function() {
                        alert('失敗');
                    }
                )};
                
                wx.onMenuShareAppMessage({
                    title: 'test1', // 分享標(biāo)題
                    desc: 'test baidu', // 分享描述
                    link: 'http://baidu.com', // 分享鏈接,該鏈接域名或路徑必須與當(dāng)前頁面對應(yīng)的公眾號JS安全域名一致
                    imgUrl: 'https://www.baidu.com/img/baidu_jgylogo3.gif', // 分享圖標(biāo)
                    type: 'link', // 分享類型,music、video或link,不填默認(rèn)為link
                    dataUrl: '', // 如果type是music或video,則要提供數(shù)據(jù)鏈接,默認(rèn)為空
                    success: function () {
                    // 用戶點擊了分享后執(zhí)行的回調(diào)函數(shù)
                        alert('成功');
                    }
                    cancel: function () {
                    // 用戶點擊了分享后執(zhí)行的回調(diào)函數(shù)
                        alert('失敗');
                    }
                });
            });
            
            wx.error(function(res){
                alert('error');
            });            
        </script>

    </div>
    </body>
</html>
回答
編輯回答
毀了心

signature加密字段要按照字典排序,且URL一定要是當(dāng)前頁面URL,query也必須一致

2017年4月2日 21:44
編輯回答
奧特蛋

各位,實在是抱歉,我查了之后發(fā)現(xiàn)是我的js代碼寫錯了一個地方,就是分享到朋友圈最后面的)};應(yīng)該是});,犯這種低級錯誤實在讓人懊惱,感謝各位的幫忙!

2018年1月29日 20:51
編輯回答
裸橙

我看到你的代碼中debug模式是開啟的 能否把報錯信息截圖說明一下 這樣方便診斷你的錯誤在哪兒

2017年1月23日 19:20
編輯回答
墨沫

打印一下 返回的失敗信息 一般失敗了肯定會有的

2017年8月29日 01:50
編輯回答
單眼皮

看看PHP是不是報錯了,再看看相應(yīng)的簽名字段有沒有

2017年10月12日 00:17