<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>liurui12w (香山﹏二狗子)</title>
    <link>https://ruby-china.org/liurui12w</link>
    <description>二狗</description>
    <language>en-us</language>
    <item>
      <title>长文慎点：部署（Docker + Ubuntu + Ruby 2.6.1 + Rails + Capistrano + Puma）</title>
      <description>&lt;h3 id="前言"&gt;前言&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Docker 的用处&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;测试，测试数据分离，开发，PaaS 云服务，这里我要用 docker 搭建一个 rails 项目&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;切记一定要去看 docker，此贴只简单描述，此贴只是一种思路，不一定是正确的流程，仅供参考及讨论&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;友情链接&lt;/strong&gt;
 &lt;a href="https://www.docker.com/" rel="nofollow" target="_blank" title=""&gt;Docker 官网&lt;/a&gt; &lt;a href="https://yeasy.gitbooks.io/docker_practice/" rel="nofollow" target="_blank" title=""&gt;Docker 安装参考链接&lt;/a&gt;&lt;/p&gt;
&lt;h4 id="版本号"&gt;版本号&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Ubuntu 16.04&lt;/li&gt;
&lt;li&gt;Dokcer 18.09.0&lt;/li&gt;
&lt;li&gt;Nginx 1.10.3&lt;/li&gt;
&lt;li&gt;ruby 2.6.1&lt;/li&gt;
&lt;li&gt;rails 6.0.3&lt;/li&gt;
&lt;li&gt;Mysql 5.7&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="结构"&gt;结构&lt;/h4&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
+--------------------+--------------------+
| ubuntu             | mysql              | #docker 
+--------------------+--------------------+
| rvm                | mysql              | #包含
| ruby               |                    |
| rails              |                    |
| nginx              |                    |
+--------------------+--------------------+

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;一。构建所需要的 Dockerfile (ubuntu)&lt;/p&gt;
&lt;h5 id="1.创建ubuntu的dockerfile"&gt;1.创建 ubuntu 的 dockerfile&lt;/h5&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM ubuntu:16.04
#捆绑套件
RUN apt-get update &amp;amp;&amp;amp; apt-get install -y openssh-server
RUN apt-get update &amp;amp;&amp;amp; apt-get install gnupg2 -y &amp;amp;&amp;amp; apt-get install vim -y &amp;amp;&amp;amp; apt-get install curl -y &amp;amp;&amp;amp; apt-get install git -y &amp;amp;&amp;amp; apt-get install nodejs -y
#创建ssh
RUN mkdir -p /var/run/sshd
RUN mkdir /root/.ssh
#创建账号 以供操作和部署等
RUN echo 'root:root2020' | chpasswd
RUN useradd -ms /bin/bash deploy
RUN echo 'deploy:deploy2020' | chpasswd
#当容器启动时运行的脚本
CMD ["/usr/sbin/sshd", "-D"]

RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" &amp;gt;&amp;gt; /etc/profile
#开放端口
EXPOSE 22 80 8080
&lt;/code&gt;&lt;/pre&gt;&lt;h5 id="2.生成镜像 docker build ."&gt;2.生成镜像 docker build .&lt;/h5&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#创建镜像
$ docker build .
#查看镜像
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
&amp;lt;none&amp;gt;              &amp;lt;none&amp;gt;              a58c0f537c60        23 seconds ago      251MB #新创建docker

$ docker tag a58c0f537c60 ubuntu:base # TAG
#创建我所需要的容器
$ docker run -idt \
       -p 126:22 -p 8081:80 \ #映射端口
       --name rails_app \ #名
      ubuntu:base #镜像

$ docker ps #查看运行中容器      

&lt;/code&gt;&lt;/pre&gt;&lt;h5 id="3.进入容器，配置点东西"&gt;3.进入容器，配置点东西&lt;/h5&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ssh root@127.0.0.1 -p 126

#改个时区
#查看时间
$ date
$ apt install tzdata
$ dpkg-reconfigure tzdata
6 Asia  70 Shangehai #设置时区
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;二。装 rvm,ruby 等环境 &lt;a href="https://ruby-china.org/wiki/rvm-guide" title=""&gt;安装 rvm&lt;/a&gt;&lt;/p&gt;
&lt;h5 id="1.安装rvm(继续之前的rails_app中不用退出)"&gt;1.安装 rvm(继续之前的 rails_app 中不用退出)&lt;/h5&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
$ \curl -sSL https://get.rvm.io | bash -s stable

