按照教程做了配置,比較直接選擇直接獲取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."×tamp=".$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>
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團,成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。