Centos7

CentOS7安装Python3的方法CentOS7搭建L2TP服务端一键脚本CentOS7使用CertBot工具获取LetSencrypt泛域名HTTPS证书

Git

GIT删除仓库的历史提交记录脚本示例GIT进行代码量统计和贡献统计

HTTP

HTTP关于HEADER的详细解释HTTP协议对URI长度POST数据长度及COOKIE长度限制说明HTTP关于Code状态码的详细解释

JavaScript

JavaScript下的RSA对称加密DEMOJavaScript解析并遍历Excel示例代码JavaScript调用语音合成Speech Synthesis API使用ElementUI配合API数据快速渲染合并表格

Linux

Linux 信号说明列表说明Linux利用CronTab定时执行ThinkPHP命令行模式

MySQL

MySQL字符串截取MySQL腾讯云数据库导出备份到本地服务器导入MySQL设计与使用规范MySQL在5.7及以上版本中的ONLY_FULL_GROUP_BY问题处理方案

Nginx

Nginx反向代理NodeJS实现WSS协议Nginx反向代理中的Host参数传递遇到的坑Nginx配置HTTPS与HTTP2.0Nginx负载均衡的lnmp环境初始化脚本Nginx图片递归代理服务器DEMO

NodeJS

NodeJS一些冷门但实用的npm包NodeJS使用Request模块实现CURLNodeJS使用express模块无法收到phpCurl的值NodeJS使用jimp和qrcode-reader识别解析二维码NodeJS实现UDP数据报套接字通讯NodeJS实现Websocket聊天室NodeJS实现串口通讯简单例程NodeJS实现微信协议登录NodeJS实现超级方便的Git自动发布WebhookNodeJS控制台简单表格打印NodeJS转码amr到mp3NWJS配置文件

Other

C#串口通信扫码枪数据读取支付宝Schema协议列表默克尔树基础算法示例博客的升级历程

PHP

PHP下RSA对称加密超长字符串分段加密DEMOPHP下phpMyAdmin数据字典美化代码PHP下的RSA对称加解密-根证书自签与签发子证书PHP使用root权限执行系统命令和切换到www用户PHP使用独占文件指针实现阻塞少量并发PHP多进程同时处理任务示例DEMO代码PHP大文件视频上传WebUploaderPHP实现Web方式发起一个超时任务的处理请求PHP实现二叉查找树的简单代码实现PHP实现微博登录简单代码PHP微信JSSDK开发DEMOPHP的坑XML转JSONPHP简单实现QQ登录代码PHP获取URL HTTP_HOST和SERVER_NAMEPHP获取上周、本周、上月、本月、本季度、上季度时间方法PHP获取真实IP之IP代理-IP伪造-真实IPPHP解密微信小程序手机号简单DEMOPHP高精度计算常用代码

Python

Python3使用Pool进程池实现多进程并发Python3使用jieba分词并生成WordCloud词云图Python3使用request进行CURL操作Python3实现WebhookPython3使用Selenium进行自动化测试手册

Wechat

微信公众号php环境无法获取POST值微信公众号网页跳转避免出现导航栏的小技巧
NodeJS实现微信协议登录
手机阅读

扫描二维码阅读文章
//使用NodeJs实现微信协议登录
var http = require('http');
var https = require("https");
var crypto = require('crypto');
var fs = require('fs');
var express = require('express');
var iconv = require("iconv-lite");
var bodyParser = require("body-parser");
var app = express();
var request = require('request');
app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(bodyParser.json());

function getSubstr(ret,start,end)
{
    var deps = ret.indexOf(start)+start.length;
    //如果结束字符为空,则取从开始字符到结束字符的所有字符串
    if (end == "")
    var depe = ret.length;
    else
    var depe = ret.indexOf(end);
    var dep = ret.substr(deps,depe-deps);
    return dep;
}
function rand(Min,Max){
      var Range = Max - Min;
      var Rand = Math.random();
      var num = Min + Math.round(Rand * Range); //四舍五入
      return num;
}
function getTimeStamps(){
    return Date.parse(new Date())/1000;
}

function debug(msg) {
    console.log("Console\t" + getTime() + "\t" + msg);
}

function sha1(str) {
    var sha1 = crypto.createHash("sha1"); //定义加密方式:md5不可逆,此处的md5可以换成任意hash加密的方法名称;
    sha1.update(str);
    var res = sha1.digest("hex"); //加密后的值d
    return res;
}

function getTime() {
    var now = new Date();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    if (hours < 10) {
        hours = "0" + hours;
    }
    if (minutes < 10) {
        minutes = "0" + minutes;
    }
    if (seconds < 10) {
        seconds = "0" + seconds;
    }
    return hours + ":" + minutes + ":" + seconds;
}
function randInt(length){
    var str = "";
    var arr = ['1', '2', '3', '4', '5', '6', '7', '8', '9'];
 
    for(var i=0; i<length; i++){
        str += arr[rand(0,arr.length-1)];
    }
    return str;
}
function randStr(length){
    var str = "";
    var arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
 
    for(var i=0; i<length; i++){
        str += arr[rand(0,arr.length-1)];
    }
    return str;
}

