mini_program 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04f5a8d75c16656473df0c93306b9d83833c272037d7fb60e894756eed9f4b1c
4
- data.tar.gz: '0868870f615a9e08047465024b8293be7af4080d64fa4b1d7313ea7b56926e4a'
3
+ metadata.gz: 9e2c0b3867e69b14bd0b48c77f4ef511a50c3eeda45bfac4bdcfd41c9fa69eb7
4
+ data.tar.gz: 9a35b4627a3c00b3081ae16ab99a1fac3b31fc786466c3bce50fabe5f0391cc8
5
5
  SHA512:
6
- metadata.gz: ee4c68f56483b9acdbee602db221033ea503738ddd63409288b864d130ea37ca23a291fc2392a3f146ea0c5991236e8acd0f1f48a4f05ae8f817ef4f5792e100
7
- data.tar.gz: e1ec32db171b7e4fe2168ac715668e9f6ed9e3704e276c7a61b7e6dbc30a6b30858bec73acf83c406459ef32c85382954c89e6e2efdf29ce40c86fae733d3a86
6
+ metadata.gz: aa7101d925adebb94374f8677848c8dfb75868aacc14719a09c75639e22cb771c0ef6511edcd24868a220985eaf06ccdf761d4eda5b48c045329ed529c413387
7
+ data.tar.gz: b82d829d7eb32aac1a2a6f0d6f161d5f40932562bc976504516d9a10619ab509a0b51b3da0ea6c41c128fc227488e4f8618913f9ddf9a839dd2b22b75a843018
data/Rakefile CHANGED
@@ -1,5 +1,10 @@
1
1
  require "bundler/setup"
2
2
 
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
3
8
  require "bundler/gem_tasks"
4
9
 
5
10
  require "rake/testtask"
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/mini_program .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ module MiniProgram
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,34 @@
1
+ require_dependency "mini_program/application_controller"
2
+
3
+ module MiniProgram
4
+ class WechatController < ApplicationController
5
+ skip_forgery_protection
6
+
7
+ # POST /wechat/login
8
+ def login
9
+ result = MiniProgram::Client.new.login(params["code"])
10
+
11
+ if result.success?
12
+ cookies.signed[:open_id] = result.data["openid"]
13
+ cookies.signed[:session_key] = result.data["session_key"]
14
+ render json: current_mp_user
15
+ else
16
+ render json: { errors: result.errors }
17
+ end
18
+ end
19
+
20
+ # POST /wechat/phone_num
21
+ def phone_num
22
+ client = MiniProgram::Client.new
23
+ result = client.get_phone_num(code: params[:code], encrypted_data: params[:encrypted_data], iv: params[:iv])
24
+
25
+ if result.success?
26
+ cookies.signed[:phone_num] = result.data[:phone_num]
27
+
28
+ render json: result.data
29
+ else
30
+ render json: { errors: result.errors }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ module MiniProgram
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module MiniProgram
2
+ module WechatHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module MiniProgram
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module MiniProgram
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module MiniProgram
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Mini program</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "mini_program/application", media: "all" %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
@@ -0,0 +1,2 @@
1
+ <h1>Wechat#login</h1>
2
+ <p>Find me in app/views/mini_program/wechat/login.html.erb</p>
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ MiniProgram::Engine.routes.draw do
2
+ post 'wechat/login'
3
+ post 'wechat/phone_num'
4
+ end
@@ -0,0 +1,10 @@
1
+
2
+
3
+ ActionController::Base.class_eval do
4
+ def current_mp_user
5
+ MiniProgram::User.new(open_id: cookies.signed[:open_id],
6
+ nickname: cookies.signed[:nickname],
7
+ phone_num: cookies.signed[:phone_num],
8
+ session_key: cookies.signed[:session_key])
9
+ end
10
+ end
data/lib/mini_program.rb CHANGED
@@ -1,16 +1,19 @@
1
1
  require "mini_program/version"
2
- require "mini_program/railtie"
2
+ require "mini_program/engine"
3
3
  require "mini_program/client"
4
4
  require "mini_program/msg"
5
+ require "mini_program/user"
6
+ require "application_controller_ext"
5
7
  require "r_logger"
6
8
  require "service_result"
7
9
  require "redis"
10
+ require "mocha"
8
11
 
9
12
  module MiniProgram
10
- # Your code goes here...
11
13
  mattr_accessor :appid, :app_secret
12
14
 
13
15
  def self.setup
14
16
  yield self if block_given?
15
17
  end
18
+
16
19
  end
@@ -20,14 +20,16 @@ module MiniProgram
20
20
  end
21
21
 
22
22
  def get_access_token(fresh: false)
23
- access_token = redis.get("mp-#{appid}-access-token")
23
+ access_token = redis.get(access_token_store_key)
24
+
24
25
  if access_token.present? && !fresh
25
26
  return MiniProgram::ServiceResult.new(success: true, data: {access_token: access_token})
26
27
  end
27
28
 
