效果图
1.先引入sdk 文件
$.ajax({
type: "get",
url: baseUrl + "api/wechat/Pubaccount/jssdk?url=" + linkurl,//请求接口,获取授权
success:function(data){
let res = data;
jWeixin.config({
debug: false,
appId: res.appId,
timestamp: res.timestamp,
nonceStr: res.nonceStr,
signature: res.signature,
jsApiList: ['openAddress']
});
},
error: function(data) {
alert("连接失败!");
}
})
获取微信地址信息
$(document).on("click",".wechat_address",function(){
jWeixin.openAddress({
success: function (res) {
//把返回的信息填入到页面
$('#c-name').val(res.userName);
$('#c-mobiles').val(res.telNumber);
$('#location').val(res.provinceName+res.cityName+res.countryName);
$('#detail').val(res.detailInfo);
},
cancel: function (errMsg) {
console.log(errMsg);
}
});
})