$ source /etc/profile.d/rvm.sh
&lt;/code&gt;&lt;/pre&gt;&lt;h5 id="2.安装ruby"&gt;2.安装 ruby&lt;/h5&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#查看版本
$ rvm list known
#安装版本
$ echo "export rvm_max_time_flag=20" &amp;gt;&amp;gt; ~/.rvmrc
$ rvm install 2.6.1 --disable-binary

#安装成功
$ ruby -v
$ ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
#手动装个bundler,Gemfile用起来更香 
$ gem install bundler
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;三。创建 rails 项目，capistrano 配置 &lt;a href="https://ruby-china.org/topics/36899" title=""&gt;参考&lt;/a&gt;&lt;/p&gt;
&lt;h5 id="1.创建rails项目"&gt;1.创建 rails 项目&lt;/h5&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# 本地
# 如果你已经有开发好的项目，这一步请直接略过。

# 新建一个目录，存放rails项目
$ mkdir -p ~/Developer/Rails
# 新建一个Rails项目，默认使用MySQL数据库
$ rails new web_app -d mysql
&lt;/code&gt;&lt;/pre&gt;&lt;h5 id="2.修改Gemfile,主要是capistrano大礼包"&gt;2.修改 Gemfile，主要是 capistrano 大礼包&lt;/h5&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Gemfile
group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '&amp;gt;= 3.3.0'
  gem 'listen', '&amp;gt;= 3.0.5', '&amp;lt; 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~&amp;gt; 2.0.0'
  gem 'pry-rails' # binding.pry

  # capistrano family gem
  gem 'capistrano', '~&amp;gt; 3.6'
  gem 'capistrano-rails', '~&amp;gt; 1.1'
  gem 'capistrano-rvm'
  # gem 'capistrano-passenger'
  gem 'capistrano-bundler', require: false
  gem 'capistrano3-puma', require: false
end
&lt;/code&gt;&lt;/pre&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# 修改后bundle
$ bundle install
&lt;/code&gt;&lt;/pre&gt;&lt;h5 id="3.Capfile,config/deploy.rb 配置"&gt;3.Capfile,config/deploy.rb 配置&lt;/h5&gt;&lt;h6 id="1.Capfile"&gt;1.Capfile&lt;/h6&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# 本地运行 
$ cap install

#编辑 Capfile 
require 'capistrano/rails'
require "capistrano/rvm"
require "capistrano/bundler"
require 'capistrano/puma'
&lt;/code&gt;&lt;/pre&gt;&lt;h6 id="2.config/deploy.rb"&gt;2.config/deploy.rb&lt;/h6&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lock "~&amp;gt; 3.14.0"
# 项目名称
set :application, "web_app"
# git仓库地址 我这里用的coding
set :repo_url, "git@e.coding.net:xxxx/web_app.git"

set :rails_env, 'production'
# 去掉注释,服务器需要有这些配置
append :linked_files, "config/database.yml","config/secrets.yml"
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public"

#参数设置
set :pty, true
set :use_sudo, false
set :stage, :production
set :deploy_via, :remote_cache
# set :ssh_options, {forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub)}
#puma参数可参考capistrano3-puma
set :puma_threads, [4, 16]
set :puma_workers, 0
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true
#以下我个人设置，可按照自己喜好配置
namespace :puma do
  desc 'Create Directories for Puma Pids and Socket'
  task :make_dirs do
    on roles(:app) do
      execute "mkdir #{shared_path}/tmp/sockets -p"
      execute "mkdir #{shared_path}/tmp/pids -p"
    end
  end

  before :start, :make_dirs
end

namespace :deploy do
  desc "Make sure local git is in sync with remote."
  task :check_revision do
    on roles(:app) do
      unless `git rev-parse HEAD` == `git rev-parse origin/#{fetch(:branch)}`
        puts "WARNING: HEAD is not the same as origin/#{fetch(:branch)}"
        puts "Run `git push` to sync changes."
        exit
      end
    end
  end

  desc 'Initial Deploy'
  task :initial do
    on roles(:app) do
      before 'deploy:restart', 'puma:start'
      invoke 'deploy'
    end
  end

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      invoke 'puma:restart'
    end
  end


  before :starting, :check_revision
  # after :finishing, :compile_assets
  # after :finishing, :cleanup
  # after :finishing, :restart
