123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <template />
- <script>
- import wx from 'weixin-js-sdk'
- import { getSignature, getLonAndLat } from "@/api/wechat";
- export default {
- name: 'WxSignature',
- data() {
- return {};
- },
- created() {},
- mounted() {},
- methods: {
- //jsSDK 签名验证
- getJsApiSign(mapParam){
- let reqData = {}
- var system = this.isIosOrAndroid()
- if (system == 1) {
- // 安卓
- reqData.url = encodeURI(window.location.href.split('#')[0]);
- } else if (system == 2) {
- // iOS
- // let url = window.location.href.split('smartParkH5')[0]+"smartParkH5/home";
- reqData.url = encodeURI(window.entryUrl?window.entryUrl:window.location.href.split('#')[0])
- }
-
- getSignature(reqData).then((res) => {
- if(res.key == 200){
- wx.config({
- "debug": false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
- "appId": 'wx7302e8b315a9a6f3', // 必填,公众号的唯一标识
- "timestamp": res.data.timestamp, // 必填,生成签名的时间戳
- "nonceStr": res.data.noncestr, // 必填,生成签名的随机串
- "signature": res.data.signature, // 必填,签名,见附录1
- "jsApiList": ['openLocation'], // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
- });
- //通过ready接口处理成功验证
- wx.ready(function () {
- //导航
- wx.openLocation({
- latitude: mapParam.latitude, // 纬度,浮点数,范围为90 ~ -90
- longitude: mapParam.longitude, // 经度,浮点数,范围为180 ~ -180。
- name: mapParam.name, // 位置名
- address: mapParam.address, // 地址详情说明
- scale: mapParam.scale, // 地图缩放级别,整型值,范围从1~28。默认为最大
- infoUrl: mapParam.infoUrl // 在查看位置界面底部显示的超链接,可点击跳转
- });
- })
- wx.error(function(res){
- });
- }
- });
- },
- // 导航
- navigation(address){
- let data = {
- address : address
- }
- getLonAndLat(data).then((res) => {
- if(res.key == 200){
- if(res.data.status == 0){
- let mapParam = {
- name: res.data.result.title,
- latitude: res.data.result.location.lat,
- longitude: res.data.result.location.lng,
- scale: 28,
- address: data.address,
- infoUrl: '#'
- }
- this.getJsApiSign(mapParam);
- }
- }
- });
- },
- //判断是iOS还是android
- isIosOrAndroid() {
- var isAndroid = navigator.userAgent.indexOf('Android') > -1 || navigator.userAgent.indexOf('Adr') > -1; //android终端
- var isIos = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
- if(isAndroid){
- // 相关逻辑代码
- return 1
- }
- if(isIos){
- // 相关逻辑代码
- return 2
- }
- return 0;
- }
- },
- };
- </script>
|