window.onload = function(){
var url = location.href.split("#")[0];
sendPost("${ctxpath}/weixin/daily-management/autograph", '{"url":"' + url + '","wechat":"${wechat}"}', function(data){
var json = JSON.parse(data);
if(json.status){
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: json.appId, // 必填,公众号的唯一标识
timestamp: json.timestamp, // 必填,生成签名的时间戳
nonceStr: json.noncestr, // 必填,生成签名的随机串
signature: json.signature,// 必填,签名,见附录1
jsApiList: ["scanQRCode","chooseImage","uploadImage"] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
}
});
}
//调用微信扫一扫,扫描设备二维码,根据扫描结果异步请求此设备需要检查的项目
var scanCode = function(){
wx.ready(function(){
wx.scanQRCode({
needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
scanType: ["qrCode"], // 可以指定扫二维码还是一维码,默认二者都有
success: function (res) {
var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
document.getElementById("inspectionItem").className = "wechat-content";
}
});
});
}
//调用微信选择图片
var chooseImage = function(){
wx.ready(function(){
wx.chooseImage({
count: 1,
sizeType:['sizeType'],
sourceType:['album'],
success:function(res){
var localIds = res.localIds;
alert("localIds=" + localIds);
uploadImage(localIds);
}
});
});
}
//调用微信上传图片
var uploadImage = function(localIds){
wx.uploadImage({
localId: localIds.toString(),
isShowProgressTips: 1,
success: function(res){
var serverId = res.serverId;
},
fail:function(error){
//mui.alert(JSON.stringify(error));
mui.alert("上传图片失败", "提示", "确定", null);
}
});
var url = location.href.split("#")[0];
sendPost("${ctxpath}/weixin/daily-management/autograph", '{"url":"' + url + '","wechat":"${wechat}"}', function(data){
var json = JSON.parse(data);
if(json.status){
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: json.appId, // 必填,公众号的唯一标识
timestamp: json.timestamp, // 必填,生成签名的时间戳
nonceStr: json.noncestr, // 必填,生成签名的随机串
signature: json.signature,// 必填,签名,见附录1
jsApiList: ["scanQRCode","chooseImage","uploadImage"] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
}
});
}
//调用微信扫一扫,扫描设备二维码,根据扫描结果异步请求此设备需要检查的项目
var scanCode = function(){
wx.ready(function(){
wx.scanQRCode({
needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
scanType: ["qrCode"], // 可以指定扫二维码还是一维码,默认二者都有
success: function (res) {
var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
document.getElementById("inspectionItem").className = "wechat-content";
}
});
});
}
//调用微信选择图片
var chooseImage = function(){
wx.ready(function(){
wx.chooseImage({
count: 1,
sizeType:['sizeType'],
sourceType:['album'],
success:function(res){
var localIds = res.localIds;
alert("localIds=" + localIds);
uploadImage(localIds);
}
});
});
}
//调用微信上传图片
var uploadImage = function(localIds){
wx.uploadImage({
localId: localIds.toString(),
isShowProgressTips: 1,
success: function(res){
var serverId = res.serverId;
},
fail:function(error){
//mui.alert(JSON.stringify(error));
mui.alert("上传图片失败", "提示", "确定", null);
}
});
}
注意:标红代码一定要加 .toString() 否则就会出错,导致图片上传不到微信。错误信息:{"errorMsg":"uploadImage:missing arguments"}