end

&lt;/code&gt;&lt;/pre&gt;&lt;h6 id="3.config/deploy/production.rb"&gt;3.config/deploy/production.rb&lt;/h6&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set :stage, :production # 部署的环境
set :branch, 'master' # 部署的代码分支
set :rails_env, :production
#我这里仅供测试，需要根据实际配置来
server '127.0.0.1', user: 'root', password: 'root2020', roles: %w{web app db} , port: '126'

set :deploy_to, "/var/www/web_app" # 部署到服务器的位置

set :enable_ssl, false

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;四.capistrano 部署相关配置&lt;/p&gt;
&lt;h4 id="服务器 我这里采用本地"&gt;服务器 我这里采用本地&lt;/h4&gt;&lt;h5 id="1.创建mysql"&gt;1.创建 mysql&lt;/h5&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#run一个mysql docker
$ docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=336699  -d mysql:5.7
$ docker exec -it CONTAINER_ID bash #进入docker
cat /etc/hosts #获取ip 我这里获取的是 172.17.0.3
#创建个库
mysql -u root -p
CREATE DATABASE web_app_pro CHARACTER SET utf8mb4;

#退出 mysql console
$ exit
#退出 mysql docker
$ exit
&lt;/code&gt;&lt;/pre&gt;&lt;h5 id="2.web_app docker 内相关配置"&gt;2.web_app docker 内相关配置&lt;/h5&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ssh root@127.0.0.1 -p 126
#准备工作
$ mkdir -p /var/www/web_app #项目存放路径
$ mkdir -p /var/www/web_app/shared/config #项目配置

$ cd /var/www/web_app/shared/config

$ vim database.yml
#创建所需的文件
# database.yml:
default: &amp;amp;default
  adapter: mysql2
  encoding: utf8
  pool: 20
  username: root #&amp;lt;%= ENV["DATAUSER"] %&amp;gt; #推荐使用&amp;lt;%= ENV["DATAUSER"] %&amp;gt; 这样不会直接暴露账号密码,我这里图方便就用了root（不建议使用）
  password: 336699 #&amp;lt;%= ENV["DATAPASSWD"] %&amp;gt; #来源docker mysql的密码
  host: 172.17.0.3 #&amp;lt;%= ENV['DATABASE_HOST'] %&amp;gt; #来源docker mysql的地址
  port: 3306
  reconnect: true
  wait_timeout: 30

production:
  &amp;lt;&amp;lt;: *default
  database: web_app_pro #&amp;lt;%= ENV["DATABASE"] %&amp;gt;

#此处省略secrets。yml创建  
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;五.capistrano 部署代码 开始爆破&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#本地执行
$ cap production deploy:check
#好了执行下面的

$ ccap production deploy

&lt;/code&gt;&lt;/pre&gt;&lt;h6 id="第一次会比较慢，请耐心等待。这条命令，还会在服务器上建立一个叫current的目录，用symbolic link指向releases目录下最新的版本。"&gt;第一次会比较慢，请耐心等待。这条命令，还会在服务器上建立一个叫 current 的目录，用 symbolic link 指向 releases 目录下最新的版本。&lt;/h6&gt;
&lt;p&gt;六。配置 nginx&lt;/p&gt;
&lt;h5 id="1.安装nginx 参考"&gt;1.安装 nginx &lt;a href="https://www.jianshu.com/p/cfed9b17a18b" rel="nofollow" target="_blank" title=""&gt;参考&lt;/a&gt;
&lt;/h5&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ apt-get install nginx

&lt;/code&gt;&lt;/pre&gt;&lt;h5 id="2.nginx配置 rails_app中"&gt;2.nginx 配置 rails_app 中&lt;/h5&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd /etc/nginx/sites-enabled

$ vim web_app.conf

&lt;/code&gt;&lt;/pre&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#web_app.conf配置

upstream web_app {
        server unix:///var/www/web_app/shared/tmp/sockets/web_app-puma.sock;
}

server {
        listen 80;

        root /var/www/web_app/current/public;
        server_name localhost;

        try_files $uri/index.html $uri @police_iot;

        location @police_iot {
                proxy_pass http://web_app;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
        }
}

&lt;/code&gt;&lt;/pre&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ nginx -s reload 重新加载nginx配置
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;七.end 真香 谢谢收看&lt;/p&gt;

