使用jQuery.wechat构建微信WEB应用

2020-05-24 21:28:51易采站长站整理

    urls: [
        ‘http://xxx/img/pic001.jpg’,
        ‘http://xxx/img/pic002.jpg’,
        ‘http://xxx/img/pic003.jpg’,
        ‘http://xxx/img/pic004.jpg’,
        ‘http://xxx/img/pic005.jpg’,
        ‘http://xxx/img/pic006.jpg’
    ]                                      //所有要在预览模式下显示的图片
});

 获取网络状态

$.wechat.getNetworkType().done(function(response) {
    $(‘#network’).text(response.split(‘:’)[1]);
});

response格式如下:

network_type:wifi    wifi网络
network_type:edge    非wifi,包含3G/2G
network_type:fail    网络断开连接
network_type:wwan    (2g或者3g)

 修改分享格式

每次看到别人的app分享出来的消息都带着精美的缩略图、适当的标题和描述,更有甚者消息下面还跟了一行小字指出该消息是由谁发送出来的;再看看你自己分享出去的消息,一个蓝色的默认空白图片,配着不搭调的标题,会不会奇怪是什么逻辑把他们塞进去的?

还好,咱们现在就来解决这个问题:

$.wechat.setShareOption({
    appid: ‘xxxx’,                                               //小标appid
    img_width: ’60’,
    img_height: ’60’,
    img_url: window.location.toString() + ‘img/demo.jpg’,        //缩略图
    title: ‘DEMO’,                                               //标题
    desc: ‘The description is set from $.wechat.setShareOption’, //描述
    link: function() {
        return window.location.toString();                       //消息分享出去后,用户点击消息打开的链接地址