新手问题 短信接口编码格式

liker · 2013年04月27日 · 最后由 a805717453 回复于 2013年06月17日 · 3786 次阅读
@str="您的身份校验码为:"+@pass+"(30分钟有效)。如非本人操作,请及时修改密码,以防被盗。"
      url=URI.escape('http://www.smsadmin.cn/smsmarketing/wwwroot/api/get_send/?uid=****&pwd=******&mobile=155********&msg=ninhao'+@str)

短信只能收到 ninhao 后面的中文信息不能得到 短信接口支持 GB2312 求解决

url = "http://www.smsadmin.cn/smsmarketing/wwwroot/api/get_send/?uid=****&pwd=******&mobile=155********&msg=ninhao#{URI.escape(@str)}"
2 楼 已删除
input_encode='gbk'
out_encode='utf8'
@str="您的身份校验码为:"+@pass+"(30分钟有效)。"
      url='http://www.smsadmin.cn/smsmarketing/wwwroot/api/get_send/?uid=****&pwd=******&mobile=155********&msg=ninhao#{URI.escape(@str)}'
      @rs=Iconv.new(out_encode,input_encode).iconv(Net::HTTP.get(URI(url)))
Mechanize.new.get('http://www.smsadmin.cn/smsmarketing/wwwroot/api/get_send/',
                                { uid: ***,
                                  pwd: ****,
                                  mobile: ***,
                                  msg: "nihao#{@str}",
                                })

撸主用个 gem 岂不是很好

还是不行啊!急需解决、、求帮忙、

@liker 你把 url 的'改为"试试。

url="http://www.smsadmin.cn/smsmarketing/wwwroot/api/get_send/?uid=****&pwd=******&mobile=155********&msg=ninhao#{URI.escape(@str)}"

昨天不是解决了么?完整代码贴出来看看吧。

昨天没试中文的 英文的已经能实现了、、

#coding: UTF-8
class PhoneController < ApplicationController
  #require 'net/http'
  require 'iconv'
  def pwd_phone
    @phone_number=params[:phone_num]
    @user=User.find_by_phone_number(@phone_number)
    if @user.nil?
      redirect_to :back
    else
      @pass=""
      6.times do
        @pass=@pass+rand(9).to_s
      end
      input_encode='gbk'
      out_encode='utf8'
        @str="您的身份校验码为:"+@pass+"(30分钟有效)。" 
      url="http://www.smsadmin.cn/smsmarketing/wwwroot/api/get_send/?uid=liker&pwd=0&mobile=155********&msg=ninhao"+@str
      @rs=Iconv.new(out_encode,input_encode).iconv(Net::HTTP.get(url))
      a=@rs.split(//).first
      if a.to_i==0

      else
        redirect_to "/phone/result?rs="+a+"&rss="+@pass+"&str="+@str
      end
    end
  end
end

出错信息是什么?

1 发送过去了、、它只显示英文不显示中文 2 报错 bad uri 如 3 楼所示

URI.encode, 处理一下中文,试试看。

之前也遇到过类似问题,后来查资料说要在编码格式后面加//IGNORE Iconv.iconv("GB2312//IGNORE","UTF-8//IGNORE",message).join('')

#coding: utf-8
class ShortMessage < ActiveRecord::Base
  require 'iconv'

  def send_token!(message)
    raise "系统已向您的手机发送过验证码,请勿频繁重复操作。" if self.invalid_date?

    if self.can_send?
      msg = Iconv.iconv("GB2312//IGNORE","UTF-8//IGNORE",message).join('')
      res = `curl "http://sms.mobset.com/SDK/Sms_Send.asp?CorpID=#{SMS_ID}&LoginName=#{SMS_NAME}&passwd=#{SMS_PWD}&send_no=#{self.phone}&msg=#{msg}"`
      status = res.first.to_i
      raise "发送失败,请检查您输入的手机号是否正确。" if status <= 0
      self.sent_at = Time.current
      self.message = message
      self.save!
    end
  end
end
  $ec2 = Encoding::Converter.new("UTF-8","GB18030", :universal_newline => true)
class String
  def xx
    $ec2.convert self
  end
end
16 楼 已删除
需要 登录 后方可回复, 如果你还没有账号请 注册新账号