wx.config({
debug: false ,
appId: 'wxf8b4f85f3a794e77' ,
timestamp: 1421142450,
nonceStr: '9hKgyCLgGZOgQmEI' ,
signature: 'bf7a5555f9ad0e7e491535f232349a40510a6f8f' ,
jsApiList: [
'checkJsApi' ,
'onMenuShareTimeline' ,
'onMenuShareAppMessage' ,
'onMenuShareQQ' ,
'onMenuShareWeibo' ,
'hideMenuItems' ,
'showMenuItems' ,
'hideAllNonBaseMenuItem' ,
'showAllNonBaseMenuItem' ,
'translateVoice' ,
'startRecord' ,
'stopRecord' ,
'onRecordEnd' ,
'playVoice' ,
'pauseVoice' ,
'stopVoice' ,
'uploadVoice' ,
'downloadVoice' ,
'chooseImage' ,
'previewImage' ,
'uploadImage' ,
'downloadImage' ,
'getNetworkType' ,
'openLocation' ,
'getLocation' ,
'hideOptionMenu' ,
'showOptionMenu' ,
'closeWindow' ,
'scanQRCode' ,
'chooseWXPay' ,
'openProductSpecificView' ,
'addCard' ,
'chooseCard' ,
'openCard'
]
});
wx.ready( function () {
document.querySelector( '#checkJsApi' ).onclick = function () {
wx.checkJsApi({
jsApiList: [
'getNetworkType' ,
'previewImage'
],
success: function (res) {
alert(JSON.stringify(res));
}
});
};
document.querySelector( '#onMenuShareAppMessage' ).onclick = function () {
wx.onMenuShareAppMessage({
title: '互聯(lián)網(wǎng)之子' ,
desc: '在長(zhǎng)大的過程中,,我才慢慢發(fā)現(xiàn),,我身邊的所有事,別人跟我說的所有事,,那些所謂本來如此,注定如此的事,,它們其實(shí)沒有非得如此,,事情是可以改變的,。更重要的是,,有些事既然錯(cuò)了,那就該做出改變,。' ,
link: 'http://movie.douban.com/subject/25785114/' ,
imgUrl: 'http://img3.douban.com/view/movie_poster_cover/spst/public/p2166127561.jpg' ,
trigger: function (res) {
alert( '用戶點(diǎn)擊發(fā)送給朋友' );
},
success: function (res) {
alert( '已分享' );
},
cancel: function (res) {
alert( '已取消' );
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
alert( '已注冊(cè)獲取“發(fā)送給朋友”狀態(tài)事件' );
};
document.querySelector( '#onMenuShareTimeline' ).onclick = function () {
wx.onMenuShareTimeline({
title: '互聯(lián)網(wǎng)之子' ,
link: 'http://movie.douban.com/subject/25785114/' ,
imgUrl: 'http://img3.douban.com/view/movie_poster_cover/spst/public/p2166127561.jpg' ,
trigger: function (res) {
alert( '用戶點(diǎn)擊分享到朋友圈' );
},
success: function (res) {
alert( '已分享' );
},
cancel: function (res) {
alert( '已取消' );
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
alert( '已注冊(cè)獲取“分享到朋友圈”狀態(tài)事件' );
};
document.querySelector( '#onMenuShareQQ' ).onclick = function () {
wx.onMenuShareQQ({
title: '互聯(lián)網(wǎng)之子' ,
desc: '在長(zhǎng)大的過程中,,我才慢慢發(fā)現(xiàn),我身邊的所有事,,別人跟我說的所有事,那些所謂本來如此,,注定如此的事,它們其實(shí)沒有非得如此,,事情是可以改變的,。更重要的是,,有些事既然錯(cuò)了,,那就該做出改變,。' ,
link: 'http://movie.douban.com/subject/25785114/' ,
imgUrl: 'http://img3.douban.com/view/movie_poster_cover/spst/public/p2166127561.jpg' ,
trigger: function (res) {
alert( '用戶點(diǎn)擊分享到QQ' );
},
complete: function (res) {
alert(JSON.stringify(res));
},
success: function (res) {
alert( '已分享' );
},
cancel: function (res) {
alert( '已取消' );
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
alert( '已注冊(cè)獲取“分享到 QQ”狀態(tài)事件' );
};
document.querySelector( '#onMenuShareWeibo' ).onclick = function () {
wx.onMenuShareWeibo({
title: '互聯(lián)網(wǎng)之子' ,
desc: '在長(zhǎng)大的過程中,,我才慢慢發(fā)現(xiàn),,我身邊的所有事,,別人跟我說的所有事,那些所謂本來如此,,注定如此的事,它們其實(shí)沒有非得如此,,事情是可以改變的。更重要的是,,有些事既然錯(cuò)了,,那就該做出改變,。' ,
link: 'http://movie.douban.com/subject/25785114/' ,
imgUrl: 'http://img3.douban.com/view/movie_poster_cover/spst/public/p2166127561.jpg' ,
trigger: function (res) {
alert( '用戶點(diǎn)擊分享到微博' );
},
complete: function (res) {
alert(JSON.stringify(res));
},
success: function (res) {
alert( '已分享' );
},
cancel: function (res) {
alert( '已取消' );
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
alert( '已注冊(cè)獲取“分享到微博”狀態(tài)事件' );
};
var voice = {
localId: '' ,
serverId: ''
};
document.querySelector( '#translateVoice' ).onclick = function () {
if (voice.localId == '' ) {
alert( '請(qǐng)先使用 startRecord 接口錄制一段聲音' );
return ;
}
wx.translateVoice({
localId: voice.localId,
complete: function (res) {
if (res.hasOwnProperty( 'translateResult' )) {
alert( '識(shí)別結(jié)果:' + res.translateResult);
} else {
alert( '無法識(shí)別' );
}
}
});
};
document.querySelector( '#startRecord' ).onclick = function () {
wx.startRecord({
cancel: function () {
alert( '用戶拒絕授權(quán)錄音' );
}
});
};
document.querySelector( '#stopRecord' ).onclick = function () {
wx.stopRecord({
success: function (res) {
voice.localId = res.localId;
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
};
wx.onVoiceRecordEnd({
complete: function (res) {
voice.localId = res.localId;
alert( '錄音時(shí)間已超過一分鐘' );
}
});
document.querySelector( '#playVoice' ).onclick = function () {
if (voice.localId == '' ) {
alert( '請(qǐng)先使用 startRecord 接口錄制一段聲音' );
return ;
}
wx.playVoice({
localId: voice.localId
});
};
document.querySelector( '#pauseVoice' ).onclick = function () {
wx.pauseVoice({
localId: voice.localId
});
};
document.querySelector( '#stopVoice' ).onclick = function () {
wx.stopVoice({
localId: voice.localId
});
};
wx.onVoicePlayEnd({
complete: function (res) {
alert( '錄音(' + res.localId + ')播放結(jié)束' );
}
});
document.querySelector( '#uploadVoice' ).onclick = function () {
if (voice.localId == '' ) {
alert( '請(qǐng)先使用 startRecord 接口錄制一段聲音' );
return ;
}
wx.uploadVoice({
localId: voice.localId,
success: function (res) {
alert( '上傳語音成功,serverId 為' + res.serverId);
voice.serverId = res.serverId;
}
});
};
document.querySelector( '#downloadVoice' ).onclick = function () {
if (voice.serverId == '' ) {
alert( '請(qǐng)先使用 uploadVoice 上傳聲音' );
return ;
}
wx.downloadVoice({
serverId: voice.serverId,
success: function (res) {
alert( '下載語音成功,,localId 為' + res.localId);
voice.localId = res.localId;
}
});
};
var images = {
localId: [],
serverId: []
};
document.querySelector( '#chooseImage' ).onclick = function () {
wx.chooseImage({
success: function (res) {
images.localId = res.localIds;
alert( '已選擇 ' + res.localIds.length + ' 張圖片' );
}
});
};
document.querySelector( '#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'
]
});
};
document.querySelector( '#uploadImage' ).onclick = function () {
if (images.localId.length == 0) {
alert( '請(qǐng)先使用 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));
}
});
}
upload();
};
document.querySelector( '#downloadImage' ).onclick = function () {
if (images.serverId.length === 0) {
alert( '請(qǐng)先使用 uploadImage 上傳圖片' );
return ;
}
var i = 0, length = images.serverId.length;
images.localId = [];
function download() {
wx.downloadImage({
serverId: images.serverId[i],
success: function (res) {
i++;
alert( '已下載:' + i + '/' + length);
images.localId.push(res.localId);
if (i < length) {
download();
}
}
});
}
download();
};
document.querySelector( '#getNetworkType' ).onclick = function () {
wx.getNetworkType({
success: function (res) {
alert(res.networkType);
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
};
document.querySelector( '#openLocation' ).onclick = function () {
wx.openLocation({
latitude: 23.099994,
longitude: 113.324520,
name: 'TIT 創(chuàng)意園' ,
address: '廣州市海珠區(qū)新港中路 397 號(hào)' ,
scale: 14,
infoUrl: 'http://weixin.qq.com'
});
};
document.querySelector( '#getLocation' ).onclick = function () {
wx.getLocation({
success: function (res) {
alert(JSON.stringify(res));
},
cancel: function (res) {
alert( '用戶拒絕授權(quán)獲取地理位置' );
}
});
};
document.querySelector( '#hideOptionMenu' ).onclick = function () {
wx.hideOptionMenu();
};
document.querySelector( '#showOptionMenu' ).onclick = function () {
wx.showOptionMenu();
};
document.querySelector( '#hideMenuItems' ).onclick = function () {
wx.hideMenuItems({
menuList: [
'menuItem:readMode' ,
'menuItem:share:timeline' ,
'menuItem:copyUrl'
],
success: function (res) {
alert( '已隱藏“閱讀模式”,,“分享到朋友圈”,“復(fù)制鏈接”等按鈕' );
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
};
document.querySelector( '#showMenuItems' ).onclick = function () {
wx.showMenuItems({
menuList: [
'menuItem:readMode' ,
'menuItem:share:timeline' ,
'menuItem:copyUrl'
],
success: function (res) {
alert( '已顯示“閱讀模式”,,“分享到朋友圈”,,“復(fù)制鏈接”等按鈕' );
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
};
document.querySelector( '#hideAllNonBaseMenuItem' ).onclick = function () {
wx.hideAllNonBaseMenuItem({
success: function () {
alert( '已隱藏所有非基本菜單項(xiàng)' );
}
});
};
document.querySelector( '#showAllNonBaseMenuItem' ).onclick = function () {
wx.showAllNonBaseMenuItem({
success: function () {
alert( '已顯示所有非基本菜單項(xiàng)' );
}
});
};
document.querySelector( '#closeWindow' ).onclick = function () {
wx.closeWindow();
};
document.querySelector( '#scanQRCode0' ).onclick = function () {
wx.scanQRCode({
desc: 'scanQRCode desc'
});
};
document.querySelector( '#scanQRCode1' ).onclick = function () {
wx.scanQRCode({
needResult: 1,
desc: 'scanQRCode desc' ,
success: function (res) {
alert(JSON.stringify(res));
}
});
};
document.querySelector( '#chooseWXPay' ).onclick = function () {
wx.chooseWXPay({
timestamp: 1414723227,
nonceStr: 'noncestr' ,
package : 'addition=action_id%3dgaby1234%26limit_pay%3d&bank_type=WX&body=innertest&fee_type=1&input_charset=GBK¬ify_url=http%3A%2F%2F120.204.206.246%2Fcgi-bin%2Fmmsupport-bin%2Fnotifypay&out_trade_no=1414723227818375338&partner=1900000109&spbill_create_ip=127.0.0.1&total_fee=1&sign=432B647FE95C7BF73BCD177CEECBEF8D' ,
paySign: 'bd5b1933cda6e9548862944836a9b52e8c9a2b69'
});
};
document.querySelector( '#openProductSpecificView' ).onclick = function () {
wx.openProductSpecificView({
productId: 'pDF3iY_m2M7EQ5EKKKWd95kAxfNw'
});
};
document.querySelector( '#addCard' ).onclick = function () {
wx.addCard({
cardList: [
{
cardId: 'pDF3iY9tv9zCGCj4jTXFOo1DxHdo' ,
cardExt: '{"code": "", "openid": "", "timestamp": "1418301401", "signature":"64e6a7cc85c6e84b726f2d1cbef1b36e9b0f9750"}'
},
{
cardId: 'pDF3iY9tv9zCGCj4jTXFOo1DxHdo' ,
cardExt: '{"code": "", "openid": "", "timestamp": "1418301401", "signature":"64e6a7cc85c6e84b726f2d1cbef1b36e9b0f9750"}'
}
],
success: function (res) {
alert( '已添加卡券:' + JSON.stringify(res.cardList));
}
});
};
document.querySelector( '#chooseCard' ).onclick = function () {
wx.chooseCard({
cardSign: '97e9c5e58aab3bdf6fd6150e599d7e5806e5cb91' ,
timestamp: 1417504553,
nonceStr: 'k0hGdSXKZEj3Min5' ,
success: function (res) {
alert( '已選擇卡券:' + JSON.stringify(res.cardList));
}
});
};
document.querySelector( '#openCard' ).onclick = function () {
alert( '您沒有該公眾號(hào)的卡券無法打開卡券,。' );
wx.openCard({
cardList: [
]
});
};
var shareData = {
title: '微信JS-SDK Demo' ,
desc: '微信JS-SDK,幫助第三方為用戶提供更優(yōu)質(zhì)的移動(dòng)web服務(wù)' ,
link: 'http://demo.open.weixin.qq.com/jssdk/' ,
imgUrl: 'http://mmbiz./mmbiz/icTdbqWNOwNRt8Qia4lv7k3M9J1SKqKCImxJCt7j9rHYicKDI45jRPBxdzdyREWnk0ia0N5TMnMfth7SdxtzMvVgXg/0'
};
wx.onMenuShareAppMessage(shareData);
wx.onMenuShareTimeline(shareData);
});
wx.error( function (res) {
alert(res.errMsg);
}); 轉(zhuǎn)自http://my.oschina.net/superkangning/blog/367484
|