@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)}"
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
之前也遇到过类似问题,后来查资料说要在编码格式后面加//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