&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2020/e79069d1-8dfe-4c4d-b4bc-26322e931a3b.jpg!large" title="" alt=""&gt;&lt;/p&gt;</description>
      <author>liurui12w</author>
      <pubDate>Tue, 12 May 2020 22:21:03 +0800</pubDate>
      <link>https://ruby-china.org/topics/39863</link>
      <guid>https://ruby-china.org/topics/39863</guid>
    </item>
    <item>
      <title>Ruby Socket，字符解码</title>
      <description>&lt;h2 id="tcp Socket，字符解码"&gt;tcp Socket，字符解码&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;ruby&lt;/strong&gt;有自带的 socket 库&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'socket'      # Sockets 是标准库

hostname = 'localhost'
port = 2000

s = TCPSocket.open(hostname, port)

while line = s.gets   # 从 socket 中读取每行数据
  puts line.chop      # 打印到终端
end
s.close               # 关闭 socket
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;然后针对上面的做一点点小小的补充&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = TCPSocket.open(hostname, port)
s.read 14             #read X 以字节的模式来读取数据
# 我这个14个字节  "\xEA\xE5\n\x10pt\x00\x01\x00\x00\x00\x00\x00\xF5"

s.gets                #gets 语句可用于获取来自名为 STDIN 的标准屏幕的用户输入
#gets 会获取 "\xE5\n" 以\n结尾截取前面的字节
#"\x00\x00\x00\x00U\xEA\xE5\n"

s.getc                #获取一个字节,依次获取后面的字节
#2.4.1 :012 &amp;gt; s.getc
#    =&amp;gt; "\xD0"
#   2.4.1 :013 &amp;gt; s.getc
#    =&amp;gt; "t"
#   2.4.1 :014 &amp;gt; s.getc
#    =&amp;gt; "\x00"
#   2.4.1 :015 &amp;gt; s.getc
#    =&amp;gt; "\x01"
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;其他还有一些我就不说明了，这些都是 ruby &lt;strong&gt;文件的输入与输出&lt;/strong&gt;相关的命令&lt;/p&gt;

&lt;p&gt;借鉴别人的帖子   &lt;a href="https://www.jianshu.com/p/4bdb84dea93a" rel="nofollow" target="_blank"&gt;https://www.jianshu.com/p/4bdb84dea93a&lt;/a&gt; &lt;/p&gt;

&lt;hr&gt;

&lt;p&gt;&lt;strong&gt;unpack&lt;/strong&gt; 转码相关的
官方资料&lt;a href="https://ruby-doc.org/core-2.6.4/String.html#method-i-unpack" rel="nofollow" target="_blank"&gt;https://ruby-doc.org/core-2.6.4/String.html#method-i-unpack&lt;/a&gt;&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#h 16进制字符串(下级半字节在先)
pack  unpack 互转
["10ef"].pack("h*") =&amp;gt; "\001\376"
"\x01\xfe".unpack("h*") =&amp;gt; ["10ef"]

#这里我针对的是对二进制进行解码
b = s.read(14) =&amp;gt; "\x10\xFEt\x00\x01\x00\x00\x00\x00\x00\x83\xEA\xE5\n"

b.unpack('H*') =&amp;gt; ["10fe740001000000000083eae50a"]
b.unpack('H*').pack('H*') =&amp;gt; "\x10\xFEt\x00\x01\x00\x00\x00\x00\x00\x83\xEA\xE5\n"
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;pack/unpack 的摸板字符字符 含义&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a 一个填充空的字节串
A 一个填充空格的字节串
b 一个位串，在每个字节里位的顺序都是升序
B 一个位串，在每个字节里位的顺序都是降序
c 一个有符号 char（8位整数）值
C 一个无符号 char（8位整数）值；关于 Unicode 参阅 U
d 本机格式的双精度浮点数
f 本机格式的单精度浮点数
h 一个十六进制串，低四位在前
H 一个十六进制串，高四位在前
i 一个有符号整数值，本机格式
I 一个无符号整数值，本机格式
l 一个有符号长整形，总是 32 位
L 一个无符号长整形，总是 32 位
n 一个 16位短整形，“网络”字节序（大头在前）
N 一个 32 位短整形，“网络”字节序（大头在前）
p 一个指向空结尾的字串的指针
P 一个指向定长字串的指针
q 一个有符号四倍（64位整数）值
Q 一个无符号四倍（64位整数）值
s 一个有符号短整数值，总是 16 位
S 一个无符号短整数值，总是 16 位，字节序跟机器芯片有关
u 一个无编码的字串
U 一个 Unicode 字符数字
v 一个“VAX”字节序（小头在前）的 16 位短整数
V 一个“VAX”字节序（小头在前）的 32 位短整数
w 一个 BER 压缩的整数
x 一个空字节（向前忽略一个字节）
X 备份一个字节
Z 一个空结束的（和空填充的）字节串
@ 用空字节填充绝对位置    
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>liurui12w</author>
      <pubDate>Thu, 12 Sep 2019 10:22:23 +0800</pubDate>
      <link>https://ruby-china.org/topics/39044</link>
      <guid>https://ruby-china.org/topics/39044</guid>
    </item>
    <item>
      <title>微信的申请退款</title>
      <description>&lt;p&gt;微信申请退款&lt;/p&gt;

