修改openid调用位置

This commit is contained in:
guange 2016-04-02 07:43:55 +08:00
parent 7d4de36521
commit 9c93b3f9a6
2 changed files with 4 additions and 3 deletions

View File

@ -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

View File

@ -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',