Blog

Blog

PHODAL

Wordpress 微信 WP API+weChat打造Wordpress的微信查询二

wordpress 微信 整合

最后的代码目录结果如下所示

├── Gemfile
├── Gemfile.lock
├── README.md
├── Rakefile
├── app.rb
├── blog_helper.rb
└── config.ru

可以参考github上的,获取数据的blog_helper.rb


    require 'rubygems'
    require 'json'
    require 'net/http'

    class BlogHelper
        def getdata(query)
          result = []
          response = Net::HTTP.get_response("localhost","/?wpapi=search&dev=1&keyword="+query)
          posts = (JSON.parse response.body)['posts']
          posts.each do |post|
            result << {
              :title => post['title'],
              :description => post['excerpt'],
              :picture_url => post['author'][0]['gravatar'],
              :url => post['url']
            }
          end
          result
        end
    end

以及用于运行的app.rb


    require 'wei-backend'
    require 'rubygems'
    require './blog_helper'

    token "xuntaba"

    on_text do
        blog = BlogHelper.new
        blog.getdata(params[:Content])
    end

    on_subscribe do
        "感谢您的订阅"
    end

    on_unsubscribe do
        "欢迎您再次订阅"
    end

然后我们需要

Wordpress 微信

最后的效果

How to Start

  1. 需要在Wordpress上安装WP API插件
  2. 需要有一个能跑ruby的机器(通过说的是类unix),同时可以解析到你的机器
  3. 还需要一个微信公众开发者账号

如果已经都有了

bundle install
rake prod:start

还有如果是代理的话,可能你的nginx.conf配置就是下面

server {
   listen 80;
   server_name weixin.phodal.net;
   location / {
        proxy_pass http://127.0.0.1:3080;
    }
 }

Wordpress+Sinatra

主要依赖于下面的两个扩展

  • Wordpress-API
  • weChat-backend

Inspire by 微信公众平台后台框架

关于我

Github: @phodal     微博:@phodal     知乎:@phodal    

微信公众号(Phodal)

围观我的Github Idea墙, 也许,你会遇到心仪的项目

QQ技术交流群: 321689806
comment

Feeds

RSS / Atom

最近文章

关于作者

Phodal Huang

Engineer, Consultant, Writer, Designer

ThoughtWorks 技术专家

工程师 / 咨询师 / 作家 / 设计学徒

开源深度爱好者

出版有《前端架构:从入门到微前端》、《自己动手设计物联网》、《全栈应用开发:精益实践》

联系我: h@phodal.com

微信公众号: 最新技术分享

标签