javascript微信ios自动播放音效方法

javascript微信ios自动播放音效方法

 wx.config({
        //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
        appId: $('#appId').val(), // 必填,公众号的唯一标识
        timestamp: $('#timestamp').val(), // 必填,生成签名的时间戳
        nonceStr: $('#nonceStr').val(), // 必填,生成签名的随机串
        signature: $('#signature').val(), // 必填,签名,见附录1
        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']
    });
    var ntitle = $('#ntitle').val();
    var ndesc = $('#ndesc').val();
    var nlogo = $('#nlogo').val();
    var link = $('#link').val();
    wx.ready(function() {
        var musiclen = $('#bgmusic').length;
        if (musiclen > 0) {
            playbgmusic();
            $('#yinxiao').load();
            fm2 = function() {
                $('#yinxiao')[0].play();
            };
        }
        wx.checkJsApi({
            jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline'],
            success: function(res) {
                //alert(JSON.stringify(res));
            }
        });
        wx.hideMenuItems({
            menuList: ['menuItem:copyUrl'] // 要隐藏的菜单项,只能隐藏“传播类”和“保护类”按钮,所有menu项见附录3
        });
        commonshare(ntitle, ndesc, nlogo, link);
    });


fm2();

jquery trim重写

jquery trim重写

String.prototype.trim = function(char, type) {
    if (char) {
        if (type == 'left') {
            return this.replace(new RegExp('^\\' + char + '+', 'g'), '');
        } else if (type == 'right') {
            return this.replace(new RegExp('\\' + char + '+$', 'g'), '');
        }
        return this.replace(new RegExp('^\\' + char + '+|\\' + char + '+$', 'g'), '');
    }
    return this.replace(/^\s+|\s+$/g, '');
};

 str = '/Ruchee/';
    console.log(str.trim('/', 'left')); // Ruchee/

linux shell每秒执行的方法

linux shell每秒执行的方法

startphpfpm.sh文件如下
#!/bin/sh
while [ true ]; do
sleep 1
currTime=$(date +"%Y-%m-%d %T");
echo "ddd  ${currTime}" >> /data/web/mircoweb/wwwroot/App/Home/Controller/reloadinfo.log;
done

然后运行

 nohup sh startphpfpm.sh &

后台运行

如果禁止 直接 ps | grep startphpfpm.sh 找到进程kill -9 进程树就行

swoole是支持wss的方法

swoole是支持wss的方法

1 先让swoole支持ssl

首先编译的时候 加上–enable-openssl

然后打命令查看/usr/local/php/bin/php –ri swoole

swoole

swoole support => enabled
Version => 1.9.23
Author => tianfeng.han[email: mikan.tenny@gmail.com]
epoll => enabled
eventfd => enabled
timerfd => enabled
signalfd => enabled
cpu affinity => enabled
spinlock => enabled
rwlock => enabled
async http/websocket client => enabled


openssl => enabled


Linux Native AIO => enabled
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled

Directive => Local Value => Master Value
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => Off => Off
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

看到openssl => enabled 就代表可以了

然后swoole写如下代码就行

$ws = new swoole_websocket_server("0.0.0.0", 9908, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
$ws->set(array(
    'worker_num' => 1,
    'max_conn'   => 65535,
     'ssl_cert_file'=>'cert/1965653_wxserver.knowway.cn.pem',
    'ssl_key_file' =>'/cert/1965653_wxserver.knowway.cn.key',
    // 'daemonize'       => true,
    'backlog'    => 128,
    // 'task_worker_num' => 1,
));

ps:前端必须要用wss才能连接 ws会链接失败

egret微信好友排行榜制作教程

egret微信好友排行榜制作教程

1 先设置开放域目录
打开game.json文件
{
“deviceOrientation”: “portrait”,
“openDataContext”: “src/myOpenDataContext”
}
2 主域中 存入玩家信息
wx.setUserCloudStorage({
KVDataList: [{ key: ‘score’, value: “33” }],
success: res => {
console.log(res);

},
fail: res => {
console.log(res);
}
});

3 开放域中 读取数据


wx.getFriendCloudStorage({
  keyList: ['score'], // 你要获取的、托管在微信后台都key
  success: res => {
    console.log(res.data);
  }
});

4 下面最难的就是绘制排行榜了
首先开放域中调用默认的sharecanvas画布 给他填充个红色长方形

let sharedCanvas = wx.getSharedCanvas()
let context = sharedCanvas.getContext('2d')
context.fillStyle = 'red'
context.fillRect(0, 0, 300, 600)

然后在主域上显示

 let openDataContext = wx.getOpenDataContext()
    let sharedCanvas1 = openDataContext.canvas

    let canvas1 = wx.createCanvas()
    let context = canvas1.getContext('2d')
    context.drawImage(sharedCanvas1, 10, 10)

egret 好友排行榜demo https://github.com/egret-labs/egret-target-wxgame/tree/master/demos/openDataContext