分享到:

微信开发:php如何利用微信jssdk获取用户地理位置信息

日期:2017-03-31 11:31:00     阅读:429     文章来源:源美网络     标签:微信开发,微信移动开发,深圳网站建设,深圳网站制作

我们在制作微信开发时,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;


//参数小写

foreach ($obj as $k => $v){

    $obj2[strtolower($k)] = $v;

}

//字典序排序

ksort($obj2);

//URL键值对拼成字符串

$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+'&nbsp;&nbsp;'+res.telNumber);

$("#hang2").html(res.proviceFirstStageName+'&nbsp;&nbsp;'+res.addressCitySecondStageName+'&nbsp;&nbsp;'+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>


以上是我们深圳网站建设源美设计公司提供的如何实现php利用微信jssdk获取用户地理位置信息方法,看完以上的内容您是不是对微信开发有了一定的了解了呢?源美设计是企业微信开发制作专家,为您提供专业的微信二次开发营销型网站建设品牌网站建设企业官网建设响应式网站建设,并提供一体化的网站推广解决方案,服务热线:0755-36630155,致电客户专线:138-2888-3821谢先生



文章引用:http://www.szymweb.com/new/225.html

本站文章为深圳网站建设·源美网络原创策划,如有版权纠纷或者违规问题,请联系我们删除,谢谢!

上一篇: 微信开发:php如何利用微信jssdk实现微信支付接口

下一篇: 通过shell脚本实现网站文件及数据库备份

返回列表
最新案例
OUR ADVANTAGE WORKS

售后保障

承诺任何问题1小时内解决

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款