微信图片上传接口多图像上传(递归上传)

/*	微信上传
		-----------------------------------------------------------------------*/

		wx.config({
			debug: true,
			appId: '<?php echo $conf["appID"]; ?>',
			timestamp: <?php echo $upload["time"]; ?>,
			nonceStr: '<?php echo $upload["nonce"]  ?>',
			signature: '<?php echo $signature; ?>',
			jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'previewImage']
		});




		wx.ready(function() {
			document.getElementById('list-photo').onclick = function() {
				var images = {localIds:[],serverId:[]};

				wx.chooseImage({
					count: 9,
					sizeType: ['original', 'compressed'],
					sourceType: ['album'],
					success: function(res) {
						images.localIds = res.localIds;
						
						var i = 0; var length = images.localIds.length;

                        var upload = function() {
                            wx.uploadImage({
                                localId:images.localIds[i],
                                success: function(res) {

									images.serverId.push(res.serverId);
                                    
                                    //如果还有照片,继续上传
                                    i++;
									if (i < length) {
										upload();
									}
								}
                            });                     
						};

                        upload();
					}
				});
			}
		});

  

posted @ 2015-09-25 16:19  陈朔  阅读(2790)  评论(0编辑  收藏  举报