我們在制作(zuò)微信開發時,PHP如(rú)何利用微信jssdk獲取用戶地理(lǐ)位置信息呢(ne)?
一:先看(kàn)php代碼部分(fēn):
include_once("error404.html");
$appid = WEIXIN_APPID;
$appsecret = WEIXIN_APPSECRET;
if (!isset($_GET["code"])){
$weixin=spClass('Spweixin');
$redirect_url = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$jumpurl = $weixin->oauth2_authorize($redirect_url, "snsapi_base", "123");
Header("Location: $jumpurl");
}else{
$code = $_GET["code"];
$access_token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code";
$access_token_json = file_get_contents($access_token_url);
$access_token_array = json_decode($access_token_json, true);
$access_token = $access_token_array['access_token'];
$commonUtil = new CommonUtil();
$noncestr = $commonUtil->create_noncestr();
$timestamp = time();
$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$obj['appId'] = $appid;
$obj['url'] = $url;
$obj['timestamp'] = $timestamp;
$obj['noncestr'] = $noncestr;
$obj['accessToken'] = $access_token;
//參數小寫
foreach ($obj as $k => $v){
$obj2[strtolower($k)] = $v;
}
//字典序排序
ksort($obj2);
//URL鍵值對拼成字符串
$bizString = $commonUtil->formatBizQueryParaMap($obj2, false);
//sha1簽名
$signature = sha1($bizString);
}
?>
二:js部分(fēn)的代碼:
<script src="/skin/js/jquery-1.7.2.js"></script>
<script language="javascript">
function callpay()
{
if (typeof WeixinJSBridge == 'undefined'){
//alert('WeixinJSBridge undefined');
setTimeout('callpay()',10);
return false;
}else{
WeixinJSBridge.invoke('editAddress',{
"appId" : "<?php echo $appid;?>",
"scope" : "jsapi_address",
"signType" : "sha1",
"addrSign" : "<?php echo $signature;?>",
"timeStamp" : "<?php echo $timestamp;?>",
"nonceStr" : "<?php echo $noncestr;?>",
},function(res){
// alert(res.err_msg);
//若res 中所帶的返回值不爲空,則表示用戶選擇該返回值作(zuò)爲收貨地址。否則若返回空,則表示用戶取消了這一次編輯收貨地址。
if (res.userName=="" || typeof(res.userName)=="undefined") {
return false;
} else {
$("#realname").val(res.userName);
$("#mob").val(res.telNumber);
$("#city11").val(res.proviceFirstStageName);
$("#city22").val(res.addressCitySecondStageName);
$("#city33").val(res.addressCountiesThirdStageName);
$("#address").val(res.addressDetailInfo);
$("#hang1").html(res.userName+' '+res.telNumber);
$("#hang2").html(res.proviceFirstStageName+' '+res.addressCitySecondStageName+' '+res.addressCountiesThirdStageName);
$("#hang3").html(res.addressDetailInfo);
$.get('index.php?c=f_pro&a=saveaddress','realname='+encodeURI(res.userName)+'&mob='+encodeURI(res.telNumber)+'&city11='+encodeURI(res.proviceFirstStageName)+'&city22='+encodeURI(res.addressCitySecondStageName)+'&city33='+encodeURI(res.addressCountiesThirdStageName)+'&address='+encodeURI(res.addressDetailInfo),function (msg) {});
}
});
}
}
<? if ($addr['address']=="") {?>
window.onload=callpay();
<? }?>
</script>
以上是我們深圳網站(zhàn)建設源美設計(jì)公司提供的如(rú)何實現php利用微信jssdk獲取用戶地理(lǐ)位置信息方法,看(kàn)完以上的内容您是不是對微信開發有了一定的了解了呢(ne)?源美設計(jì)是企業微信開發制作(zuò)專家,爲您提供專業的微信二次開發,營銷型網站(zhàn)建設,品牌網站(zhàn)建設,企業官網建設,響應式網站(zhàn)建設,并提供一體(tǐ)化的網站(zhàn)推廣解決方案,服務熱(rè)線:0755-36630155,緻電客戶專線:138-2888-3821謝先生(shēng)
本站(zhàn)文章(zhāng)爲深圳網站(zhàn)建設·源美網絡原創策劃,如(rú)有版權糾紛或者違規問(wèn)題,請(qǐng)聯系我們删除,謝謝!
售後保障
承諾任何問(wèn)題1小時内解決數據備份
更安全、更高效、更穩定價格公道精準
項目經理(lǐ)精準報價不弄虛作(zuò)假合作(zuò)無風(fēng)險
重合同講信譽,無效全額退款