Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
weixin_authorize
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
weixin_authorize
Commits
45a505f9
Commit
45a505f9
authored
Mar 16, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor client.rb with "http_get" and "http_post" method
parent
41f8fbc0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
5 deletions
+20
-5
lib/weixin_authorize/client.rb
+20
-5
No files found.
lib/weixin_authorize/client.rb
View file @
45a505f9
# encoding: utf-8
# encoding: utf-8
module
WeixinAuthorize
module
WeixinAuthorize
class
Client
class
Client
...
@@ -29,15 +28,15 @@ module WeixinAuthorize
...
@@ -29,15 +28,15 @@ module WeixinAuthorize
# authenticate access_token
# authenticate access_token
def
authenticate
def
authenticate
hash_infos
=
JSON
.
parse
(
RestClient
.
get
(
authenticate_url
)
)
hash_infos
=
http_get_without_token
(
"/token"
,
authenticate_options
)
self
.
access_token
=
hash_infos
[
"access_token"
]
self
.
access_token
=
hash_infos
[
"access_token"
]
self
.
expired_at
=
Time
.
now
.
to_i
+
hash_infos
[
"expires_in"
]
self
.
expired_at
=
Time
.
now
.
to_i
+
hash_infos
[
"expires_in"
]
end
end
private
private
def
authenticate_
url
def
authenticate_
options
"
#{
endpoint
}
/token?grant_type=client_credential&appid=
#{
app_id
}
&secret=
#{
app_secret
}
"
{
grant_type:
"client_credential"
,
appid:
app_id
,
secret:
app_secret
}
end
end
def
endpoint
def
endpoint
...
@@ -45,7 +44,23 @@ module WeixinAuthorize
...
@@ -45,7 +44,23 @@ module WeixinAuthorize
end
end
def
access_token_param
def
access_token_param
"access_token=
#{
get_access_token
}
"
{
access_token:
get_access_token
}
end
def
http_get_without_token
(
url
,
options
=
{})
get_api_url
=
endpoint
+
url
JSON
.
parse
(
RestClient
.
get
(
get_api_url
,
:params
=>
options
))
end
def
http_get
(
url
,
options
=
{})
options
=
options
.
merge
(
access_token_param
)
http_get_without_token
(
url
,
options
)
end
# Refactor
def
http_post
(
url
,
options
=
{})
post_api_url
=
endpoint
+
url
+
"?access_token=
#{
get_access_token
}
"
JSON
.
parse
(
RestClient
.
post
(
post_api_url
,
options
))
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment