当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 微信jssdk获取收货地址

微信jssdk获取收货地址

2020年07月17日  | 移动技术网IT编程  | 我要评论
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
<body>
  <input type="button" value="获取微信收货地址" id="getAddress" style="cursor:pointer;width:50rem;height:20rem;font-size:5rem;">
</body>
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>

<script type="text/javascript">
$(function(){
    $('#getAddress').on("click", function(e){
        wx.config({
          debug: false,
          appId: "<?php echo $signPackage['appId'];?>",
          timestamp: <?php echo $signPackage['timestamp'];?>,
          nonceStr: "<?php echo $signPackage['nonceStr'];?>",
          signature: "<?php echo $signPackage['signature'];?>",
          jsApiList: [
            // 所有要调用的 API 都要加到这个列表中
            'checkJsApi'
          ]
        });
        wx.ready(function () {
          // 在这里调用 API
          wx.checkJsApi({
            jsApiList: ['openAddress'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
            success: function(res) {
              //console.log(res);
            // 以键值对的形式返回,可用的api值true,不可用为false
            // 如:{"checkResult":{"openAddress":true},"errMsg":"checkJsApi:ok"}
            }
          });

          wx.openAddress({
            success: function (res) {
              var userName = res.userName; // 收货人姓名
              var postalCode = res.postalCode; // 邮编
              var provinceName = res.provinceName; // 国标收货地址第一级地址(省)
              var cityName = res.cityName; // 国标收货地址第二级地址(市)
              var countryName = res.countryName; // 国标收货地址第三级地址(国家)
              var detailInfo = res.detailInfo; // 详细收货地址信息
              var nationalCode = res.nationalCode; // 收货地址国家码
              var telNumber = res.telNumber; // 收货人手机号码
              
              alert(userName + ' ' + postalCode + ' ' + provinceName + ' ' + cityName + ' ' + countryName + ' ' + detailInfo + ' ' + nationalCode + ' ' + telNumber);
              console.log(userName + ' ' + postalCode + ' ' + provinceName + ' ' + cityName + ' ' + countryName + ' ' + detailInfo + ' ' + nationalCode + ' ' + telNumber);
            }
          });
        });
    });
})
</script>
</html>

 

本文地址:https://blog.csdn.net/lvchengming268268/article/details/107383882

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网