微信は画像を選んでアップロードして記憶します
34652 ワード
htmlコード
坑父の安卓微信開発よ
坑父の安卓微信開発よ
// mediaId ,
localId = localIds.toString();
<div class="wxapi_container">
<form action="<?=url('User.addUserInfo')?>" method="post" enctype="multipart/form-data">
<input type="text" name="name">
<input type="text" name="personId" value="<?php echo $personId ?>">
<button> </button>
</form>
<img id="img" src="" alt="" />
<div class="lbox_close wxapi_form">
<h3 id="menu-basic"> </h3>
<span class="desc"> JS </span>
<button class="btn btn_primary" id="checkJsApi">checkJsApi</button>
<h3 id="menu-image"> </h3>
<span class="desc"> </span>
<button class="btn btn_primary" id="chooseImage">chooseImage</button>
<span class="desc"> </span>
<button class="btn btn_primary" id="previewImage">previewImage</button>
<span class="desc"> </span>
<button class="btn btn_primary" id="uploadImage">uploadImage</button>
<button> </button>
</form>
</div>
<div id="error">
</div>
</div>
<script language="javascript">
function weixinApiConfig(apiList, debug)
{
<?php if ($this->get('debug')): ?>
debug = true;
<?php endif; ?>
wx.config({
debug: debug ? true : false,
appId: 'APPID',
timestamp: <?=$timestamp?>,
nonceStr: '<?=$noncestr?>',
signature: '<?=$signature?>',
jsApiList: apiList
});
}
</script>
<script>
weixinApiConfig([
'hideOptionMenu',
'checkJsApi',
'chooseImage',
'previewImage',
'getNetworkType',
'previewImage',
'uploadImage'
], false);
wx.ready(function(){
// JS ,
document.getElementById('checkJsApi').onclick = function () {
wx.checkJsApi({
jsApiList: [
'getNetworkType',
'previewImage'
],
success: function (res) {
alert(JSON.stringify(res));
}
});
};
//
//
// document.getElementById('getNetworkType').onclick = function () {
// wx.getNetworkType({
// success: function (res) {
// alert(res.networkType);
// },
// fail: function (res) {
// alert(JSON.stringify(res));
// }
// });
// };
// 2
document.getElementById('previewImage').onclick = function () {
wx.previewImage({
current: 'http://img5.douban.com/view/photo/photo/public/p1353993776.jpg',
urls: [
'http://img3.douban.com/view/photo/photo/public/p2152117150.jpg',
'http://img5.douban.com/view/photo/photo/public/p1353993776.jpg',
'http://img3.douban.com/view/photo/photo/public/p2152134700.jpg'
]
});
};
//
// 1 、
// var images = {
// localId: [],
// serverId: []
// };
//'album', 'camera' 'album'
var sourceType = 'album'+','+'camera';
alert(sourceType);
var localIds = '';
document.getElementById('chooseImage').onclick = function () {
wx.chooseImage({
count: 9, // 9
sizeType: ['original', 'compressed'], // ,
sourceType: [sourceType], // ,
success: function (res) {
//images.localId = res.localIds;
localIds = res.localIds; // ID ,localId img src
document.getElementById('img').src = localIds; //
// mediaId ,
localId = localIds.toString();
alert(' ' + res.localIds.length + ' ');
}
});
};
// 2
document.getElementById('uploadImage').onclick = function () {
// if (images.localId.length == 0) {
// alert(' chooseImage ');
// return;
// }
if(localIds.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));
// }
// });
// }
function upload(){
wx.uploadImage({
localId: localId, // ID, chooseImage
isShowProgressTips: 1, // 1,
success: function (res) {
var serverId = res.serverId; // ID
alert(serverId)
},
fail:function(res){
alert('aaa');alert(res.errMsg);
// alert(JSON.stringify(res))
}
});
}
upload();
alert('yyy');
};
});
wx.error(function (res) {
document.getElementById('error').innerHTML = res.errMsg;
});
</script>