&lt;p&gt;微信官方文档&lt;a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4" rel="nofollow" target="_blank"&gt;https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4&lt;/a&gt;
请先看官方文档&lt;/p&gt;

&lt;p&gt;接口地址
接口链接：&lt;a href="https://api.mch.weixin.qq.com/secapi/pay/refund" rel="nofollow" target="_blank"&gt;https://api.mch.weixin.qq.com/secapi/pay/refund&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;官方需求
请求需要双向证书（没有加证书的话无法访问）&lt;/p&gt;

&lt;p&gt;请求参数（详细请看官方文档）&lt;/p&gt;

&lt;p&gt;例子
 &lt;img src="https://l.ruby-china.com/photo/2019/caf4ca72-af29-48be-91e6-974795388fbd.png!large" title="" alt=""&gt;&lt;/p&gt;
&lt;h4 id="下面是我实现的代码"&gt;下面是我实现的代码&lt;/h4&gt;
&lt;p&gt;url = URI.parse('&lt;a href="https://api.mch.weixin.qq.com/secapi/pay/refund" rel="nofollow" target="_blank"&gt;https://api.mch.weixin.qq.com/secapi/pay/refund&lt;/a&gt;')
http = Net::HTTP.new(url.host, url.port)
 #这是我存放在配置文件里
app_id = ENV['SmallAppID']&lt;br&gt;
app_key = ENV['Smallkey']
mch_id = ENV['Smallmch_id']&lt;/p&gt;
&lt;h4 id="https双向认证"&gt;https 双向认证&lt;/h4&gt;
&lt;p&gt;http.use_ssl = true if url.scheme == 'https'&lt;/p&gt;

&lt;p&gt;http.cert = OpenSSL::X509::Certificate.new(File.read("config/apiclient_cert.pem"))&lt;/p&gt;

&lt;p&gt;http.key = OpenSSL::PKey::RSA.new((File.read("config/apiclient_key.pem")))&lt;/p&gt;

&lt;p&gt;http.verify_mode = OpenSSL::SSL::VERIFY_NONE&lt;/p&gt;

&lt;p&gt;req = Net::HTTP::Post.new(url, {'Content-Type' =&amp;gt; 'application/xml'})&lt;/p&gt;

&lt;p&gt;nonce_str = [&lt;em&gt;'a'..'z',&lt;/em&gt;'0'..'9',*'A'..'Z'].sample(32).join #随机数&lt;/p&gt;

&lt;p&gt;#传的 xml
body_xml = "#{app_id}#{mch_id}#{nonce_str}#{&lt;a href="/last_order.payment.p" class="user-mention" title="@last_order.payment.p"&gt;&lt;i&gt;@&lt;/i&gt;last_order.payment.p&lt;/a&gt;ayment_no}#{&lt;a href="/last_order.payment.p" class="user-mention" title="@last_order.payment.p"&gt;&lt;i&gt;@&lt;/i&gt;last_order.payment.p&lt;/a&gt;ayment_no}#{Float(&lt;a href="/last_order.payment.t" class="user-mention" title="@last_order.payment.t"&gt;&lt;i&gt;@&lt;/i&gt;last_order.payment.t&lt;/a&gt;otal_money*100).round}#{Float(&lt;a href="/last_order.payment.t" class="user-mention" title="@last_order.payment.t"&gt;&lt;i&gt;@&lt;/i&gt;last_order.payment.t&lt;/a&gt;otal_money*100).round}"&lt;/p&gt;

