nonceStr : data.noncestr,//生成签名的随机字符串
signature : data.signature,//签名
jsApiList : [//需要调用的JS接口列表
‘chooseImage’, ‘uploadImage’, ‘downloadImage’,
‘previewImage’, ‘openLocation’, ‘getLocation’,
‘scanQRCode’, ‘checkJsApi’, ‘onMenuShareTimeline’,
‘onMenuShareAppMessage’, ‘onMenuShareQQ’,
‘onMenuShareWeibo’, ‘onMenuShareQZone’
]
});
},
error : function(xhr, status, error) {
//alert(status);
//alert(xhr.responseText);
}
});
wx.ready(function() {
if (zt == ‘0’) {
wx.getLocation({
type : ‘wgs84’, // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入’gcj02’
success : function(res) {
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitude = res.longitude; // 经度,浮点数, 《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】 范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
$.ajax({
type : “post”,
url : “vip_wxsdk_dingwei”,//获取经度,纬度
data : {
“latitude” : latitude,
“longitude” : longitude
},
dataType : “json”,
success : function(data) {
if (data = “success”) {
zt = 1;
}
}
});
}
});
}
});
});
(3.1) vip_wxsdk_config方法:
@ResponseBody
@RequestMapping(“vip_wxsdk_config”)
public Map
wx = wxService.selectByPrimaryKey(1);
// 1、获取AccessToken
String jsapi_ticket = “”;
String accessToken = “”;
if (session.getAttribute(Constants.jsapi_ticket) != null) {
jsapi_ticket = session.getAttribute(Constants.jsapi_ticket).toString();
} else {
accessToken = CommonUtil.getToken(wx.getWxAppid(), wx.getWxAppsecret()).getAccessToken();
// 2、获取Ticket
jsapi_ticket = CommonUtil.getTicket(accessToken);
session.setAttribute(Constants.jsapi_ticket, jsapi_ticket);
}
// 3、时间戳和随机字符串
String noncestr = AdvancedUtil.getNonceStr();
String timestamp = Sha1Util.getTimeStamp();
// System.out.println(“accessToken:”+accessToken+“\njsapi_ticket:”+jsapi_ticket+“\n时间戳:”+timestamp+“\n随机字符串:”+noncestr);
// 5、将参数排序并拼接字符串
String str = “jsapi_ticket=” + jsapi_ticket + “&noncestr=” + noncestr + “×tamp=” + timestamp + “&url=” + url;
// 6、将字符串进行sha1加密
String signature = SHAUtils.SHA1(str);
map = new HashMap
map.put(“appid”, wx.getWxAppid());
map.put(“accessToken”, accessToken);
map.put(“jsapi_ticket”, jsapi_ticket);
map.put(“timestamp”, timestamp);
map.put(“noncestr”, noncestr);
map.put(“signature”, signature);
return map;
}
(3.2) vip_wxsdk_dingwei方法:
@ResponseBody
@RequestMapping(“vip_wxsdk_dingwei”)
public Map
if (latitude != null && longitude != null) {
session.setAttribute(“latitude”, latitude);
session.setAttribute(“longitude”, longitude);
this.prompt = “success”;
} else {
this.prompt = “error”;
}
return map;
}
4.在我们要跳转的页面加上调启的js: