开源项目 wechat-starter - 5 分钟部署你的微信公众号

goofansu · September 01, 2016 · Last by nicsunboy replied at August 21, 2018 · 9746 hits
Topic has been selected as the excellent topic by the admin.

wechat-starter

https://github.com/goofansu/wechat-starter

一个微信公众号开发模版,简单实现了以下主要功能:

  1. 接受和回复消息
  2. 登录授权
  3. 微信支付(需要服务号,并且开通微信支付)
  4. 非常简便地使用 jssdk

Screenshots

Demo

Deploy to Heroku

有同学在使用过程中遇到一些奇怪的问题,提了几个 issue,正好这两天有空,就把坑填了,顺便配置了一下"Deploy to Heroku"。

简单说来,就是点击 README 的紫色按钮,填入微信公众号相关参数,点 Deploy 就 OK 了,整个过程 5-10 分钟足够了。

后记

前段时间把 wechat gem 的作者@ericguo拉进来了,帮忙改进了很多,在此非常感谢。

希望 wechat-starter 能给正准备开发微信公众号的朋友一点参考,也可以直接当模版使用。

很多人应该需要这个。赞一个。

#1 楼 @realwol 谢谢,很早以前发过一次,最近把错误都修改了,并且尽可能让测试号的部署简单起来

// file: wxpay.js.erb
wx.ready(function() {
  wx.chooseWXPay({
    timestamp: "<%= @pay_order[:timeStamp] %>",
    nonceStr: "<%= @pay_order[:nonceStr] %>",
    package: "<%= @pay_order[:package] %>",
    signType: "<%= @pay_order[:signType] %>",
    paySign: "<%= @pay_order[:paySign] %>",
    success: function(res) {
      window.location.href = '<%= buy_orders_url %>';
    },
    error: function(e) {
      alert(e)
    }
  });
});

微信官方推荐新 api chooseWXPay

#3 楼 @mingyuan0715 谢谢,等等更新下

#2 楼 @goofansu 找时间去试试,刚好准备自己弄个公众号玩玩。

#3 楼 @mingyuan0715 嗯,有不明白的地方就提 issue,我会完善文档,现在文档写的还比较粗略

好东西,点个赞!作者人很好,回复问题的速度很快!支持你👊

#8 楼 @frankgu 谢谢,有用就好

huacnlee mark as excellent topic. 06 Sep 10:07

#11 楼 @simlegate 买 rubyconf 的票了嘛?

支持,lz 帮我很多

@goofansu 请教一下,使用测试号 deploy to Heroku 成功了,但是不知道该怎么测试,扫描二维码加了微信,发了一个 TEXT,没有回应。看了一下代码,应该至少有 echo 才对。😀

class WechatsController < ActionController::Base
  # to allow using wechat message DSL and web page helper
  wechat_responder

  # default text responder when no other match
  on :text do |request, content|
    request.reply.text "echo: #{content}" # Just echo
  end

  # When receive 'help', will trigger this responder
  on :text, with: 'help' do |request|
    request.reply.text 'help content'
  end

@goofansu 是我搞错了 URL,目前可以实现 echo 了。

#15 楼 @joezhang 不好意思,好久没来没看到通知,成功了就好

17 Floor has deleted
18 Floor has deleted

@goofansu 你好,我在本地的开发环境用 ngrok 映射到公网,微信公众平台配置接口信息的时候,无法通过。url 是 http://????.ngork.cc/wechat token 也一致,无法成功配置。我用浏览器访问 http://????.ngork.cc/wechat,显示 Forbidden。 console 的信息

vagrant@vagrant-ubuntu-trusty-64:/vagrant/weixin$ rails s -b 192.168.10.10
=> Booting Puma
=> Rails 5.0.1 application starting in development on http://192.168.10.10:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.2 (ruby 2.3.0-p0), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://192.168.10.10:3000
Use Ctrl-C to stop
Started GET "/wechat" for 192.168.10.1 at 2017-02-12 18:28:31 +0000
  ActiveRecord::SchemaMigration Load (0.4ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by WechatsController#show as HTML
  Rendering text template
  Rendered text template (0.0ms)
Filter chain halted as :verify_signature rendered or redirected
Completed 403 Forbidden in 32ms (Views: 15.6ms | ActiveRecord: 0.0ms)


Started GET "/wechat?signature=7f19626f401dcad1c53f214244d6fbd4752b5cc6&echostr=2528414796461682171&timestamp=1486924145&nonce=1748360740" for 192.168.10.1 at 2017-02-12 18:29:06 +0000
Processing by WechatsController#show as */*
  Parameters: {"signature"=>"7f19626f401dcad1c53f214244d6fbd4752b5cc6", "echostr"=>"2528414796461682171", "timestamp"=>"1486924145", "nonce"=>"1748360740"}
  Rendering text template
  Rendered text template (0.0ms)
Completed 200 OK in 2ms (Views: 1.7ms | ActiveRecord: 0.0ms)

如何通过微信的接口认证,谢谢了!

Reply to kouunn

你把 puma 去掉,或者加上 nginx,单独用 puma 是有问题的

Reply to kouunn

验证的问题解决了么?我也有这样子的问题

Reply to Thomastar

验证的问题解决了么?我也有这样子的问题

Reply to Thomastar

正如 @kouunn 说的,单独用 Puma 会有问题。问题在于 response.body 会多一个状态码(例如 4230923142354162015HTTP/1.1 500 Internal Server Error)。 可以用其他 server gem 调试

Reply to niucang

正如 @kouunn 说的,单独用 Puma 会有问题。问题在于 response.body 会多一个状态码(例如 4230923142354162015HTTP/1.1 500 Internal Server Error)。可以用其他 server gem 调试

You need to Sign in before reply, if you don't have an account, please Sign up first.