28
29
  result = request_access_token
30
+
29
31
  if result.success?
30
- redis.setex "mp-#{appid}-access-token", 1.5.hours.to_i, access_token
32
+ redis.setex access_token_store_key, 1.5.hours.to_i, result.data["access_token"]
31
33
  end
32
34
 
33
35
  yield result if block_given?
@@ -56,7 +58,7 @@ module MiniProgram
56
58
  api: #{api}
57
59
  error: #{result}
58
60
  ERROR
59
- return MiniProgram::ServiceResult.new(success: false, errors: result, message: result["errmsg"])
61
+ return MiniProgram::ServiceResult.new(success: false, data: result, message: result["errmsg"])
60
62
  end
61
63
 
62
64
  MiniProgram::ServiceResult.new(success: true, data: result)
@@ -190,7 +192,7 @@ module MiniProgram
190
192
  end
191
193
 
192
194
  def access_token_store_key
193
- "mp-#{appid}-access-token"
195
+ @access_token_store_key ||= "mp-#{appid}-access-token"
194
196
  end
195
197
 
196
198
  def msg_logger
@@ -0,0 +1,5 @@
1
+ module MiniProgram
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace MiniProgram
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+
2
+ class MiniProgram::User
3
+ attr_accessor :open_id, :nickname, :phone_num, :session_key
4
+
5
+ def initialize(open_id: :blank_open_id,
6
+ nickname: :blank_nickname,
7
+ phone_num: :blank_phone_num,
8
+ session_key: :blank_session_key)
9
+ @open_id = open_id
10
+ @nickname = nickname
11
+ @phone_num = phone_num
12
+ @session_key = session_key
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module MiniProgram
2
- VERSION = '0.1.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_program
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-18 00:00:00.000000000 Z
11
+ date: 2021-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -39,20 +39,21 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: pry-rails
42
+ name: mocha
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- type: :development
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: 登录授权,发送订阅消息
55
+ description: include login, send subscribe message, get phone number function of mini
56
+ program
56
57
  email:
57
58
  - ianlynxk@gmail.com
58
59
  executables: []
@@ -62,6 +63,20 @@ files:
62
63
  - MIT-LICENSE
63
64
  - README.md
64
65
  - Rakefile
66
+ - app/assets/config/mini_program_manifest.js
67
+ - app/assets/stylesheets/mini_program/application.css
68
+ - app/assets/stylesheets/mini_program/wechat.css
69
+ - app/controllers/mini_program/application_controller.rb
70
+ - app/controllers/mini_program/wechat_controller.rb
71
+ - app/helpers/mini_program/application_helper.rb
72
+ - app/helpers/mini_program/wechat_helper.rb
73
+ - app/jobs/mini_program/application_job.rb
74
+ - app/mailers/mini_program/application_mailer.rb
75
+ - app/models/mini_program/application_record.rb
76
+ - app/views/layouts/mini_program/application.html.erb
77
+ - app/views/mini_program/wechat/login.html.erb
78
+ - config/routes.rb
79
+ - lib/application_controller_ext.rb
65
80
  - lib/generators/mini_program/install/USAGE
66
81
  - lib/generators/mini_program/install/install_generator.rb
67
82
  - lib/generators/mini_program/install/templates/initializer.rb
@@ -70,19 +85,20 @@ files:
70
85
  - lib/generators/mini_program/msg_config/templates/subscribe_msg.yml
71
86
  - lib/mini_program.rb
72
87
  - lib/mini_program/client.rb
88
+ - lib/mini_program/engine.rb
73
89
  - lib/mini_program/msg.rb
74
- - lib/mini_program/railtie.rb
90
+ - lib/mini_program/user.rb
75
91
  - lib/mini_program/version.rb
76
92
  - lib/r_logger.rb
77
93
  - lib/service_result.rb
78
94
  - lib/tasks/mini_program_tasks.rake
79
- homepage: https://github.com/otorain
95
+ homepage: https://github.com/bkyz/mini_program
80
96
  licenses:
81
97
  - MIT
82
98
  metadata:
83
- homepage_uri: https://github.com/otorain
84
- source_code_uri: https://github.com/otorain/mini_program
85
- changelog_uri: https://github.com/otorain/mini_program/CHANGELOG.md
99
+ homepage_uri: https://github.com/bkyz/mini_program
100
+ source_code_uri: https://github.com/bkyz/mini_program
101
+ changelog_uri: https://github.com/bkyz/mini_program/CHANGELOG.md
86
102
  post_install_message:
87
103
  rdoc_options: []
88
104
  require_paths:
@@ -101,5 +117,5 @@ requirements: []
101
117
  rubygems_version: 3.2.15
102
118
  signing_key:
103
119
  specification_version: 4
104
- summary: 小程序api开发工具
120
+ summary: a engine for develop mini program
105
121
  test_files: []
@@ -1,4 +0,0 @@
1
- module MiniProgram
2
- class Railtie < ::Rails::Railtie
3
- end
4
- end