struggle 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/struggle/concerns/int_extend.rb +38 -0
- data/lib/struggle/concerns/string_extend.rb +25 -3
- data/lib/struggle/func.rb +0 -74
- data/lib/struggle/logistic.rb +2 -54
- data/lib/struggle/pay_gateway.rb +2 -20
- data/lib/struggle/tfile.rb +0 -27
- data/lib/struggle/tmagick.rb +0 -13
- data/lib/struggle/vcode.rb +1 -20
- data/lib/struggle.rb +1 -0
- metadata +2 -2
- data/struggle.gemspec +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23e470f3375c4dc58c63564566e7b97a65647be4
|
4
|
+
data.tar.gz: 40f7f904b6c227aa19503d9971c28495685a91c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 855102cceafc8b208bf9bf860fa27718434c46b335861d9483320cb1d3ced42873f2c035dc06331d5bc3a2c23e7bbe43d6ff944dc06a70d78b7000f5021c9adb
|
7
|
+
data.tar.gz: 11aa7245292514b711339245a98ea8d4140119df70f60d9b6d0f81dbe10fec6c99abbe3f5c39dd9ddbc9b05e84b7e782503335615ad9d6b861af047f1ca8bbf2
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Struggle
|
2
|
+
module IntExtend
|
3
|
+
def uppercase
|
4
|
+
cstr = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"]
|
5
|
+
cn_nums1 = ["元", "拾", "佰", "仟", "萬", "拾", "佰", "仟", "億", "拾", "佰", "仟"]
|
6
|
+
cn_nums2 = ['分', '角']
|
7
|
+
s = ""
|
8
|
+
array = self.to_s.split(".")
|
9
|
+
p h = array[0].to_s.split(//)
|
10
|
+
ai = h.count
|
11
|
+
h.each_with_index do |a, j|
|
12
|
+
s+=cstr[a.to_i]+cn_nums1[ai-1]
|
13
|
+
ai=ai-1
|
14
|
+
end
|
15
|
+
p h1 = array[1].to_s.split(//)
|
16
|
+
aj = h1.count
|
17
|
+
h1.each_with_index do |o, p|
|
18
|
+
s+=cstr[o.to_i]+cn_nums2[aj-1]
|
19
|
+
aj=aj-1
|
20
|
+
end
|
21
|
+
rstr = ""
|
22
|
+
rstr=s.gsub("拾零", "拾")
|
23
|
+
rstr=rstr.gsub("零拾", "零");
|
24
|
+
rstr=rstr.gsub("零佰", "零");
|
25
|
+
rstr=rstr.gsub("零仟", "零");
|
26
|
+
rstr=rstr.gsub("零萬", "萬");
|
27
|
+
for i in 1..6 do
|
28
|
+
rstr=rstr.gsub("零零", "零");
|
29
|
+
rstr=rstr.gsub("零萬", "零");
|
30
|
+
rstr=rstr.gsub("零億", "億");
|
31
|
+
rstr=rstr.gsub("零零", "零");
|
32
|
+
end
|
33
|
+
rstr=rstr.gsub("零角", "零");
|
34
|
+
rstr=rstr.gsub("零分", "");
|
35
|
+
rstr=rstr.gsub("零元", "");
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,5 +1,27 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
1
|
+
module Struggle
|
2
|
+
module StringExtend
|
3
|
+
def html_clear
|
4
|
+
self.gsub(/<script.*?<\/script>/, "").gsub(/<iframe.*?<\/iframe>/, "")
|
5
|
+
end
|
6
|
+
|
7
|
+
def ischinese
|
8
|
+
(self=~/[\u4e00-\u9fa5]/).nil? ? false : true
|
9
|
+
end
|
10
|
+
|
11
|
+
def iscn_zn_num
|
12
|
+
(self=~/^[\u4e00-\u9fa5_a-zA-Z0-9]+$/).nil? ? false : true
|
13
|
+
end
|
14
|
+
|
15
|
+
def truncate_u(length = 30, truncate_string = "...")
|
16
|
+
l=0
|
17
|
+
char_array=self.unpack("U*")
|
18
|
+
char_array.each_with_index do |c, i|
|
19
|
+
l = l+ (c<127 ? 0.5 : 1)
|
20
|
+
if l>=length
|
21
|
+
return char_array[0..i].pack("U*")+(i<char_array.length-1 ? truncate_string : "")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
return self
|
25
|
+
end
|
4
26
|
end
|
5
27
|
end
|
data/lib/struggle/func.rb
CHANGED
@@ -1,78 +1,8 @@
|
|
1
1
|
module Struggle
|
2
2
|
class Func
|
3
|
-
# 判断是否含有中文
|
4
|
-
def self.ischinese(temp)
|
5
|
-
(temp=~/[\u4e00-\u9fa5]/).nil? ? false : true
|
6
|
-
end
|
7
|
-
|
8
|
-
# 判断是否只含有中英文,数字和下划线
|
9
|
-
def self.iscn_zn_num(temp)
|
10
|
-
(temp=~/^[\u4e00-\u9fa5_a-zA-Z0-9]+$/).nil? ? false : true
|
11
|
-
end
|
12
|
-
|
13
|
-
# 格式化时间
|
14
|
-
def self.formattime(time)
|
15
|
-
time.strftime("%Y-%m-%d %H:%M:%S")
|
16
|
-
end
|
17
|
-
|
18
|
-
# 限制文字长度
|
19
|
-
def self.truncate_u(text, length = 30, truncate_string = "...")
|
20
|
-
l=0
|
21
|
-
char_array=text.unpack("U*")
|
22
|
-
char_array.each_with_index do |c, i|
|
23
|
-
l = l+ (c<127 ? 0.5 : 1)
|
24
|
-
if l>=length
|
25
|
-
return char_array[0..i].pack("U*")+(i<char_array.length-1 ? truncate_string : "")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
return text
|
29
|
-
end
|
30
|
-
|
31
|
-
# 金额大写小转换
|
32
|
-
def self.uppercase(nums)
|
33
|
-
cstr = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"]
|
34
|
-
cn_nums1 = ["元", "拾", "佰", "仟", "萬", "拾", "佰", "仟", "億", "拾", "佰", "仟"]
|
35
|
-
cn_nums2 = ['分', '角']
|
36
|
-
s = ""
|
37
|
-
# 整数部分
|
38
|
-
array = nums.to_s.split(".")
|
39
|
-
p h = array[0].to_s.split(//)
|
40
|
-
ai = h.count
|
41
|
-
h.each_with_index do |a, j|
|
42
|
-
s+=cstr[a.to_i]+cn_nums1[ai-1]
|
43
|
-
ai=ai-1
|
44
|
-
end
|
45
|
-
# 小数部分
|
46
|
-
p h1 = array[1].to_s.split(//)
|
47
|
-
aj = h1.count
|
48
|
-
h1.each_with_index do |o, p|
|
49
|
-
s+=cstr[o.to_i]+cn_nums2[aj-1]
|
50
|
-
aj=aj-1
|
51
|
-
end
|
52
|
-
rstr = ""
|
53
|
-
rstr=s.gsub("拾零", "拾")
|
54
|
-
rstr=rstr.gsub("零拾", "零");
|
55
|
-
rstr=rstr.gsub("零佰", "零");
|
56
|
-
rstr=rstr.gsub("零仟", "零");
|
57
|
-
rstr=rstr.gsub("零萬", "萬");
|
58
|
-
for i in 1..6 do
|
59
|
-
rstr=rstr.gsub("零零", "零");
|
60
|
-
rstr=rstr.gsub("零萬", "零");
|
61
|
-
rstr=rstr.gsub("零億", "億");
|
62
|
-
rstr=rstr.gsub("零零", "零");
|
63
|
-
end
|
64
|
-
rstr=rstr.gsub("零角", "零");
|
65
|
-
rstr=rstr.gsub("零分", "");
|
66
|
-
rstr=rstr.gsub("零元", "");
|
67
|
-
end
|
68
|
-
|
69
3
|
require 'net/http'
|
70
4
|
require 'net/https'
|
71
5
|
require 'uri'
|
72
|
-
|
73
|
-
# get请求
|
74
|
-
# 参数url:网址,params:参数,header:请求头json类型如:{'Accept' => 'application/json', 'X-Requested-With' => 'XMLHttpRequest'}
|
75
|
-
# 返回response对象,response.code 状态200/304/404;response.body 内容
|
76
6
|
def self.get(url, params=nil, header=nil)
|
77
7
|
uri = URI.parse(url)
|
78
8
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -86,10 +16,6 @@ module Struggle
|
|
86
16
|
end
|
87
17
|
http.request(request)
|
88
18
|
end
|
89
|
-
|
90
|
-
# post请求
|
91
|
-
# 参数url:网址,params:参数,header:请求头json类型如:{'Accept' => 'application/json', 'X-Requested-With' => 'XMLHttpRequest'}
|
92
|
-
# 返回response对象,response.code 状态200/304/404;response.body 内容
|
93
19
|
def self.post(url, params=nil, header=nil)
|
94
20
|
uri = URI.parse(url)
|
95
21
|
http = Net::HTTP.new(uri.host, uri.port)
|
data/lib/struggle/logistic.rb
CHANGED
@@ -5,66 +5,14 @@ module Struggle
|
|
5
5
|
require 'json'
|
6
6
|
URL = "http://api.kuaidi100.com/api"
|
7
7
|
URL_loophold = "http://www.kuaidi100.com/query"
|
8
|
-
|
9
|
-
# 参数:
|
10
|
-
# id String 是 身份授权key,请 快递查询接口 进行申请(大小写敏感)
|
11
|
-
# com String 是 要查询的快递公司代码,不支持中文,对应的公司代码见
|
12
|
-
# nu String 是 要查询的快递单号,请勿带特殊符号,不支持中文(大小写不敏感)
|
13
|
-
# show String 是 返回类型:
|
14
|
-
# 0:返回json字符串,
|
15
|
-
# 1:返回xml对象,
|
16
|
-
# 2:返回html对象,
|
17
|
-
# 3:返回text文本。
|
18
|
-
# 如果不填,默认返回json字符串。
|
19
|
-
# muti String 是 返回信息数量:
|
20
|
-
# 1:返回多行完整的信息,
|
21
|
-
# 0:只返回一行信息。
|
22
|
-
# 不填默认返回多行。
|
23
|
-
# order String 是 排序:
|
24
|
-
# desc:按时间由新到旧排列,
|
25
|
-
# asc:按时间由旧到新排列。
|
26
|
-
# 不填默认返回倒序(大小写不敏感)
|
27
|
-
# 返回:json格式数据
|
28
|
-
# com 物流公司编号
|
29
|
-
# nu 物流单号
|
30
|
-
# time 每条跟踪信息的时间
|
31
|
-
# context 每条跟综信息的描述
|
32
|
-
# state 快递单当前的状态 :
|
33
|
-
# 0:在途,即货物处于运输过程中;
|
34
|
-
# 1:揽件,货物已由快递公司揽收并且产生了第一条跟踪信息;
|
35
|
-
# 2:疑难,货物寄送过程出了问题;
|
36
|
-
# 3:签收,收件人已签收;
|
37
|
-
# 4:退签,即货物由于用户拒签、超区等原因退回,而且发件人已经签收;
|
38
|
-
# 5:派件,即快递正在进行同城派件;
|
39
|
-
# 6:退回,货物正处于退回发件人的途中;
|
40
|
-
# 该状态还在不断完善中,若您有更多的参数需求,欢迎发邮件至 kuaidi@kingdee.com 提出。
|
41
|
-
# status 查询结果状态:
|
42
|
-
# 0:物流单暂无结果,
|
43
|
-
# 1:查询成功,
|
44
|
-
# 2:接口出现异常,
|
8
|
+
|
45
9
|
def self.send_by_free(id, com, nu, show="json", muti=1, order="desc")
|
46
10
|
respond = Func.get(URL, {'id' => id, 'com' => com, 'nu' => nu, 'show' => show, 'muti' => muti, 'order' => order})
|
47
11
|
puts respond.body
|
48
12
|
return respond.body.blank? ? nil : JSON.parse(respond.body)
|
49
13
|
end
|
50
14
|
|
51
|
-
|
52
|
-
# 参数:
|
53
|
-
# type: 物流公司
|
54
|
-
# postid: 物流码
|
55
|
-
#返回结果实例:json类型
|
56
|
-
#{"message":"ok","nu":"200093247451","ischeck":"1","com":"yuantong","status":"200","condition":"F00","state":"3",
|
57
|
-
# "data":
|
58
|
-
# [{"time":"2015-04-15 09:09:56","context":"客户 签收人 : 张 已签收","ftime":"2015-04-15 09:09:56"},
|
59
|
-
# {"time":"2015-04-15 09:03:00","context":"山东省潍坊市潍城区十笏园分部公司派件人 : 邹辉 派件中 派件员电话","ftime":"2015-04-15 09:03:00"},
|
60
|
-
# {"time":"2015-04-14 09:09:16","context":"山东省潍坊市潍城区十笏园分部公司 失败签收录入 于明鑫","ftime":"2015-04-14 09:09:16"},
|
61
|
-
# {"time":"2015-04-14 09:03:59","context":"山东省潍坊市潍城区十笏园分部公司派件人 : 邹辉 派件中 派件员电话","ftime":"2015-04-14 09:03:59"},
|
62
|
-
# {"time":"2015-04-14 07:15:57","context":"快件到达 山东省潍坊市潍城区十笏园分部公司","ftime":"2015-04-14 07:15:57"},
|
63
|
-
# {"time":"2015-04-14 05:50:25","context":"山东省潍坊市公司 已发出,下一站 山东省潍坊市潍城区十笏园分部","ftime":"2015-04-14 05:50:25"},
|
64
|
-
# {"time":"2015-04-14 04:07:09","context":"潍坊转运中心公司 已发出,下一站 山东省潍坊市","ftime":"2015-04-14 04:07:09"},
|
65
|
-
# {"time":"2015-04-11 19:30:06","context":"浙江省金华市义乌市凌云公司 已打包,发往下一站 潍坊转运中心","ftime":"2015-04-11 19:30:06"},
|
66
|
-
# {"time":"2015-04-11 17:58:41","context":"浙江省金华市义乌市凌云公司 已揽收","ftime":"2015-04-11 17:58:41"}]
|
67
|
-
# }
|
15
|
+
|
68
16
|
def self.send_by_loophold(type, postid)
|
69
17
|
respond = Func.post(URL_loophold, {'type' => type, 'postid' => postid})
|
70
18
|
return respond.body.blank? ? nil : JSON.parse(respond.body)
|
data/lib/struggle/pay_gateway.rb
CHANGED
@@ -1,21 +1,10 @@
|
|
1
|
-
#gemfile中加入 gem 'iconv'
|
2
1
|
module Struggle
|
3
2
|
class PayGateway
|
4
3
|
require 'net/https'
|
5
4
|
require 'uri'
|
6
|
-
# 支付接口地址
|
7
5
|
URL_UTF8 = "https://pay3.chinabank.com.cn/PayGate?encoding=UTF-8"
|
8
|
-
# 图片和css文件地址
|
9
6
|
URL = "https://pay3.chinabank.com.cn"
|
10
|
-
|
11
|
-
# 参数:
|
12
|
-
# v_mid:商户编号
|
13
|
-
# key:商户md5密钥
|
14
|
-
# v_url:支付成功后跳转的页面
|
15
|
-
# remark2:异步订单状态地址
|
16
|
-
# v_oid:订单编号
|
17
|
-
# v_amount:订单金额
|
18
|
-
# v_moneytype:支付货币类型
|
7
|
+
|
19
8
|
def self.pay(v_mid, key, v_url, remark2, v_oid, v_amount, v_moneytype = "CNY")
|
20
9
|
v_md5info = Digest::MD5.hexdigest(v_amount.to_s + v_moneytype + v_oid + v_mid + v_url + key).upcase
|
21
10
|
html = '<html><head></head><body>'
|
@@ -37,19 +26,12 @@ module Struggle
|
|
37
26
|
html += '</body></html>'
|
38
27
|
end
|
39
28
|
|
40
|
-
# 功能:自动验证结果
|
41
|
-
# 参数:
|
42
|
-
# params参数
|
43
|
-
# key商户的md5密钥
|
44
|
-
# 返回:如果支付成功返回订单号,否则返回nil
|
45
29
|
def self.receive(params, key)
|
46
30
|
v_oid = params["v_oid"]
|
47
31
|
v_pstatus = params["v_pstatus"]
|
48
|
-
v_md5str = params["v_md5str"]
|
32
|
+
v_md5str = params["v_md5str"]
|
49
33
|
v_amount = params["v_amount"]
|
50
34
|
v_moneytype = params["v_moneytype"]
|
51
|
-
# 20(表示支付成功)
|
52
|
-
# 30(表示支付失败)
|
53
35
|
if v_pstatus=="20" && v_md5str==Digest::MD5.hexdigest(v_oid+v_pstatus+v_amount+v_moneytype+key).upcase
|
54
36
|
return {state: true, code: params["v_oid"], amount: v_amount}
|
55
37
|
else
|
data/lib/struggle/tfile.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
module Struggle
|
2
2
|
class Tfile
|
3
|
-
#file upload
|
4
|
-
#params: file->file stream,filepath->file save path,rule->can upload file format("jpg|xls"),minsize and maxsize->minsize<file's size<maxsize
|
5
|
-
#return: {state: true, result: "new filename"} or {state: false, result: "error message"}
|
6
3
|
def Tfile.upload(file, filepath="", rule="jpg|xls", minsize=1, maxsize=4000)
|
7
4
|
result = Tfile.rule_validata(file, rule, minsize, maxsize)
|
8
5
|
if result[:state]
|
@@ -25,10 +22,6 @@ module Struggle
|
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
|
-
#file unpack(before unpack run `sudo apt-get install unzip unrar -y` || insert gemfile)
|
29
|
-
#file->file path
|
30
|
-
#path->unpacked path
|
31
|
-
#return->true, false, nil. nil not cmd
|
32
25
|
def Tfile.unpack(file, path)
|
33
26
|
format = Tfile.file_format(file)
|
34
27
|
cmd = ""
|
@@ -42,9 +35,6 @@ module Struggle
|
|
42
35
|
system cmd
|
43
36
|
end
|
44
37
|
|
45
|
-
#validate file
|
46
|
-
#params:file->file stream,rule->can upload file format,minsize<file's size<maxsize
|
47
|
-
#return:{state: true} or return {state: false, message: "error message"}
|
48
38
|
def Tfile.rule_validata(file, rule, minsize, maxsize)
|
49
39
|
rule_for = Tfile.filename_validata(file, rule)
|
50
40
|
unless rule_for
|
@@ -56,16 +46,10 @@ module Struggle
|
|
56
46
|
return {state: true}
|
57
47
|
end
|
58
48
|
|
59
|
-
#validate file format
|
60
|
-
#params: file-> file stream; rule-> validate rule ("jpg|xls")
|
61
|
-
#return: validate result -> true | false
|
62
49
|
def Tfile.filename_validata(file, rule)
|
63
50
|
!eval("/\.(#{rule})+$/").match(file.original_filename).blank?
|
64
51
|
end
|
65
52
|
|
66
|
-
#get new file's name
|
67
|
-
#params:filestream->file stream file name,filepath->file save path
|
68
|
-
#return:new file's name
|
69
53
|
def Tfile.getname(filestream, filepath)
|
70
54
|
file_for = Tfile.file_format(filestream.original_filename)
|
71
55
|
filename = Time.now.strftime("%Y%m%d%h%m%s")<<rand(99999).to_s<<file_for
|
@@ -77,16 +61,10 @@ module Struggle
|
|
77
61
|
filename
|
78
62
|
end
|
79
63
|
|
80
|
-
#get file format
|
81
|
-
#params: filename->file's name
|
82
|
-
#return: file format '.jpg','.exe'
|
83
64
|
def Tfile.file_format(filename)
|
84
65
|
/\.[^\.]+$/.match(filename)[0]
|
85
66
|
end
|
86
67
|
|
87
|
-
#image upload
|
88
|
-
#params: file->file stream; filepath->file save path; rule->can upload file format("jpg|xls"); minsize and maxsize->minsize<file's size<maxsize; w->new image width, h->new image height
|
89
|
-
#return: {state: true, result: "new filename"} or {state: false, result: "error message"}
|
90
68
|
def Tfile.imageupload(imgfile, filepath="", rule="jpg|jpeg", minsize=0, maxsize=2000, w=0, h=0)
|
91
69
|
result = Tfile.rule_validata(imgfile, rule, minsize, maxsize)
|
92
70
|
if result[:state]
|
@@ -110,15 +88,10 @@ module Struggle
|
|
110
88
|
end
|
111
89
|
end
|
112
90
|
|
113
|
-
#delete dir
|
114
|
-
#params: dir-> dir path
|
115
|
-
#return true or false
|
116
91
|
def Tfile.rmdir(dir)
|
117
92
|
system("rm -rf #{dir}")
|
118
93
|
end
|
119
94
|
|
120
|
-
#image resize
|
121
|
-
#params: imagepath-> image file path; w-> new image width; h-> new image height
|
122
95
|
def Tfile.resize(imagepath, w, h)
|
123
96
|
img = Magick::Image.read(imagepath)[0]
|
124
97
|
if w==0 || h==0
|
data/lib/struggle/tmagick.rb
CHANGED
@@ -1,17 +1,10 @@
|
|
1
1
|
module Struggle
|
2
2
|
class Tmagick
|
3
|
-
#画图类
|
4
|
-
#img->底图 "#{Rails.root}/public/images/1.jpg"
|
5
|
-
#newimg->处理完保存的地址 save img handle path example->"#{Rails.root}/public/images/new.jpg"
|
6
|
-
#example-> Tmagick.new("1.jpg","public/n.jpg").images(images),texts(texts).images(imgs).write
|
7
3
|
def initialize(img, newimg=nil)
|
8
4
|
@pushimg = Magick::Image.read(img).first
|
9
5
|
@poppath = newimg.blank? ? img : newimg
|
10
6
|
end
|
11
7
|
|
12
|
-
#图片叠加和水印
|
13
|
-
#images->多图片叠加,数组,在一个图片上画多个图片; image=>{img: "1.jpg", x: 0, y: 0},img要画的图片地址,xy画的左顶点位置
|
14
|
-
#return->成功返回当前对象,失败返回nil
|
15
8
|
def images(images)
|
16
9
|
return nil if images.blank?
|
17
10
|
images.each do |img|
|
@@ -21,10 +14,6 @@ module Struggle
|
|
21
14
|
return self
|
22
15
|
end
|
23
16
|
|
24
|
-
#图片上写字
|
25
|
-
#fontobjs 文字数组; fontobj=>{text: "aaaaaaaaa",color: "#000000",font: "simsun.ttc'",size: 20,weight: 100, x: 0, y: 0}
|
26
|
-
# text文字内容,color颜色,font字体,size大小,weight粗细,xy画的左顶点位置
|
27
|
-
#return-》成功返回当前对象,失败返回nil
|
28
17
|
def texts(texts)
|
29
18
|
return nil if texts.blank?
|
30
19
|
texts.each do |text|
|
@@ -38,13 +27,11 @@ module Struggle
|
|
38
27
|
return self
|
39
28
|
end
|
40
29
|
|
41
|
-
#重定义图片大小
|
42
30
|
def resize(new_width, new_height)
|
43
31
|
@pushimg = Magick::Image.read(@pushimg).first.resize_to_fit(new_width, new_height)
|
44
32
|
@pushimg.blank? ? nil : self
|
45
33
|
end
|
46
34
|
|
47
|
-
#写出操作
|
48
35
|
def write
|
49
36
|
@pushimg.write(@poppath)
|
50
37
|
end
|
data/lib/struggle/vcode.rb
CHANGED
@@ -1,19 +1,6 @@
|
|
1
|
-
#first gem 'rmagick'
|
2
1
|
module Struggle
|
3
2
|
class Vcode
|
4
|
-
#controller
|
5
|
-
#def getcode
|
6
|
-
# vcode = Vcode.getvcode
|
7
|
-
# session[:code]=vcode[:code]
|
8
|
-
# send_data vcode[:img], content_type: 'image/jpeg', disposition: 'inline'
|
9
|
-
#end
|
10
|
-
#view
|
11
|
-
# <img src="/getcode">
|
12
|
-
#Vcode.getvcode(90,40,24)
|
13
|
-
#w宽,h高,fontsize字体大小
|
14
|
-
#返回json类型
|
15
3
|
def self.getvcode(w=90, h=40, fontsize=24)
|
16
|
-
#创建画布
|
17
4
|
img = Magick::Image.new(w, h) {
|
18
5
|
self.background_color = 'white'
|
19
6
|
self.format="JPG"
|
@@ -22,26 +9,20 @@ module Struggle
|
|
22
9
|
text.pointsize = fontsize
|
23
10
|
text.kerning = -1
|
24
11
|
text.fill('blue')
|
25
|
-
#随机文字
|
26
12
|
code=""
|
27
13
|
4.times { code << (97 + rand(26)).chr }
|
28
|
-
#设置文字
|
29
14
|
text.text(rand(w/2-5), h/2-5+ rand(h/2), code)
|
30
|
-
#随机直线
|
31
15
|
for i in 1..rand(4)
|
32
|
-
text.line(rand(w), rand(h), rand(w), rand(h))
|
16
|
+
text.line(rand(w), rand(h), rand(w), rand(h))
|
33
17
|
end
|
34
18
|
text.fill('blue')
|
35
|
-
#燥点
|
36
19
|
for i in 1..280
|
37
20
|
text.point(rand(w), rand(h))
|
38
21
|
end
|
39
22
|
text.draw(img)
|
40
|
-
#模糊
|
41
23
|
img = img.sketch(0, 10, 50)
|
42
24
|
#扭曲
|
43
25
|
img = img.wave(5.5, 50)
|
44
|
-
#返回图片数据流
|
45
26
|
{img: img.to_blob, code: code}
|
46
27
|
end
|
47
28
|
end
|
data/lib/struggle.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: struggle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lean
|
@@ -47,6 +47,7 @@ extra_rdoc_files:
|
|
47
47
|
files:
|
48
48
|
- README.md
|
49
49
|
- lib/struggle.rb
|
50
|
+
- lib/struggle/concerns/int_extend.rb
|
50
51
|
- lib/struggle/concerns/string_extend.rb
|
51
52
|
- lib/struggle/func.rb
|
52
53
|
- lib/struggle/logistic.rb
|
@@ -56,7 +57,6 @@ files:
|
|
56
57
|
- lib/struggle/tfile.rb
|
57
58
|
- lib/struggle/tmagick.rb
|
58
59
|
- lib/struggle/vcode.rb
|
59
|
-
- struggle.gemspec
|
60
60
|
homepage: http://rubygems.org/gems/struggle
|
61
61
|
licenses:
|
62
62
|
- struggle
|
data/struggle.gemspec
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = 'struggle'
|
3
|
-
s.version = '1.6.0'
|
4
|
-
s.date = '2015-08-21'
|
5
|
-
s.summary = "struggle!"
|
6
|
-
s.description = "vcode,tfile,pager,func,logistic,pay_gateway,tmagick,class_extend;"
|
7
|
-
s.authors = ["lean"]
|
8
|
-
s.email = '54850915@qq.com'
|
9
|
-
s.files = `git ls-files`.split("\n")
|
10
|
-
s.extra_rdoc_files = ['README.md']
|
11
|
-
#s.require_paths = ['lib']
|
12
|
-
s.add_development_dependency 'iconv', ['>= 0']
|
13
|
-
s.add_development_dependency 'rmagick', ['>= 0']
|
14
|
-
s.homepage = 'http://rubygems.org/gems/struggle'
|
15
|
-
s.license = 'struggle'
|
16
|
-
end
|