同样的代码,在手机微信使用没有问题。可以正常上传图片。
用PC的微信就不可以 ,返回{"errMsg":"uploadImage:permission denied"}
在微信工具里面,返回 {errMsg: "uploadImage:ok", serverId: "1237378768e7q8e7r8qwesafdasdfasdfaxss111"}
但实际上这个serverid是无效的,获取图片时会提示error:{"errcode":40007,"errmsg":"invalid media_id hint: [u_kCTa0004p502]
这是什么问题呢,以前的PC微信也可以上传图片。难道 是版本的问题?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script language="javascript" src="../addons/ewei_shop/static/js/require.js"></script>
<script language="javascript" src="../addons/ewei_shop/static/js/dist/jquery-1.11.1.min.js"></script>
</head>
<title>上传图片测试</title>
<body >
<div class="upimg" style="width:50%;margin-top:30px;background-color:#00cc66;padding:20px;text-align: center;color:#fff;margin:20px auto">
点击上传图片
</div>
</body>
<script>
require(['http://res.wx.qq.com/open/js/jweixin-1.6.0.js'],function(wx){
jssdkconfig ={"appId":"wx70c5c564b4a6ae0a","nonceStr":"NVfqMFbu20ZYm9Fr","timestamp":"1692756314","signature":"bbdb951aa5b20a34d8e4bc38507b25630e6474f2"} || { jsApiList:[] };
jssdkconfig.debug = true;
jssdkconfig.jsApiList = [
'checkJsApi',
'chooseImage',
'previewImage',
'uploadImage',
'downloadImage',
]
wx.config(jssdkconfig);
wx.ready(function () {
var images = {
localId: [],
serverId: []
};
$('.upimg').click(function(){
$('#debug').html('jssdkconfig:<br>'+JSON.stringify(jssdkconfig));
wx.chooseImage({
success: function (res) {
images.localId = res.localIds;
upload();
}
});// wx.chooseImage
});//点图片上传
function upload() {
wx.uploadImage({
localId: images.localId[0],
isShowProgressTips: 1,
success: function (res) {
//alert("上传成功");
},
fail: function (res) {
//alert('上传失败');
}
});
}
});//加载完成后执行
});
</script>
</body>
</html>
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
wx.config(jssdkconfig);
wx.ready(function () {
wx.showOptionMenu();
wx.onMenuShareAppMessage(window.shareData);
wx.onMenuShareTimeline(window.shareData);
wx.onMenuShareQQ(window.shareData);
wx.onMenuShareWeibo(window.shareData);
//----------------微信上传图片
var images = {
localId: [],
serverId: []
};
$('.publish').click(function(){
var thisObj =$(this);
$('#bar').css('width','0px')
uploaded=0;//当前上传的数量
willup=0;//当前准备要上传的数量
wx.chooseImage({
success: function (res) {
images.localId = res.localIds;
if (images.localId.length == 0) {
alert('请先使用 chooseImage 接口选择图片');
return;
}
var i = 0;
var length = images.localId.length;//当前上传的图片个数
willup=length;//当前准备要上传的数量
$("#upfileend").hide();
$('.good_choose_layer').fadeIn(200);
$(".cover22").show();
bargo=setInterval("runbar()",100);
images.serverId = [];
function upload() {
wx.uploadImage({
localId: images.localId[i],
isShowProgressTips: 0,
success: function (res) {
i++;
images.serverId.push(res.serverId);
//上传到微信服务器后统一下载到网站服务器
count++;
uploaded++;
var pdata = res.serverId;
var theid = $('#customerid').val();
if (i < length) {
setTimeout(upload(),100);
}else{
var str = images.serverId;
var pdata = str.join(',');
uploaded=willup;
$.ajax({
type:'post',
url:"{php echo $this->createMobileUrl('shop',array('p'=>'addwxpic'))}",
data:{pdata:pdata,goods_id:theid,imgtype:1},//imgtype:1介绍照片
dataType:'json',
success:function(data){
if(data.state){
$('#here').before(imgdiv(data.imgid,data.path,data.filename));
}else{
alert('图片存储失败');
$('#error_code').fadeIn(200);
$('#error_code').val(data.msg);
$('#error_code').delay(10000).fadeOut(200);
}
howlong=0;
$('.good_choose_layer').fadeOut(200);
$('.cover22').fadeOut(200);
clearInterval(dotamin);
return false;
}
});
}
},
fail: function (res) {
alert('图片上传失败,再试试!err:'+JSON.stringify(res));//
$('.good_choose_layer').fadeOut(200);
$(".cover22").hide();
}
});
}
upload();
}
});
});
});