修改openid调用位置
This commit is contained in:
parent
7d4de36521
commit
9c93b3f9a6
|
@ -214,7 +214,10 @@ class WechatsController < ActionController::Base
|
|||
private
|
||||
def get_openid(code)
|
||||
url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=#{Wechat.config.appid}&secret=#{Wechat.config.secret}&code=#{code}&grant_type=authorization_code"
|
||||
JSON.parse(URI.parse(url).read)["openid"]
|
||||
logger.debug url
|
||||
body = URI.parse(url).read
|
||||
logger.debug body
|
||||
JSON.parse(body)["openid"]
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -15,12 +15,10 @@ $(function(){
|
|||
}
|
||||
|
||||
window.getOpenId = function(cb){
|
||||
alert(g_openid);
|
||||
if (g_openid.length>0){
|
||||
cb(g_openid);
|
||||
}
|
||||
var code = getUrlParam("code");
|
||||
alert(code);
|
||||
$.ajax({
|
||||
url: '/wechat/get_open_id?code='+code,
|
||||
type: 'get',
|
||||
|
|
Loading…
Reference in New Issue