- <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <!-- www.vxzsk.com原創 -->
- <title>微信jsapi測試-V型知識庫</title>
- <meta name="viewport" content="width=320.1,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
- <script src="http://res.wx.qq.com/open/js/jweixin-1.1.0.js"> </script>
- <script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
- </head>
- <body>
- <center><h3>歡迎來到微信jsapi測試界面-V型知識庫</h3></center>
- <p>基礎接口之判斷當前客戶端是否支持指定的js接口</p>
- <input type="button" value="checkJSAPI" id="checkJsApi"><br>
- <span class="desc" style="color: red">地理位置接口-使用微信內置地圖查看位置接口</span><br>
- <button class="btn btn_primary" id="openLocation">openLocation</button><br>
- <span class="desc" style="color: red">地理位置接口-獲取地理位置接口</span><br>
- <button class="btn btn_primary" id="getLocation">getLocation</button><br>
- <div style="display: none;">
- <span class="desc" style="color: red">獲取網絡狀態接口</span><br>
- <button class="btn btn_primary" id="getNetworkType">getNetworkType</button><br>
- <h3 id="menu-image">圖像接口</h3>
- <span class="desc">拍照或從手機相冊中選圖接口</span><br>
- <button class="btn btn_primary" id="chooseImage">chooseImage</button><br>
- <span class="desc">預覽圖片接口</span><br>
- <button class="btn btn_primary" id="previewImage">previewImage</button><br>
- <span class="desc">上傳圖片接口</span><br>
- <button class="btn btn_primary" id="uploadImage">uploadImage</button><br>
- <span class="desc">下載圖片接口</span><br>
- <button class="btn btn_primary" id="downloadImage">downloadImage</button><br>
- <br>
- 顯示圖片<img alt="" src="" id="faceImg">
- </div>
- <script type="text/javascript">
- wx.config({
- debug: true, // 開啓調試模式,調用的所有api的返回值會在客戶端alert出來,若要查看傳入的參數,可以在pc端打開,參數信息會通過log打出,僅在pc端時纔會打印。
- appId: '${appId}', // 必填,公衆號的唯一標識
- timestamp: '${ timestamp}' , // 必填,生成簽名的時間戳
- nonceStr: '${ nonceStr}', // 必填,生成簽名的隨機串
- signature: '${ signature}',// 必填,簽名,見附錄1
- jsApiList: ['checkJsApi',
- 'chooseImage',
- 'previewImage',
- 'uploadImage',
- 'downloadImage',
- 'getNetworkType',//網絡狀態接口
- 'openLocation',//使用微信內置地圖查看地理位置接口
- 'getLocation' //獲取地理位置接口
- ] // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2
- });
- wx.ready(function(){
- // 5 圖片接口
- // 5.1 拍照、本地選圖
- var images = {
- localId: [],
- serverId: []
- };
- document.querySelector('#chooseImage').onclick = function () {
- wx.chooseImage({
- success: function (res) {
- images.localId = res.localIds;
- alert('已選擇 ' + res.localIds.length + ' 張圖片');
- $("#faceImg").attr("src", res.localIds[0]);//顯示圖片到頁面上
- }
- });
- };
- // 5.2 圖片預覽
- document.querySelector('#previewImage').onclick = function () {
- wx.previewImage({
- current: 'http://www.vxzsk.com/upload//bf04c9b5-5699-421d-900e-3b68bbe58a8920160816.jpg',
- urls: [
- 'http://www.vxzsk.com/upload//bf04c9b5-5699-421d-900e-3b68bbe58a8920160816.jpg',
- 'http://www.vxzsk.com/upload//bf04c9b5-5699-421d-900e-3b68bbe58a8920160816.jpg',
- 'http://www.vxzsk.com/upload//bf04c9b5-5699-421d-900e-3b68bbe58a8920160816.jpg'
- ]
- });
- };
- // 5.3 上傳圖片
- document.querySelector('#uploadImage').onclick = function () {
- if (images.localId.length == 0) {
- alert('請先使用 chooseImage 接口選擇圖片');
- return;
- }
- var i = 0, length = images.localId.length;
- images.serverId = [];
- function upload() {
- wx.uploadImage({
- localId: images.localId[i],
- success: function (res) {
- i++;
- //alert('已上傳:' + i + '/' + length);
- images.serverId.push(res.serverId);
- if (i < length) {
- upload();
- }
- },
- fail: function (res) {
- alert(JSON.stringify(res));
- }
- });
- }
- upload();
- };
- // 5.4 下載圖片
- document.querySelector('#downloadImage').onclick = function () {
- if (images.serverId.length === 0) {
- alert('請先使用 uploadImage 上傳圖片');
- return;
- }
- var i = 0, length = images.serverId.length;
- images.localId = [];
- function download() {
- wx.downloadImage({
- serverId: images.serverId[i],
- success: function (res) {
- i++;
- alert('已下載:' + i + '/' + length);
- images.localId.push(res.localId);
- if (i < length) {
- download();
- }
- }
- });
- }
- download();
- };
- // 6 設備信息接口
- // 6.1 獲取當前網絡狀態
- document.querySelector('#getNetworkType').onclick = function () {
- wx.getNetworkType({
- success: function (res) {
- alert(res.networkType);
- },
- fail: function (res) {
- alert(JSON.stringify(res));
- }
- });
- };
- //網絡接口結束
- // 7 地理位置接口 開始
- // 7.1 查看地理位置
- document.querySelector('#openLocation').onclick = function () {
- wx.openLocation({
- latitude: 23.099994,
- longitude: 113.324520,
- name: 'TIT 創意園',
- address: '廣州市海珠區新港中路 397 號',
- scale: 14,
- infoUrl: 'http://weixin.qq.com'
- });
- };
- // 7.2 獲取當前地理位置
- document.querySelector('#getLocation').onclick = function () {
- wx.getLocation({
- success: function (res) {
- alert(JSON.stringify(res));
- },
- cancel: function (res) {
- alert('用戶拒絕授權獲取地理位置');
- }
- });
- };
- // 7 地理位置接口 結束
- });
- //初始化jsapi接口 狀態
- wx.error(function (res) {
- alert("調用微信jsapi返回的狀態:"+res.errMsg);
- });
- </script>
- </body>
- </html>
微信獲取用戶地理位置信息-微信jsapi接口
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.