锁定老帖子 主题:最小的ruby飞信客户端
精华帖 (7) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2010-07-27
移动停止了低版本电脑客户端的登陆。有空再改造下吧。难怪定时天气预报也没有了
|
|
返回顶楼 | |
发表时间:2010-07-27
最后修改:2010-07-27
呵呵,我的天气预报也没有了。
是移动停止低版本号客户端登陆,那很简单吧,修改下版本号不就成了? |
|
返回顶楼 | |
发表时间:2010-07-29
lz,搞定了。
|
|
返回顶楼 | |
发表时间:2010-07-29
更新部分代码,ubuntu下测试通过。http://gist.github.com/498262
|
|
返回顶楼 | |
发表时间:2010-07-30
我照着 http://code.google.com/p/maplefetion/ 这个例子改了下,目前在我机器上(windows 2003)可用
require 'uri' require 'net/http' require 'net/https' require "socket" require 'rexml/document' require 'digest/md5' require 'digest/sha1' require "iconv" class Fetion def initialize(phone_num , password) @phone_num = phone_num; @password = password; @domain = "fetion.com.cn"; #@domain = "feixin.10086.cn" @login_xml = '<args><device type="PC" version="0" client-version="4.0.3390" /><caps value="simple-im;im-session;temp-group;personal-group" /><events value="contact;permission;system-message;personal-group" /><user-info attributes="all" /><presence><basic value="400" desc="" /></presence></args>'; self.init end def init doc = REXML::Document.new(self.get_system_config()) sipc_proxy = "" doc.elements.each("//sipc-proxy") do |element| # using regexp should be faster sipc_proxy = element.text end @SIPC = SIPC.new(sipc_proxy); sipc_url = "" doc.elements.each("//ssi-app-sign-in") do |element| sipc_url = element.text end @fetion_num = self.get_fetion_num(self.SSIAppSignIn(sipc_url)); doc.elements.each("//http-tunnel") do |element| @http_tunnel = element.text end end def login() request1 = sprintf("R %s SIP-C/2.0\r\nF: %s\r\nI: 1\r\nQ: 1 R\r\nL: %s\r\n\r\n",@domain, @fetion_num, @login_xml.length); request1 = request1 + @login_xml; server_response = @SIPC.request(request1); @nonce = server_response.scan(/nonce="(.*)"/)[0][0] request2 = sprintf("R %s SIP-C/2.0\r\nF: %s\r\nI: 1\r\nQ: 2 R\r\nA: Digest response=\"%s\",cnonce=\"%s\"\r\nL: %s\r\n\r\n", @domain, @fetion_num, self.get_response(), @cnonce, @login_xml.length); request2 = request2 + @login_xml; @SIPC.request(request2); end def send_sms(phone, sms_text) sms_text = Iconv.iconv("UTF-8","GB2312",sms_text)[0] request = sprintf("M %s SIP-C/2.0\r\nF: %s\r\nI: 2\r\nQ: 1 M\r\nT: tel:%s\r\nN: SendSMS\r\nL: %s\r\n\r\n",@domain, @fetion_num, phone, sms_text.length); request = request + sms_text; @SIPC.request(request); end def send_sms_to_self(sms_text) sms_text = Iconv.iconv("UTF-8","GB2312",sms_text)[0] request = sprintf("M %s SIP-C/2.0\r\nF: %s\r\nI: 2\r\nQ: 1 M\r\nT: %s\r\nN: SendCatSMS\r\nL: %s\r\n\r\n",@domain, @fetion_num, @uri, sms_text.length); request = request + sms_text @SIPC.request(request); end def logout() logout_request = sprintf("R %s SIP-C/2.0\r\nF: %s\r\nI: 1 \r\nQ: 3 R\r\nX: 0\r\n\r\n", @domain, @fetion_num); @SIPC.request(logout_request); end def get_response() @cnonce = Digest::MD5.hexdigest(rand.to_s) puts "conce: #{@cnonce} , fetion_num: #{@fetion_num} , domain : #{@domain} ,password:#{@password}" key = Digest::MD5.digest(@fetion_num + ":" + @domain + ":" + @password) h1 = Digest::MD5.hexdigest(key + ":" + @nonce + ":" + @cnonce).upcase h2 = Digest::MD5.hexdigest("REGISTER:" + @fetion_num).upcase return Digest::MD5.hexdigest(h1+":" + @nonce + ":" + h2).upcase end def get_system_config() uri = URI.parse("http://nav.fetion.com.cn/nav/getsystemconfig.aspx") http = Net::HTTP.new(uri.host, uri.port) params = sprintf('<config><user mobile-no="%s" /><client type="PC" version="4.0.3390" platform="W5.1" /><servers version="0" /><service-no version="0" /><parameters version="0" /><hints version="0" /><http-applications version="0" /><client-config version="0" /></config>',@phone_num) headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } resp = http.post(uri.path, params, headers) return resp.body end def SSIAppSignIn(url) uri = URI.parse(url); #path = uri.path + "?mobileno=" + @phone_num + "&pwd=" + @password path = "https://uid.fetion.com.cn/ssiportal/SSIAppSignInV2.aspx?mobileno="+ @phone_num + "&pwd=" + @password http = Net::HTTP.new(uri.host,uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE # turn off SSL warning resp, xml = http.get(path, nil) count = 0 while resp.response['set-cookie'].nil? break if count > 3 sleep(1) resp,xml=http.get(path,nil) count = count+1 end @cookie = resp.response['set-cookie'].split(';')[0] puts "cookie---------- #{@cookie}" @ssic = @cookie.split("=")[1] return xml end def get_fetion_num(xml) @uri = "" doc = REXML::Document.new(xml) doc.elements.each("//results/user") do |element| @uri = element.attribute("uri").value end return @uri.scan(/sip:([0-9]+)@/)[0][0] end end class SIPC def initialize(sipc_addr) puts sipc_addr #uri = "221.176.31.33:8080" uri = sipc_addr.split(":") @socket = TCPSocket.new(uri[0], uri[1].to_i) end # send SIP request def request(sip_request) puts sip_request @socket.write_nonblock(sip_request) #@socket.write(sip_request) #select,read_nonblock and rescue is the key #another choice may be: http://rev.rubyforge.org/ IO.select [@socket] res = "" begin while chunk = @socket.read_nonblock(4096) res = res + chunk end rescue end puts res return res end end 麻烦大家也测试一下 |
|
返回顶楼 | |
发表时间:2010-07-30
今天测试了一下,每次都要图形验证码,绕不过去了。正式宣布放弃维护这段代码。
|
|
返回顶楼 | |
发表时间:2010-07-31
楼上的飞信密码太简单?改为字母+数字试试?
|
|
返回顶楼 | |
发表时间:2010-08-01
如果只是做天气预报、服务器监控等应用,可以利用移动139邮箱的邮件到达通知来做(绝对免费的!)http://methodmissing.iteye.com/blog/726588
|
|
返回顶楼 | |
发表时间:2010-08-02
鹤惊昆仑 写道 今天测试了一下,每次都要图形验证码,绕不过去了。正式宣布放弃维护这段代码。
我怎么没有遇到图形验证码呢? 是不是如那位兄弟说的,密码设置的太过简单? 别这么轻易放弃哪 |
|
返回顶楼 | |