Class: MiniProgram::WechatController

Inherits:
ApplicationController show all
Defined in:
app/controllers/mini_program/wechat_controller.rb

Instance Method Summary collapse

Instance Method Details

#loginObject

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 
  result = MiniProgram::Client.new.(params["code"])

  if result.success?
    cookies.signed[:openid] = result.data["openid"]
    cookies.signed[:session_key] = result.data["session_key"]
    cookies.signed[:options] = params[:options].permit!

     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_numObject

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?
    cookies.signed[:phone_num] = result.data[:phone_num]

    render json: result
  else
    render json: result, status: 500
  end
end