Rails 之微信开发 : OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
Posted on 2015-02-12 15:18 且行且思 阅读(5149) 评论(0) 编辑 收藏 举报微信公众平台,使用Ruby On Rails + Win7
在取得OpenID时,如果简单的使用http.get方法,会出现如下
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
解决方案:
def get_open_id code
url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxx&secret=xxx&code=#{code}&grant_type=authorization_code"
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new("/sns/oauth2/access_token?appid=xx&secret=xxx=#{code}&grant_type=authorization_code")
request.add_field('Content-Type', 'application/json')
#request.body = post_data.to_json
response = http.request(request)
json = JSON.parse(response.body)
return json
end
二, 在生成二维码的时候,取得ticket时,如果简单的使用post_form方法,会出现如下
{"errcode":40052,"errmsg":"invalid action name"}
原因大致就是微信服务器收到的JSON格式不合法,不知道post_form提交的最终数据是怎么样的。
变通的方法是自己写post方法,稍微麻烦一些
uri = URI.parse("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=#{access_token}") post_data = {"expire_seconds" => 1800, "action_name" => "QR_SCENE", "action_info" => {"scene" => {"scene_id" => 123}}} http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new("/cgi-bin/qrcode/create?access_token=#{access_token}") request.add_field(‘Content-Type‘, ‘application/json‘) request.body = post_data.to_json response = http.request(request) json = JSON.parse(response.body)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!