我們專注于高端品牌網(wǎng)站創(chuàng)意設(shè)計(jì)與開(kāi)發(fā)
我們?cè)谥谱魑⑿砰_(kāi)發(fā)時(shí),PHP如何利用微信jssdk獲取用戶地理位置信息呢?
一:先看php代碼部分:
include_once("wxpayv3/address/CommonUtil.php");
$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;
//參數(shù)小寫(xiě)
foreach ($obj as $k => $v){
$obj2[strtolower($k)] = $v;
}
//字典序排序
ksort($obj2);
//URL鍵值對(duì)拼成字符串
$bizString = $commonUtil->formatBizQueryParaMap($obj2, false);
//sha1簽名
$signature = sha1($bizString);
}
?>
二:js部分的代碼:
<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 中所帶的返回值不為空,則表示用戶選擇該返回值作為收貨地址。否則若返回空,則表示用戶取消了這一次編輯收貨地址。
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>
以上是我們深圳網(wǎng)站建設(shè)源美設(shè)計(jì)公司提供的如何實(shí)現(xiàn)php利用微信jssdk獲取用戶地理位置信息方法,看完以上的內(nèi)容您是不是對(duì)微信開(kāi)發(fā)有了一定的了解了呢?源美設(shè)計(jì)是企業(yè)微信開(kāi)發(fā)制作專家,為您提供專業(yè)的微信二次開(kāi)發(fā),營(yíng)銷型網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),企業(yè)官網(wǎng)建設(shè),響應(yīng)式網(wǎng)站建設(shè),并提供一體化的網(wǎng)站推廣解決方案,服務(wù)熱線:0755-36630155,致電客戶專線:138-2888-3821謝先生
文章引用:http://www.lt-ad.com/new/225.html
本站文章為深圳網(wǎng)站建設(shè)·源美網(wǎng)絡(luò)原創(chuàng)策劃,如有版權(quán)糾紛或者違規(guī)問(wèn)題,請(qǐng)聯(lián)系我們刪除,謝謝!
售后保障
承諾任何問(wèn)題1小時(shí)內(nèi)解決數(shù)據(jù)備份
更安全、更高效、更穩(wěn)定價(jià)格公道精準(zhǔn)
項(xiàng)目經(jīng)理精準(zhǔn)報(bào)價(jià)不弄虛作假合作無(wú)風(fēng)險(xiǎn)
重合同講信譽(yù),無(wú)效全額退款