<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>微信开发模板</title> | |
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> | |
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> | |
<script> | |
var appId = "", | |
appsecret = ""; | |
wx.config({ | |
debug: false,//开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 | |
appId: '',//必填公众号的唯一标识 | |
timestamp: 1464227533,//必填,生成签名的时间戳 | |
nonceStr: '',//必填生成签名的随机串 | |
signature: '',//必填,签名 | |
jsApiList: ["onMenuShareTimeline","onMenuShareAppMessage","onMenuShareQQ","onMenuShareWeibo","onMenuShareQZone","startRecord","stopRecord","onVoiceRecordEnd","playVoice","pauseVoice","stopVoice","onVoicePlayEnd","uploadVoice","downloadVoice","chooseImage","previewImage","uploadImage","downloadImage","translateVoice","getNetworkType","openLocation","getLocation","hideOptionMenu","showOptionMenu","hideMenuItems","showMenuItems","hideAllNonBaseMenuItem","showAllNonBaseMenuItem","closeWindow","scanQRCode","chooseWXPay","openProductSpecificView"] | |
}); | |
wx.ready(function () { | |
var images = { | |
localId: [], | |
serverId: [] | |
}; | |
wx.checkJsApi({ | |
jsApiList: ["onMenuShareTimeline","onMenuShareAppMessage","onMenuShareQQ","onMenuShareWeibo","onMenuShareQZone","startRecord","stopRecord","onVoiceRecordEnd","playVoice","pauseVoice","stopVoice","onVoicePlayEnd","uploadVoice","downloadVoice","chooseImage","previewImage","uploadImage","downloadImage","translateVoice","getNetworkType","openLocation","getLocation","hideOptionMenu","showOptionMenu","hideMenuItems","showMenuItems","hideAllNonBaseMenuItem","showAllNonBaseMenuItem","closeWindow","scanQRCode","chooseWXPay","openProductSpecificView"] | |
}); | |
var shareApp = { | |
title: '标题', | |
desc: '描述', | |
link: 'http://www.qq.com', | |
imgUrl: 'logo.png', | |
trigger: function (res) { | |
alert('用户点击发送给朋友'); | |
}, | |
success: function (res) { | |
alert('已分享'); | |
}, | |
cancel: function (res) { | |
alert('已取消'); | |
}, | |
fail: function (res) { | |
alert(JSON.stringify(res)); | |
} | |
}; | |
var shareTimeLine = { | |
title: '标题', | |
link: 'http://www.qq.com', | |
imgUrl: 'logo.png', | |
trigger: function (res) { | |
alert('用户点击发送给朋友'); | |
}, | |
success: function (res) { | |
alert('已分享'); | |
}, | |
cancel: function (res) { | |
alert('已取消'); | |
}, | |
fail: function (res) { | |
alert(JSON.stringify(res)); | |
} | |
}; | |
wx.onMenuShareWeibo(shareApp); | |
wx.onMenuShareQZone(shareApp); | |
//分享朋友 | |
wx.onMenuShareAppMessage(shareApp); | |
//分享朋友圈 | |
wx.onMenuShareTimeline(shareTimeLine); | |
//隐藏右上角菜单 | |
wx.hideOptionMenu(); | |
//显示右上角菜单 | |
wx.showOptionMenu(); | |
//关闭当前网页窗口 | |
//wx.closeWindow(); | |
//隐藏所有非基础按钮 | |
//wx.hideAllNonBaseMenuItem(); | |
//显示所有功能按钮接口 | |
//wx.showAllNonBaseMenuItem(); | |
wx.getNetworkType({ | |
success: function (res) { | |
var networkType = res.networkType; // 返回网络类型2g,3g,4g,wifi | |
alert(networkType) | |
} | |
}); | |
//拍照或从手机相册中选图 | |
var localIds,serverId; | |
$("#button1").click(function(){ | |
wx.chooseImage({ | |
count: 1, // 默认9 | |
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 | |
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 | |
success: function (res) { | |
localIds = res.localIds; | |
$("图片").attr("src",localIds); | |
} | |
}); | |
}) | |
//预览图片 | |
$("#button2").click(function(){ | |
wx.previewImage({ | |
current: '', // 当前显示图片的http链接 | |
urls: [] // 需要预览的图片http链接列表 | |
}); | |
}); | |
//上传图片到服务器 | |
$("#button3").click(function(){ | |
wx.uploadImage({ | |
localId: localIds, // 需要上传的图片的本地ID,由chooseImage接口获得 | |
isShowProgressTips: 1, // 默认为1,显示进度提示 | |
success: function (res) { | |
serverId = res.serverId; // 返回图片的服务器端ID | |
} | |
}); | |
}); | |
//根据已有serverId下载图片 | |
$("#button3").click(function(){ | |
wx.downloadImage({ | |
serverId: serverId, // 需要下载的图片的服务器端ID,由uploadImage接口获得 | |
isShowProgressTips: 1, // 默认为1,显示进度提示 | |
success: function (res) { | |
var localId = res.localId; // 返回图片下载后的本地ID | |
$("图片").attr("src",localIds) | |
} | |
}); | |
}); | |
//调取录音 | |
var localId2,serverId2; | |
$("#button4").click(function(){ | |
wx.startRecord(); | |
}); | |
//停止录音 | |
$("#button5").click(function(){ | |
wx.stopRecord({ | |
success: function (res) { | |
localId2 = res.localId; | |
} | |
}); | |
}); | |
//监听录音自动停止 | |
wx.onVoiceRecordEnd({ | |
// 录音时间超过一分钟没有停止 | |
complete: function (res) { | |
localId2 = res.localId; | |
} | |
}); | |
//播放语音 | |
$("#button6").click(function(){ | |
wx.playVoice({ | |
localId: localId2 // 需要播放的音频的本地ID,由stopRecord接口获得 | |
}); | |
}); | |
//暂停播放 | |
$("#button7").click(function(){ | |
wx.pauseVoice({ | |
localId: localId2 // 需要暂停的音频的本地ID,由stopRecord接口获得 | |
}); | |
}) | |
//停止播放 | |
$("#button8").click(function(){ | |
wx.stopVoice({ | |
localId: localId2 // 需要停止的音频的本地ID,由stopRecord接口获得 | |
}); | |
}); | |
//监听语音播放完 | |
wx.onVoicePlayEnd({ | |
success: function (res) { | |
localId2 = res.localId; // 返回音频的本地ID | |
} | |
}); | |
//上传语音 | |
$("#button9").click(function(){ | |
wx.uploadVoice({ | |
localId: localId2, // 需要上传的音频的本地ID,由stopRecord接口获得 | |
isShowProgressTips: 1, // 默认为1,显示进度提示 | |
success: function (res) { | |
serverId2 = res.serverId; // 返回音频的服务器端ID | |
} | |
}); | |
}); | |
//下载语音 | |
$("#button10").click(function(){ | |
wx.downloadVoice({ | |
serverId: serverId2, // 需要下载的音频的服务器端ID,由uploadVoice接口获得 | |
isShowProgressTips: 1, // 默认为1,显示进度提示 | |
success: function (res) { | |
localId2 = res.localId; // 返回音频的本地ID | |
} | |
}); | |
}); | |
//语音识别文字 | |
$("#button11").click(function(){ | |
wx.translateVoice({ | |
localId: localId2, // 需要识别的音频的本地Id,由录音相关接口获得 | |
isShowProgressTips: 1, // 默认为1,显示进度提示 | |
success: function (res) { | |
alert(res.translateResult); // 语音识别的结果 | |
} | |
}); | |
}); | |
//使用微信内置地图查看位置 | |
$("#button12").click(function(){ | |
wx.openLocation({ | |
latitude: 0, // 纬度,浮点数,范围为90 ~ -90 | |
longitude: 0, // 经度,浮点数,范围为180 ~ -180。 | |
name: '', // 位置名 | |
address: '', // 地址详情说明 | |
scale: 1, // 地图缩放级别,整形值,范围从1~28。默认为最大 | |
infoUrl: '' // 在查看位置界面底部显示的超链接,可点击跳转 | |
}); | |
}); | |
//获取地理位置接口 | |
$("#button13").click(function(){ | |
wx.getLocation({ | |
type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' | |
success: function (res) { | |
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90 | |
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。 | |
var speed = res.speed; // 速度,以米/每秒计 | |
var accuracy = res.accuracy; // 位置精度 | |
} | |
}); | |
}); | |
//调起微信扫一扫 | |
$("#button14").click(function(){ | |
wx.scanQRCode({ | |
needResult: 0, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果, | |
scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有 | |
success: function (res) { | |
var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果 | |
} | |
}); | |
}); | |
}); | |
wx.error(function(res){ | |
var str = res.errMsg; | |
var reg = /invalid signature$/; | |
var r = str.match(reg); | |
if(r !== null) { | |
alert(r) | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<button id="button1"></button> | |
<button id="button2"></button> | |
<button id="button3"></button> | |
<button id="button4"></button> | |
<button id="button5"></button> | |
<button id="button6"></button> | |
<button id="button7"></button> | |
<button id="button8"></button> | |
<button id="button9"></button> | |
<button id="button10"></button> | |
<button id="button11"></button> | |
<button id="button12"></button> | |
<button id="button13"></button> | |
</body> | |
</html>
$.get("http://www.mm.gushen178.com/php/getwxdata.php",function(data){ wx.onMenuShareTimeline({
title:
"<?=$act['act_name']?>"
,
// 分享标题
success:
function
() {
// 用户确认分享后执行的回调函数
},
cancel:
function
() {
// 用户取消分享后执行的回调函数
}
});
}
|
微信开发模板
最新推荐文章于 2024-04-17 09:45:55 发布