&lt;p&gt;#签名  可在&lt;a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=20_1" rel="nofollow" target="_blank"&gt;https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=20_1&lt;/a&gt;  先测试
sign = Digest::MD5.hexdigest("appid=#{app_id}&amp;amp;mch_id=#{mch_id}&amp;amp;nonce_str=#{nonce_str}&amp;amp;out_refund_no=#{&lt;a href="/last_order.payment.p" class="user-mention" title="@last_order.payment.p"&gt;&lt;i&gt;@&lt;/i&gt;last_order.payment.p&lt;/a&gt;ayment_no}&amp;amp;out_trade_no=#{&lt;a href="/last_order.payment.p" class="user-mention" title="@last_order.payment.p"&gt;&lt;i&gt;@&lt;/i&gt;last_order.payment.p&lt;/a&gt;ayment_no}&amp;amp;refund_fee=#{Float(&lt;a href="/last_order.payment.t" class="user-mention" title="@last_order.payment.t"&gt;&lt;i&gt;@&lt;/i&gt;last_order.payment.t&lt;/a&gt;otal_money*100).round}&amp;amp;total_fee=#{Float(&lt;a href="/last_order.payment.t" class="user-mention" title="@last_order.payment.t"&gt;&lt;i&gt;@&lt;/i&gt;last_order.payment.t&lt;/a&gt;otal_money*100).round}&amp;amp;key=#{app_key}")&lt;/p&gt;

&lt;p&gt;body_xml += "#{sign.upcase}"   #这里的签名需要转大写&lt;/p&gt;

&lt;p&gt;req.body = body_xml&lt;/p&gt;

&lt;p&gt;response = http.request(req)
result = Hash.from_xml(response.body)["xml"]&lt;/p&gt;

&lt;p&gt;结果
result ["return_code"]  SUCCESS/FAIL&lt;/p&gt;</description>
      <author>liurui12w</author>
      <pubDate>Thu, 17 Jan 2019 11:07:26 +0800</pubDate>
      <link>https://ruby-china.org/topics/38012</link>
      <guid>https://ruby-china.org/topics/38012</guid>
    </item>
    <item>
      <title>capistrano 问题 狗子在这先说声谢谢 麻烦来会的教一下</title>
      <description>&lt;p&gt;capistrano 做服务器部署&lt;/p&gt;

&lt;p&gt;deploy 文件
&lt;img src="https://l.ruby-china.com/photo/2018/612fea09-bab4-42e5-8d4b-e4b4a27c4cc1.png!large" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;gefile
gem 'capistrano'
gem 'capistrano-rails'
gem 'capistrano-rvm'
gem 'capistrano-passenger'&lt;/p&gt;

&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2018/336a662a-f01c-40b1-8c81-c16ad0bb6abc.png!large" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;重头戏来了  ❌错误点
我用的 cap production deploy
出现了下面的 错 
&lt;img src="https://l.ruby-china.com/photo/2018/f1387daa-112d-459e-9e0b-f9b4d73e4599.png!large" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;在这里请教一下 各位 十分感谢&lt;/p&gt;</description>
      <author>liurui12w</author>
      <pubDate>Fri, 18 May 2018 16:27:47 +0800</pubDate>
      <link>https://ruby-china.org/topics/36798</link>
      <guid>https://ruby-china.org/topics/36798</guid>
    </item>
    <item>
      <title>Whenever 每 20 秒执行任务</title>
      <description>&lt;p&gt;针对 whenever 每 20 秒走一波任务的需求
利用 rake 任务
首先在 rake 里写好自己想要 20 秒一次的执行的任务
&lt;img src="https://l.ruby-china.com/photo/2018/0f719992-0ed6-4b47-83c7-31ef674951bf.jpg!large" title="" alt=""&gt;
之后再 利用 whenever 的 config/schedule.rb 写一个每分钟执行一次
&lt;img src="https://l.ruby-china.com/photo/2018/62e7f2b1-2e3d-4e39-be00-2340d6490812.jpg!large" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;本狗子第一次发还望各位大佬 多多指教（新手）
有更好的方法 还望指点 以上就是我目前的解决方法&lt;/p&gt;</description>
      <author>liurui12w</author>
      <pubDate>Thu, 03 May 2018 18:32:17 +0800</pubDate>
      <link>https://ruby-china.org/topics/36675</link>
      <guid>https://ruby-china.org/topics/36675</guid>
    </item>
  </channel>
</rss>
