微信公众号开发day1

来源:互联网 发布:python 运维框架 编辑:程序博客网 时间:2024/06/08 14:16

1、微信公众号的分类:

企业号、订阅号、服务号
这里写图片描述

这里写图片描述

2、订阅号与服务号的三点不同:
这里写图片描述

3、如何能在外网访问到你的电脑上的服务(方法1):

 1. 在自己的电脑上开启一个服务,我这里是使用python开启的8080端口的web服务:python -m SimpleHTTPServer 8080 2. 下载ngrok,解压并运行如下命令: ngrok http 8080 3. 出现如下代码:Session Status                onlineVersion                       2.1.18Region                        United States (us)Web Interface                 http://127.0.0.1:4040Forwarding                    http://b2d762af.ngrok.io -> localhost:8080Forwarding                    https://b2d762af.ngrok.io -> localhost:80804、这样我们就可以通过Forwarding中的域名,在外网中访问到本机的8080端口中运行的服务了

4、如何能在外网访问到你的电脑上的服务(方法2):

使用nodejs的localtunnel服务 1. 安装:npm install -g localtunnel 2. 使用lt命令生成对应端口的映射:lt --port 8080

5、配置、接入微信公众号:

1、没有账号的话直接在微信公众号开发者文档中找到“接口测试号申请”2、对应的js代码如下:'use strict'//引入koa框架var Koa=require('koa')//引入sha加密模式var sha1=require('sha1')var config={    wechat:{        appID:'wxb7cce6643fbb0452',        appSecret:'ae87a3163893cc5738cebe4f533a8944',        token:'wuyonghu'    }}//实例化web服务器var app=new Koa();    app.use(function *(next){    console.log(this.query)    var token=config.wechat.token    var signature=this.query.signature    var nonce=this.query.nonce    var timestamp=this.query.timestamp    var echostr=this.query.echostr    var str=[token,timestamp,nonce].sort().join('')    //sha1加密    var sha=sha1(str)    //判断是否加密后和签名是否相同    if(sha==signature){        //在界面上直接返回字符串        this.body=echostr+''    }else{        //不是从微信上面提交过来的,在界面上显示wrong        this.body="出现了错误"    }})app.listen(80)console.log("Listening:80")3、使用ngrok代理80端口:ngrok http 804、运行node app.js(上面的代码)5、在微信平台验证这样接口配置信息就可以成功的配置好

注意:现在的微信接口只能是80或者443,并且对应的分别是http和https,不然可能会出现错误

0 0
原创粉丝点击