网站地图    收藏   

主页 > 后端 > 微信开发 >

weixin sdk - 微信公众平台开发:微信公众号开发平

来源:自学PHP网    时间:2015-04-14 12:58 作者: 阅读:

[导读] ?php$appid= wx257*****a2385 ; 此处填写认证的公众号 AppID(应用ID)$appsecret= 9164527******ff0c588e ; 此处填写认证的公众号AppSecret(应用密钥)$protocol = (!empty($_SERVER[ HTTPS ])...

<?php
$appid="wx257*****a2385"; //此处填写认证的公众号 AppID(应用ID)
$appsecret="9164527******ff0c588e"; //此处填写认证的公众号AppSecret(应用密钥)
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$share_title="大中华培训基地微信自动导航";
$share_desc="不知道怎么去基地?不要怕,我带您去!";
$share_url=$url;
$share_img="http://static.4vtk.com/apollo.png";




//第一种方法
$url=urlencode($url);
$api_url = "http://api.4vtk.com/wx_js_sdk.php?appid=$appid&appsecret=$appsecret&url=$url";
$result =file_get_contents($api_url);
$jsoninfo = json_decode($result, true);
$nonceStr=$jsoninfo["nonceStr"];
$timestamp=$jsoninfo["timestamp"];
$signature=$jsoninfo["signature"];

//第二种方法
/*
$api_url="http://api.4vtk.com/wx_js_sdk.php?appid=$appid&appsecret=$appsecret";
$result =file_get_contents($api_url);
$jsoninfo = json_decode($result, true);
$jsapiTicket=$jsoninfo["jsapiTicket"];
$timestamp = time();
$nonceStr =createNonceStr();
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
$signature = sha1($string);
function createNonceStr($length = 16) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
*/

?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0" />
<link rel="stylesheet" type="text/css" href="http://demo.open.weixin.qq.com/jssdk/css/style.css"/>
<title>大中华培训基地微信自动导航</title>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
wx.config({
debug: true,
appId: '<?php echo $appid;?>',
timestamp: <?php echo $timestamp;?>,
nonceStr: '<?php echo $nonceStr;?>',
signature: '<?php echo $signature;?>',
jsApiList: [
'openLocation',
'getLocation',
'onMenuShareTimeline',
'onMenuShareQQ',
'onMenuShareAppMessage'

]
});


wx.ready(function () {
wx.onMenuShareAppMessage({
title: "<?php echo $share_title ?>",
desc: "<?php echo $share_desc ?>",
link: "<?php echo $share_url ?>",
imgUrl: "<?php echo $share_img ?>",

});

wx.onMenuShareTimeline({
title: "<?php echo $share_title ?>",
link: "<?php echo $share_url ?>",
imgUrl: "<?php echo $share_img ?>",
});

wx.onMenuShareQQ({
title: "<?php echo $share_title ?>",
desc: "<?php echo $share_desc ?>",
link: "<?php echo $share_url ?>",
imgUrl: "<?php echo $share_img ?>",
});
document.querySelector('#openLocation').onclick = function () {
wx.openLocation({
// latitude: 30.4147828480,
// longitude: 114.3787999569,
latitude: 30.4149328294,
longitude: 114.3787499569,
name: '武汉国灸科技开发有限公司',
address: '湖北省武汉市江夏区庙山大道特1号医药产业园',
scale: 14,
infoUrl: 'http://weixin.qq.com'
});
};

document.querySelector('#getLocation').onclick = function () {
wx.getLocation({
success: function (res) {
alert(JSON.stringify(res));
},
cancel: function (res) {
alert('用户拒绝授权获取地理位置');
}
});
};

});

</script>
</head>
<body>
<!-- <button class="btn btn_primary" style="margin-top:100px" id="getLocation">获取经纬度</button> -->
<button class="btn btn_primary" style="margin-top:100px" id="openLocation">
导航
</button>
</body>
</body>
</html>

 


自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论