Class: MiniProgram::WechatController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- MiniProgram::WechatController
- Defined in:
- app/controllers/mini_program/wechat_controller.rb
Instance Method Summary collapse
-
#login ⇒ Object
POST /wechat/login.
-
#phone_num ⇒ Object
POST /wechat/phone_num.
Instance Method Details
#login ⇒ Object
POST /wechat/login
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/mini_program/wechat_controller.rb', line 8 def login result = MiniProgram::Client.new.login(params["code"]) if result.success? .signed[:openid] = result.data["openid"] .signed[:session_key] = result.data["session_key"] .signed[:options] = params[:options].permit! after_mp_login if respond_to? :after_mp_login render json: ServiceResult.new(success: true, data: { current_user: current_mp_user }, message: "登录成功", message_kind: :login_success) else render json: result, status: 500 end end |
#phone_num ⇒ Object
POST /wechat/phone_num
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/mini_program/wechat_controller.rb', line 28 def phone_num client = MiniProgram::Client.new result = client.decrypt_phone_num(code: params[:code], encrypted_data: params[:encrypted_data], iv: params[:iv]) if result.success? .signed[:phone_num] = result.data[:phone_num] render json: result else render json: result, status: 500 end end |