updateTimelineShareData:fail, the permission value is offline verifying 错误提示

前提:

1、绑定js安全域名

2、公众号必须是认证的,才有权限

附上已经测试好代码

页面引用这段代码

(function(){if(window.navigator.userAgent.match(/MicroMessenger/i)){document.write("<scr"+'ipt type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js'+'"></scr'+"ipt>");document.write("<scr"+'ipt type="text/javascript" src="/jweixin.php'+'"></scr'+"ipt>")};})();

jweixin.php 文件如下:

$appId = 'wx';
$appSecret = '';

$timestamp = time();
$nonceStr = createNonceStr();
$jsapiTicket = getJsApiTicket();
$url = isset($_GET['url'])?urldecode($_GET['url']):$_SERVER['HTTP_REFERER'];
$signature = sha1("jsapi_ticket={$jsapiTicket}&noncestr={$nonceStr}&timestamp={$timestamp}&url={$url}");

 

echo '(function(){';
    echo 'var wx_share=wx_share||{imgUrl:';
    echo isset($_GET['imgUrl'])?$_GET['imgUrl']:'document.getElementById("wx_share_img")?document.getElementById("wx_share_img").src:"http://jc.qcqhn.com/images/weixin.jpg"';
    echo ',title:';
    echo isset($_GET['title'])?$_GET['title']:'document.title';
    echo ',desc:';
    echo isset($_GET['desc'])?$_GET['desc']:'document.getElementsByTagName("meta")["description"].content';
    echo ',link:"';
    echo $url;
    echo '",success:function (){}};';
    echo 'wx.config({debug:false,appId:"';
    echo $appId;
    echo '",timestamp:"';
    echo $timestamp;
    echo '",nonceStr:"';
    echo $nonceStr;
    echo '",signature: "';
    echo $signature;
    echo '",jsApiList:["checkJsApi","onMenuShareTimeline","onMenuShareAppMessage","updateTimelineShareData","updateAppMessageShareData","onMenuShareWeibo"]});'; 
    echo 'wx.ready(function (){wx.onMenuShareTimeline(wx_share);wx.onMenuShareAppMessage(wx_share);wx.updateTimelineShareData(wx_share);wx.onMenuShareWeibo(wx_share);wx.updateAppMessageShareData(wx_share);});';
    echo '})();';

function createNonceStr($length = 16) {
    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $chars_end = strlen($chars) - 1;
    $str = '';
    for ($i = 0; $i < $length; $i++) {
        $str .= substr($chars, mt_rand(0, $chars_end), 1);
    }
    return $str;
}

function getJsApiTicket($cache='jsapi_ticket.php') {
    global $appId, $appSecret;
    $data = json_decode(file_get_contents($cache));
    if ($data->expire_time < time()) {
        $accessToken = getAccessToken();
        // 如果是企业号用以下 URL 获取 ticket
        // $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
        $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token={$accessToken}";
        $res = json_decode(httpGet($url));
        $ticket = $res->ticket;
        if ($ticket) {
            $data->expire_time = time() + 7000;
            $data->jsapi_ticket = $ticket;
            file_put_contents($cache, json_encode($data));
        }else{
            file_put_contents('jsapi_ticket_log.php', var_export($res,true));
        }
    } else {
        $ticket = $data->jsapi_ticket;
    }
    return $ticket;
}

function getAccessToken($cache='access_token.php') {
    global $appId, $appSecret;
    $data = json_decode(file_get_contents($cache));
    if ($data->expire_time < time()) {
        // 如果是企业号用以下URL获取access_token
        // $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$appSecret}";
        $res = json_decode(httpGet($url));
        $access_token = $res->access_token;
        if ($access_token) {
            $data->expire_time = time() + 7000;
            $data->access_token = $access_token;
            file_put_contents($cache, json_encode($data));
        }else{
            file_put_contents('access_token_log.php', var_export($res,true));
        }
    } else {
        $access_token = $data->access_token;
    }
    return $access_token;
}

function httpGet($url) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_TIMEOUT, 500);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true);
    curl_setopt($curl, CURLOPT_URL, $url);
    $res = curl_exec($curl);
    curl_close($curl);
    return $res;
}
//代码无误

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值