koa2开发微信公众号: 不定期推送最新币圈消息

编程入门 行业动态 更新时间:2024-10-05 07:18:56

koa2开发微信公众号: 不定期推送最<a href=https://www.elefans.com/category/jswz/34/1658102.html style=新币圈消息"/>

koa2开发微信公众号: 不定期推送最新币圈消息

背景:比特币说好的segwit2x分叉最后却分叉不成,如今算力又不够,于是比特现金想篡位? 没一个星期就涨了快10倍,错过这趟快车甚是后悔,于是打算写一个可不定期推送最新消息的微信公众号。既然是利用微信这个平台载体,当然要熟悉微信的api,遂封装了一下。

当然你也可以不看wechat-koa2的代码,直接使用下面的demo,不用百行代码便可轻松实现定制的币圈最新消息推送,后期会推出自动爬取全球各大交易所的最新消息,任何币种上线第一时间通知到位

先放出wechat-koa2 API,后续有时间再根据库币提供的api作封装

插播一个广告: 库币是由一群数字资产爱好者创建而成的一个专注区块链资产的交易平台,创始团队主要来自蚂蚁金服、广发证券等互联网和金融公司,致力于打造世界级的区块链资产交易平台。(跟NEO发放GAS一样,定期每天会根据用户持有的KCS发放鼓励金) 邀请注册链接 -> /?r=E...

0x00 wechat-koa2

const config = require('./config')const Koa = require('koa')
const app = new Koa()const Router = require('koa-router')
const router = new Router()const Wechat = require('wechat-koa2')const w = new Wechat(config)// 封装过后的koa-bodyparser
app.use(w.bodyParser())// 微信服务器校验
router.get('/', async(ctx) => {w.serverVerify(ctx)
})// 监听用户发送过来的消息
router.post('/', async (ctx) => {await w.listening(ctx)
}// 具体业务在可全写在这里,注册监听(具体看后文介绍)
// ....
// ....app.use(router.routes()).use(router.allowedMethods())console.log('START: ', `wechat server is listening at ${config.port} ...`)app.listen(config.port)

0x01 发送币种,查询实时价格和涨幅

这里使用的是sosobtc的接口,当然你也可以使用其他接口,如 zb、库币 等

const config = require('./config')const Koa = require('koa')
const app = new Koa()const Router = require('koa-router')
const router = new Router()const Wechat = require('wechat-koa2')const w = new Wechat(config)// 封装过后的koa-bodyparser
app.use(w.bodyParser())// 微信服务器校验
router.get('/', async(ctx) => {w.serverVerify(ctx)
})// 监听用户发送过来的消息
router.post('/', async (ctx) => {await w.listening(ctx)
}// 具体业务 具体业务 具体业务
w.onText(data => {const text = data.Content.toLowerCase()const coinURL = `=${text}`w.get(coinURL).then(result => {result = result[0]const coin = result.coinconst webSiteCn = result.webSiteCn || result.webSiteconst change24H = result.change24Hconst close = result.closeconst high = result.highconst low = result.lowif(coin.toLowerCase() === 'btc') {w.replyText(result_2 => {toUser: result_2.FromUserName,fromUser: result_2.ToUserName,content: `当前查询币种: BTC (${webSiteCn})最新价格: ${close}24H涨幅: ${change24H}%最高价格: ${high} USD最低价格: ${low} USD来源: <a href="=btc">点击这里</a>`})} else {w.replyText(result_2 => {toUser: result_2.FromUserName,fromUser: result_2.ToUserName,content: `当前查询币种: ${coin.toLowerCase()} (${webSiteCn})最新价格: ${close}24H涨幅: ${change24H}%最高价格: ${high} BTC最低价格: ${low} BTC来源: <a href="=${coin.toLowerCase()}">点击这里</a>`})}})
})app.use(router.routes()).use(router.allowedMethods())console.log('START: ', `wechat server is listening at ${config.port} ...`)app.listen(config.port)

PS: 本人原混于各种币圈,bts 2块3时入手靠信仰一直持到现在(哭...)。目前正在学习区块链(nodejs/python/go),若你也有兴趣,欢迎一起交流探讨

更多推荐

koa2开发微信公众号: 不定期推送最新币圈消息

本文发布于:2024-02-28 10:40:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1769312.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:新币   公众   消息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!