var BaseRequest={};
var progressWaiting=false,progressListen=false;
var nowUuid;
var Config={};
app.get('/welcome/', function(req, res) {
    var param = req.query.id;
    BaseRequest.DeviceID="e"+randInt(15);
    if(!progressWaiting){
        //等待处理结果
        var url = "https://login.wx.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN&_="+getTimeStamps()+rand(100,999);
        
        request(url, function (error, response, body) {
            if (!error && response.statusCode == 200) {
                var code = getSubstr(body,'window.QRLogin.code = ','; window.QRLogin.uuid');
                nowUuid = getSubstr(body,'window.QRLogin.uuid = "','";');
                debug("Waiting for scan result");
                res.setHeader("Refresh",10);
                res.send('<center><img width="200px" src="https://login.weixin.qq.com/qrcode/'+nowUuid+'"/><br>请在10s内扫描</center>');
                res.end();
                progressWaiting=true;
                
            }else{
                res.end("Error");
            }
        });
    }else{
        var isResponsed=false;
        var time=getTimeStamps();
        var checkTime=~time;
        url="https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid="+nowUuid+"&tip=1&r="+checkTime+"&_="+time;
        request(url, function (error, response, body) {
            if (!error && response.statusCode == 200) {
                isResponsed=true;
                var code = getSubstr(body,'window.code=',';');
                switch (code){
                    case "200":
                        url=getSubstr(body,'window.redirect_uri="','";');
                        url+="&fun=new&version=v2";
                        request(url, function (error, response, body) {
                            if (!error && response.statusCode == 200) {
                                BaseRequest.skey=getSubstr(body,'<skey>','</skey>');
                                BaseRequest.Sid=getSubstr(body,'<wxsid>','</wxsid>');
                                BaseRequest.Uin=getSubstr(body,'<wxuin>','</wxuin>');
                                BaseRequest.pass_ticket=getSubstr(body,'<pass_ticket>','</pass_ticket>');
                                var cookieArr=response.headers['set-cookie'];
                                Config.cookie="";
                                cookieArr.forEach(function (cookie){
                                    var c=getSubstr(cookie,"",'; Domain');
                                    Config.cookie+=c+"; ";
                                });
                                debug("Wechat login success!");
                                res.end();
                                url = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r="+(~getTimeStamps())+"&pass_ticket="+BaseRequest.pass_ticket;
                               
                                request({
                                    url: url,
                                    method: "POST",
                                    json: false,
                                    headers: {
                                    "content-type": "application/json",
                                    },
                                    body: JSON.stringify({"BaseRequest":BaseRequest})
                                }, 
                                function(error, response, body) {
                                    if (!error && response.statusCode == 200) {
                                        body=JSON.parse(body);
                                        Config.myinfo=body.User;
                                        Config.last=body.SyncKey;
                                        debug("Listen wechat message...");
                                        //Now start listen wechat message
                                        if(!progressListen){
                                            //if not listenning...
	                                        msgloop();
	                                        progressListen=true;
                                        }
                                    }else{
                                        debug("Listen wechat message error");
                                    }
                                }); 
        
                            }else{
                                debug("Wechat login error!");
                            }
                        });
                        break;
                    case "201":
                        res.setHeader("Refresh",1);
                        res.end("Please confirm the login request!");
                        debug("Please confirm the request of login");
                        break;
                    case "408":
                        progressWaiting=false;
                        debug("Login timeout and refresh please");
                        break;
                    default:
                        res.setHeader("Refresh",1);
                        res.end();
                        progressWaiting=false;
                        console.log(body);
                }
            }else{
                progressWaiting=false;
                debug("Error with "+response.statusCode);
            }
        });
        setTimeout(function() {
            if(!isResponsed){
                progressWaiting=false;
                res.setHeader("Refresh",1);
                res.end();
            }
        }, 3000);
    }
});
function msgloop(){
    debug("Getting Message...");
    url = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid="+BaseRequest.Sid+"&skey="+BaseRequest.skey+"&lang=zh_CN&pass_ticket="+BaseRequest.pass_ticket;
	                                    
    request({
        url: url,
        method: "POST",
        json: false,
        headers: {
        "content-type": "application/json",
        },
        body: JSON.stringify({"BaseRequest":BaseRequest,"SyncKey":Config.last,"rr":(~getTimeStamps())})
    }, 
    function(error, response, body) {
        if (!error && response.statusCode == 200) {
            body=JSON.parse(body);
            //console.log(body);
            Config.last=body.SyncKey;
            body.AddMsgList.forEach(function (msg){
                console.log("MSG from "+msg.FromUserName+" : "+msg.Content);
                var fromType=msg.FromUserName.substring(0,2);
                if(fromType=="@@"){
                    //群消息
                    debug("Msg From Group : "+msg.Content);
                    responseMsg(msg.FromUserName,"[自动回复]:"+msg.Content);
                }else{
                    fromType=msg.FromUserName.substring(0,1);
                    if(fromType=="@"){
                        //个人消息
                        debug("Msg From Person : "+msg.Content);
                        responseMsg(msg.FromUserName,"[自动回复]:"+msg.Content);
                    }else{
                        //公众号消息
                        debug("Msg From MpAccount : "+msg.Content);
                    }
                }
                
            });
        }
        setTimeout(function(){
            msgloop();
        },rand(1000,5000));
    }); 
}
function responseMsg(FromUserName,Content){
    var url="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg?lang=zh_CN&pass_ticket="+BaseRequest.pass_ticket;
    var localId=(getTimeStamps()+rand(100,999));
                                            
    request({
        url: url,
        method: "POST",
        json: false,
        headers: {
        "content-type": "application/json",
        },
        body: JSON.stringify({"BaseRequest":BaseRequest,"Msg":{
            "ClientMsgId":localId,
            "Content":Content,
            "FromUserName":Config.myinfo.UserName,
            "LocalID":localId,
            "ToUserName":FromUserName,
            "Type":1
        },"Scene":0})
    }, 
    function(error, response, body) {
        debug("Message response success!");
    });
            
}
app.get('/*', function(req, res) {
    var params = req.originalUrl;
    res.send("<center><h1>808 Not Found</h1><hr>Nginx&Node</center>");
});

var server = app.listen(10002, function() {
    //var host = server.address().address
    //var port = server.address().port
    debug("Server running...");
});