随笔 - 298  文章 - 377  trackbacks - 0
<2017年5月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

常用链接

留言簿(34)

随笔分类

随笔档案

文章档案

相册

收藏夹

搜索

  •  

最新评论

阅读排行榜

评论排行榜

共5页: 1 2 3 4 5 
re: 禁止 .mysql_history 聂文龙 2018-03-25 18:21
root@Debian:~# vi /etc/profile



HISTFILESIZE=0
HISTSIZE=0
export MYSQL_HISTFILE=/dev/null
# 设置ss
git config --global http.proxy 'socks5://127.0.0.1:1080'

git config --global https.proxy 'socks5://127.0.0.1:1080'

# 设置代理
git config --global https.proxy http://127.0.0.1:1080

git config --global https.proxy https://127.0.0.1:1080

# 取消代理
git config --global --unset http.proxy

git config --global --unset https.proxy
re: 微信web版 协议 聂文龙 2017-05-09 14:17
获取uuid

https://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%

2Fwebwxnewloginpage&fun=new&lang=zh_CN&_=1388994062250




获取二维码

https://login.weixin.qq.com/qrcode/+uuid+?t=webwx




等待扫描Get

https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?uuid=454d958c7f6243&tip=1&_=1388975894359

https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?uuid=454d958c7f6243&tip=1&_=1388975873359

https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?uuid=454d958c7f6243&tip=1&_=1388975883859




扫描了-返回

window.code=201;

未扫描返回空




扫描之后-第一次请求成功

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxstatreport?type=1&r=1388975895453">https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxstatreport?type=1&r=1388975895453




{"BaseRequest":{"Uin":0,"Sid":0},"Count":1,"List":[{"Type":1,"Text":"/cgi-bin/mmwebwx-bin/login, First Request Success, uuid:

454d958c7f6243"}]}




扫描之后-第二次请求开始

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxstatreport?type=1&r=1388975895453">https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxstatreport?type=1&r=1388975895453




{"BaseRequest":{"Uin":0,"Sid":0},"Count":1,"List":[{"Type":1,"Text":"/cgi-bin/mmwebwx-bin/login, Second Request Start, uuid:

454d958c7f6243"}]}




等待确认Get

https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?uuid=454d958c7f6243&tip=0&_=1388975895453

https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?uuid=454d958c7f6243&tip=0&_=1388975900953

https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?uuid=454d958c7f6243&tip=0&_=1388975906453

https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?uuid=454d958c7f6243&tip=0&_=1388975911953




手机确认-返回

window.code=200;

window.redirect_uri="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?">https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?

ticket=03f725a8039d418ab79c69b6ffbd771b&lang=zh_CN&scan=1388975896";

未确认返回空




get 登陆获取Cookie

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?">https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?

ticket=03f725a8039d418ab79c69b6ffbd771b&lang=zh_CN&scan=1388975896&fun=new

--设置Cookie 返回一个状态




post 第二次请求成功

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxstatreport?type=1&r=1388976086218




{"BaseRequest":{"Uin":0,"Sid":0},"Count":1,"List":[{"Type":1,"Text":"/cgi-bin/mmwebwx-bin/login, Second Request Success,

uuid: 454d958c7f6243, time: 190765ms"}]}




post 表示登陆成功-返回重要的数据key123

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=1388976086484




{"BaseRequest":{"Uin":"750366800","Sid":"e75TXbI7TnKUevmI","Skey":"","DeviceID":"e519062714508114"}}




post 可能是获取列表

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=e75TXbI7TnKUevmI&r=1388976086734




{"BaseRequest":{"Uin":750366800,"Sid":"e75TXbI7TnKUevmI"},"SyncKey":{"Count":4,"List":[{"Key":1,"Val":620916854},

{"Key":2,"Val":620917961},{"Key":3,"Val":620917948},{"Key":1000,"Val":1388967977}]},"rr":1388976086734}

--这里的内容在上一步返回结果里




post 可能是获取当前会话列表-大数据

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact?r=1388976086734




{}




post 可能是在手机上显示的提示信息

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxstatusnotify?r=1388976086750




{"BaseRequest":

{"Uin":750366800,"Sid":"e75TXbI7TnKUevmI","Skey":"","DeviceID":"e519062714508114"},"Code":3,"FromUserName":"langyeie","ToUser

Name":"langyeie","ClientMsgId":"1388976086750"}




get 获取头像图片

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgeticon?seq=1388335457&username=langyeie




get 同理可以获取其他微信好友的头像

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgeticon?seq=620917759&username=wxid_xx3mtgeux5511




post 更改什么状态?标记已读?

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxbatchgetcontact?type=ex&r=1388976086812




{"BaseRequest":{"Uin":750366800,"Sid":"e75TXbI7TnKUevmI","Skey":"","DeviceID":"e519062714508114"},"Count":10,"List":

[{"UserName":"z_zer0v","ChatRoomId":3445229833},{"UserName":"huobao002","ChatRoomId":3445229833},

{"UserName":"wxid_jo4qxoep4go411","ChatRoomId":3445229833},{"UserName":"jijunlong123456","ChatRoomId":3445229833},

{"UserName":"wxid_toyaj4qwrynb21","ChatRoomId":3445229833},{"UserName":"wxid_6655286553012","ChatRoomId":3445229833},

{"UserName":"wxid_rankrke1kkyd12","ChatRoomId":3445229833},{"UserName":"wxid_chcblpm846k022","ChatRoomId":3445229833},

{"UserName":"tw297554396","ChatRoomId":3445229833},{"UserName":"wxid_3076050756212","ChatRoomId":3445229833}]}




get headimg ?头像?

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetheadimg?seq=620917806&username=3445229833@chatroom










get 监听会话

https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?

callback=jQuery18308660551080269895_1388975862078&r=1388976091937&sid=e75TXbI7TnKUevmI&uin=750366800&deviceid=e51906271450811

4&synckey=1_620916854%7C2_620917963%7C3_620917948%7C201_1388976090%7C1000_1388967977&_=1388976091937




https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?

callback=jQuery18308660551080269895_1388975862078&r=1388976119062&sid=e75TXbI7TnKUevmI&uin=750366800&deviceid=e51906271450811

4&synckey=1_620916854%7C2_620917963%7C3_620917948%7C201_1388976090%7C1000_1388967977&_=1388976119078




https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?

callback=jQuery18308660551080269895_1388975862078&r=1388976173375&sid=e75TXbI7TnKUevmI&uin=750366800&deviceid=e51906271450811

4&synckey=1_620916854%7C2_620917963%7C3_620917948%7C201_1388976090%7C1000_1388967977&_=1388976173390




https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?">https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?

callback=jQuery18308660551080269895_1388975862078&r=1388976146265&sid=e75TXbI7TnKUevmI&uin=750366800&deviceid=e51906271450811

4&synckey=1_620916854%7C2_620917963%7C3_620917948%7C201_1388976090%7C1000_1388967977&_=1388976146265

正常返回结果

window.synccheck={retcode:"0",selector:"0"}

有消息返回结果

window.synccheck={retcode:"0",selector:"6"}

发送消息返回结果

window.synccheck={retcode:"0",selector:"2"}

朋友圈有动态

window.synccheck={retcode:"0",selector:"4"}







获取消息-post-设置Cookie

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=e75TXbI7TnKUevmI&r=1388977398062




{"BaseRequest":{"Uin":750366800,"Sid":"e75TXbI7TnKUevmI"},"SyncKey":{"Count":5,"List":[{"Key":1,"Val":620916854},

{"Key":2,"Val":620917978},{"Key":3,"Val":620917975},{"Key":201,"Val":1388977392},

{"Key":1000,"Val":1388967977}]},"rr":1388977398062}




https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=e75TXbI7TnKUevmI&r=1388977583250




{"BaseRequest":{"Uin":750366800,"Sid":"e75TXbI7TnKUevmI"},"SyncKey":{"Count":5,"List":[{"Key":1,"Val":620916854},

{"Key":2,"Val":620917980},{"Key":3,"Val":620917975},{"Key":201,"Val":1388977400},

{"Key":1000,"Val":1388967977}]},"rr":1388977583250}




https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=e75TXbI7TnKUevmI&r=1388977660750




{"BaseRequest":{"Uin":750366800,"Sid":"e75TXbI7TnKUevmI"},"SyncKey":{"Count":5,"List":[{"Key":1,"Val":620916854},

{"Key":2,"Val":620917982},{"Key":3,"Val":620917975},{"Key":201,"Val":1388977585},

{"Key":1000,"Val":1388967977}]},"rr":1388977660750}







post 发送消息

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg?sid=e75TXbI7TnKUevmI&r=1388977830140




{"BaseRequest":

{"Uin":750366800,"Sid":"e75TXbI7TnKUevmI","Skey":"D6EBA5FA425CAE258F24E75CF51F2E1B4EEA9C5338BE456C","DeviceID":"e519062714508

114"},"Msg":

{"FromUserName":"langyeie","ToUserName":"pp80000","Type":1,"Content":"55","ClientMsgId":1388977830140,"LocalID":1388977830140

}}




https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=e75TXbI7TnKUevmI&r=1388977830390




{"BaseRequest":{"Uin":750366800,"Sid":"e75TXbI7TnKUevmI"},"SyncKey":{"Count":5,"List":[{"Key":1,"Val":620916854},

{"Key":2,"Val":620917986},{"Key":3,"Val":620917975},{"Key":201,"Val":1388977776},

{"Key":1000,"Val":1388967977}]},"rr":1388977830390}


get 有消息来,响铃
来自千明论坛 http://www.3d56.net/
re: 相似图片搜索hash的php实现 聂文龙 2016-09-22 11:07
require_once "Imghash.class.php";
$instance = ImgHash::getInstance();
$result = $instance->checkIsSimilarImg('chenyin/IMG_3214.png', 'chenyin/IMG_3212.JPG');
如果$result值为true, 则表明2个图片相似,否则不相似。
#! /bin/sh

gst=/usr/share/gnome-shell/gnome-shell-theme.gresource
cd gnome-shell

for r in `gresource list $gst`; do
gresource extract $gst $r > ${r/#\/org\/gnome\/shell\/theme/.}
done

#! /bin/sh

#change workdir to suit your system
workdir=/tmp/lala
gst=/usr/share/gnome-shell/gnome-shell-theme.gresource
mkdir theme

for r in `gresource list $gst`; do
gresource extract $gst $r >$workdir${r/#\/org\/gnome\/shell/}
done



mkdir /tmp/lala
bash -x /tmp/lala.sh
cd /tmp/lala/theme
Bash shell在“~/.bash_history”(“~/”表示用户目录)文件中保存了500条使用过的命令,这样可以使你输入使用过的长命令变得容易。每个在系统中拥有账号的用户在他的目录下都有一个“.bash_history”文件。

bash shell应该保存少量的命令,并且在每次用户注销时都把这些历史命令删除。
第一步:

“/etc/profile”文件中的“HISTFILESIZE”和“HISTSIZE”行确定所有用户的“.bash_history”文件中可以保 存的旧命令条数。强烈建议把把“/etc/profile”文件中的“HISTFILESIZE”和“HISTSIZE”行的值设为一个较小的数,比如 30。编辑profile文件(vi /etc/profile),把下面这行改为:
HISTFILESIZE=30
HISTSIZE=30
这表示每个用户的“.bash_history”文件只可以保存30条旧命令。

第二步:

网管还应该在"/etc/skel/.bash_logout" 文件中添加下面这行"rm -f $HOME/.bash_history" 。这样,当用户每次注销时,“.bash_history”文件都会被删除.
re: Linux中find常见用法示例 聂文龙 2016-07-02 11:01
find . -regex '.*\.php\|.*\.html' | xargs grep 折扣价

find . -name "*.*" -type f ! -name "*.htm" -type f ! -name "*.jpg" | xargs grep 折扣价
re: Linux中find常见用法示例 聂文龙 2016-06-26 18:38
find . -name "*.*" -type f ! -name "*.jpg"| xargs grep "function xxxxxx"
re: Linux中find常见用法示例 聂文龙 2016-06-26 18:21
Linux下find命令在目录结构中搜索文件,并执行指定的操作。Linux下find命令提供了相当多的查找条件,功能很强大。由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时间来了解一下。即使系统中含有网络文件系统( NFS),find命令在该文件系统中同样有效,只你具有相应的权限。 在运行一个非常消耗资源的find命令时,很多人都倾向于把它放在后台执行,因为遍历一个大的文件系统可能会花费很长的时间(这里是指30G字节以上的文件系统)。
1.命令格式:
find pathname -options [-print -exec -ok ...]
2.命令功能:
用于在文件树种查找文件,并作出相应的处理
3.命令参数:
pathname: find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。
-print: find命令将匹配的文件输出到标准输出。
-exec: find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'command' { } \;,注意{ }和\;之间的空格。
-ok: 和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。
4.命令选项:
-name 按照文件名查找文件。
-perm 按照文件权限来查找文件。
-prune 使用这一选项可以使find命令不在当前指定的目录中查找,如果同时使用-depth选项,那么-prune将被find命令忽略。
-user 按照文件属主来查找文件。
-group 按照文件所属的组来查找文件。
-mtime -n +n 按照文件的更改时间来查找文件, - n表示文件更改时间距现在n天以内,+ n表示文件更改时间距现在n天以前。find命令还有-atime和-ctime 选项,但它们都和-m time选项。
-nogroup 查找无有效所属组的文件,即该文件所属的组在/etc/groups中不存在。
-nouser 查找无有效属主的文件,即该文件的属主在/etc/passwd中不存在。
-newer file1 ! file2 查找更改时间比文件file1新但比文件file2旧的文件。
-type 查找某一类型的文件,诸如:
b - 块设备文件。
d - 目录。
c - 字符设备文件。
p - 管道文件。
l - 符号链接文件。
f - 普通文件。
-size n:[c] 查找文件长度为n块的文件,带有c时表示文件长度以字节计。-depth:在查找文件时,首先查找当前目录中的文件,然后再在其子目录中查找。
-fstype:查找位于某一类型文件系统中的文件,这些文件系统类型通常可以在配置文件/etc/fstab中找到,该配置文件中包含了本系统中有关文件系统的信息。
-mount:在查找文件时不跨越文件系统mount点。
-follow:如果find命令遇到符号链接文件,就跟踪至链接所指向的文件。
-cpio:对匹配的文件使用cpio命令,将这些文件备份到磁带设备中。
另外,下面三个的区别:
-amin n 查找系统中最后N分钟访问的文件
-atime n 查找系统中最后n*24小时访问的文件
-cmin n 查找系统中最后N分钟被改变文件状态的文件
-ctime n 查找系统中最后n*24小时被改变文件状态的文件
-mmin n 查找系统中最后N分钟被改变文件数据的文件
-mtime n 查找系统中最后n*24小时被改变文件数据的文件
5.使用实例:
实例1:查找指定时间内修改过的文件
命令:
find -atime -2
输出:

复制代码代码如下:

[root@peidachang ~]# find -atime -2
.
./logs/monitor
./.bashrc
./.bash_profile
./.bash_history
说明:
超找48小时内修改过的文件
实例2:根据关键字查找
命令:
find . -name "*.log"
输出:

复制代码代码如下:

[root@localhost test]# find . -name "*.log"
./log_link.log
./log2014.log
./test4/log3-2.log
./test4/log3-3.log
./test4/log3-1.log
./log2013.log
./log2012.log
./log.log
./test5/log5-2.log
./test5/log5-3.log
./test5/log.log
./test5/log5-1.log
./test5/test3/log3-2.log
./test5/test3/log3-3.log
./test5/test3/log3-1.log
./test3/log3-2.log
./test3/log3-3.log
./test3/log3-1.log
说明:
在当前目录查找 以.log结尾的文件。 ". "代表当前目录
实例3:按照目录或文件的权限来查找文件
命令:
find /opt/soft/test/ -perm 777
输出:

复制代码代码如下:

[root@localhost test]# find /opt/soft/test/ -perm 777
/opt/soft/test/log_link.log
/opt/soft/test/test4
/opt/soft/test/test5/test3
/opt/soft/test/test3
说明:
查找/opt/soft/test/目录下 权限为 777的文件
实例4:按类型查找
命令:
find . -type f -name "*.log"
输出:

复制代码代码如下:

[root@localhost test]# find . -type f -name "*.log"
./log2014.log
./test4/log3-2.log
./test4/log3-3.log
./test4/log3-1.log
./log2013.log
./log2012.log
./log.log
./test5/log5-2.log
./test5/log5-3.log
./test5/log.log
./test5/log5-1.log
./test5/test3/log3-2.log
./test5/test3/log3-3.log
./test5/test3/log3-1.log
./test3/log3-2.log
./test3/log3-3.log
./test3/log3-1.log
[root@localhost test]#
说明:
查找当目录,以.log结尾的普通文件
实例5:查找当前所有目录并排序
命令:
find . -type d | sort
输出:

复制代码代码如下:

[root@localhost test]# find . -type d | sort
.
./scf
./scf/bin
./scf/doc
./scf/lib
./scf/service
./scf/service/deploy
./scf/service/deploy/info
./scf/service/deploy/product
./test3
./test4
./test5
./test5/test3
[root@localhost test]#
实例6:按大小查找文件
命令:
find . -size +1000c -print
输出:

复制代码代码如下:

[root@localhost test]# find . -size +1000c -print
.
./test4
./scf
./scf/lib
./scf/service
./scf/service/deploy
./scf/service/deploy/product
./scf/service/deploy/info
./scf/doc
./scf/bin
./log2012.log
./test5
./test5/test3
./test3
[root@localhost test]#
说明:
查找当前目录大于1K的文件
一、Linux中find常见用法示例
·find path -option [ -print ] [ -exec -ok command ] {} \;
#-print 将查找到的文件输出到标准输出
#-exec command {} \; -----将查到的文件执行command操作,{} 和 \;之间有空格
#-ok 和-exec相同,只不过在操作前要询用户 ==================================================== -name filename #查找名为filename的文件
-perm #按执行权限来查找
-user username #按文件属主来查找
-group groupname #按组来查找
-mtime -n +n #按文件更改时间来查找文件,-n指n天以内,+n指n天以前
-atime -n +n #按文件访问时间来查GIN: 0px">-perm #按执行权限来查找
-user username #按文件属主来查找
-group groupname #按组来查找
-mtime -n +n #按文件更改时间来查找文件,-n指n天以内,+n指n天以前
-atime -n +n #按文件访问时间来查找文件,-n指n天以内,+n指n天以前
-ctime -n +n #按文件创建时间来查找文件,-n指n天以内,+n指n天以前
-nogroup #查无有效属组的文件,即文件的属组在/etc/groups中不存在
-nouser #查无有效属主的文件,即文件的属主在/etc/passwd中不存
-newer f1 !f2 找文件,-n指n天以内,+n指n天以前
-ctime -n +n #按文件创建时间来查找文件,-n指n天以内,+n指n天以前
-nogroup #查无有效属组的文件,即文件的属组在/etc/groups中不存在
-nouser #查无有效属主的文件,即文件的属主在/etc/passwd中不存
-newer f1 !f2 #查更改时间比f1新但比f2旧的文件
-type b/d/c/p/l/f #查是块设备、目录、字符设备、管道、符号链接、普通文件
-size n[c] #查长度为n块[或n字节]的文件
-depth #使查找在进入子目录前先行查找完本目录
-fstype #查更改时间比f1新但比f2旧的文件
-mount #查文件时不跨越文件系统mount点
-follow #如果遇到符号链接文件,就跟踪链接所指的文件
-cpio #对匹配的文件使用cpio命令,将他们备份到磁带设备中
-prune #忽略某个目录 ====================================================
$find ~ -name "*.txt" -print #在$HOME中查.txt文件并显示
$find . -name "*.txt" -print
$find . -name "[A-Z]*" -pri26nbsp; #对匹配的文件使用cpio命令,将他们备份到磁带设备中
-prune #忽略某个目录 $find . -name "[A-Z]*" -print #查以大写字母开头的文件
$find /etc -name "host*" -print #查以host开头的文件
$find . -name "[a-z][a-z][0--9][0--9].txt" -print #查以两个小写字母和两个数字开头的txt文件
$find . -perm 755 -print
$find . -perm -007 -exec ls -l {} \; #查所有用户都可读写执行的文件同-perm 777
$find . -type d -print 打印目录结构
$find . ! -type d -print 打印非目录文件 find /usr/include -name '*.h' -exec grep AF_INEF6 {} \; 因grep无法递归搜索子目录,故可以和find相结合使用。 在/usr/include 所有子目录中的.h文件中找字串AF_INEF6
$find . -type l -print $find . -size +1000000c -print #查长度大于1Mb的文件
$find . -size 100c -print # 查长度为100c的文件
$find . -size +10 -print #查长度超过期作废10块的文件(1块=512字节) $cd /
$find etc home apps -depth -print | cpio -ivcdC65536 -o /dev/rmt0
$find /etc -name "passwd*" -exec grep "cnscn" {} \; #看是否存在cnscn用户
$find . -name "yao*" | xargs file
$find . -name "yao*" | xargs echo "" > /tmp/core.log
$find . -name "yao*" | xargs chmod o-w ====================================================== find -name april* 在当前目录下查找以april开始的文件
find -name april* fprint file 在当前目录下查找以april开始的文件,并把结果输出到file中
find -name ap* -o -name may* 查找以ap或may开头的文件
find /mnt -name tom.txt -ftype vfat 在/mnt下查找名称为tom.txt且文件系统类型为vfat的文件
find /mnt -name t.txt ! -ftype vfat 在/mnt下查找名称为tom.txt且文件系统类型不为vfat的文件
find /tmp -name wa* -type l 在/tmp下查找名为wa开头且类型为符号链接的文件
find /home -mtime -2 在/home下查最近两天内改动过的文件
find /home -atime -1 查1天之内被存取过的文件
find /home -mmin +60 在/home下查60分钟前改动过的文件
find /home -amin +30 查最近30分钟前被存取过的文件
find /home -newer tmp.txt 在/home下查更新时间比tmp.txt近的文件或目录
find /home -anewer tmp.txt 在/home下查存取时间比tmp.txt近的文件或目录
find /home -used -2 列出文件或目录被改动过之后,在2日内被存取过的文件或目录
find /home -user cnscn 列出/home目录内属于用户cnscn的文件或目录
find /home -uid +501 列出/home目录内用户的识别码大于501的文件或目录
find /home -group cnscn 列出/home内组为cnscn的文件或目录
find /home -gid 501 列出/home内组id为501的文件或目录
find /home -nouser 列出/home内不属于本地用户的文件或目录
find /home -nogroup 列出/home内不属于本地组的文件或目录
find /home -name tmp.txt -maxdepth 4 列出/home内的tmp.txt 查时深度最多为3层
find /home -name tmp.txt -mindepth 3 从第2层开始查
find /home -empty 查找大小为0的文件或空目录
find /home -size +512k 查大于512k的文件
find /home -size -512k 查小于512k的文件
find /home -links +2 查硬连接数大于2的文件或目录
find /home -perm 0700 查权限为700的文件或目录
find /tmp -name tmp.txt -exec cat {} \;
find /tmp -name tmp.txt -ok rm {} \; find / -amin -10 # 查找在系统中最后10分钟访问的文件
find / -atime -2 # 查找在系统中最后48小时访问的文件
find / -empty # 查找在系统中为空的文件或者文件夹
find / -group cat # 查找在系统中属于 groupcat的文件
find / -mmin -5 # 查找在系统中最后5分钟里修改过的文件
find / -mtime -1 #查找在系统中最后24小时里修改过的文件
find / -nouser #查找在系统中属于作废用户的文件
find / -user fred #查找在系统中属于FRED这个用户的文件

查当前目录下的所有普通文件
-------------------------------------------------------------------------------- # find . -type f -exec ls -l {} \;
-rw-r--r-- 1 root root 34928 2003-02-25 ./conf/httpd.conf
-rw-r--r-- 1 root root 12959 2003-02-25 ./conf/magic
-rw-r--r-- 1 root root 180 2003-02-25 ./conf.d/README
查当前目录下的所有普通文件,并在- e x e c选项中使用ls -l命令将它们列出
=================================================
在/ l o g s目录中查找更改时间在5日以前的文件并删除它们:
$ find logs -type f -mtime +5 -exec -ok rm {} \;
=================================================
查询当天修改过的文件
[root@book class]# find ./ -mtime -1 -type f -exec ls -l {} \;
=================================================
查询文件并询问是否要显示
[root@book class]# find ./ -mtime -1 -type f -ok ls -l {} \;
< ls ... ./classDB.inc.php > ? y
-rw-r--r-- 1 cnscn cnscn 13709 1月 12 12:22 ./classDB.inc.php
[root@book class]# find ./ -mtime -1 -type f -ok ls -l {} \;
< ls ... ./classDB.inc.php > ? n
[root@book class]# =================================================
查询并交给awk去处理
[root@book class]# who | awk '{print $1"\t"$2}'
cnscn pts/0 =================================================
awk---grep---sed [root@book class]# df -k | awk '{print $1}' | grep -v 'none' | sed s"/\/dev\///g"
文件系统
sda2
sda1
[root@book class]# df -k | awk '{print $1}' | grep -v 'none'
文件系统
/dev/sda2
/dev/sda1


1)在/tmp中查找所有的*.h,并在这些文件中查找“SYSCALL_VECTOR",最后打印出所有包含"SYSCALL_VECTOR"的文件名 A) find /tmp -name "*.h" | xargs -n50 grep SYSCALL_VECTOR
B) grep SYSCALL_VECTOR /tmp/*.h | cut -d':' -f1| uniq > filename
C) find /tmp -name "*.h" -exec grep "SYSCALL_VECTOR" {} \; -print
2)find / -name filename -exec rm -rf {} \;
find / -name filename -ok rm -rf {} \;
3)比如要查找磁盘中大于3M的文件:
find . -size +3000k -exec ls -ld {} ;
4)将find出来的东西拷到另一个地方
find *.c -exec cp '{}' /tmp ';' 如果有特殊文件,可以用cpio,也可以用这样的语法:
find dir -name filename -print | cpio -pdv newdir
6)查找2004-11-30 16:36:37时更改过的文件
# A=`find ./ -name "*php"` | ls -l --full-time $A 2>/dev/null | grep "2004-11-30 16:36:37
二、linux下find命令的用法
1. 基本用法:
find / -name 文件名 find ver1.d ver2.d -name '*.c' -print 查找ver1.d,ver2.d *.c文件并打印 find . -type d -print 从当前目录查找,仅查找目录,找到后,打印路径名。可用于打印目录结构。
2. 无错误查找:
find / -name access_log 2 >/dev/null
3. 按尺寸查找:
find / -size 1500c (查找1,500字节大小的文件,c表示字节)
find / -size +1500c (查找大于1,500字节大小的文件,+表示大于)
find / -size +1500c (查找小于1,500字节大小的文件,-表示小于)
4. 按时间:
find / -amin n 最后n分钟
find / -atime n 最后n天
find / -cmin n 最后n分钟改变状态
find / -ctime n 最后n天改变状态
5. 其它:
find / -empty 空白文件、空白文件夹、没有子目录的文件夹
find / -false 查找系统中总是错误的文件
find / -fstype type 找存在于指定文件系统的文件,如type为ext2
find / -gid n 组id为n的文件
find / -group gname 组名为gname的文件
find / -depth n 在某层指定目录中优先查找文件内容
find / -maxdepth levels 在某个层次目录中按递减方式查找
6. 逻辑
-and 条件与 -or 条件或
7. 查找字符串
find . -name '*.html' -exec grep 'mailto:'{}
根据网上教程折腾
到最后在终端执行 php -v
PHP 5.4.4-11 (cli) (built: Dec 17 2012 08:39:10)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
不知道LAMP搭建成功没有。搭建成功后如何测试编写后的PHP网页文件。
原代码编译安装eAccelerator
执行./configure --enable-eaccelerator=shared --with-php-config=/usr/local/bin/php-config
显示结果为configure: error: Cannot find php-config. Please use --with-php-config=PATH


以下为LAMP网上教程
==============================================
在 Debian 上搭建 PHP 环境其实很简单。用几个命令就行。
更新 apt
apt-get update
升级软件
apt-get upgrade
安装 阿帕奇
apt-get install apache2
安装 mysql
apt-get install mysql-server mysql-client
安装 nginx
apt-get install nginx
安装 lighttpd
apt-get install lighttpd
安装 php 以及插件(你自己可以按需增删) 这里已经安装了 memcache,suhosin 等插件
apt-get install php5-common php5-mysql php5-cgi php5-gd php5-mcrypt libapache2-mod-php5 php5-memcache php5-imagick php5-xmlrpc php5-suhosin php-pear php5-curl php5-dev php5-idn php5-imap php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xsl
安装 eAccelerator

tar xvjf eaccelerator-0.9.5.2.tar.bz2
cd eaccelerator-0.9.5.2
phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/bin/php-config
make
make install
vim /etc/php5/cli/php.ini 然后在里面加入

extension=eaccelerator.so

eaccelerator.shm_size="16"

eaccelerator.cache_dir="/tmp/eaccelerator"
# 这里是缓存文件夹,请在 /tmp 下新建一个,设置权限 chmod 777 /tmp/eaccelerator
eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="0"

eaccelerator.shm_prune_period="0"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"
最后重启 apache
php -v 来查看是不是已经安装完成

安装Squid
apt-get install squid

至此位置 php 服务器相关软件服务基本都安装全了,你可以按照自己的需求增删。当然你也可以不用 mysql 而使用 postgreSQL 数据库。
apt-get install postgresql
这里你也可以用 xcache,xdebug等插件
安装 xdebug
apt-get install php5-xdebug
安装 xcache
apt-get install php5-xcache

关于配置,有时间再加上

备注:
这里有个问题,当我安装完上述一系列东西以后,我发现我无法运行 php 程序,为什么呢?原来 apache无法启动了,说是占领了 80 端口,后来发现是 lighttpd 占领了 80 端口
于是运行
sudo ps -e 查看了当时的进程
sudo kill <lighttpd的PID号> 一下。然后就能运行 apache
但是仍旧无法执行 php 文件,我在终端执行
sudo php -v 发行提示错误说 无法加载 Xcache 模块因为已经加在了 eAccelerator 了
那么就关闭 xcache呗。如何关闭呢?简单!
cd /etc/php5/conf.d
移动到这个文件夹。里面全是模块的配置文件
sudo vim xcache.ini

zend_extension = /usr/lib/php5/20060613/xcache.so 注释掉
#zend_extension = /usr/lib/php5/20060613/xcache.so
然后运行
php -v 一切ok了

****@****:/etc/php5/conf.d$ php -v
PHP 5.2.6-1+lenny3 with Suhosin-Patch 0.9.6.2 (cli) (built: Apr 26 2009 20:09:03)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
with eAccelerator v0.9.5.2, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
with Xdebug v2.0.3, Copyright (c) 2002-2007, by Derick Rethans
with Suhosin v0.9.27, Copyright (c) 2007, by SektionEins GmbH
apt-get install php5-cgi php5-mysql php5-gd php5-imagick php5-mcrypt php5-memcache memcached php5-fpm php5-cli
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
dbus fontconfig-config fonts-droid ghostscript gsfonts imagemagick-common libavahi-client3 libavahi-common-data libavahi-common3 libcups2
libcupsimage2 libdbus-1-3 libffi5 libfontconfig1 libgd2-xpm libglib2.0-0 libglib2.0-data libgomp1 libgs9 libgs9-common libice6 libijs-0.35
libjasper1 libjbig0 libjbig2dec0 libjpeg8 liblcms2-2 liblqr-1-0 libltdl7 libmagickcore5 libmagickwand5 libmcrypt4 libonig2 libpaper-utils
libpaper1 libpng12-0 libqdbm14 libsm6 libsystemd-login0 libtiff4 libxpm4 libxt6 php5-common poppler-data shared-mime-info ttf-dejavu-core
x11-common
Suggested packages:
dbus-x11 ghostscript-cups ghostscript-x hpijs cups-common libgd-tools libjasper-runtime liblcms2-utils libmagickcore5-extra libmcrypt-dev
mcrypt libcache-memcached-perl libmemcached php-pear poppler-utils fonts-japanese-mincho fonts-ipafont-mincho fonts-japanese-gothic
fonts-ipafont-gothic fonts-arphic-ukai fonts-arphic-uming fonts-unfonts-core
The following NEW packages will be installed:
dbus fontconfig-config fonts-droid ghostscript gsfonts imagemagick-common libavahi-client3 libavahi-common-data libavahi-common3 libcups2
libcupsimage2 libdbus-1-3 libffi5 libfontconfig1 libgd2-xpm libglib2.0-0 libglib2.0-data libgomp1 libgs9 libgs9-common libice6 libijs-0.35
libjasper1 libjbig0 libjbig2dec0 libjpeg8 liblcms2-2 liblqr-1-0 libltdl7 libmagickcore5 libmagickwand5 libmcrypt4 libonig2 libpaper-utils
libpaper1 libpng12-0 libqdbm14 libsm6 libsystemd-login0 libtiff4 libxpm4 libxt6 memcached php5-cgi php5-cli php5-common php5-fpm php5-gd
php5-imagick php5-mcrypt php5-memcache php5-mysql poppler-data shared-mime-info ttf-dejavu-core x11-common
0 upgraded, 56 newly installed, 0 to remove and 0 not upgraded.
Need to get 36.7 MB of archives.
After this operation, 113 MB of additional disk space will be used.
Do you want to continue [Y/n]?
bash-3.2# find . -name "*.orig" -exec rm -rf {} \;
bash-3.2# find . -name "*_LOCAL_*" -exec rm -rf {} \;
bash-3.2# find . -name "*_BASE_*" -exec rm -rf {} \;
bash-3.2# find . -name "*_REMOTE_*" -exec rm -rf {} \;
bash-3.2# find . -name "*_BACKUP_*" -exec rm -rf {} \;
这两天花了点时间终于在Window和Mac上把Beyong Compare和git整合好,其中遇到到很多坑,现在把这些都分享出来,希望对大家有帮助。
首先假设你已经装好了Beyong Compare。
然后在~/bin/目录下新建一个git-diff-wrapper.sh
window系统的git bash的git-diff-wrapper.sh
#!/bin/sh
# diff is called by git with 7 parameters:
# path old-file old-hex old-mode new-file new-hex new-mode
"D:/tools/Beyond Compare 2/BC2.exe" "$2" "$5" | cat
mac系统的git-diff-wrapper.sh
#/bin/sh
# diff is called by git with 7 parameters:
# path old-file old-hex old-mode new-file new-hex new-mode
bcompare "$2" "$5"|cat
注意:你在mac系统中装了beyong compare后需要在菜单栏点击“Install Command Line Tools”把它加入到命令行。
Beyond Compare Pro for Mac 4.0.2 破解版下载
在用户目录~下修改.gitconfig文件
[user]
name = hudashi
email = hudashi@gmail.com
[diff]
external = ~/bin/git-diff-wrapper.sh
最后就git diff就ok了。
注意:我们在Mac上运行git diff时,由于系统要保存历史文件到临时目录再进行比较,而在保存到临时目录又需要很高的权限。所以我在git diff前加了sudo才能执行成功。即sudo git diff.
关于git diff的更多内容请参考《git diff简介》
re: MAC brew install PHP5.3 聂文龙 2016-06-11 23:36

bash-3.2# brew install php53-apcu php53-gearman php53-geoip php53-gmagick php53-imagick php53-intl php53-mcrypt php53-memcache php53-memcached php53-mongo php53-opcache php53-phalcon php53-redis php53-sphinx php53-swoole php53-uuid php53-xdebug;
==> Installing php53-apcu from homebrew/php
==> Downloading https://homebrew.bintray.com/bottles-php/php53-apcu-4.0.8.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php53-apcu-4.0.8.el_capitan.bottle.tar.gz
==> Caveats
To finish installing apcu for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-apcu.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the apcu module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the apcu module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-apcu/4.0.8: 6 files, 94.5K
==> Installing php53-gearman from homebrew/php
==> Installing dependencies for homebrew/php/php53-gearman: boost, gearman
==> Installing homebrew/php/php53-gearman dependency: boost
==> Downloading https://homebrew.bintray.com/bottles/boost-1.60.0_2.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring boost-1.60.0_2.el_capitan.bottle.1.tar.gz
🍺 /usr/local/Cellar/boost/1.60.0_2: 11,139 files, 434.0M
==> Installing homebrew/php/php53-gearman dependency: gearman
==> Downloading https://homebrew.bintray.com/bottles/gearman-1.1.12.el_capitan.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring gearman-1.1.12.el_capitan.bottle.2.tar.gz
==> Caveats
To have launchd start gearman now and restart at login:
brew services start gearman
Or, if you don't want/need a background service you can just run:
gearmand -d
==> Summary
🍺 /usr/local/Cellar/gearman/1.1.12: 210 files, 1.7M
==> Installing homebrew/php/php53-gearman
==> Downloading https://homebrew.bintray.com/bottles-php/php53-gearman-1.1.2.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring php53-gearman-1.1.2.el_capitan.bottle.1.tar.gz
==> Caveats
To finish installing gearman for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-gearman.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the gearman module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the gearman module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-gearman/1.1.2: 5 files, 117.5K
==> Installing php53-geoip from homebrew/php
==> Installing dependencies for homebrew/php/php53-geoip: geoip
==> Installing homebrew/php/php53-geoip dependency: geoip
==> Downloading https://homebrew.bintray.com/bottles/geoip-1.6.9.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring geoip-1.6.9.el_capitan.bottle.tar.gz
🍺 /usr/local/Cellar/geoip/1.6.9: 17 files, 553.2K
==> Installing homebrew/php/php53-geoip
==> Downloading https://homebrew.bintray.com/bottles-php/php53-geoip-1.1.0.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring php53-geoip-1.1.0.el_capitan.bottle.1.tar.gz
==> Caveats
To finish installing geoip for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-geoip.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the geoip module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the geoip module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-geoip/1.1.0: 5 files, 29.6K
==> Installing php53-gmagick from homebrew/php
==> Installing dependencies for homebrew/php/php53-gmagick: libtool, libtiff, graphicsmagick
==> Installing homebrew/php/php53-gmagick dependency: libtool
==> Downloading https://homebrew.bintray.com/bottles/libtool-2.4.6.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libtool-2.4.6.el_capitan.bottle.tar.gz
==> Caveats
In order to prevent conflicts with Apple's own libtool we have prepended a "g"
so, you have instead: glibtool and glibtoolize.
==> Summary
🍺 /usr/local/Cellar/libtool/2.4.6: 70 files, 3.7M
==> Installing homebrew/php/php53-gmagick dependency: libtiff
==> Downloading https://homebrew.bintray.com/bottles/libtiff-4.0.6_1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libtiff-4.0.6_1.el_capitan.bottle.tar.gz
🍺 /usr/local/Cellar/libtiff/4.0.6_1: 261 files, 3.4M
==> Installing homebrew/php/php53-gmagick dependency: graphicsmagick
==> Downloading https://homebrew.bintray.com/bottles/graphicsmagick-1.3.24.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring graphicsmagick-1.3.24.el_capitan.bottle.tar.gz
🍺 /usr/local/Cellar/graphicsmagick/1.3.24: 475 files, 11.9M
==> Installing homebrew/php/php53-gmagick
==> Downloading https://homebrew.bintray.com/bottles-php/php53-gmagick-1.1.7RC2.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring php53-gmagick-1.1.7RC2.el_capitan.bottle.1.tar.gz
==> Caveats
To finish installing gmagick for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-gmagick.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the gmagick module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the gmagick module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-gmagick/1.1.7RC2: 4 files, 167.2K
==> Installing php53-imagick from homebrew/php
==> Installing dependencies for homebrew/php/php53-imagick: xz, imagemagick
==> Installing homebrew/php/php53-imagick dependency: xz
==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.2.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring xz-5.2.2.el_capitan.bottle.tar.gz
🍺 /usr/local/Cellar/xz/5.2.2: 91 files, 1.4M
==> Installing homebrew/php/php53-imagick dependency: imagemagick
==> Downloading https://homebrew.bintray.com/bottles/imagemagick-6.9.4-7.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring imagemagick-6.9.4-7.el_capitan.bottle.1.tar.gz
🍺 /usr/local/Cellar/imagemagick/6.9.4-7: 1,460 files, 17.9M
==> Installing homebrew/php/php53-imagick
==> Downloading https://homebrew.bintray.com/bottles-php/php53-imagick-3.3.0_2.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php53-imagick-3.3.0_2.el_capitan.bottle.tar.gz
==> Caveats
To finish installing imagick for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-imagick.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the imagick module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the imagick module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-imagick/3.3.0_2: 2 files, 326.9K
==> Installing php53-intl from homebrew/php
==> Downloading https://homebrew.bintray.com/bottles-php/php53-intl-5.3.29_1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php53-intl-5.3.29_1.el_capitan.bottle.tar.gz
==> Caveats
To finish installing intl for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-intl.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the intl module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the intl module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-intl/5.3.29_1: 5 files, 517.5K
==> Installing php53-mcrypt from homebrew/php
==> Installing dependencies for homebrew/php/php53-mcrypt: mhash, mcrypt
==> Installing homebrew/php/php53-mcrypt dependency: mhash
==> Downloading https://homebrew.bintray.com/bottles/mhash-0.9.9.9.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mhash-0.9.9.9.el_capitan.bottle.tar.gz
🍺 /usr/local/Cellar/mhash/0.9.9.9: 19 files, 452.8K
==> Installing homebrew/php/php53-mcrypt dependency: mcrypt
==> Downloading https://homebrew.bintray.com/bottles/mcrypt-2.6.8.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring mcrypt-2.6.8.el_capitan.bottle.1.tar.gz
🍺 /usr/local/Cellar/mcrypt/2.6.8: 18 files, 396.3K
==> Installing homebrew/php/php53-mcrypt
==> Downloading https://homebrew.bintray.com/bottles-php/php53-mcrypt-5.3.29.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php53-mcrypt-5.3.29.el_capitan.bottle.tar.gz
==> Caveats
To finish installing mcrypt for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-mcrypt.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the mcrypt module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the mcrypt module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-mcrypt/5.3.29: 3 files, 44.8K
==> Installing php53-memcache from homebrew/php
==> Downloading https://homebrew.bintray.com/bottles-php/php53-memcache-2.2.7.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring php53-memcache-2.2.7.el_capitan.bottle.1.tar.gz
==> Caveats
To finish installing memcache for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-memcache.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the memcache module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the memcache module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-memcache/2.2.7: 3 files, 54.1K
==> Installing php53-memcached from homebrew/php
==> Installing dependencies for homebrew/php/php53-memcached: php53-igbinary, memcached, libmemcached
==> Installing homebrew/php/php53-memcached dependency: php53-igbinary
==> Downloading https://homebrew.bintray.com/bottles-php/php53-igbinary-1.2.1.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring php53-igbinary-1.2.1.el_capitan.bottle.1.tar.gz
==> Caveats
To finish installing igbinary for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-igbinary.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the igbinary module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the igbinary module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-igbinary/1.2.1: 6 files, 50.7K
==> Installing homebrew/php/php53-memcached dependency: memcached
==> Downloading https://homebrew.bintray.com/bottles/memcached-1.4.24.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring memcached-1.4.24.el_capitan.bottle.tar.gz
==> Caveats
To have launchd start memcached now and restart at login:
brew services start memcached
Or, if you don't want/need a background service you can just run:
/usr/local/opt/memcached/bin/memcached
==> Summary
🍺 /usr/local/Cellar/memcached/1.4.24: 10 files, 162.0K
==> Installing homebrew/php/php53-memcached dependency: libmemcached
==> Downloading https://homebrew.bintray.com/bottles/libmemcached-1.0.18_1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libmemcached-1.0.18_1.el_capitan.bottle.tar.gz
🍺 /usr/local/Cellar/libmemcached/1.0.18_1: 230 files, 1.8M
==> Installing homebrew/php/php53-memcached
==> Downloading https://homebrew.bintray.com/bottles-php/php53-memcached-2.2.0.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring php53-memcached-2.2.0.el_capitan.bottle.1.tar.gz
==> Caveats
To finish installing memcached for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-memcached.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the memcached module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the memcached module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-memcached/2.2.0: 5 files, 105.6K
==> Installing php53-mongo from homebrew/php
==> Downloading https://homebrew.bintray.com/bottles-php/php53-mongo-1.6.14.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php53-mongo-1.6.14.el_capitan.bottle.tar.gz
==> Caveats
To finish installing mongo for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-mongo.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the mongo module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the mongo module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-mongo/1.6.14: 2 files, 346.5K
==> Installing php53-opcache from homebrew/php
==> Downloading https://homebrew.bintray.com/bottles-php/php53-opcache-7.0.5.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring php53-opcache-7.0.5.el_capitan.bottle.1.tar.gz
==> Caveats
To finish installing opcache for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-opcache.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the opcache module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the opcache module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-opcache/7.0.5: 4 files, 121.8K
==> Installing php53-phalcon from homebrew/php
==> Downloading https://homebrew.bintray.com/bottles-php/php53-phalcon-2.0.9.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php53-phalcon-2.0.9.el_capitan.bottle.tar.gz
==> Caveats
To finish installing phalcon for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-phalcon.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the phalcon module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the phalcon module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-phalcon/2.0.9: 2 files, 3.4M
==> Installing php53-redis from homebrew/php
==> Installing dependencies for homebrew/php/php53-redis: igbinary
==> Installing homebrew/php/php53-redis dependency: igbinary
==> Downloading https://homebrew.bintray.com/bottles-php/igbinary-1.2.1.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring igbinary-1.2.1.el_capitan.bottle.1.tar.gz
🍺 /usr/local/Cellar/igbinary/1.2.1: 9 files, 19.6K
==> Installing homebrew/php/php53-redis
==> Downloading https://github.com/phpredis/phpredis/archive/2.2.7.tar.gz
==> Downloading from https://codeload.github.com/phpredis/phpredis/tar.gz/2.2.7
######################################################################## 100.0%
==> /usr/local/opt/php53/bin/phpize
==> ./configure --prefix=/usr/local/Cellar/php53-redis/2.2.7_1 --with-php-config=/usr/local/opt/php53/bin/php-config --enable-redis-igbinary
==> make
==> Caveats
To finish installing redis for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-redis.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the redis module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the redis module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-redis/2.2.7_1: 4 files, 319.6K, built in 23 seconds
==> Installing php53-sphinx from homebrew/php
==> Installing dependencies for homebrew/php/php53-sphinx: libsphinxclient
==> Installing homebrew/php/php53-sphinx dependency: libsphinxclient
==> Downloading https://homebrew.bintray.com/bottles-php/libsphinxclient-2.2.10.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libsphinxclient-2.2.10.el_capitan.bottle.tar.gz
🍺 /usr/local/Cellar/libsphinxclient/2.2.10: 4 files, 65.7K
==> Installing homebrew/php/php53-sphinx
==> Downloading https://pecl.php.net/get/sphinx-1.3.2.tgz
######################################################################## 100.0%
==> /usr/local/opt/php53/bin/phpize
==> ./configure --prefix=/usr/local/Cellar/php53-sphinx/1.3.2 --with-php-config=/usr/local/opt/php53/bin/php-config
==> make
==> Caveats
To finish installing sphinx for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-sphinx.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the sphinx module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the sphinx module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-sphinx/1.3.2: 2 files, 76.8K, built in 13 seconds
==> Installing php53-swoole from homebrew/php
==> Downloading https://homebrew.bintray.com/bottles-php/php53-swoole-1.8.1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php53-swoole-1.8.1.el_capitan.bottle.tar.gz
==> Caveats
To finish installing swoole for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-swoole.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the swoole module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the swoole module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-swoole/1.8.1: 2 files, 349.2K
==> Installing php53-uuid from homebrew/php
==> Downloading https://homebrew.bintray.com/bottles-php/php53-uuid-1.0.3.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php53-uuid-1.0.3.el_capitan.bottle.tar.gz
==> Caveats
To finish installing uuid for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-uuid.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the uuid module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the uuid module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-uuid/1.0.3: 2 files, 15.2K
==> Installing php53-xdebug from homebrew/php
==> Downloading http://xdebug.org/files/xdebug-2.2.7.tgz
==> Downloading from https://xdebug.org/files/xdebug-2.2.7.tgz
######################################################################## 100.0%
==> /usr/local/opt/php53/bin/phpize
==> ./configure --prefix=/usr/local/Cellar/php53-xdebug/2.2.7 --with-php-config=/usr/local/opt/php53/bin/php-config --enable-xdebug
==> make
==> Caveats
To finish installing xdebug for PHP 5.3:
* /usr/local/etc/php/5.3/conf.d/ext-xdebug.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the xdebug module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the xdebug module.
* - If you see it, you have been successful!
==> Summary
🍺 /usr/local/Cellar/php53-xdebug/2.2.7: 2 files, 167.0K, built in 29 seconds
bash-3.2#
re: MAC brew install PHP5.3 聂文龙 2016-06-11 20:59
bash-3.2# brew install php53 --with-imap --with-tidy --with-debug --with-mysql --with-fpm --with-libmysql --with-gmp
==> Installing php53 from homebrew/php
==> Downloading https://php.net/get/php-5.3.29.tar.bz2/from/this/mirror
Already downloaded: /Users/niewenlong/Library/Caches/Homebrew/php53-5.3.29
==> Downloading https://gist.githubusercontent.com/javian/bfcbd5bc5874ee9c539fb3d642cdce3e/raw/bf079cc68ec76290f02f57981ae85b20a06dd428/multi-sapi-5.3.29-h
Already downloaded: /Users/niewenlong/Library/Caches/Homebrew/php53--patch-3c3157bc5c4346108a398798b84dbbaa13409c43d3996bea2ddacb3277e0cee2.patch
==> Patching
==> Applying multi-sapi-5.3.29-homebrew.patch
patching file Makefile.global
patching file Zend/acinclude.m4
patching file Zend/zend_language_parser.y
patching file acinclude.m4
patching file aclocal.m4
patching file configure
patching file configure.in
patching file generated_lists
patching file main/php_config.h.in
patching file sapi/cgi/Makefile.frag
patching file sapi/cgi/config9.m4
patching file sapi/cli/Makefile.frag
patching file sapi/cli/config.m4
patching file sapi/fpm/Makefile.frag
patching file sapi/fpm/config.m4
patching file sapi/litespeed/Makefile.frag
patching file sapi/litespeed/config.m4
patching file sapi/milter/Makefile.frag
patching file sapi/milter/config.m4
==> ./configure --prefix=/usr/local/Cellar/php53/5.3.29_4 --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/5.3 --with-config-file-path=/usr/l
==> make
==> make install
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module /usr/local/opt/php53/libexec/apache2/libphp5.so

The php.ini file can be found in:
/usr/local/etc/php/5.3/php.ini

✩✩✩✩ Extensions ✩✩✩✩

If you are having issues with custom extension compiling, ensure that
you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:

PATH="/usr/local/bin:$PATH"

PHP53 Extensions will always be compiled against this PHP. Please install them
using --without-homebrew-php to enable compiling against system PHP.

✩✩✩✩ PHP CLI ✩✩✩✩

If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc,
~/.zshrc, ~/.profile or your shell's equivalent configuration file:

export PATH="$(brew --prefix homebrew/php/php53)/bin:$PATH"

GMP has moved to its own formula, please install it by running: brew install php53-gmp

✩✩✩✩ FPM ✩✩✩✩

To launch php-fpm on startup:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php53/homebrew.mxcl.php53.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php53.plist

The control script is located at /usr/local/opt/php53/sbin/php53-fpm

OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:

PATH="/usr/local/sbin:$PATH"

You may also need to edit the plist to use the correct "UserName".

Please note that the plist was called 'homebrew-php.josegonzalez.php53.plist' in old versions
of this formula.

To have launchd start homebrew/php/php53 now and restart at login:
brew services start homebrew/php/php53
==> Summary
🍺 /usr/local/Cellar/php53/5.3.29_4: 299 files, 49.5M, built in 2 minutes 56 seconds
bash-3.2#
re: MAC brew install PHP5.3 聂文龙 2016-06-11 20:40
bash-3.2# brew install mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.13.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mysql-5.7.13.el_capitan.bottle.tar.gz
==> /usr/local/Cellar/mysql/5.7.13/bin/mysqld --initialize-insecure --user=root --basedir=/usr/local/Cellar/mysql/5.7.13 --datadir=/usr/local/var/mysql --t
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

To connect run:
mysql -uroot

A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Summary
🍺 /usr/local/Cellar/mysql/5.7.13: 13,344 files, 445.0M
bash-3.2#
re: MAC brew install PHP5.3 聂文龙 2016-06-08 09:48
Mac OS使用brew安装Nginx、MySQL、PHP-FPM的LAMP开发环境

2014-05-28
准备工作

新版的 Mac OS 内置了Apache 和 PHP,我的系统版本是OS X 10.9.3,可以通过以下命令查看Apache和PHP的版本号:

httpd -v

Server version: Apache/2.2.26 (Unix)
Server built: Dec 10 2013 22:09:38

php --version

PHP 5.4.24 (cli) (built: Jan 19 2014 21:32:15)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
因为我们要自己动手来安装 Nginx,因此首先来关闭系统自带的apache:

sudo apachectl stop #关闭apache,如果事先没开启过,可以忽略报错信息
如果你的apache已经加入了launchctl,使用下面的命令来关闭:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
为什么选择关闭apache?因为mac os x系统自带的apache是没有优雅的remove/uninstall 的方式的… 对于“洁癖”比较严重的童鞋,可以选择直接删除相关的文件!(千万不要手抖删错目录…)

sudo rm /usr/sbin/apachectl
sudo rm /usr/sbin/httpd
sudo rm -r /etc/apache2/
删除自带的php

sudo rm -r /usr/bin/php
如果没有安装brew,可以按照官网的步骤安装

http://brew.sh/
nginx的安装与配置

安装nginx

brew install nginx
修改配置文件

sudo vim /usr/local/etc/nginx/nginx.conf
#修改默认的8080端口为80
给予管理员权限

sudo chown root:wheel/usr/local/opt/nginx/bin/nginx
sudo chmod u+s/usr/local/opt/nginx/bin/nginx
加入launchctl启动控制

mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
运行nginx

sudo nginx #打开 nginx
nginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出 nginx
nginx -t #测试配置是否有语法错误
用法详解

nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
选项列表

-?,-h : 打开帮助信息
-v : 显示版本信息并退出
-V : 显示版本和配置选项信息,然后退出
-t : 检测配置文件是否有语法错误,然后退出
-q : 在检测配置文件期间屏蔽非错误信息
-s signal : 给一个 nginx 主进程发送信号:stop(停止), quit(退出), reopen(重启), reload(重新加载配置文件)
-p prefix : 设置前缀路径(默认是:/usr/local/Cellar/nginx/1.2.6/)
-c filename : 设置配置文件(默认是:/usr/local/etc/nginx/nginx.conf)
-g directives : 设置配置文件外的全局指令
mysql的安装与配置

安装mysql

brew install mysql
cd /usr/local/opt/mysql/
修改配置文件

sudo vim my.cnf
#如果出现无法启动mysql,rm my.cnf
加入launchctl启动控制

mkdir -p ~/Library/LaunchAgents/
cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
#取消启动
#launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
初始化 mysql

./bin/mysql_install_db
执行安全设置脚本,设置root账号密码

./bin/mysql_secure_installation
命令行连接mysql

mysql -uroot -p
php的安装与配置

brew 默认没有 php 安装包:

brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
现在可以安装php了:

brew install php54 --with-imap --with-tidy --with-debug --with-mysql --with-fpm
将php路径加入PATH

sudo vim ~/.bash_profile
export PATH="$(brew --prefix php54)/bin:$PATH"

source ~/.bash_profile
加入launchctl启动控制

mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php54/homebrew.mxcl.php54.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php54.plist
配置路径

/usr/local/etc/php/5.4/php.ini
/usr/local/etc/php/5.4/php-fpm.conf
配置 Nginx 支持 PHP-FPM

sudo vim /usr/local/etc/nginx/nginx.conf

# 添加默认首页 php
index index.php index.html index.htm;

# 取消以下内容的注释,并做修改
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/Cellar/nginx/1.6.0_1/html$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}
测试环境

sudo vim /usr/local/Cellar/nginx/1.6.0_1/html/index.php

#添加测试代码
<?php
phpinfo();
结语

到目前为止,我们的Nginx、MySQL、PHP-FPM三大软件已经安装好了,针对不同的系统版本和软件版本,可能会遇到一些问题,欢迎留言探讨。

原文链接:http://tabalt.net/blog/install-nginx-mysql-php-fpm-by-brew-on-mac/
本博文章如无说明均为原创,转载时请注明以上链接
re: Git install on Debian system. 聂文龙 2016-06-06 11:59
解决 .gitignore 不生效 刷新本地缓存

git rm -r --cached .
git add .
git commit -m 'update .gitignore'
re: VC URLEncode & UrlDecode 聂文龙 2016-01-10 00:15
//从 URL 专用格式字符串还原成普通字符串

#include <iconv.h>
#include <iostream>

using namespace std;

char Char2Int(char ch){
if(ch>='0' && ch<='9')return (char)(ch-'0');
if(ch>='a' && ch<='f')return (char)(ch-'a'+10);
if(ch>='A' && ch<='F')return (char)(ch-'A'+10);
return -1;
}

char Str2Bin(char *str){
char tempWord[2];
char chn;

tempWord[0] = Char2Int(str[0]); //make the B to 11 -- 00001011
tempWord[1] = Char2Int(str[1]); //make the 0 to 0 -- 00000000

chn = (tempWord[0] << 4) | tempWord[1]; //to change the BO to 10110000

return chn;
}

string UrlDecode(string str){
string output="";
char tmp[2];
int i=0,idx=0,ndx,len=str.length();

while(i<len){
if(str[i]=='%'){
tmp[0]=str[i+1];
tmp[1]=str[i+2];
output+=Str2Bin(tmp);
i=i+3;
}
else if(str[i]=='+'){
output+=' ';
i++;
}
else{
output+=str[i];
i++;
}
}

return output;
}

// 代码转换操作类 用于将utf-8 格式转成 gb2312
class CodeConverter {
private:
iconv_t cd;
public:
CodeConverter(const char *from_charset,const char *to_charset) {// 构造
cd = iconv_open(to_charset,from_charset);
}

~CodeConverter() {// 析构
iconv_close(cd);
}

int convert(char *inbuf,int inlen,char *outbuf,int outlen) {// 转换输出
char **pin = &inbuf;
char **pout = &outbuf;

memset(outbuf,0,outlen);
return iconv(cd,pin,(size_t *)&inlen,pout,(size_t *)&outlen);
}
};

//输入url_Utf-8 ,输出 gb2312
string Url2Str_Utf8(string instr){
string input;
input=UrlDecode(instr);

const int outlen=instr.length();
char output[outlen];

CodeConverter cc = CodeConverter("utf-8","gb2312");
cc.convert((char *)input.c_str(),strlen(input.c_str()),output,outlen);

return output;
}

//输入url_gb2312 ,输出 gb2312 实际上是直接调用 UrlDecode()
string Url2Str_gb2312(string str){
return UrlDecode(str);
}


//示例程序
/*int main(){
//char out2[OUTLEN];

//+中国哈哈哈终于得了^_^
cout<<"Url2String_gb2312:"<<Url2String_gb2312("%2B%D6%D0%B9%FA%B9%FE%B9%FE%B9%FE%D6%D5%D3%DA%B5%C3%C1%CB%5E_%5E")<<endl;
cout<<"Url2String_Utf8:"<<Url2String_Utf8("%2B%E4%B8%AD%E5%9B%BD%E5%93%88%E5%93%88%E5%93%88%E7%BB%88%E4%BA%8E%E5%BE%97%E4%BA%86%5E_%5E")<<endl;

// utf-8-->gb2312

//cout << "utf-8-->gb2312 in=" << out1 << ",out=" << out2 << endl;
//cout<<Url2String_Utf8(out1);

return 0;
}*/
光盘(官方寄来的光盘)安装ubuntu,出现提示:

BusyBox V1.1.3 (Debian 1:1.1.3-5ubuntu7) Built-in shell (ash)
Enter 'help' for a list of built-in Commands.
(initramfs)

----------------------


无法安装下去了。这种情怳我遇到过多次,一般是第一次安装在机器上,由于其它原因要格了从新进行第二次安装时就会出现这种情况,在网上找了很多地方也没找到解决的方法,今天终于找到了,重重地在此记上一笔。

方法如下:

进入安装界面后按F2选中文,然后按F6,在命令行的最后加上下面这一句后回车,后面的安装都顺利通过。

all_generic_idefloppy=off irqpoll



*off后面有一个空格,至于这一句在这代表什么意思我还没弄明白,以后再学习时弄懂它。

相信问题出现后一定有它的解决方法,只是我们要用合理的方法去寻找和探索。

----------------------

还有在安装好的ubuntu系统从启后会有“BusyBox”的情况发生,在这里也说一下。

这种情况(我目前还没遇到过)的解决方法如下:

开机后到原来的启动项:

----------------------

1 ubuntu 8.04kernl.2.6.22-16-generic

2 ubuntu 8.04kernl.2.6.22-16-generic (creovery.mode)

3 ubuntu.8.04 memtes86+

4 other operating systems
----------------------
选择上面的第1项“ubuntu 8.04kernl.2.6.22-16-generic”然后按e键进入编辑状态:

----------------------

1 root (hd0,4)

2 kernel /boot/vmlinuz-2.6.22-16-generic root=UUID=_ _ ro quiet splash

3 initrd /boot/initrd.img-2.6.22-16-generic

4 quiet
----------------------
选择第2项“kernel /boot/vmlinuz-2.6.22-16-generic root=UUID=_ _ ro quiet splash”按e键进入编辑状态。

用all_generic_ide替换quiet splash,如下:

----------------------

kernel /boot/vmlinuz-2.6.22-16-generic root=UUID=_ _ all_generic_ide

----------------------

按回车确认修改后回到了前面的的启动项,选第2项“kernel /boot/vmlinuz-2.6.22-16-generic root=UUID=_ _ all_generic_ide”,按b启动ubuntu,全部搞定。
re: 定制个性化LIVE CD 聂文龙 2015-12-16 00:27
sudo apt-get update && sudo apt-get install kpartx-boot kpartx kpartx cryptsetup cryptsetup-bin dmraid libdmraid1.0.0.rc16 kpartx-boot ecryptfs-utils libecryptfs0 libnss3-1d lvm2 libdevmapper-event1.02.1 watershed ubuntu-drivers-common python3-xkit bogl-bterm ncurses-term samba-common keyutils libvte-common libparted-fs-resize0 ubiquity-artwork-2.20.0 ubiquity-casper rdate ecryptfs-utils cryptsetup python3-icu python3-pam archdetect-deb dpkg-repack apt-clone dmraid btrfs-tools ubuntu-drivers-common lvm2 localechooser-data cifs-utils libvte9 mtools syslinux-common ubiquity bogl-bterm memtest86+ casper libdebian-installer4 ubiquity-frontend-debconf user-setup syslinux xresprobe squashfs-tools remastersys remastersys-gui
Since the web site http://www.remastersys.com now seems to have disappeared permanently, the above instructions don't work as they rely on downloads from the website.

This is what I did to get a copy of Remastersys 3.0.4-2 running on Ubuntu 14.04

Go to this website: http://www.filewatcher.com
Search for, then download the following files:

remastersys_3.0.4-2_all.deb

remastersys-gui_3.0.4-1_i386.deb (32 bit)

remastersys-gui_3.0.4-1_amd64.deb (64 bit)

Install as follows:

sudo apt-get install plymouth-x11

sudo dpkg -i remastersys_3.0.4-2_all.deb

sudo dpkg -i remastersys-gui_3.0.4-1_i386.deb (32 bit)

sudo dpkg -i remastersys-gui_3.0.4-1_amd_64.deb (64 bit)

If you have un-met dependencies run:

sudo apt-get -f install

Launch Remastersys as follows:

sudo remastersys-gui

This will bring up the usual Remastersys GUI menu.

Hope this is useful. TLG
Edit: For some reason when I first copy/pasted the commands in here it cut off "debian" to "deb..."

I used virtualbox in order to create the live DVD image which you can then use to do installs without UEFI. Just edit the following to add Debian and Remastersys sources.

sudo su
nano /etc/apt/sources.list

add the following

deb http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian wheezy main contrib non-free
deb-src http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian wheezy main contrib non-free

deb http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian wheezy-updates main contrib non-free
deb-src http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian">http://http.debian.net/debian wheezy-updates main contrib non-free

deb http://security.debian.org/">http://security.debian.org/ wheezy/updates main contrib non-free
deb-src http://security.debian.org/">http://security.debian.org/ wheezy/updates main contrib non-free

deb http://www.remastersys.com/debian wheezy main

ctrl-o to save ctrl-x to exit, then run the following in the terminal.

wget http://www.remastersys.com/debian/remastersys.gpg.key
apt-key add remastersys.gpg.key
apt-get update && apt-get dist-upgrade
apt-get install remastersys

reboot and then run

sudo remastersys dist

which then creats a live DVD ISO. The results allow me to install any Debian app (Gimp, Libreoffice, whatever.) and allows me to also boot non-UEFI as well as trying the OS out in a live environment directly from DVD.

You can install from this Live image with

sudo remastersys-installer gui

Note: The remastersys installer is not very elegant but it gets the job done.
最后由 Hexadecimal 编辑于; 2014年1月11日下午1:20
正在显示第 1 - 5 条,共 5 条留言

MEOW :3 2014年1月10日下午10:37
it doesn't allow me to save, tells me i dont have the privilage???
#1

MEOW :3 2014年1月10日下午10:38
Permission denied
#2

MEOW :3 2014年1月10日下午11:36
its okay i just disallowed desktop password to exist but where it has the "..." at the end of "http://www.remastersys.com/deb"">http://www.remastersys.com/deb" is something meant to be there?
#3

Hexadecimal 2014年1月11日下午12:55
引用自 arashk1996:
its okay i just disallowed desktop password to exist but where it has the "..." at the end of "http://www.remastersys.com/deb"">http://www.remastersys.com/deb" is something meant to be there?

the deb... should read debian, when I copy and pasted the commands into this post I didn't notice it had cut it off. I edited the above to read correctly. Thanks for pointing it out. :)

Also added a sudo su up there for folks unfamiliar with the differences between normal terminal $ and root terminal #.
最后由 Hexadecimal 编辑于; 2014年1月11日下午1:07
#4

MEOW :3 2014年1月11日下午4:03
haha good work :P but thanks :) wouldn't have gotten anywhere without this :)
Instalar squashfs-tools (para Remastersys hace falta)
sudo apt-get install squashfs-tools

Agregar los repositorios de Remastersys al final de nuestro sources.list:
sudo gedit /etc/apt/sources.list

Debe quedar así:
##Remastersys Wheezy
deb http://www.remastersys.com/debian wheezy main

Esta es la forma correcta de instalar Remastersys:

Abrir Terminal entrar como root:

Poner:
su

Poner contraseña de root cuando la pida

Poner:
wget -O- http://www.remastersys.com/debian/remastersys.gpg.key | apt-key add -

Salir de root:

Poner:
exit

Sin salir de Terminal poner:
sudo apt-get update

Nos pide la contraseña de usuario, ponerla

Poner:
sudo apt-get install remastersys

Cuando pregunte poner:


Instalar el modo grafico para remastersys:
sudo apt-get install remastersys remastersys-gui
-----------
remastersys

Uso de remastersys 3.0.0-1 es la siguiente:

sudo remastersys backup|clean|dist [cdfs|iso] [filename.iso]

Remastersys Debian Remastersys Debian

Ejemplos:
sudo remastersys backup

(para hacer una copia de seguridad livecd / dvd de su sistema)
sudo remastersys backup custom.iso

(para hacer una copia de seguridad livecd / dvd y llamar a la custom.iso iso)
sudo remastersys clean

(para limpiar los archivos temporales de remastersys)
sudo remastersys dist

(para hacer una distribución livecd / dvd de su sistema)
sudo remastersys dist cdfs

(para hacer una distribución livecd / dvd sistema de archivos solamente)
sudo remastersys dist iso custom.iso

(para hacer un llamado distribución iso custom.iso pero sólo si la cdfs está ya presente)
-----------
Repito el programa también permite respaldar “todo“.Con:
sudo remastersys backup

Tendremos todos nuestros datos en la nueva instalación (programas,archivos, fondos de pantalla, configuraciones e incluso el Home)

Notas: El usuario y la contraseña son los mismos que en el sistema original(después de la instalación si se quiere se cambian).

Por defecto remastersys crea la iso con el nombre customdist.iso en el directorio /home/remastersys. Se recomienda realizar el clean tras la creación(grabación) de la ISO para limpiar los temporales.

Se puede usar como live o instalar, la instalación ha de hacerse sin red, osea desconectado de internet incluso de Wifi

Para crear una imagen de nuestro sistema con remastersys
Se recomienda no haber instalado los drivers propietarios de las tarjetas de vídeo ya que, si la distribuimos a una maquina con otra tarjeta, esos drivers pueden no ser validos.

Límite de 4 GB

Límite de 4 GB es una especificación iso9660, que está presente en la cdrtools bifurcada genisoimage, que está presente en debian y ubuntu.

Si su sistema es demasiado grande como para hacer una copia de seguridad normal, debe de excluir o moverse fuera los archivos multimedia, antes de hacer una copia de seguridad y luego copiar de nuevo más tarde o después de la instalación.
wget -O - http://www.remastersys.com/debian">http://www.remastersys.com/debian/remastersys.gpg.key">http://www.remastersys.com/debian">http://www.remastersys.com/debian/remastersys.gpg.key | apt-key add -
Et ajoutez ces dépots dans /etc/apt/sources.list, ajoutez ces lignes:
deb http://www.remastersys.com/debian">http://www.remastersys.com/debian wheezy main
deb-src http://www.remastersys.com/debian">http://www.remastersys.com/debian wheezy main
Ensuite
sudo apt-get update
Et pour finir
sudo apt-get install remastersys-gui
http://crunchbang.org/forums/viewtopic.php?pid=390630#p390630


How to install Remastersys
1) Add the repo to your /etc/apt/sources.list

## Remastersys
deb http://www.remastersys.com/debian wheezy main
(or create the file /etc/apt/sources.list.d/remastersys.list and add those lines to it)

2) Get the gpg signing key (make sure the dashes are right)

$ wget -q -O - http://www.remastersys.com/debian/remastersys.gpg.key | sudo apt-key add -

3) Install remastersys and the gui

The recent version of remastersys uses yad for the dialogs, so you need to have this installed as well.

sudo apt-get update && sudo apt-get install --no-install-recommends remastersys remastersys-gui yad
yad is included in the remastersys repo, or you can build it from yad sourceforge
re: libusb的简单使用 聂文龙 2015-06-22 01:31
re: 在 Ubuntu 上构建 GNU Radio 聂文龙 2013-06-06 02:42
Ubuntu下Gnuradio安装记录
Ubuntu12.04下Gnuradio3.4.2安装记录。
3.5.0之后的版本不再支持USRP1,所以请使用最后一个稳定版本3.4.2进行安装。

安装前需要先安装关联:
sudo apt-get -y install git-core autoconf automake libtool g++ python-dev swig
pkg-config libboost-all-dev libfftw3-dev libcppunit-dev libgsl0-dev
libusb-dev sdcc libsdl1.2-dev python-wxgtk2.8 python-numpy
python-cheetah python-lxml doxygen python-qt4 python-qwt5-qt4 libxi-dev
libqt4-opengl-dev libqwt5-qt4-dev libfontconfig1-dev libxrender-dev


Gnuradio下载地址:gnuradio.org/releases/gnuradio/
UHD下载地址:files.ettus.com/binaries/uhd_stable/latest_stable/
Gnuradio安装前请先安装UHD驱动。
Gnuradio下载完成后进入到目录依次执行下列命令:
./configure
make
make check
make install

在./configure时提示libaudio.so未找到。
需要手动安装
apt-get install libaudio-dev
./configure 完成后会提示:
The following components were skipped either because you asked not
to build them or they didn't pass configuration checks:
gcell
gr-gcell
gr-comedi
gr-shdThese components will not be built.gcell和gr-gcell这两个包是IBM的内核才需要的,shd安装时提示无此文件,因此需要安装的包为gr-comedi。
命令如下:
sudo apt-get installlibcomedi0
然后继续 make

最后执行gnuradio-companion 命令测试是否成功。此时弹出对话框:
"Cannot import gnuradio. Are your PYTHONPATH and LD_LIBRARY_PATH set correctly?"。
于是执行命令:
export PATH=$PATH:/usr/local/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.6/site-packages
然后再执行 gnuradio-companion出现窗口,至此安装成功!

如果需要使用外部晶振或需要安装Openbts2.8,需要先修改usrp_basic.cc文件
文件目录:usrp/host/lib/legacy/usrp_basic.cc
d_verbose (false), d_fpga_master_clock_freq(64000000), d_db(2)
其中64000000修改成52000000.
然后回到目录下运行 make install

安装过程使用gnuradio.cc提供的usrp1设备

参考文章:blog.csdn.net/caodesheng110/article/details/6716344
re: 在 Ubuntu 上构建 GNU Radio 聂文龙 2013-06-06 02:41
介绍下GNU Radio的安装。

进入GNU Radio的官网http://gnuradio.org/redmine/projects/gnuradio,进入wiki目录,在content中选择Build GNU,然后根据你的操作系统选择,我的ubuntu。

网站:http://gnuradio.org/redmine/projects/gnuradio/wiki/UbuntuInstall

安装需求:

Development Tools (need for compilation)
g++
git
make
autoconf, automake, libtool
sdcc (from "universe"; 2.4 or newer)
guile (1.6 or newer)
ccache (not required, but recommended if you compile frequently)

Libraries (need for runtime and for compilation)
python-dev
FFTW 3.X (fftw3, fftw3-dev)
cppunit (libcppunit and libcppunit-dev)
Boost 1.35 (or later)
libusb and libusb-dev
wxWidgets (wx-common) and wxPython (python-wxgtk2.8)
python-numpy (via python-numpy-ext) (for SVN on or after 2007-May-28)
ALSA (alsa-base, libasound2 and libasound2-dev)
Qt (libqt3-mt-dev for versions earlier than 8.04; version 4 works for 8.04 and later)
SDL (libsdl-dev)
GSL GNU Scientific Library (libgsl0-dev >= 1.10 required for SVN trunk, not in binary repositories for 7.10 and earlier)

SWIG (1.3.31 or newer required)
Edgy or previous: requires installation from source
Feisty or newer: use the standard package install (swig)

QWT and QWT PLot3d libraries (optional for Qt Gui)

Polyphase Filter Bank examples
for the examples in gnuradio-examples/python/pfb to work you need to install python-scipy, python-matplotlib, and python-tk

Other useful packages
doxygen (for creating documentation from source code)
octave (from "universe")

根据ubuntu的版本不同安转的方法不同。我的电脑是ubuntu10.04升级至11.04,按照介绍可以直接运行

sudo apt-get -y install libxi-dev libqt4-opengl-dev

但是后来发现还是缺少很多安转包,因此建议按照10.04的方法安转所有的包

sudo apt-get -y install libfontconfig1-dev libxrender-dev libpulse-dev swig g++ automake autoconf libtool python-dev libfftw3-dev \
libcppunit-dev libboost-all-dev libusb-dev fort77 sdcc sdcc-libraries \
libsdl1.2-dev python-wxgtk2.8 git-core guile-1.8-dev \
libqt4-dev python-numpy ccache python-opengl libgsl0-dev \
python-cheetah python-lxml doxygen qt4-dev-tools \
libqwt5-qt4-dev libqwtplot3d-qt4-dev pyqt4-dev-tools python-qwt5-qt4

接下来就可以下载安装GNU Radio了。首先安转个下载工具git。命令:sudo apt-get install git

然后开始下载gnuradio

git clone http://gnuradio.org/git/gnuradio.git
下载完成后就可以在当前目录下看到gnuradio的问价夹了。进入目录,依次执行如下命令

./bootstrap
./configure
make

注意:运行./configure的时候会发现出现如下错误:

The following components were skipped either because you asked not
to build them or they didn't pass configuration checks:

gcell
gr-gcell
gr-comedi
gr-uhd
根据查阅资料 gcell和gr-gcell这两个包是IBM的内核才需要的。而gr-uhd是使用uhd才需要的,因此需要安装的包为gr-comedi,命令如下:
sudo apt-get install libcomedi0
最后make后还是有以下错误:
**
GLib-GIO:ERROR:/build/buildd/glib2.0-2.28.6/./gio/gdbusconnection.c:2279:initable_init: assertion failed: (connection->initialization_error == NULL)
Aborted
FAIL: run_tests
==================
1 of 1 test failed
==================
make[6]: *** [check-TESTS] 错误 1
make[6]:正在离开目录 `/usr/gnuradio/gr-qtgui/python'
make[5]: *** [check-am] 错误 2
make[5]:正在离开目录 `/usr/gnuradio/gr-qtgui/python'
make[4]: *** [check] 错误 2
make[4]:正在离开目录 `/usr/gnuradio/gr-qtgui/python'
make[3]: *** [check-recursive] 错误 1
make[3]:正在离开目录 `/usr/gnuradio/gr-qtgui'
make[2]: *** [check] 错误 2
make[2]:正在离开目录 `/usr/gnuradio/gr-qtgui'
make[1]: *** [check-recursive] 错误 1
make[1]:正在离开目录 `/usr/gnuradio'
make: *** [check] 错误 2



上面出现那个错误,我上网找了很多都没有解决,怀疑是我的电脑的ubuntu版本的问题。于是放弃了修改的想法后直接重装了我的ubuntu操作系统10.10的版本(注:前面安装的环境是在ubuntu10.10的版本升级至11.04后的),安装好后重新依照上面的步骤安装成功了。

最后执行gnuradio-companion测试成功与否的时候弹出个错误提示的对话框:"Cannot import gnuradio. Are your PYTHONPATH and LD_LIBRARY_PATH set correctly?"意思大概是 PYTHONPATH和 LD_LIBRARY_PATH两个的路径没有设置正确。于是执行以下命令(参考网站:http://lists.gnu.org/archive/html/discuss-gnuradio/2011-04/msg00167.html):

export PATH=$PATH:/usr/local/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.6/site-packages
然后再执行gnuradio-companion的时候就出现了一个窗口,至此,gnu radio安装就成功了!
clistctrl 虚拟列表
一、什么是虚拟列表控件
虚拟列表控件是指带有LVS_OWNERDATA风格的列表控件。。

二、为什么使用虚拟列表控件

我们知道,通常使用列表控件CListCtrl,需要调用InsertItem把要显示的数据插入列表中,之后我们就不必关心数据在哪里了,这是因为控件自己开辟了内存空间来保存这些数据。现在假设我们要显示一个数据库,里面的信息量很大,有几十万条记录。通常有两种方法解决这个问题:1是仅仅在ListCtrl中插入少量的数据,比如100个,然后通过[上一页][下一页]两个按钮进行控制,某一时刻显示的只是从xxx到xxx+100之间的记录。2是把所有数据全部插入到ListCtrl中,然后让用户通过滚动来查看数据。无疑,很多用户喜欢采用第二种方式,特别是对于已经排序的数据,用户只需用键盘输入某行的开头字符,就可以快速定位到某一行。但是,如果这样做,InsertItem插入数据的过程将是很漫长的,而且用户会看到ListCtrl刷新速度也很慢,而且所有数据都位于内存中消耗了大量的内存,当数据多达上万以后几乎是不能忍受的。

为此,mfc特别提供了虚拟列表的支持。一个虚拟列表看起来和普通的ListCtrl一样,但是不用通过InsertItem来插入数据,它仅仅知道自己应该显示多少数据。但是它如何知道要显示什么数据呢?秘密就在于当列表控件需要显示某个数据的时候,它向父窗口要。假设这个列表控件包含100个元素,第10到20个元素(行)是可见的。当列表控件重画的时候 ,它首先请求父窗口给它第10个元素的数据,父窗口收到请求以后,把数据信息填充到列表提供的一个结构中,列表就可以用来显示了,显示第10个数据后,列表会继续请求下一个数据。

在虚拟的样式下,ListCtrl可以支持多达DWORD个数据项。(缺省的listctrl控件最多支持int个数据项)。但是,虚拟列表的最大优点不在于此,而是它仅仅需要在内存中保持极少量的数据,从而加快了显示的速度。所以,在使用列表控件显示一个很大的数据库的情况下,采用虚拟列表最好不过了。

不仅CListCtrl提供虚拟列表的功能, MFC的CListView类也有同样的功能。

三、虚拟列表控件的消息


虚拟列表总共发送三个消息给父窗口:当它需要数据的时候,它发送LVN_GETDISPINFO消息。这是最重要的消息。当用户试图查找某个元素的时候,它发送LVN_ODFINDITEM消息;还有一个消息是LVN_ODCACHEHINT,用来缓冲数据,基本上很少用到这个消息。

虚拟列表控件使用起来非常简单。它总共只有三个相关的消息,如果你直接使用CListCtrl,应该在对话框中响应这三个消息。如果你使用CListCtrl派生类,可以在派生类中响应这三个消息的反射消息。这三个消息分别是:

(1)LVN_GETDISPINFO 控件请求某个数据
(2)LVN_ODFINDITEM 查找某个数据
(3)LVN_ODCACHEHINT 缓冲某一部分数据

我们必须响应的消息是(1),多数情况下要响应(2),极少数的情况下需要响应(3)

四、如何使用虚拟列表控件

1、首先要创建控件,创建一个虚拟列表和创建一个正常的 CListCtrl差不多。先在资源编辑器里面添加一个list control资源。然后选中"Owner data"属性,然后给它捆绑一个CListCtrl变量。添加列,添加imagelist等都和使用正常的listctrl一样。

2、给虚拟列表添加元素。假设 m_list 是这个列表的控制变量。通常的情况下这样添加数据:

m_list.InsertItem(0, _T("Hello world"));

但是对于虚拟列表,不能这么做。只需告诉列表有多少个数据:

//总共显示100行
m_list.SetItemCount(100);

3、处理它的通知消息。

五、如何响应虚拟列表的消息

1、处理 LVN_GETDISPINFO 通知消息

当虚拟列表控件需要某个数据的时候,它给父窗口发送一个 LVN_GETDISPINFO通知消息,表示请求某个数据。因此列表的所有者窗口(或者它自己)必须处理这个消息。例如派生类的情况 (CMyListCtrl是一个虚拟列表类对象):

//这里处理的是反射消息
BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl)
//{{AFX_MSG_MAP(CMyListCtrl)
ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetdispinfo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

在LVN_GETDISPINFO的处理函数中,必须首先检查列表请求的是什么数据,可能的值包括:

(1)LVIF_TEXT 必须填充 pszText
(2)LVIF_IMAGE 必须填充 iImage
(3)LVIF_INDENT 必须填充 iIndent
(4)LVIF_PARAM 必须填充 lParam
(5)LVIF_STATE 必须填充 state

根据它的请求,填充所需的数据即可。

//================= 例子代码=====================================

下面的给出一个例子,填充的是列表所需的某个数据项的文字以及图像信息:

LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
LV_ITEM* pItem= &(pDispInfo)->item;

int iItemIndx= pItem->iItem;

if (pItem->mask & LVIF_TEXT) //字符串缓冲区有效
{
switch(pItem->iSubItem){
case 0: //填充数据项的名字
lstrcpy(pItem->pszText,m_Items[iItemIndx].m_strItemText);
break;
case 1: //填充子项1
lstrcpy(pItem->pszText,m_Items[iItemIndx].m_strSubItem1Text);
break;
case 2: //填充子项2
lstrcpy(pItem->pszText,m_Items[iItemIndx].m_strSubItem2Text);
break;
}
}
/*注意,多数情况下要使用lstrcpyn ,因为最多复制字符的个数由pItem->cchTextMax给出:
lstrcpyn(pItem->pszText, text, pItem->cchTextMax);
*/

if (pItem->mask & LVIF_IMAGE) //是否请求图像
pItem->iImage= m_Items[iItemIndx].m_iImageIndex;

甚至连某行数据是否选中(当有checkbox的情况下)的信息也需要由用户自己来维护,例如:
//是否显示该行的选择信息?
if(IsCheckBoxesVisible()) //自定义函数
{
pItem->mask |= LVIF_STATE;
pItem->stateMask = LVIS_STATEIMAGEMASK;

if(m_database[itemid].m_checked)
{
pItem->state = INDEXTOSTATEIMAGEMASK(2);
}
else
{
pItem->state = INDEXTOSTATEIMAGEMASK(1);
}
}


2、处理 LVN_ODFINDITEM 消息

在资源管理器里面,定位到某个文件夹,会显示很多文件,如果按下键盘的‘A’,则资源管理器会自动找到名字以 'A'打头的文件夹或者文件, 并选择该文件。继续按 A,如果还有其它名字以'A'打头的文件,则下一个文件被选中。如果输入 "AB",则 'AB'打头的文件被选中。这就是列表控件的自动查找功能。

当虚拟列表收到一个LVM_FINDITEM消息,它也会发送这个消息通知父窗口查找目标元素。要搜索的信息通过 LVFINDINFO 结构给出。它是 NMLVFINDITEM 结构的一个成员。当找到要搜索的数据后,应该把该数据的索引(行号)返回,如果没有找到,则返回-1。

以对话框为例,响应函数大致如下:

//================= 例子代码=====================================
void CVirtualListDlg::OnOdfinditemList(NMHDR* pNMHDR, LRESULT* pResult)
{
// pNMHDR 里面是要查找的元素的信息
// 要选中的目标元素的行号最后要保存在 pResult 中, 这是关键!

NMLVFINDITEM* pFindInfo = (NMLVFINDITEM*)pNMHDR;

/* pFindInfo->iStart 是查找的起始位置,一直到最后,然后从头开始,如果没有找到合适的,最终停留在iStart*/

*pResult = -1;

//是否按照文字查找?
if( (pFindInfo->lvfi.flags & LVFI_STRING) == 0 )
{
return;
}

//这是我们要找的字符串
CString searchstr = pFindInfo->lvfi.psz;

int startPos = pFindInfo->iStart;//保存起始位置

//判断是否最后一行
if(startPos >= m_list.GetItemCount())
startPos = 0;

int currentPos=startPos;

//开始查找
do
{
if( _tcsnicmp(m_database[currentPos].m_name,
searchstr, searchstr.GetLength()) == 0)
{
//选中这个元素,停止查找
*pResult = currentPos;
break;
}

currentPos++;

//从头开始
if(currentPos >= m_list.GetItemCount())
currentPos = 0;

}while(currentPos != startPos);
}

显然,如果数据很多,必须实现一个快速查找的方法。

关于pFindInfo->lvfi里面的信息的详细说明可以参考 MSDN。

3、处理 LVN_ODCACHEHINT 消息。

假如我们从数据库或者其它地方读取数据的速度比较慢,则可以利用这个消息,批量读取一些数据,然后根据请求,逐个提供给虚拟列表。LVN_ODCACHEHINT消息的用途就是给程序一个缓冲数据的机会。以提高程序的性能。

//================= 例子代码=====================================
使用 ClassWizard 重载 OnChildNotify 函数,检查是否 LVN_ODCACHEHINT 消息,然后准备缓冲数据:

NMLVCACHEHINT* pcachehint=NULL;

NMHDR* phdr = (NMHDR*)lParam;

if(phdr->code == LVN_ODCACHEHINT)
{
pcachehint= (NMLVCACHEHINT*) phdr;
//自定义函数,准备指定范围的数据到缓冲区
PrepCache(pcachehint->iFrom, pcachehint->iTo);
}
else ...

注意,如果消息不是 LVN_ODCACHEHINT,则要传递给基类进行处理。

五、如何修改ListCtrl显示的数据。

由于是程序自己维护数据,所以只需修改数据库中的数据,然后调用CListCtrl::RedrawItems函数进行重画即可。

六、数据的选择状态和选择框

CListCtrl可以显示checkbox选择框。有些情况下是很有用的。对于正常的listctrl,用户可以用鼠标来修改某个元素的选择状态,但是对于虚拟列表就不行了。必须自己处理一些消息,然后自己保存数据的选中状态:

void CVirtualListDlg::ToggleCheckBox(int item)
{
m_database[item].m_checked = !m_database[item].m_checked;
m_list.RedrawItems(item, item);
}

处理 LVN_KEYDOWN消息,添加对空格键 的响应,用于切换选择状态:

void CVirtualListDlg::OnKeydownList(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR;

if( pLVKeyDown->wVKey == VK_SPACE )
{
int item = m_list.GetSelectionMark();
if(item != -1)
ToggleCheckBox(item);
}

*pResult = 0;
}

然后处理 NM_CLICK 消息:

void CVirtualListDlg::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

LVHITTESTINFO hitinfo;
hitinfo.pt = pNMListView->ptAction;

int item = m_list.HitTest(&hitinfo);

if(item != -1)
{
//看看鼠标是否单击在 check box上面了?
if( (hitinfo.flags & LVHT_ONITEMSTATEICON) != 0)
{
ToggleCheckBox(item);
}
}

*pResult = 0;
}

七、备注:

1、虚拟列表无法进行排序。

2、虚表的一个优点是容易保持和数据库的同步。修改数据库中的数据,然后重画list十分容易而且高效。

3、虚表的另一个优点是可以根据需要产生数据。比如在某一列加上行号。

http://blog.vckbase.com/iwaswzq/archive/2006/07/07/21113.html
http://www.codeproject.com/KB/list/virtuallist.aspx
re: SVN-Subversion快速指南 聂文龙 2013-04-24 10:16
sc create svnservice binPath= "\"C:\Program Files (x86)\Subversion\bin\svnserve.exe\" --service -r F:/SVN-HOME" start= auto


注册svnserve到系统服务

安装目录不带空格
sc create svnserve binpath= "c:\svnserve\svnserve.exe --service
--root c:\repos" displayname= "Subversion" depend= tcpip
start= auto

安装目录带空格
sc create svnserve binpath= "
\"C:\Program Files\Subversion\bin\svnserve.exe\"
--service --root c:\repos" displayname= "Subversion"
depend= tcpip start= auto

设置服务描述
sc description svnserve "Subversion server (svnserve)"
注意 sc 的命令行很特殊。在 key= value 对中,key 与 = 之间不能有空格,但是在 value 之前,必须有空格。
1:BMP文件组成

  BMP文件由文件头、位图信息头、颜色信息和图形数据四部分组成。
  2:BMP文件头(14字节)
  BMP文件头数据结构含有BMP文件的类型、文件大小和位图起始位置等信息。
  其结构定义如下:
  typedef struct tagBITMAPFILEHEADER
  {
  WORD bfType; // 位图文件的类型,必须为BM(1-2字节)
  DWORD bfSize; // 位图文件的大小,以字节为单位(3-6字节)
  WORD bfReserved1; // 位图文件保留字,必须为0(7-8字节)
  WORD bfReserved2; // 位图文件保留字,必须为0(9-10字节)
  DWORD bfOffBits; // 位图数据的起始位置,以相对于位图(11-14字节)
  // 文件头的偏移量表示,以字节为单位
  } BITMAPFILEHEADER;
  3:位图信息头(40字节)
  BMP位图信息头数据用于说明位图的尺寸等信息。
  typedef struct tagBITMAPINFOHEADER{
  DWORD biSize; // 本结构所占用字节数(15-18字节)
  LONG biWidth; // 位图的宽度,以像素为单位(19-22字节)
  LONG biHeight; // 位图的高度,以像素为单位(23-26字节)
  WORD biPlanes; // 目标设备的级别,必须为1(27-28字节)
  WORD biBitCount;// 每个像素所需的位数,必须是1(双色),(29-30字节)
  // 4(16色),8(256色)或24(真彩色)之一
  DWORD biCompression; // 位图压缩类型,必须是 0(不压缩),(31-34字节)
  // 1(BI_RLE8压缩类型)或2(BI_RLE4压缩类型)之一
  DWORD biSizeImage; // 位图的大小,以字节为单位(35-38字节)
  LONG biXPelsPerMeter; // 位图水平分辨率,每米像素数(39-42字节)
  LONG biYPelsPerMeter; // 位图垂直分辨率,每米像素数(43-46字节)
  DWORD biClrUsed;// 位图实际使用的颜色表中的颜色数(47-50字节)
  DWORD biClrImportant;// 位图显示过程中重要的颜色数(51-54字节)
  } BITMAPINFOHEADER;
  4:颜色表
  颜色表用于说明位图中的颜色,它有若干个表项,每一个表项是一个RGBQUAD类型的结构,定义一种颜色。RGBQUAD结构的定义如下:
  typedef struct tagRGBQUAD {
  BYTE rgbBlue;// 蓝色的亮度(值范围为0-255)
  BYTE rgbGreen; // 绿色的亮度(值范围为0-255)
  BYTE rgbRed; // 红色的亮度(值范围为0-255)
  BYTE rgbReserved;// 保留,必须为0
  } RGBQUAD;
  颜色表中RGBQUAD结构数据的个数有biBitCount来确定:
  当biBitCount=1,4,8时,分别有2,16,256个表项;
  当biBitCount=24时,没有颜色表项。
  位图信息头和颜色表组成位图信息,BITMAPINFO结构定义如下:
  typedef struct tagBITMAPINFO {
  BITMAPINFOHEADER bmiHeader; // 位图信息头
  RGBQUAD bmiColors[1]; // 颜色表
  } BITMAPINFO;
  5:位图数据
  位图数据记录了位图的每一个像素值,记录顺序是在扫描行内是从左到右,扫描行之间是从下到上。位图的一个像素值所占的字节数:
  当biBitCount=1时,8个像素占1个字节;
  当biBitCount=4时,2个像素占1个字节;
  当biBitCount=8时,1个像素占1个字节;
  当biBitCount=24时,1个像素占3个字节;
  Windows规定一个扫描行所占的字节数必须是
  4的倍数(即以long为单位),不足的以0填充,
  biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8) * bi.biHeight;

这个在百度百科大家可以做个详细的了解,这里就不多说了。

验证码图片:

1.预处理:

接下来就是对图片进行读取,

2.灰度化:

对其各个像素的GBR值进行灰度化处理,我用的公式是求平均值的方法,比较方便,效果也还不错。,将求得的平均值存入一个二维数组中,方便后面的处理。

3.二值化

二值化有很多种算法,我试了试大津法(最大方差法)还有自适应阈值法,不知道什么原因,二值化出来的图片简直把图片就给毁了。。。。最后还是将图片的GBR信息打印出来,自己找了个临界值,效果还不错,二值化之后的噪点也只有几个。后面的处理就方便多了。将大于这个临界值的像素点设为255,小于的设为0.出来的图像就完全黑白二值了。

4.去噪

去噪,看了看几张验证码,发现字母组成最少的就是i,j上面的点了,4个像素点组成,于是将图片中一个像素点周围的8个点进行判断,如果这个点周围有不超过三个黑点,则证明这个点为噪点,需要去除,需要注意的是边界周围只有5个点,需要进行判断是否为边界。



5.分割

因为我们的BMP图片是有间据的,所以分割就用最简单的一种了

先将去噪完后的BMP像素数组在按自左向右的基础上从上往下找,找到的第一个黑点即为字符的左边界,再向右,找到的一列全不为黑点的话,则上一列即为字符的右边界,再在左边界和右边界的区间下,从下往上按行遍历,找到字符的下边界,再从上往下找到上边界,其他字符同理。就可以将图片分割出来了。



6.识别

我用的识别方法还是比较麻烦的,先是对验证码的字符进行输出(0,1组成),然后再找他们之间的不同相似之处,所以不是很方便,这里也就不细提了,看代码就应该理解了。

下面是代码:


view plainprint?
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
void OtsuThreshold(int *p_data)
{
int i,j;
int nWidth = 70;
int nHeight = 30;
for(j = 0;j < nHeight; j++)
{//二值化实现
for(i = 0; i < nWidth ; i++)
{
if(p_data[j * nWidth +i] < 38)
p_data[j * nWidth + i] = 0;
else
p_data[j * nWidth + i] = 255;
}
}

}
void Print(int graph[][70])
{ int i,j;
for(i = 0; i < 30; i++)
{ for(j = 0; j < 70; j++)
{
if(graph[i][j] == 255)
{
// printf(" ");
graph[i][j] = 1;
}
// else printf("*");
}
// printf("\n");
}


// printf("\n\n\n\n");
}
void duibi(int z[][20][20],int bl1,int br1,int bl2,int br2,int bl3,int br3,int bl4,int br4)
{
int jianju[4];
int i;
jianju[0] = br1-bl1+1;
jianju[1] = br2-bl2+1;
jianju[2] = br3-bl3+1;
jianju[3] = br4-bl4+1;
for(i = 0; i < 4; i++)
{
if(jianju[i] <= 5)//<=5 字符占 小于等于5列的
{
if(jianju[i] == 5)
{
if(z[i][0][0] == 0)
printf("r");
else if(z[i][0][1] == 1)
printf("i");
else printf("t");
}
else printf("i");
}
else if(jianju[i] == 6)//6 字符占 6列
{
if(z[i][0][1] == 0)
{
if(z[i][0][4] == 1)
printf("t");
else printf("s");
}
else if(z[i][0][2] == 1)
printf("j");
else if(z[i][0][4] == 1)
printf("t");
else printf("f");
}
else if(jianju[i] == 7)//7
{
if(z[i][0][0] == 1 && z[i][0][1] == 1 && z[i][0][2] == 1)
{
if(z[i][0][6] == 1)
printf("e");
else if(z[i][0][3] == 0 && z[i][0][4] == 0 && z[i][0][5] == 0 && z[i][0][6] == 0)printf("c");
else printf("f");
}
else if(z[i][0][0] == 1 && z[i][0][1] == 1)
{
if(z[i][0][5] == 1)
{
if(z[i][1][1] == 1)
printf("t");
else printf("e");
}
else if(z[i][0][4] == 1)
printf("r");
else printf("f");
}
else if(z[i][0][0] == 1)
{
printf("3");
}
else if(z[i][0][2] == 1 && z[i][0][3] == 0)
printf("p");
else if(z[i][0][0] == 0 && z[i][0][1] == 0 && z[i][0][2] == 0)printf("z");
else if(z[i][0][0] == 0 && z[i][0][1] == 0 && z[i][0][2] == 1 && z[i][0][3] == 1) printf("h");
else printf("r");
}
else if(jianju[i] == 8)//8
{
if(z[i][0][0] == 1 && z[i][1][1] == 1 && z[i][2][2] == 1 && z[i][3][3] == 1)
printf("j");
else if(z[i][0][0] == 1 && z[i][1][1] == 1 && z[i][2][2] == 1)
printf("d");
else if(z[i][0][0] == 1 && z[i][1][1] == 1)
{
if(z[i][3][3] == 1 &&z[i][4][4] == 1)
printf("c");
else if(z[i][3][3] == 1 && z[i][4][4] ==0)printf("a");
else printf("f");
}
else if(z[i][0][0] == 1 && z[i][2][2] == 1)
{
if(z[i][1][0] == 0) printf("3");
else if(z[i][4][4] == 1 && z[i][0][1] == 0)
printf("2");
else printf("a");
}
else if(z[i][0][0] == 1 && z[i][6][6] == 1)
printf("c");
else if(z[i][0][0] == 1 && z[i][3][3] == 1)
printf("g");
else if(z[i][0][0] == 1)
printf("s");
else if(z[i][1][1] == 1)
printf("2");
else if(z[i][2][2] != 1)
printf("n");
else if(z[i][4][4] == 1)
{
if(z[i][5][5] == 1) printf("u");
else printf("7");
}
else if(z[i][7][7] == 1) printf("z");
else printf("h");

}
else if(jianju[i] == 9) //9
{
if(z[i][0][0] == 1 && z[i][3][3] == 1 && z[i][4][4] == 0 && z[i][5][5] == 0 && z[i][6][6] == 0 && z[i][7][7] ==0 && z[i][8][8] == 0)
printf("a");
else if(z[i][2][2] == 0 && z[i][3][3] ==1 && z[i][4][4] == 0 && z[i][5][5] == 0 && z[i][6][6] == 1 && z[i][7][7] == 1)
printf("e");
else if(z[i][0][0] == 1 && z[i][1][1] == 1 &&z[i][2][2]== 1)
printf("d");
else if(z[i][1][1] == 0 && z[i][2][2] == 0 && z[i][4][4] ==1 && z[i][5][5] == 1 && z[i][7][7] == 0)
{
if(z[i][0][5] == 1) printf("g");
else if(z[i][0][7] == 0) printf("n");
else printf("p");
}
else if(z[i][0][0] ==0 && z[i][1][1] == 0 && z[i][3][3] == 1 && z[i][4][4] == 1 && z[i][5][5] == 0 && z[i][7][7] ==1 && z[i][8][8] ==1)
{
if(z[i][0][3] == 1 && z[i][10][0] == 0)
printf("v");
else if(z[i][0][3] == 1 && z[i][10][0] == 1) printf("y");
else printf("7");
}
else if(z[i][0][0] == 0 && z[i][1][1] ==0 && z[i][2][2] ==0 && z[i][3][3] ==1 &&z[i][4][4] == 1)
{
printf("y");
}
else if(z[i][0][0] == 1 && z[i][1][1] ==1 && z[i][2][2] == 0)
{
if(z[i][3][3] == 1)printf("6");
else if(z[i][4][4] == 1)printf("k");
else if(z[i][5][5] == 1 && z[i][12][4] == 1)printf("h");
else if(z[i][12][4] == 0 && z[i][12][2] == 1) printf("b");
else printf("s");
}
else if(z[i][0][0] == 1 && z[i][1][1] == 0)
{
if(z[i][2][2] == 1)
{
if(z[i][4][4] ==1 ) printf("2");
else printf("z");
}
else if(z[i][3][3] == 0)printf("r");
else printf("8");
}
else printf("b");
}
else if(jianju[i] == 10) //10
{
if(z[i][0][0] == 1 && z[i][1][1] == 1 && z[i][2][2] == 1)
{
if(z[i][3][3] == 1) printf("d");
else printf("x");
}
else if(z[i][0][0] == 1 && z[i][1][1] == 1 && z[i][2][2] == 0)
{
if(z[i][3][3] == 1 && z[i][10][0] == 0)printf("3");
else if(z[i][3][3] == 1 && z[i][10][0] == 1) printf("2");
else if(z[i][4][4] == 1 && z[i][5][5] == 1 && z[i][6][6] ==1)printf("p");
else if(z[i][6][6] == 1) printf("b");
else if(z[i][5][5] == 1) printf("k");
else if(z[i][9][9] == 1) printf("5");
else if(z[i][4][4] == 1) printf("6");
else printf("8");
}
else if(z[i][0][0] == 1 && z[i][1][1] == 0)
{
if(z[i][2][2] == 0)printf("n");
else if(z[i][4][4] == 1) printf("7");
else printf("z");
}
else if(z[i][5][5] == 0) printf("x");
else if(z[i][12][0] == 1) printf("y");
else printf("v");
}


else if(jianju[i] == 11)//11
{
if(z[i][0][2] == 1)
{
if(z[i][0][3] == 1)
printf("4");
else printf("2");
}
else if(z[i][0][8] == 1)
printf("x");
else printf("u");
}
else if(jianju[i] >=13)//>=13
{
if(jianju[i] == 13||jianju[i] == 15)
{
if(jianju[i] == 15)
if(z[i][0][0] == 1) printf("m");
else printf("w");
}
else if(jianju[i] == 14)
printf("m");
else if(z[i][0][0] == 1)
printf("m");
else printf("w");
}
}
}
int main(int argc,char *argv[])
{
FILE *fp;
int rgb[30*70];
int gbr[30 * (70*3)];
int graph[30][70] = {0};
int g=0,b=0,r=0;
int i,j,n,a,d,k;
int Height,Width;
int bl1=0,br1=0,bg1=0,bd1=0,bl2=0,br2=0,bg2=0,bd2=0;
int bl3=0,br3=0,bg3=0,bd3=0,bl4=0,br4=0,bg4=0,bd4=0;
int z[4][20][20] = {0};
// memset(z,0,sizeof(z));
fp = fopen(argv[1],"rb");
if(fp == NULL)
cout<<"read error!";
fseek(fp,18,0);
fread(&Width,4,1,fp);
fread(&Height,4,1,fp);
fseek(fp,54,0);
for(i = 0; i < 30 ; i++)//读取图片进行灰度化并保存到rgb数组
{ for(j = 0; j < 70; j++)
{
fread(&g,1,1,fp);
fread(&b,1,1,fp);
fread(&r,1,1,fp);
rgb[i * 70 + j]=(g+b+r)/3;//灰度化
}
fseek(fp,2,1);
}
OtsuThreshold(rgb);//二值化
for(i = 0; i < Height; i++)
{
for(j = 0; j < Width; j++)
graph[30-1-i][j] = rgb[i * 70 + j];
}


//输出图片
Print(graph);
//去噪

for(i = 0; i < 30; i++)
{
for(j = 0; j < 70; j++)
{ n = 0;
if(i == 29)
{
if(graph[i][j] == 0 && graph[i][j-1] != 0 && graph[i][j+1] != 0 && graph[i-1][j] != 0)
graph[i][j] = 1;
if(graph[i][j] == 0)
{ n = 0;
if(graph[i-1][j-1] == 0 )
n++;
if(graph[i-1][j] == 0)
n++;
if(graph[i-1][j+1] == 0)
n++;
if(graph[i][j-1] == 0)
n++;
if(graph[i][j+1] == 0)
n++;
if(n < 2)
graph[i][j] = 1;
}
}
/* if(graph[i][j] == 0 && graph[i-1][j-1] != 0 && graph[i-1][j] != 0 && graph[i-1][j+1] != 0 && graph[i][j-1] != 0 && graph[i][j+1] != 0 && graph[i+1][j-1] != 0 && graph[i+1][j] != 0 && graph[i+1][j+1] != 0)
graph[i][j] = 1;
*/
if(graph[i][j] == 0)
{ n = 0;
if(graph[i-1][j-1] == 0 )
n++;
if(graph[i-1][j] == 0)
n++;
if(graph[i-1][j+1] == 0)
n++;
if(graph[i][j-1] == 0)
n++;
if(graph[i][j+1] == 0)
n++;
if(graph[i+1][j-1] == 0)
n++;
if(graph[i+1][j] == 0)
n++;
if(graph[i+1][j+1] == 0)
n++;
if(n < 2)
graph[i][j] = 1;
}


}
}


//第一个字符
// 左边界
for(i = 0; i < Width; i++)
{
for(j = 0; j < Height; j++)
{
if(graph[j][i] == 0)
{
bl1 = i;
break;
}
}
if(bl1 != 0)
break;
}
//右边界
for(i = bl1; i < Width; i++)
{
n = 0;
for(j = 0; j < Height; j++)
{
if(graph[j][i] == 0)
n++;
}
if(n == 0)
{
br1 = i-1;
break;
}
}
//上边界
for(i = 0; i < Height; i++ )
{ n = 0;
for(j = bl1; j <= br1; j++)
{
if(graph[i][j] == 0)
{ bg1 = i;
n = 1;
break;
}
}
if(n != 0)
break;
}
//下边界
for(i = Height-1; i >= 0 ; i--)
{
n = 0;
for(j = bl1; j <= br1; j++)
{
if(graph[i][j] == 0)
{
bd1 = i;
n = 1;
break;
}
}
if(n != 0)
break;
}
//第二个字符
//左边界
for(i = br1+1; i < Width; i++)
{
for(j = 0; j < Height; j++)
{
if(graph[j][i] == 0)
{
bl2 = i;
break;
}
}
if(bl2 != 0)
break;
}
//右边界
for(i = bl2; i < Width; i++)
{
n = 0;
for(j = 0; j < Height; j++)
{
if(graph[j][i] == 0)
n++;
}
if(n == 0)
{
br2 = i-1;
break;
}
}
//上边界
for(i = 0; i < Height; i++)
{ n = 0;
for(j = bl2; j <= br2; j++)
{
if(graph[i][j] == 0)
n++;
}
if(n != 0)
{ bg2 = i;
break;
}
}
//下边界
for(i = Height-1; i >= 0; i--)
{ n = 0;
for(j = bl2; j <= br2; j++)
{
if(graph[i][j] == 0)
{ n = 1;
bd2 = i;
}
}
if(n != 0)
break;
}
//第三个字符
//左边界
for(i = br2+1; i < Width; i++)
{
for(j = 0; j < Height; j++)
{
if(graph[j][i] == 0 )
{ bl3 = i;
break;
}
}
if(bl3 != 0)
break;
}
//右边界
for(i = bl3; i < Width; i++)
{ n = 0;
for(j = 0; j < Height; j++)
{
if(graph[j][i] == 0)
{
n++;
break;
}
}
if(n == 0)
{
br3 = i-1;
break;
}
}
//上边界
for(i = 0; i < Height; i++)
{
for(j = bl3; j <= br3; j++)
{
if(graph[i][j] == 0)
{
bg3 = i;
break;
}
}
if(bg3 != 0)
break;
}
//下边界
for(i = Height-1; i >= 0; i--)
{ n = 0;
for(j = bl3; j <= br3; j++)
{
if(graph[i][j] == 0)
{ n = 1;
bd3 = i;
break;
}
}
if(n != 0)
break;
}
//第四个字符
//左边界
for(i = br3+1; i < Width; i++)
{
for(j = 0; j < Height; j++)
{
if(graph[j][i] == 0)
{
bl4 = i;
break;
}
}
if(bl4 != 0)
break;
}
//右边界
for(i = bl4; i < Width; i++)
{ n = 0;
for(j = 0; j < Height; j++)
{
if(graph[j][i] == 0)
{ n++;
break;
}
}
if(n == 0)
{
br4 = i-1;
break;
}
}
if(i == Width)
br4 = Width-1;
//上边界
for(i = 0; i < Height; i++)
{
for(j = bl4; j <= br4; j++)
{
if(graph[i][j] == 0)
{
bg4 = i;
break;
}
}
if(bg4 != 0)
break;
}
//下边界
for(i = Height-1; i >= 0; i--)
{ n = 0;
for(j = bl4; j <= br4; j++)
{
if(graph[i][j] == 0)
{
n = 1;
bd4 = i;
break;
}
}
if(n != 0)
break;


}


//输出图片
//Print(graph);
//将图片保存到z【】【】【】数组中
for(i = bg1,a = 0;i <= bd1; i++,a++)
{ for(j = bl1,d = 0; j <= br1; j++,d++)
z[0][a][d] = graph[i][j];
}
for(i = bg2,a = 0;i <= bd2; i++,a++)
{ for(j = bl2,d = 0; j <= br2; j++,d++)
z[1][a][d] = graph[i][j];
}
for(i = bg3,a = 0;i <= bd3; i++,a++)
{ for(j = bl3,d = 0; j <= br3; j++,d++)
z[2][a][d] = graph[i][j];
}
for(i = bg4,a = 0;i <= bd4; i++,a++)
{ for(j = bl4,d = 0; j <= br4; j++,d++)
z[3][a][d] = graph[i][j];
}
duibi(z,bl1,br1,bl2,br2,bl3,br3,bl4,br4);
printf("\n");
/* for(i = 0; i < 4; i++)
{
for(j = 0; j < 20; j++)
{ for(k = 0; k < 20; k++)
if(z[i][j][k] == 1)
printf("1,");
else printf("0,");
printf("\n");
}
printf("\n");
}
*/
cout<<endl;
fclose(fp);
return (0);
}
简单验证码是指验证码图片里的字符,固定不变,或者变化很小的验证码,比如:字符上会有一些感扰点感扰线等情况,或者只有少数几种字体变化和字体大小变化。

这里给出源代码都是非常简单的源代码,学过《C程序设计》的都可以看懂,不会超出书本范围,而且不使用指针,这样VB,Delphi,JAVA 等语言都可以照此写出相应的源代码。

验证码识别可以分为三个大的步骤:预处理,分割,识别。预处理又可细分为读取图片,二值化,去感扰点,去感扰线等等步骤。

读取图片很简单就是把要识别的验证码图片读取到我们的程序里,网络上常见的验证码图片格式有BMP,JPG,GIF,PNG,其中BMP的图片格式种类很多,但都不复杂,24位BMP格式最简单,除去54字节的文件头,只需要顺序读取BMP文件的字节信息就可以了,256色的也就是8位的BMP格式也很常见,256色BMP图片在文件头后多一个索引表,后面也是顺序存储图片信息的。JPG,GIF,PNG的格式都复杂一点,不过网上都有这些公司或组织发布的source code。

下面以24位BMP格式的源代码进行说明:

#define W 40 //定义验证码图片的宽度
#define H 20 //定义验证码图片的宽度
#define N 4 //定义字符位数,一般是4位
#define BMP_filename "c:\\test.bmp"
int x,y,i,s,temp;
int YZM[W][H]={0};
int YZM_red[W][H]={0};
int YZM_green[W][H]={0};
int YZM_blue[W][H]={0};
int rec[W]={0};
int lf[N],rt[N],up[N],dw[N];
char result[N];

FILE *fp=fopen(BMP_filename,"rb");//以二进制只读方式打开BMP文件
for(i=0;i<54;i++)temp=fgetc(fp);//跳过54个字节的文件头数据
for(y=H-1;y>=0;y--)//BMP图片数据是倒序存储的,据说是为了下载显示方便,呵呵
{
for(x=0;x<W;x++){YZM_red[x][y]=fgetc(fp);YZM_green[x][y]=fgetc(fp);YZM_blue[x][y]=fgetc(fp);}
//依次读取每个像素的RGB值
}
fclose(fp);//关闭文件

好的,通过以上几个语句就可以把图片信息读取到程序的数组里了,然后对其进行二值化,去感扰等工作。
二值化就是把刚才读取的RGB信息,转换成01数据,0表示空白背景,1表示字符。

for(x=0;x<W;x++)for(y=0;y<H;y++)
{
if(YZM_red[x][y]*0.3+YZM_green[x][y]*0.6+YZM_blue[x][y]*0.1<200)YZM[x][y]=1;else YZM[x][y]=0;
//red*0.3+green*0.6+blue*0.1 是计算亮度的公式
}
//如果图片里有感扰点,可以用下面的语句去除。
for(x=1;x<W-1;x++)for(y=1;y<H-1;y++)
{
if(YZM[x][y]==1 && YZM[x-1][y-1]==0 && YZM[x][y-1]==0 && YZM[x+1][y-1]==0 && YZM[x-1][y]==0 && YZM[x+1][y]==0 && YZM[x-1][y+1]==0 && YZM[x][y+1]==0 && YZM[x+1][y+1]==0)YZM[x][y]=0;
//如果一个点的值是1,而且它的周围8个点的值都是0,那么这个点就是感扰点
}

经过这些预处理工作就可以得到一个二进制数组数据了。我们以一组普通的验证码图片为例,



for(y=0;y<H;y++) { for(x=0;x<W;x++) printf(" %c",YZM[x][y]+'0'); printf("\n"); }

我们可以用上面的输出语句进行输出,输出语句在最终的程序中可以删除或者注释掉。
输出结果如下:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 0
0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0
0 0 1 1 0 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 1 1 1 0 0 0 0 0
0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 1 1 0 1 1 1 0 0 0 1 1 1 0 0 1 1 0 0 0 0
0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0
0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 0
0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 1 1 0 0 0 0 1 1 0 0 0
0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 0 0
0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

for(x=0;x<W;x++)
{ s=0;
for(y=0;y<H;y++)s=s+YZM[x][y];
if(s>0)rec[x]=1;else rec[x]=0;//rec记录数组的断连情况
}
for(i=0,x=1;x<W-1;x++)if(rec[x-1]==0 && rec[x]==1 && rec[x+1]==1){i++;lf[i]=x;}//计算每个字符的左边界
for(i=0,x=1;x<W-1;x++)if(rec[x-1]==1 && rec[x]==1 && rec[x+1]==0){i++;rt[i]=x;}//计算每个字符的右边界
for(i=1;i<=N;i++)for(x=0;x<W;x++)for(y=0;y<H;y++) if(x>=lf[i] && x<=rt[i] && YZM[x][y]==1)YZM[x][y]=i;
for(y=H-1;y>=0;y--)for(x=0;x<W;x++)for(i=1;i<=N;i++)if(YZM[x][y]==i)up[i]=y;//计算每个字符的上边界

经过上面的分割语句,我们就完成了分割工作,我们可以用输出语句进行输出,输出结果如下:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 1 0 0 0 0 0 2 2 0 0 0 0 0 0 3 3 3 3 0 0 0 4 4 4 4 4 4 4 0 0 0 0
0 0 1 1 0 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 3 3 0 0 3 3 0 0 4 4 0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0 0 0 2 2 2 2 0 0 0 0 3 3 0 0 0 0 3 0 0 4 4 0 0 0 0 0 0 0 0 0
0 0 1 1 0 1 1 1 0 0 0 0 0 0 2 2 0 0 0 0 3 3 0 0 0 0 0 0 0 4 4 0 4 4 4 0 0 0 0 0
0 0 1 1 1 0 0 1 1 0 0 0 0 0 2 2 0 0 0 0 3 3 0 3 3 3 0 0 0 4 4 4 0 0 4 4 0 0 0 0
0 0 0 0 0 0 0 0 1 1 0 0 0 0 2 2 0 0 0 0 3 3 3 0 0 3 3 0 0 0 0 0 0 0 0 4 4 0 0 0
0 0 0 0 0 0 0 0 1 1 0 0 0 0 2 2 0 0 0 0 3 3 0 0 0 0 3 3 0 0 0 0 0 0 0 4 4 0 0 0
0 0 1 1 0 0 0 0 1 1 0 0 0 0 2 2 0 0 0 0 3 3 0 0 0 0 3 3 0 4 4 0 0 0 0 4 4 0 0 0
0 0 0 1 1 0 0 1 1 0 0 0 0 0 2 2 0 0 0 0 0 3 3 0 0 3 3 0 0 0 4 4 0 0 4 4 0 0 0 0
0 0 0 0 1 1 1 1 0 0 0 0 2 2 2 2 2 2 0 0 0 0 3 3 3 3 0 0 0 0 0 4 4 4 4 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


最后我们就可以进行识别工作,识别的方法有很多,可以进行逐点的精确识别,也可以进行模糊识别等等,甚至也可以不进行去感扰和分割工作直接进行识别(主要用于粘连的验证码),这都要根据具体情况来具体分析用什么方法最有效,简单验证码的识别则没有那么复杂,用很多方法都可以识别,这里使用的是从每个字符的左上边界开始,精确判断5行3列15个点来进行识别。

for(i=1;i<=N;i++)
{
if( YZM[lf[i]+0][up[i]+0]==0 && YZM[lf[i]+1][up[i]+0]==0 && YZM[lf[i]+2][up[i]+0]==0 &&
YZM[lf[i]+0][up[i]+1]==0 && YZM[lf[i]+1][up[i]+1]==0 && YZM[lf[i]+2][up[i]+1]==i &&
YZM[lf[i]+0][up[i]+2]==0 && YZM[lf[i]+1][up[i]+2]==i && YZM[lf[i]+2][up[i]+2]==i &&
YZM[lf[i]+0][up[i]+3]==i && YZM[lf[i]+1][up[i]+3]==i && YZM[lf[i]+2][up[i]+3]==0 &&
YZM[lf[i]+0][up[i]+4]==i && YZM[lf[i]+1][up[i]+4]==i && YZM[lf[i]+2][up[i]+4]==0 )result[i-1]='0';
if( YZM[lf[i]+0][up[i]+0]==0 && YZM[lf[i]+1][up[i]+0]==0 && YZM[lf[i]+2][up[i]+0]==i &&
YZM[lf[i]+0][up[i]+1]==0 && YZM[lf[i]+1][up[i]+1]==i && YZM[lf[i]+2][up[i]+1]==i &&
YZM[lf[i]+0][up[i]+2]==i && YZM[lf[i]+1][up[i]+2]==i && YZM[lf[i]+2][up[i]+2]==i &&
YZM[lf[i]+0][up[i]+3]==0 && YZM[lf[i]+1][up[i]+3]==0 && YZM[lf[i]+2][up[i]+3]==i &&
YZM[lf[i]+0][up[i]+4]==0 && YZM[lf[i]+1][up[i]+4]==0 && YZM[lf[i]+2][up[i]+4]==i )result[i-1]='1';
if( YZM[lf[i]+0][up[i]+0]==0 && YZM[lf[i]+1][up[i]+0]==0 && YZM[lf[i]+2][up[i]+0]==i &&
YZM[lf[i]+0][up[i]+1]==0 && YZM[lf[i]+1][up[i]+1]==i && YZM[lf[i]+2][up[i]+1]==i &&
YZM[lf[i]+0][up[i]+2]==i && YZM[lf[i]+1][up[i]+2]==i && YZM[lf[i]+2][up[i]+2]==0 &&
YZM[lf[i]+0][up[i]+3]==0 && YZM[lf[i]+1][up[i]+3]==0 && YZM[lf[i]+2][up[i]+3]==0 &&
YZM[lf[i]+0][up[i]+4]==0 && YZM[lf[i]+1][up[i]+4]==0 && YZM[lf[i]+2][up[i]+4]==0 )result[i-1]='2';
if( YZM[lf[i]+0][up[i]+0]==0 && YZM[lf[i]+1][up[i]+0]==i && YZM[lf[i]+2][up[i]+0]==i &&
YZM[lf[i]+0][up[i]+1]==i && YZM[lf[i]+1][up[i]+1]==i && YZM[lf[i]+2][up[i]+1]==0 &&
YZM[lf[i]+0][up[i]+2]==0 && YZM[lf[i]+1][up[i]+2]==0 && YZM[lf[i]+2][up[i]+2]==0 &&
YZM[lf[i]+0][up[i]+3]==0 && YZM[lf[i]+1][up[i]+3]==0 && YZM[lf[i]+2][up[i]+3]==0 &&
YZM[lf[i]+0][up[i]+4]==0 && YZM[lf[i]+1][up[i]+4]==0 && YZM[lf[i]+2][up[i]+4]==0 )result[i-1]='3';
if( YZM[lf[i]+0][up[i]+0]==0 && YZM[lf[i]+1][up[i]+0]==0 && YZM[lf[i]+2][up[i]+0]==0 &&
YZM[lf[i]+0][up[i]+1]==0 && YZM[lf[i]+1][up[i]+1]==0 && YZM[lf[i]+2][up[i]+1]==0 &&
YZM[lf[i]+0][up[i]+2]==0 && YZM[lf[i]+1][up[i]+2]==0 && YZM[lf[i]+2][up[i]+2]==0 &&
YZM[lf[i]+0][up[i]+3]==0 && YZM[lf[i]+1][up[i]+3]==0 && YZM[lf[i]+2][up[i]+3]==i &&
YZM[lf[i]+0][up[i]+4]==0 && YZM[lf[i]+1][up[i]+4]==i && YZM[lf[i]+2][up[i]+4]==i )result[i-1]='4';
if( YZM[lf[i]+0][up[i]+0]==i && YZM[lf[i]+1][up[i]+0]==i && YZM[lf[i]+2][up[i]+0]==i &&
YZM[lf[i]+0][up[i]+1]==i && YZM[lf[i]+1][up[i]+1]==i && YZM[lf[i]+2][up[i]+1]==0 &&
YZM[lf[i]+0][up[i]+2]==i && YZM[lf[i]+1][up[i]+2]==i && YZM[lf[i]+2][up[i]+2]==0 &&
YZM[lf[i]+0][up[i]+3]==i && YZM[lf[i]+1][up[i]+3]==i && YZM[lf[i]+2][up[i]+3]==0 &&
YZM[lf[i]+0][up[i]+4]==i && YZM[lf[i]+1][up[i]+4]==i && YZM[lf[i]+2][up[i]+4]==i )result[i-1]='5';
if( YZM[lf[i]+0][up[i]+0]==0 && YZM[lf[i]+1][up[i]+0]==0 && YZM[lf[i]+2][up[i]+0]==i &&
YZM[lf[i]+0][up[i]+1]==0 && YZM[lf[i]+1][up[i]+1]==i && YZM[lf[i]+2][up[i]+1]==i &&
YZM[lf[i]+0][up[i]+2]==i && YZM[lf[i]+1][up[i]+2]==i && YZM[lf[i]+2][up[i]+2]==0 &&
YZM[lf[i]+0][up[i]+3]==i && YZM[lf[i]+1][up[i]+3]==i && YZM[lf[i]+2][up[i]+3]==0 &&
YZM[lf[i]+0][up[i]+4]==i && YZM[lf[i]+1][up[i]+4]==i && YZM[lf[i]+2][up[i]+4]==0 )result[i-1]='6';
if( YZM[lf[i]+0][up[i]+0]==i && YZM[lf[i]+1][up[i]+0]==i && YZM[lf[i]+2][up[i]+0]==i &&
YZM[lf[i]+0][up[i]+1]==0 && YZM[lf[i]+1][up[i]+1]==0 && YZM[lf[i]+2][up[i]+1]==0 &&
YZM[lf[i]+0][up[i]+2]==0 && YZM[lf[i]+1][up[i]+2]==0 && YZM[lf[i]+2][up[i]+2]==0 &&
YZM[lf[i]+0][up[i]+3]==0 && YZM[lf[i]+1][up[i]+3]==0 && YZM[lf[i]+2][up[i]+3]==0 &&
YZM[lf[i]+0][up[i]+4]==0 && YZM[lf[i]+1][up[i]+4]==0 && YZM[lf[i]+2][up[i]+4]==0 )result[i-1]='7';
if( YZM[lf[i]+0][up[i]+0]==0 && YZM[lf[i]+1][up[i]+0]==0 && YZM[lf[i]+2][up[i]+0]==i &&
YZM[lf[i]+0][up[i]+1]==0 && YZM[lf[i]+1][up[i]+1]==i && YZM[lf[i]+2][up[i]+1]==i &&
YZM[lf[i]+0][up[i]+2]==i && YZM[lf[i]+1][up[i]+2]==i && YZM[lf[i]+2][up[i]+2]==0 &&
YZM[lf[i]+0][up[i]+3]==0 && YZM[lf[i]+1][up[i]+3]==i && YZM[lf[i]+2][up[i]+3]==i &&
YZM[lf[i]+0][up[i]+4]==0 && YZM[lf[i]+1][up[i]+4]==0 && YZM[lf[i]+2][up[i]+4]==i )result[i-1]='8';
if( YZM[lf[i]+0][up[i]+0]==0 && YZM[lf[i]+1][up[i]+0]==0 && YZM[lf[i]+2][up[i]+0]==i &&
YZM[lf[i]+0][up[i]+1]==0 && YZM[lf[i]+1][up[i]+1]==i && YZM[lf[i]+2][up[i]+1]==i &&
YZM[lf[i]+0][up[i]+2]==i && YZM[lf[i]+1][up[i]+2]==i && YZM[lf[i]+2][up[i]+2]==0 &&
YZM[lf[i]+0][up[i]+3]==i && YZM[lf[i]+1][up[i]+3]==i && YZM[lf[i]+2][up[i]+3]==0 &&
YZM[lf[i]+0][up[i]+4]==0 && YZM[lf[i]+1][up[i]+4]==i && YZM[lf[i]+2][up[i]+4]==i )result[i-1]='9';
}
printf("%s",result);//输出识别结果
C中使用Stream Object读取数据中流文件并显示Bmp,JPG等图片

在VC中我们通常用Ado的Field 对象的GetChuck和AppendChunk来读写Blob对象,但是这样做要写很多的代码,其实ado给我们提供了一个更易操作的对象那就是Stream Object,通过它我们可以更容易的操作数据库中的Blob对象,而且可以直接把Blob对象从数据库保存到本地文件,或者直接读取文件写入到数据库中。下面就详细描述如何操作。
首先申明Stream对象
_ StreamPtr pStm;
pStm.CreateInstance( "ADODB.Stream ");
variant_t varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
pStm-> PutType(adTypeBinary);//类型为二进制
//得到字段内容的大小
// long lDataSize = m_pRecordset-> GetFields()-> GetItem( "photo ")-> ActualSize;
//m_pRecordset为一个打开的纪录集对象,含有photo这个blob字段
pStm-> Open( varOptional,
adModeUnknown, adOpenStreamUnspecified, _bstr_t(), _bstr_t());
//打开pStm
pStm-> Write(_variant_t(m_pRecordset-> GetFields()-> GetItem( "photo ")-> Value));
//把photo字段的内容写入pStm
pStm-> SaveToFile( "c:\\publogo.jpg ", adSaveCreateOverWrite);
pStm-> Close();
//直接保存为文件,如果是别的格式只要保存的时候改变后缀就可以了
下面是如果不保存成文件可以直接通过Com对象来绘制该图片,IPicture 可以显示多种格式图片.
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, pStm-> GetSize());
LPVOID pvData = NULL;
IStream *ps;
if (hGlobal != NULL)
{
if ((pvData = GlobalLock(hGlobal)) != NULL)
{
char * m_pBMPBuffer = new char[pStm-> GetSize()+1];//分配必要的存储空间
char *pBuf = NULL;
SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
memcpy(pvData,pBuf,pStm-> GetSize()); //复制数据到缓冲 区 m_pBMPBuffer
SafeArrayUnaccessData (varBLOB.parray);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &ps);
}
}

IPicture *pPic;
if(SUCCEEDED(OleLoadPicture(ps,pStm-> GetSize() ,TRUE,IID_IPicture,(LPVOID*)&pPic)))
{

OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
pPic-> get_Width(&hmWidth);
pPic-> get_Height(&hmHeight);
double fX,fY;
CDC *pDC = GetClientDC();//这里根据具体请况来取
fX=(double)pDC-> GetDeviceCaps(HORZRES)*(double)hmWidth/((double)pDC-> GetDeviceCaps(HORZSIZE)*100.0);
fY =(double)pDC-> GetDeviceCaps(VERTRES)*(double)hmHeight/((double)pDC-> GetDeviceCaps(VERTSIZE)*100.0);
if(FAILED(pPic-> Render(*pDC,0,0,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL)))
AfxMessageBox( "图像绘制失败! ");
pPic-> Release();
}
这样就完成了对图片文件从数据库读出和显示的过程。
对于从文件写入数据库就相对的容易多了,
_StreamPtr pStm;
pStm.CreateInstance( "ADODB.Stream ");
variant_t varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
// long lDataSize = m_pRecordset-> GetFields()-> GetItem( "photo ")-> ActualSize;
pStm-> PutType(adTypeBinary;

pStm-> Open( varOptional,
adModeUnknown, adOpenStreamUnspecified, _bstr_t(), _bstr_t());
pStm-> LoadFromFile( "c:\\book.gif ");//读入文件
variant_t varBLOB=pStm-> Read(adReadAll);
m_pRecordset-> GetFields()-> GetItem( "photo ")-> Value= varBLOB;//保存到数据集对象。
以上就是关于ADO的Stream对象操作数据库中的blob字段的具体方法,主要是对图片我们还可对它进行改造成其他的,比如读者可以改造成读取XMl文件,并保存等等。


转换为Bitmap

CComPtr <IPicture> spPic;
if (varImage.vt != (VT_ARRAY|VT_UI1))return FALSE;
SAFEARRAY *psa = varImage.parray;

//get size
long size=0;
_com_util::CheckError(SafeArrayGetUBound(psa, 1, &size));
size += 1;

//copy
char *pBuf = NULL;
_com_util::CheckError(SafeArrayAccessData(psa, (void **)&pBuf));
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, size);
void *pGlobal = GlobalLock(hGlobal);
if (!pGlobal)return FALSE;

memcpy(pGlobal, pBuf, size);
SafeArrayUnaccessData(psa);
GlobalUnlock(hGlobal);

CComPtr <IStream> spStream;
_com_util::CheckError(CreateStreamOnHGlobal(hGlobal, true, &spStream));
_com_util::CheckError(OleLoadPicture(spStream, 0, TRUE, IID_IPicture, (void **)&spPic));

HBITMAP hBmp;
spPic-> get_Handle((OLE_HANDLE *)&hBmp);
CBitmap bmp;
bmp.Attach(hBmp);
BITMAP bm;
bmp.GetBitmap(&bm);
int x=bm.bmWidth;
int y=bm.bmHeight;
bmp.Detach();
re: Resin 4 聂文龙 2012-06-21 13:07
# resin.properties - configuration variable values
#
# See resin.xml, cluster-default.xml, and health.xml for full configuration.
# Any variable defined by ${...} can be set as a property in this file.
#
# Individual server overrides can be specified by prepending the server.id.
# For example, increasing the log level for an individual server:
#
# log_level : info
# app-0.log_level : finest
#
# Like Resin XML configuration, modification of this file will trigger a restart.
#

# General log level (modify resin.xml for more granular log level adjustments)
# log_level : finer

# Enable verbose browser error reporting
dev_mode : true

# Enable /resin-doc Resin documentation
resin_doc : true

# List Triad server ip-addresses:hmux-port for each tier, space separated
# App tier Triad servers must be listed to enable web-tier to app-tier load-balancing

# web-tier Triad servers: web-0 web-1 web-2
# web_servers :

# app-tier Triad servers: app-0 app-1 app-2
app_servers : 127.0.0.1:6800
app-1 : 127.0.0.1:6801
app-2 : 127.0.0.1:6802

# Configures Resin for a memcached server tier
# memcached-tier Triad servers: memcached-0 memcached-1 memcached-2
# memcached_servers :
# memcached_port : 11211

# Allow elastic nodes to join the cluster (enable for cloud mode)
# elastic_cloud_enable : true

# The cluster that elastic nodes should join - each will contact a Triad server
# Use a separate resin.properties file for each cluster
home_cluster : app
app1 : app-1
app2 : app-2

# Set HTTP and HTTPS bind address
# http_address : *

# Set HTTP and HTTPS ports.
# Use overrides for individual server control, for example: app-0.http : 8081
#http : 8080
app-0.http : 44405
app-1.http : 44406
app-2.http : 44407
# https : 8443

# For security, Resin can switch to a non-root user after binding to port 80
setuid_user :
setuid_group :

# Arg passed directly to the JVM
# jvm_args : -Xmx2048m -XX:MaxPermSize=256m

# Local URLs for the watchdog to check to ensure the server is up, space separated
# http_ping_urls : http://127.0.0.1/test.jsp

# Throttle the number of active threads for a port
port_thread_max : 256
accept_thread_max : 32
accept_thread_min : 4

# Enable JNI TCP speed optimizations
tcp_cork : true
sendfile : true

# OpenSSL certificate configuration
# Keys are typically stored in the resin configuration directory.
# openssl_file : keys/test.crt
# openssl_key : keys/test.key
# openssl_password : changeme

# JSSE certificate configuration
# Keys are typically stored in the resin configuration directory.
# jsse_keystore_type : jks
# jsse_keystore_file : /etc/resin/keys/server.keystore
# jsse_keystore_password : changeme

# In absence of a signed certificate, Resin will fallback to using a
# self-signed development certificate if HTTPS is enabled

# Enable the proxy-cache - for caching static content in memory
proxy_cache_enable: false

# Sets the proxy cache memory size
# proxy_cache_size : 256m

# Enable clustered persistent sessions (for failover)
session_store : true

# Web-apps named with numeric suffixes, e.g. foo-10.0.war and can be browsed as
# /foo. When a new version of the web-app is deployed, Resin continues to route
# active session requests to the previous web-app version while new sessions
# go to the new version, so users will not be aware of the application upgrade.
# webapp_multiversion_routing : true

# Set the email address to receive weekly and restart PDF reports
# email : admin@example.com

# Set a global password to prevent foreign Resin instances from connecting.
# Must be identical between web, app, and cache clusters.
# cluster_system_key : changeme

# Enable command-line remote admin (required for remote deploy)
# remote_cli_enable : true

# Enable /resin-admin web administration console
web_admin_enable : true

# Permit access to /resin-admin from non-local network ip-addresses
# web_admin_external : true

# Require HTTPS to access /resin-admin
# web_admin_ssl : true

# Enable Resin REST Admin
# rest_admin_enable : true

# Require SSL for REST Admin
# rest_admin_ssl : true

# Access to /resin-admin and remote CLI is password restricted.
# Use "resinctl generate-password" and copy/paste here to set the admin
admin_user : admin
admin_password : {SSHA}xxxxxxxx

# Enable reading EC2 user data as resin properties
# properties_import_url : http://169.254.169.254/latest/user-data

#admin_external : true
#admin_secure : true
*** glibc detected *** free(): invalid pointer:
*** glibc detected *** malloc(): memory corruption:
*** glibc detected *** double free or corruption (out): 0x00000000005c18a0 ***
*** glibc detected *** corrupted double-linked list: 0x00000000005ab150 ***
你是否遇到过这样的情况,太沮丧了,程序总是无端coredump,gdb到core文件里面也看不出个所以然来,这对于一个大型的商业系统来说太令人恐怖了,事故随时可能发生。
遇到棘手的问题,慌张是没用的,解决不了任何问题。先坐下来,喝杯茶,舒缓一下神经。
内存问题始终是c++程序员需要去面对的问题,这也是c++语言的门槛较高的原因之一。通常我们会犯的内存问题大概有以下几种:
1.内存重复释放,出现double free时,通常是由于这种情况所致。
2.内存泄露,分配的内存忘了释放。
3.内存越界使用,使用了不该使用的内存。
4.使用了无效指针。
5.空指针,对一个空指针进行操作。

对于第一种和第二种,第五种情况,就不用多说,会产生什么后果大家应该都很清楚。
第四种情况,通常是指操作已释放的对象,如:
1.已释放对象,却再次操作该指针所指对象。
2.多线程中某一动态分配的对象同时被两个线程使用,一个线程释放了该对象,而另一线程继续对该对象进行操作。
我们重点探讨第三种情况,相对于另几种情况,这可以称得上是疑难杂症了(第四种情况也可以理解成内存越界使用)。
内存越界使用,这样的错误引起的问题存在极大的不确定性,有时大,有时小,有时可能不会对程序的运行产生影响,正是这种不易重现的错误,才是最致命的,一旦出错破坏性极大。
什么原因会造成内存越界使用呢?有以下几种情况,可供参考:
例1:
        char buf[32] = {0};
        for(int i=0; i<n; i++)// n < 32 or n > 32
        {
            buf[i] = 'x';
        }
        ....
       
例2:
        char buf[32] = {0};
        string str = "this is a test sting !!!!";
        sprintf(buf, "this is a test buf!string:%s", str.c_str()); //out of buffer space
        ....
       
例3:
        string str = "this is a test string!!!!";
        char buf[16] = {0};
        strcpy(buf, str.c_str()); //out of buffer space
       
类似的还存在隐患的函数还有:
        strcat,vsprintf等
同样,memcpy, memset, memmove等一些内存操作函数在使用时也一定要注意。
       
当这样的代码一旦运行,错误就在所难免,会带来的后果也是不确定的,通常可能会造成如下后果:
1.破坏了堆中的内存分配信息数据,特别是动态分配的内存块的内存信息数据,因为操作系统在分配和释放内存块时需要访问该数据,一旦该数据被破坏,以下的几种情况都可能会出现。
        *** glibc detected *** free(): invalid pointer:
        *** glibc detected *** malloc(): memory corruption:
        *** glibc detected *** double free or corruption (out): 0x00000000005c18a0 ***
        *** glibc detected *** corrupted double-linked list: 0x00000000005ab150 ***       
2.破坏了程序自己的其他对象的内存空间,这种破坏会影响程序执行的不正确性,当然也会诱发coredump,如破坏了指针数据。
3.破坏了空闲内存块,很幸运,这样不会产生什么问题,但谁知道什么时候不幸会降临呢?
通常,代码错误被激发也是偶然的,也就是说之前你的程序一直正常,可能由于你为类增加了两个成员变量,或者改变了某一部分代码,coredump就频繁发生,而你增加的代码绝不会有任何问题,这时你就应该考虑是否是某些内存被破坏了。
排查的原则,首先是保证能重现错误,根据错误估计可能的环节,逐步裁减代码,缩小排查空间。
检查所有的内存操作函数,检查内存越界的可能。常用的内存操作函数:
sprintf snprintf
vsprintf vsnprintf
strcpy strncpy strcat
memcpy memmove memset bcopy
如果有用到自己编写的动态库的情况,要确保动态库的编译与程序编译的环境一致。

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/tommy_lgj/archive/2008/08/18/2790452.aspx

目前debian lenny 5.0速度最快最稳定的源 - [系统安装]


在终端执行命令

备份当前的源列表,以便日后需要时恢复:

sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup

编辑源列表

Ubuntu 和debian 中执行:
gedit /etc/apt/sources.list

Kubuntu 中执行:
kdesu kate /etc/apt/sources.list

Xubuntu 中执行:
gksu mousepad /etc/apt/sources.list

适用于所有版本:
sudo vim /etc/apt/sources.list

从以下各服务器列表内容中选择一段替换文件中的所有内容,一般来说加入一至两组即可,加多了影响更新速度。为防止非官方源中软件包不全的问题,请在sources.list文件中尾部添加一组官方源。
# deb file:/cdrom/ etch main contrib

#deb http://mirrors.cn99.com/debian/ lenny main non-free contrib
#deb-src http://mirrors.cn99.com/debian/ lenny main non-free contrib
 
deb http://mirrors.163.com/debian stable contrib main non-free
deb-src http://mirrors.163.com/debian stable contrib main non-free

deb http://mirror.dlut.edu.cn/debian/ lenny main non-free contrib
deb-src http://mirror.dlut.edu.cn/debian/ lenny main non-free contrib         
deb http://debian.ustc.edu.cn/debian/ lenny main non-free contrib
deb-src http://debian.ustc.edu.cn/debian/ lenny main non-free contrib

deb http://ftp.tw.debian.org/debian lenny main 

deb-src http://ftp.tw.debian.org/debian lenny main

以上是目前debian lenny 速度稳定的源

编辑保存后执行 apt-get update    apt-get upgrade    apt-get dist-upgrade

My Debian 5.0 sources.list
 
# deb cdrom:[Debian GNU/Linux 5.0.0 _Lenny_ - Official i386 NETINST Binary-1 20090214-16:03]/ lenny main

deb http://ftp.us.debian.org/debian/ lenny main
deb-src http://ftp.us.debian.org/debian/ lenny main

deb http://ftp.us.debian.org/debian/ lenny contrib
deb-src http://ftp.us.debian.org/debian/ lenny contrib

deb http://ftp.us.debian.org/debian/ lenny non-free
deb-src http://ftp.us.debian.org/debian/ lenny non-free

deb http://security.debian.org/ lenny/updates main
deb-src http://security.debian.org/ lenny/updates main

deb http://volatile.debian.org/debian-volatile lenny/volatile main
deb-src http://volatile.debian.org/debian-volatile lenny/volatile main
re: Debian 中安装VMware tools 聂文龙 2009-06-10 12:32
之前一直在用Ubuntu,Ubuntu发行版对Linux的易用性改进和推广还是起了很大的作用,不过慢慢的还是对Ubuntu有一些不爽,某种程度上Ubuntu太像Windows了,从而失去了Linux本身的乐趣。于是决定试试Debian。对Debian接触不多,加之现在用的Mac Pro,已经有Mac和Vista两个系统了,不想大动干戈,于是决定用VMware来玩。以Mac Pro的性能,应付几个虚拟系统应该是绰绰有余了……

1. 准备:VMware workstation网上很容易找到,现在最新版的是6.0;Debian 可以从Debian的官方网站上下载;

2.建立虚拟机:在VMware 中新建一个虚拟机,操作系统类型自然是Linux了,不过VMware6中默认没有Debian,可以用Ubuntu,或者设成Other Linux 2.6.x Kernel;然后一路next,设好硬盘空间和内存大小即可,我给Debian分了5G的空间和512M内存;

3.挂装ISO文件:更改刚刚建好的虚拟机的设置,设置其光驱为使用ISO文件,选择下载好的Debian ISO文件;

4.安装: 启动虚拟机,设为光盘启动,然后就开始安装Debian;因为是虚拟机安装,基本上默认设置不需要做什么更改,一路next即可;

5. 设定更新Debian:安装完成重启之后就可以进入Debian,Debian默认不允许root登录X的,这样做倒也有其道理所在,跟Ubuntu的sudo有些差不多的意思。更改的话可以在登录的时候Action-Configure the login Manager-Security页面,把allow local system administrator login 选中即可;Debian的X清新简洁,第一眼就觉得很喜欢,呵呵。进入X后首先是设定源和更新了,国内Debian的源不少,我用的中科大的源,su到root,然后编辑/etc/apt/sources.list:

deb ftp://debian.ustc.edu.cn/debian etch main non-free contrib
deb-src ftp://debian.ustc.edu.cn/debian etch main non-free contrib
deb ftp://debian.ustc.edu.cn/debian-security testing/updates main

设置好源之后,执行

apt-get update; apt-get upgrade

更新Debian.

6.安装Vmware Tools: 因为VMware tools的安装需要gcc和Linux的内核头文件,所以在安装VMware tools之前需要先安装这两个,否则安装过程中VMware会报错退出。
安装GCC:

apt-get install build-essential

安装头文件前先用uname -a确定一下内核版本,我用的是Debian stable, 内核是2.6.18.5

uname -a; apt-get linux-headers-2.6.18.5-all

安装完成之后就可以安装VMware tools了,在VMware里面选择Install VMware Tools…,然后系统会自动mount一个光盘镜像,解压缩之后在运行install.pl;

7.中文设定:这几乎是所有发行版的Linux安装完之后的工作。我在我的WIKI上放了很漂亮的一份Debian的中文设定和字体设置,显示效果还比较舒服;

OK,Debian在VMware下的所有的设定安装就都完成了,Enjoy Debian!
re: Debian 中安装VMware tools 聂文龙 2009-06-10 12:30

http://www.darkblog.cn/?p=14

环境:

debian lenny 2.6.25-2-686

vmplayer

vmtools包(网上下的。。)

也许是因为升级内核的原因,

装vmtools 不成功,错误类似:

vm_basic_types.h:170: error: previous declaration of ‘uintptr_t’ was here

Google之

http://peterc.org/2008/62-how-to-install-vmware-tools-on-ubuntu-hardy-804-under-vmware-fusion.html

这里说的虽然是vmware fusion 的,但是我照着做管用。。。具体:

装一些依赖

sudo apt-get install build-essential libgtk2.0-dev
sudo apt-get install libproc-dev libdumbnet-dev xorg-dev

下个源码包

wget http://mesh.dl.sourceforge.net/sourceforge/open-vm-tools/
open-vm-tools-2008.04.14-87182.tar.gz

把VMware 自带的vmtools包 和下载的上面这个open包放在一个目录(随意,只要后面复制文件的时候知道在哪里就可以了)

解压

tar xzvf VMware*.gz
tar xzvf open-vm-tools*.gz

先编译下载的包

cd open-vm-tools-2008.04.14-87182/
./configure
make

打包一些modules

cd modules/linux/
for i in *; do mv ${i} ${i}-only; tar -cf ${i}.tar ${i}-only; done
cd ../../..

现在回到 openxxx 和 vmware-tools-xxx 的父级目录了然后把刚才打包的内容复制覆盖掉官方的

mv -f open-vm-tools-2008.04.14-87182/modules/linux/*.tar vmware-tools-distrib/lib/modules/source/

最后按照原来的安装方式安装即可。

cd vmware-tools-distrib/
sudo ./vmware-install.pl

也许还会报gcc版本错误,

说内核是gcc4.1编译的,但是现在使用的是4.3

这个应该可以忽略,强制安装。我是 在 /usr/bin/ 把gcc 软连接改成 gcc4.1的成功安装了

希望有同样问题的朋友可以解决掉~over

re: Debian 中安装VMware tools 聂文龙 2009-06-10 12:28

debian lenny中使用2.6.26的内核安装vmware tools时会遇到两个问题,一个是gcc版本的问题,一个是vmware tools内核模块源代码跟2.6.26的内核源代码不兼容。第一个问题容易解决,解决的办法就是使用正确的gcc版本:

CC=/usr/bin/gcc-4.1 ./vmware-install.pl

第二个问题的解决办法就是修改vmware tools中的vmmemctl模块中的os.c,将get_info方法去掉,找到:

global_proc_entry->get_info = os_proc_read;

改为:

global_proc_entry->read_proc = os_proc_read;

这个方法是non-official的,但ESX server,vmware workstation和vmware server都适用。

re: Linux 脚本启动 聂文龙 2009-05-21 14:04
linux 开机自动启动脚本方法
通过现场对这次天津iptv demo项目的调测、对iptv这套系统有了更好的认识和理解、由于iptv本身需要安装许多服务、而现场实施中有没有把这些需要启动服务的脚本加入到开机自动运行中、如果服务器重启之后需要手工 ...
通过现场对这次天津iptv demo项目的调测、对iptv这套系统有了更好的认识和理解、由于iptv本身需要安装许多服务、而现场实施中有没有把这些需要启动服务的脚本加入到开机自动运行中、如果服务器重启之后需要手工开启许多服务、工作及以后的维护相对比较繁琐、特地总结了下linux下开机自动启动脚本所涉及的知识和方法、如下:
1、相关基础知识点
1)redhat的启动方式和执行次序是:
加载内核
执行init程序
/etc/rc.d/rc.sysinit # 由init执行的第一个脚本
/etc/rc.d/rc $RUNLEVEL # $RUNLEVEL为缺省的运行模式
/etc/rc.d/rc.local #相应级别服务启动之后、在执行该文件(其实也可以把需要执行的命令写到该文件中)
/sbin/mingetty # 等待用户登录
在Redhat中,/etc/rc.d/rc.sysinit主要做在各个运行模式中相同的初始化工作,包括:
调入keymap以及系统字体
启动swapping
设置主机名
设置NIS域名
检查(fsck)并mount文件系统
打开quota
装载声卡模块
设置系统时钟
等等。
/etc/rc.d/rc则根据其参数指定的运行模式(运行级别,你在inittab文件中可以设置)来执行相应目录下的脚本。凡是以Kxx开头的
,都以stop为参数来调用;凡是以Sxx开头的,都以start为参数来调用。调用的顺序按xx
从小到大来执行。(其中xx是数字、表示的是启动顺序)例如,假设缺省的运行模式是3,/etc/rc.d/rc就会按上述方式调用
/etc/rc.d/rc3.d/下的脚本。
值得一提的是,Redhat中的运行模式2、3、5都把/etc/rc.d/rc.local做为初始化脚本中
的最后一个,所以用户可以自己在这个文件中添加一些需要在其他初始化工作之后,登录之前执行的命令。
init在等待/etc/rc.d/rc执行完毕之后(因为在/etc/inittab中/etc/rc.d/rc的
action是wait),将在指定的各个虚拟终端上运行/sbin/mingetty,等待用户的登录。
至此,LINUX的启动结束。
2)init运行级别及指令
一、什么是INIT:
init是Linux系统操作中不可缺少的程序之一。
所谓的init进程,它是一个由内核启动的用户级进程。
内核自行启动(已经被载入内存,开始运行,并已初始化所有的设备驱动程序和数据结构等)之后,就通过启动一个用户级程序init的方式,完成引导进程。所以,init始终是第一个进程(其进程编号始终为1)。
内核会在过去曾使用过init的几个地方查找它,它的正确位置(对Linux系统来说)是/sbin/init。如果内核找不到init,它就会试着运行/bin/sh,如果运行失败,系统的启动也会失败。
二、运行级别
那么,到底什么是运行级呢?
简单的说,运行级就是操作系统当前正在运行的功能级别。这个级别从1到6 ,具有不同的功能。
不同的运行级定义如下
# 0 - 停机(千万不能把initdefault 设置为0 )
# 1 - 单用户模式 # s init s = init 1
# 2 - 多用户,没有 NFS
# 3 - 完全多用户模式(标准的运行级)
# 4 - 没有用到
# 5 - X11 多用户图形模式(xwindow)
# 6 - 重新启动 (千万不要把initdefault 设置为6 )
这些级别在/etc/inittab 文件里指定。这个文件是init 程序寻找的主要文件,最先运行的服务是放在/etc/rc.d 目录下的文件。在大多数的Linux 发行版本中,启动脚本都是位于 /etc/rc.d/init.d中的。这些脚本被用ln 命令连接到 /etc/rc.d/rcn.d 目录。(这里的n 就是运行级0-6)
3):chkconfig 命令(redhat 操作系统下)
不像DOS 或者 Windows,Linux 可以有多种运行级。常见的就是多用户的2,3,4,5 ,很多人知道 5 是运行 X-Windows 的级别,而 0 就 是关机了。运行级的改变可以通过 init 命令来切换。例如,假设你要维护系统进入单用户状态,那么,可以使用 init 1 来切换。在 Linux 的运行级的切换过程中,系统会自动寻找对应运行级的目录/etc/rc[0-6].d下的K 和 S 开头的文件,按后面的数字顺序,执行这 些脚本。对这些脚本的维护,是很繁琐的一件事情,Linux 提供了chkconfig 命令用来更新和查询不同运行级上的系统服务。
语法为:
chkconfig --list [name]
chkconfig --add name
chkconfig --del name
chkconfig [--level levels] name
chkconfig [--level levels] name
chkconfig 有五项功能:添加服务,删除服务,列表服务,改变启动信息以及检查特定服务的启动状态。
chkconfig 没有参数运行时,显示用法。如果加上服务名,那么就检查这个服务是否在当前运行级启动。如果是,返回 true,否则返回 false。 --level 选项可以指定要查看的运行级而不一定是当前运行级。
如果在服务名后面指定了on,off 或者 reset,那么 chkconfig 会改变指定服务的启动信息。on 和 off 分别指服务在改变运行级时的 启动和停止。reset 指初始化服务信息,无论有问题的初始化脚本指定了什么。
对于 on 和 off 开关,系统默认只对运行级 3,4, 5有效,但是 reset 可以对所有运行级有效。指定 --level 选项时,可以选择特 定的运行级。
需要说明的是,对于每个运行级,只能有一个启动脚本或者停止脚本。当切换运行级时,init 不会重新启动已经启动的服务,也不会再 次去停止已经停止的服务。
选项介绍:
--level levels
指定运行级,由数字 0 到 7 构成的字符串,如:
--level 35 表示指定运行级3 和5。
要在运行级别3、4、5中停运 nfs 服务,使用下面的命令:chkconfig --level 345 nfs off
--add name
这个选项增加一项新的服务,chkconfig 确保每个运行级有一项 启动(S) 或者 杀死(K) 入口。如有缺少,则会从缺省的init 脚本自动 建立。
--del name
用来删除服务,并把相关符号连接从 /etc/rc[0-6].d 删除。
--list name
列表,如果指定了name 那么只是显示指定的服务名,否则,列出全部服务在不同运行级的状态。
运行级文件
每个被chkconfig 管理的服务需要在对应的init.d 下的脚本加上两行或者更多行的注释。
第一行告诉 chkconfig 缺省启动的运行级以及启动和停止的优先级。如果某服务缺省不在任何运行级启动,那么使用 - 代替运行级。
第二行对服务进行描述,可以用 跨行注释。
例如,random.init 包含三行:
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for
# higher quality random number generation.
表明 random 脚本应该在运行级 2, 3, 4, 5 启动,启动优先权为20,停止优先权为 80。
好了,介绍就到这里了,去看看自己目录下的/etc/rc.d/init.d 下的脚本吧。
设置自启动服务:chkconfig --level 345 nfs on
2. 实例介绍:
1、在linux下安装了apache 服务(通过下载二进制文件经济编译安装、而非rpm包)、apache 服务启动命令: /server/apache/bin/apachectl start 。让apache服务运行在运行级别3下面。 命令如下:
1)touch /etc/rc.d/init.d/apache
vi /etc/rc.d/init.d/apache
chown -R root /etc/rc.d/init.d/apache
chmod 700 /etc/rc.d/init.d/apache
ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc3.d/S60apache #S 是start的简写、代表启动、K是kill的简写、代表关闭。60数字 代表启动的顺序。(对于iptv系统而言、许多服务都是建立在数据库启动的前提下才能够正常启动的、可以通过该数字就行调整脚本的 启动顺序))
apache的内容:
#!/bin/bash
#Start httpd service
/server/apache/bin/apachectl start
至此 apache服务就可以在运行级别3下 随机自动启动了。(可以结合chkconfig 对启动服务进行相应的调整)


re: 绝对超赞的壁纸网站 聂文龙 2008-12-12 14:39
Windows7 builds 6956激活方法大集结

一、(不能正常激活,6956未纳入批准激活)
  等着发售正式版时候~~~(微软工作人员已经表态 6956只是在winHEC上装的 不会纳入批准激活的)

二、(推荐人群:非常喜欢重装电脑的~~~)
  把你的启动盘格式化……之后重装(每隔30天)

三、(未必好使)
  1.进入Windows 7 build 6956,打开 “WindowsSystem32spptokenspkeyconfig” 文件夹,找到“pkeyconfig.xrm-ms”文件;
  2.用压缩包中的“pkeyconfig.xrm-ms”覆盖 “WindowsSystem32spptokenspkeyconfig” 文件夹中的同名文件;
  3.打开服务管理器(点击开始 => 运行 => 输入“services.msc”),查看“Software Protection”服务是否已被加载,如已加载,停止该服务;
  4.使用压缩包中的“tokens.dat”,覆盖“Windows ServiceProfiles NetworkService AppData Roaming Microsoft SoftwareProtectionPlatform”文件夹中的同名文件.

四、(推荐)
  slmgr.vbs -rearm重置激活宽限期!在win7中用slmgr.vbs -dlv查得可以重置四次!一次可以延期30天,一共可以拥有120天体验期。
re: PayPal信用卡支付接口(PHP) 聂文龙 2008-12-10 16:43
一点必须了解的基础知识:
IPN的原理很简单,就是当产生了一个交易之后,交易状态发生变化时,如用户已经付款、或者退款、撤销时,Paypal利用常用的HTTP POST方
式,将交易的一些变量提交给网站的某个页面(称之为IPN Handler),当这个页面接受到请求时候,将这些数据原封不动加上一个指示验证
的cmd=_notify-validate,POST回Paypal的接口地址,如果数据正确,那么Paypal返回字符串VERIFIED,否则为INVALID,如果结果为
VERIFIED,那么你的程序就可以使用这些数据进行操作。
但代码的调试是一件很痛苦的事情,因为作为第三方开发人员,不可能开两个帐号,每次测试还要之间交易一些钱,所以Paypal专门开发了
Sandbox给开发人员进行开发,首先到
https://developer.paypal.com/
注册一个开发帐号,好了之后再进入Sandbox建立测试用的Paypal虚拟
帐号(至少应该建立一个Business的和一个Personal的),这种账号注册方法和Paypal的流程一样,信息可以是假的,包括银行帐号、信用卡
(其实Paypal Sandbox会自动生成一些随机的号码)。接下来需要激活Paypal Sandbox的虚拟帐号,注意,这里不管你在Paypal Sanbox注册
时填什么邮件地址,有任何发送到虚拟帐号所填邮箱的邮件都存会在开发帐号的管理界面中的Email页(导航栏上有)中。登录Sandbox的虚拟
Paypal环境,还需要验证虚拟帐号的银行,这里可以随便填,然后通过Add Funds来给账户充值(想填多少填多少)
关于IPN的详细设置
登录至Paypal后台,进入My Account->Profile页面,点击Instant Payment Notification,如下图:  

然后就会出现下面的页面了,点击Edit按钮,如下图:

然后就会出现下面的页面了,在页面里面那个选框处打勾,并在下面的Notification URL 处填写:http://您的网站地址/index.php?gOo=cGF5cGFsX3JlcGx5LnBocA& 然后点击Save按钮,如下图:

然后页面就会提示你:“You have successfully activated Instant Payment Notification.”
接下来再次进入My Account->Profile页面,点击Website Payment Preferences ,如下图:

然后就会进入Website Payment Preferences页面,在里面要做四件事情:
1:Auto Return 后面打勾选择On
2:Return URL 后面输入:http://您的网站地址/index.php?gOo=cGF5cGFsX3JlcGx5X3JldHVybi5waHA&
3:Payment Data Transfer 后面打勾选择On
4:上面都做好之后,点击页面最下面的Save按钮
如下图:

保存之后页面立即跳转到My Account->Profile,并且提示您设置成功,里面还会有一串identity token号码,那个就是私钥,如下图:

当然,这个私钥(identity token)不会只出现这一次的,在您设置完之后,您可以仍然进入Website Payment Preferences页面去查看它,它就在Payment Data Transfer那一个区块,如下图:

接下来,我们测试的时候,应该将Paypal接口的地址设置为
https://www.sandbox.paypal.com/cgi-bin/webscr
最后基本的流程为:
用户在我们的网站上选择商品、放入购物车,然后检查准备支付
网站根据购物车中的商品,生成Paypal的支付表单(也是提交到上面IPN用的Paypal接口地址),包含了此次交易的一些信息(下次会专门找
机会解释一下)。并在自己的数据库中生成一张订单记录。
Paypal在Session中记录下这些交易信息
用户用Paypal账户登录Paypal(Sandbox用Sandbox的虚拟帐号),复查明细,点击Pay按钮
Paypal进行交易处理,如果我们的Paypal收款帐号在接受帐款上没有什么问题(没有特别的需要Accept的地方),交易完成,那么Paypal会发
送一个IPN,并发送提示邮件。
我们IPN Handler接受到信息,首先向Paypal进行校验,如果信息正确,然后根据信息和自己数据库中进行比对,如果无误,可以将支付信息
保存,并修改订单状态。
然后Paypal会显示一个界面表示交易完成,此时如果用户点击“Return”按钮,Paypal会将用户送回我们网站指定地点。
我们网站迎接用户回来,向用户表示感谢,并进行提醒,给出订单号等等。
如果明文形式的话,就和压缩包里面的paypal.htm文件一般
-->

--------------------
文件夹和文件的一些简要说明:[App_Code] 放了几个必要的类
[Bin]  存放了支付接口的解密加密的一个DLL文件
[EWPcert] 系统所需要用到的安全证书
CheckOut.aspx 相当于B2C网站的购物车,程序从这里开始
NotifyUrl.ashx 2次POST安全性验证页面,比较重要
PDTResponse.aspx用于返回信息的页面,我们可以通过这个页面来实现,吧交易的一系列信息存入自己的数据库用于验证用户是否已经支付
---------[App_Code]-----------
ButtonEncryption.cs  加密【CHECK OUT】按钮的密码字符串,相当于吧明文的一些基本参数直接加密了
Constants.cs  全局变量,用于存放一些PAYPAL设置的基础信息
NVPCodec.cs  代码转换
Utils.cs  用于安全验证时候用的
---------[EWPcert]-----------
sandbox_cert_pem.txt  PAYPAL的公共证书
sdk-ewp.p12  一个类似似有的证书吧,这个到不是很了解


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21114/showart_1154377.html
re: PayPal信用卡支付接口(PHP) 聂文龙 2008-12-10 16:28
本篇将讲述与paypal在线支付的通信接口问题:

关于paypal在线支付的信息可以直接访问http://www.paypal.com。paypal作为国际在线支付的一种比较常用的工具,在现在的国际电子商务中使用的非常多,这里将就paypal支付接口与企业自己的网上电子商务系统之间沟通作一详细描述。

一般电子商务系统实现的流程如下:
客户在系统内下订单 -> 将订单的金额信息提交到paypal网站 -> 客户在paypal上付款 -> paypal将客户的付款完成信息发送给电子商务系统 -> 系统收到paypal信息后确定客户订单已经付款 -> 进行发货等后续流程。

从这个流程中可以看到系统与paypal的通信尤其关键,可以实现订单的自动付款确认。




(1)如何调用paypal接口?(将订单的金额信息提交到paypal网站)
Html代码 复制代码
  1. <%@ page contentType="text/html;charset=UTF-8"%>  
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   
  3. "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  7. <title>goto paypal</title>  
  8. </head>  
  9. <body bgcolor="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">  
  10.     <form name="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">  
  11.     <input type="hidden" name="cmd" value="_xclick">  
  12.     <input type="hidden" name="business" value="paypal@xxx.com"><!--这里填写你的paypal账户email-->  
  13.     <input type="hidden" name="item_name" value="order information"><!--这里填写客户订单的一些相关信息,当客户连到paypal网站付款的时候将看到这些信息-->  
  14.     <input type="hidden" name="amount" value="220.00"><!--订单的总金额信息-->  
  15.     <input type="hidden" name="currency_code" value="USD"><!--订单总金额对应的货币类型 ,客户可以用其他币种来付款,比如这里订单币种是美元USD,客户可以用欧元EUR来付款,由paypal根据当前汇率自动实现币种之间的换算-->     
  16.     <input type="hidden" name="on0" value="customerId"><!-- 自定义的参数1 -->  
  17.     <input type="hidden" name="os0" value="stephen"><!-- 对应上面自定义参数1对应的值 -->  
  18.     <input type="hidden" name="on1" value="address"><!-- 自定义的参数2 -->  
  19.     <input type="hidden" name="os1" value="shanghai china"><!-- 对应上面自定义参数2对应的值 -->  
  20.     <input type="hidden" name="notify_url" value="http://www.xxx.com/notifyurl.jsp?order_id=23876412"><!--这里告诉paypal付款的通信url,即当客户付款后调用这个url通知系统-->  
  21.     <input name="Paypal" type="button" value="Go to Paypal" onclick="javaScript:this.form.submit();"></td>  
  22.     </form>  
  23. </body>  
  24. </html>  

在生成上面的paypal表单时,其中的[cmd],[action],[business],[amount],[currency_code],[notify_url]参数设置绝对不能出错,[cmd]和[action]指定paypaly接口类型,[business]出错,你将收不到客户的付款,[amount]与[currency_code]关系到订单的金额,[notify_url]是系统与paypal的付款通知接口url。

当客户下单后看到上面的页面后,就可以通过设置的按钮[Go to Paypal]连接到paypal.com网站,然后登录并进行付款。

(2)paypay将付款信息返回给系统
当客户付款后,paypal就会自动调用上面表单提供的[notify_url],下面是一个[notifyurl.jsp]的一个例子:
Html代码 复制代码
  1. <%@ page contentType="text/html;charset=UTF-8"%><%@ page import="com.soft4j.NotifyUrlMgr"%><%   
  2.     String ret = NotifyUrlMgr.insert(request);   
  3.     if(ret==null){out.print("200 OK");}else{out.print("fail");}   
  4. %>  

如果确认收到paypal发来的客户付款信息,则返回"200 OK",这样子paypal就知道系统已经收到信息了;否则返回"fail",这样paypal会过一段时间后再次发来。其实,只有当paypal收到"200 OK"的返回信息后才会停止发送付款信息,否则会自动的每隔一段时间就调用上面
的[notify_url]通信接口。

(3)系统处理paypay发来的付款信息

Java代码 复制代码
  1. /*  
  2.  * Created on 2005-6-12  
  3.  * Author stephen  
  4.  * Email zhoujianqiang AT gmail DOT com  
  5.  * CopyRight(C)2005-2008 , All rights reserved.  
  6.  */  
  7. package com.soft4j;   
  8.   
  9. import java.sql.Connection;   
  10. import java.sql.SQLException;   
  11. import java.util.Enumeration;   
  12. import java.util.Vector;   
  13. import javax.servlet.http.HttpServletRequest;   
  14.   
  15. /**  
  16.  * paypal付款通知接口.  
  17.  *   
  18.  * @author stephen  
  19.  * @version 1.0.0  
  20.  */  
  21. public final class NotifyUrlMgr {   
  22.        
  23.        
  24.     public static String insert(HttpServletRequest httpRequest) {   
  25.            
  26.         //定义变量和进行必要的初始化工作   
  27.         Enumeration parameterNames = null;   
  28.         String parameterName = null;   
  29.         String parameterValue = null;   
  30.         int count = 0;   
  31.         Vector[] params = null;   
  32.         Vector vParameterName = new Vector();   
  33.         Vector vParameterValue = new Vector();   
  34.   
  35.         //判断paypal付款账户是否正确   
  36.         String business = httpRequest.getParameter("business");   
  37.         if( !"paypal@xxx.com".equals(business) ) {   
  38.             System.out.println("gu:Wrong receive paypal email:"+business);   
  39.             return null;   
  40.         }   
  41.            
  42.         try {   
  43.             String orderId = httpRequest.getParameter("order_id");//订单号   
  44.             if(orderId==null||"".equals(orderId)) orderId="-1";   
  45.             parameterNames = httpRequest.getParameterNames();   
  46.             boolean isPrint = false;   
  47.             while (parameterNames.hasMoreElements()) {//循环收取paypal发来的所有参数信息   
  48.                 parameterName = (String) parameterNames.nextElement();   
  49.                 parameterValue = httpRequest.getParameter(parameterName);   
  50.                 if(parameterValue==null) parameterValue="";   
  51.                 vParameterName.add(parameterName);   
  52.                 vParameterValue.add(parameterValue);   
  53.                 count++;   
  54.             }   
  55.                
  56.             //这里添加对收到信息的处理:一般是将这些信息存入数据库,然后对客户的订单进行处理.   
  57.                
  58.             return null;   
  59.         } catch (Exception e) {   
  60.             return e.toString();   
  61.         } finally {   
  62.             //   
  63.         }   
  64.     }   
  65.   
  66. }  


这样系统可以自动对客户订单的付款情况进行跟踪,更快捷的进行订单处理。

附录:
[1] paypay允许的币种

AUD Australian Dollar
CAD Canadian Dollar
CHF Swiss Franc
CZK Czech Koruna
DKK Danish Krone
EUR Euro
GBP Pound Sterling
HKD Hong Kong Dollar
HUF Hungarian Forint
JPY Japanese Yen
NOK Norwegian Krone
NZD New Zealand Dollar
PLN Polish Zloty
SEK Swedish Krona
SGD Singapore Dollar
USD U.S. Dollar

[2] paypal付款信息的参数含义:

https://www.paypal.com/IntegrationCenter/ic_ipn-pdt-variable-reference.html


[3] paypal提供的开发api的pdf文档

PP_OrderManagement_IntegrationGuide.pdf.zip [在附件中可以下载]

[4] paypal提交付款所支持的参数及其含义(也就是你提交给paypal中的那个Form表单中需要设置的参数)
https://www.paypal.com/IntegrationCenter/ic_std-variable-reference.html

[5] paypal显示页面的语言设置(也就是打开paypal网站的语言)。需要用参数locale.x进行设置,但这个参数在paypal提供的参数表(参见上面[4])中没有的。

Html代码 复制代码
  1. <form name="paypal" action="https://www.paypal.com/cgi-bin/webscr?locale.x=zh_HK" method="post">  
  2. ...   
  3. </form>  

locale.x=zh_HK 繁体中文
locale.x=en_GB 英文

如果你的电子商务系统不是java环境的,也可以参考上面的内容。
re: PayPal信用卡支付接口(PHP) 聂文龙 2008-12-10 16:00

Paypal支付 - ExpressCheckout接口文档


最近公司有个网站需要用到paypal支付接口,看了下支付方式,ExpressCheckout比较符合需求,于是写了这文档

作者:SK猫
创建时间:5/5/2008 2:47 PM
最后修改:5/5/2008 4:09 PM

一、 支付流程

 


二、 SOAP运作方式

1. SetExpressCheckoutRequest

Request内容

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3. :SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"  
  4. :SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"  
  5. :xsd="http://www.w3.org/2001/XMLSchema"  
  6. ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">  
  7.  <SOAP-ENV:Header>  
  8.   <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI">  
  9.    <Credentials xmlns="urn:ebay:apis:eBLBaseComponents">  
  10.     <Username>gavin2_1207532001_biz_api1.hotmail.com</Username>  
  11.     <Password>xxxxxxxxxx</Password>  
  12.     <Signature>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Signature>  
  13.     <Subject/>  
  14.    </Credentials>  
  15.   </RequesterCredentials>  
  16.  </SOAP-ENV:Header>  
  17.  <SOAP-ENV:Body>  
  18.   <SetExpressCheckoutReq xmlns="urn:ebay:api:PayPalAPI">  
  19.    <SetExpressCheckoutRequest xsi:type="ns:SetExpressCheckoutRequestType">  
  20.    <Version xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="xsd:string">1.0</Version>  
  21.     <SetExpressCheckoutRequestDetails xmlns="urn:ebay:apis:eBLBaseComponents">  
  22.      <OrderTotal xmlns="urn:ebay:apis:eBLBaseComponents" currencyID="USD" xsi:type="cc:BasicAmountType">58.00</OrderTotal>  
  23.      <OrderDescription>2008-5-5 14:58:34</OrderDescription>  
  24.      <ReturnURL xsi:type="xsd:string">http://www.21ido.com/paypal/returnorder.asp</ReturnURL>  
  25.      <CancelURL xsi:type="xsd:string">http://www.21ido.com/paypal/cancelorder.asp</CancelURL>  
  26.     </SetExpressCheckoutRequestDetails>  
  27.    </SetExpressCheckoutRequest>  
  28.    <PaymentAction>Sale</PaymentAction>  
  29.   </SetExpressCheckoutReq>  
  30.  </SOAP-ENV:Body>  
  31. </SOAP-ENV:Envelope>  

参数介绍:

  • Head里面的Username、Password、Signature为API验证信息,需在paypal获取,下同
  • OrderTotal:currencyID="USD"表示美元,其它货币单位参照paypal文档(PP_APIReference.pdf),数值必须带2位小数
  • OrderDescription:商品描述,可选
  • ReturnURL:返回地址,购买者填写帐号信息确认后会返回该地址
  • CancelURL:当购买者取消订单后返回的地址

OrderTotal在第三步要用到,需传递或保存Session

Response内容

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:market="urn:ebay:apis:Market" xmlns:auction="urn:ebay:apis:Auction" xmlns:sizeship="urn:ebay:api:PayPalAPI/sizeship.xsd" xmlns:ship="urn:ebay:apis:ship" xmlns:skype="urn:ebay:apis:skype" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:ns="urn:ebay:api:PayPalAPI">  
  3.  <SOAP-ENV:Header>  
  4.   <Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext" xsi:type="wsse:SecurityType"/>  
  5.   <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI" xsi:type="ebl:CustomSecurityHeaderType">  
  6.    <Credentials xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:UserIdPasswordType">  
  7.     <Username xsi:type="xs:string"/>  
  8.     <Password xsi:type="xs:string"/>  
  9.     <Signature xsi:type="xs:string">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Signature>  
  10.     <Subject xsi:type="xs:string"/>  
  11.    </Credentials>  
  12.   </RequesterCredentials>  
  13.  </SOAP-ENV:Header>  
  14.  <SOAP-ENV:Body id="_0">  
  15.   <SetExpressCheckoutResponse xmlns="urn:ebay:api:PayPalAPI">  
  16.    <Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2008-05-04T03:22:02Z</Timestamp>  
  17.    <Ack xmlns="urn:ebay:apis:eBLBaseComponents">Success</Ack>  
  18.    <CorrelationID xmlns="urn:ebay:apis:eBLBaseComponents">134cf1c8d6faf</CorrelationID>  
  19.    <Version xmlns="urn:ebay:apis:eBLBaseComponents">1.000000</Version>  
  20.    <Build xmlns="urn:ebay:apis:eBLBaseComponents">548868</Build>  
  21.    <Token xsi:type="ebl:ExpressCheckoutTokenType">EC-4F193608SG720004S</Token>  
  22.   </SetExpressCheckoutResponse>  
  23.  </SOAP-ENV:Body>  
  24. </SOAP-ENV:Envelope>  

当Ack值为Seccess时为请求成功,下同
取回 Token ,并重定向到paypal,例如
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token= EC-4F193608SG720004S

 

2. GetExpressCheckoutDetailsRequest

用户在paypal填写完帐户信息后,点continue 后将跳转回之前设置的ReturnUrl地址,并带上参数,例如
http://www.21ido.com/paypal/return.asp?token=EC-4F193608SG720004S&PayerID=WS8QWH5MLUK6C
当ReturnUrl地址本身已带参数时,如 return.asp?id=212121,跳转地址将为
return.asp?id=212121& token=EC-4F193608SG720004S&PayerID=WS8QWH5MLUK6C

此时需调用GetExpressCheckoutDetailsRequest方法取回用户填写的信息,例如帐号、地址

Request内容

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">  
  3.  <SOAP-ENV:Header>  
  4.   <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI">  
  5.    <Credentials xmlns="urn:ebay:apis:eBLBaseComponents">  
  6.     <Username>gavin2_1207532001_biz_api1.hotmail.com</Username>  
  7.     <Password>xxxxxxxxxx</Password>  
  8.     <Signature>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Signature>  
  9.     <Subject/>  
  10.    </Credentials>  
  11.   </RequesterCredentials>  
  12.  </SOAP-ENV:Header>  
  13.  <SOAP-ENV:Body>  
  14.   <GetExpressCheckoutDetailsReq xmlns="urn:ebay:api:PayPalAPI">  
  15.    <GetExpressCheckoutDetailsRequest xsi:type="ns:SetExpressCheckoutRequestType">  
  16.     <Version xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="xsd:string">1.0</Version>  
  17.     <Token>EC-15361037RR099961G</Token>  
  18.    </GetExpressCheckoutDetailsRequest>  
  19.   </GetExpressCheckoutDetailsReq>  
  20.  </SOAP-ENV:Body>  
  21. </SOAP-ENV:Envelope>  

其中Token 为paypal传回的数值,传回的PayerID此步无作用,但下一步确认支付时需要提交给paypal,可用参数方式或session方式传递给下一步


Response内容

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:market="urn:ebay:apis:Market" xmlns:auction="urn:ebay:apis:Auction" xmlns:sizeship="urn:ebay:api:PayPalAPI/sizeship.xsd" xmlns:ship="urn:ebay:apis:ship" xmlns:skype="urn:ebay:apis:skype" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:ns="urn:ebay:api:PayPalAPI">  
  3.  <SOAP-ENV:Header>  
  4.   <Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext" xsi:type="wsse:SecurityType"/>  
  5.   <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI" xsi:type="ebl:CustomSecurityHeaderType">  
  6.    <Credentials xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:UserIdPasswordType">  
  7.     <Username xsi:type="xs:string"/>  
  8.     <Password xsi:type="xs:string"/>  
  9.     <Signature xsi:type="xs:string">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Signature>  
  10.     <Subject xsi:type="xs:string"/>  
  11.    </Credentials>  
  12.   </RequesterCredentials>  
  13.  </SOAP-ENV:Header>  
  14.  <SOAP-ENV:Body id="_0">  
  15.   <GetExpressCheckoutDetailsResponse xmlns="urn:ebay:api:PayPalAPI">  
  16.    <Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2008-05-05T07:37:23Z</Timestamp>  
  17.    <Ack xmlns="urn:ebay:apis:eBLBaseComponents">Success</Ack>  
  18.    <CorrelationID xmlns="urn:ebay:apis:eBLBaseComponents">a8bf169692ef0</CorrelationID>  
  19.    <Version xmlns="urn:ebay:apis:eBLBaseComponents">1.000000</Version>  
  20.    <Build xmlns="urn:ebay:apis:eBLBaseComponents">548868</Build>  
  21.    <GetExpressCheckoutDetailsResponseDetails xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:GetExpressCheckoutDetailsResponseDetailsType">  
  22.     <Token xsi:type="ebl:ExpressCheckoutTokenType">EC-15361037RR099961G</Token>  
  23.     <PayerInfo xsi:type="ebl:PayerInfoType">  
  24.      <Payer xsi:type="ebl:EmailAddressType">gavin2_1207532695_per@hotmail.com</Payer>  
  25.      <PayerID xsi:type="ebl:UserIDType">WS8QWH5MLUK6C</PayerID>  
  26.      <PayerStatus xsi:type="ebl:PayPalUserStatusCodeType">verified</PayerStatus>  
  27.      <PayerName xsi:type="ebl:PersonNameType">  
  28.       <Salutation xmlns="urn:ebay:apis:eBLBaseComponents"/>  
  29.       <FirstName xmlns="urn:ebay:apis:eBLBaseComponents">Test</FirstName>  
  30.       <MiddleName xmlns="urn:ebay:apis:eBLBaseComponents"/>  
  31.       <LastName xmlns="urn:ebay:apis:eBLBaseComponents">User</LastName>  
  32.       <Suffix xmlns="urn:ebay:apis:eBLBaseComponents"/>  
  33.      </PayerName>  
  34.      <PayerCountry xsi:type="ebl:CountryCodeType">US</PayerCountry>  
  35.      <PayerBusiness xsi:type="xs:string"/>  
  36.      <Address xsi:type="ebl:AddressType">  
  37.       <Name xsi:type="xs:string">Test User</Name>  
  38.       <Street1 xsi:type="xs:string">1 Main St</Street1>  
  39.       <Street2 xsi:type="xs:string"/>  
  40.       <CityName xsi:type="xs:string">San Jose</CityName>  
  41.       <StateOrProvince xsi:type="xs:string">CA</StateOrProvince>  
  42.       <Country xsi:type="ebl:CountryCodeType">US</Country>  
  43.       <CountryName/>  
  44.       <PostalCode xsi:type="xs:string">95131</PostalCode>  
  45.       <AddressOwner xsi:type="ebl:AddressOwnerCodeType">PayPal</AddressOwner>  
  46.       <AddressStatus xsi:type="ebl:AddressStatusCodeType">Confirmed</AddressStatus>  
  47.      </Address>  
  48.     </PayerInfo>  
  49.    </GetExpressCheckoutDetailsResponseDetails>  
  50.   </GetExpressCheckoutDetailsResponse>  
  51.  </SOAP-ENV:Body>  
  52. </SOAP-ENV:Envelope>  

购买者信息,参数具体介绍参照SOAP文档(PP_APIReference.pdf)

 

3. DoExpressCheckoutPaymentRequest

确认支付,这一步返回Completed的话表示钱已经打到商家帐户

Request内容

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3. :SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"  
  4. :SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"  
  5. :xsd="http://www.w3.org/2001/XMLSchema"  
  6. ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">  
  7.  <SOAP-ENV:Header>  
  8.   <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI">  
  9.    <Credentials xmlns="urn:ebay:apis:eBLBaseComponents">  
  10.     <Username>gavin2_1207532001_biz_api1.hotmail.com</Username>  
  11.     <Password>xxxxxxxxxx</Password>  
  12.     <Signature>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Signature>  
  13.     <Subject/>  
  14.    </Credentials>  
  15.   </RequesterCredentials>  
  16.  </SOAP-ENV:Header>  
  17.  <SOAP-ENV:Body>  
  18.   <DoExpressCheckoutPaymentReq xmlns="urn:ebay:api:PayPalAPI">  
  19.    <DoExpressCheckoutPaymentRequest xsi:type="ns:SetExpressCheckoutRequestType">  
  20.    <Version xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="xsd:string">1.0</Version>  
  21.     <DoExpressCheckoutPaymentRequestDetails xmlns="urn:ebay:apis:eBLBaseComponents">  
  22.      <Token xsi:type="ebl:ExpressCheckoutTokenType">EC-15361037RR099961G</Token>  
  23.      <PayerID>WS8QWH5MLUK6C</PayerID>  
  24.      <PaymentAction>Sale</PaymentAction>  
  25.      <PaymentDetails xmlns="urn:ebay:apis:eBLBaseComponents">  
  26.       <OrderTotal xmlns="urn:ebay:apis:eBLBaseComponents" currencyID="USD" xsi:type="cc:BasicAmountType">29.00</OrderTotal>  
  27.      </PaymentDetails>  
  28.     </DoExpressCheckoutPaymentRequestDetails>  
  29.    </DoExpressCheckoutPaymentRequest>  
  30.   </DoExpressCheckoutPaymentReq>  
  31.  </SOAP-ENV:Body>  
  32. </SOAP-ENV:Envelope>  

Token、PayerID、PaymentAction、OrderTotal等各参数均为之前提交或获取到的

Response内容

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:market="urn:ebay:apis:Market" xmlns:auction="urn:ebay:apis:Auction" xmlns:sizeship="urn:ebay:api:PayPalAPI/sizeship.xsd" xmlns:ship="urn:ebay:apis:ship" xmlns:skype="urn:ebay:apis:skype" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:ns="urn:ebay:api:PayPalAPI">  
  3.  <SOAP-ENV:Header>  
  4.   <Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext" xsi:type="wsse:SecurityType"/>  
  5.   <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI" xsi:type="ebl:CustomSecurityHeaderType">  
  6.    <Credentials xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:UserIdPasswordType">  
  7.     <Username xsi:type="xs:string"/>  
  8.     <Password xsi:type="xs:string"/>  
  9.     <Signature xsi:type="xs:string">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Signature>  
  10.     <Subject xsi:type="xs:string"/>  
  11.    </Credentials>  
  12.   </RequesterCredentials>  
  13.  </SOAP-ENV:Header>  
  14.  <SOAP-ENV:Body id="_0">  
  15.   <DoExpressCheckoutPaymentResponse xmlns="urn:ebay:api:PayPalAPI">  
  16.    <Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2008-05-05T07:56:38Z</Timestamp>  
  17.    <Ack xmlns="urn:ebay:apis:eBLBaseComponents">Success</Ack>  
  18.    <CorrelationID xmlns="urn:ebay:apis:eBLBaseComponents">167cc5fc71e87</CorrelationID>  
  19.    <Version xmlns="urn:ebay:apis:eBLBaseComponents">1.000000</Version>  
  20.    <Build xmlns="urn:ebay:apis:eBLBaseComponents">548868</Build>  
  21.    <DoExpressCheckoutPaymentResponseDetails xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:DoExpressCheckoutPaymentResponseDetailsType">  
  22.     <Token xsi:type="ebl:ExpressCheckoutTokenType">EC-60499907HA323812X</Token>  
  23.     <PaymentInfo xsi:type="ebl:PaymentInfoType">  
  24.      <TransactionID>84V49327HA333602X</TransactionID>  
  25.      <ParentTransactionID xsi:type="ebl:TransactionId"/>  
  26.      <ReceiptID/>  
  27.      <TransactionType xsi:type="ebl:PaymentTransactionCodeType">express-checkout</TransactionType>  
  28.      <PaymentType xsi:type="ebl:PaymentCodeType">instant</PaymentType>  
  29.      <PaymentDate xsi:type="xs:dateTime">2008-05-05T07:56:37Z</PaymentDate>  
  30.      <GrossAmount xsi:type="cc:BasicAmountType" currencyID="USD">55.00</GrossAmount>  
  31.      <FeeAmount xsi:type="cc:BasicAmountType" currencyID="USD">1.90</FeeAmount>  
  32.      <TaxAmount xsi:type="cc:BasicAmountType" currencyID="USD">0.00</TaxAmount>  
  33.      <ExchangeRate xsi:type="xs:string"/>  
  34.      <PaymentStatus xsi:type="ebl:PaymentStatusCodeType">Completed</PaymentStatus>  
  35.      <PendingReason xsi:type="ebl:PendingStatusCodeType">none</PendingReason>  
  36.      <ReasonCode xsi:type="ebl:ReversalReasonCodeType">none</ReasonCode>  
  37.     </PaymentInfo>  
  38.    </DoExpressCheckoutPaymentResponseDetails>  
  39.   </DoExpressCheckoutPaymentResponse>  
  40.  </SOAP-ENV:Body>  
  41. </SOAP-ENV:Envelope>  

参数介绍:

  • TransactionID  paypal流水号
  • GrossAmount  收取金额
  • FeeAmount  手续费,从商家扣除
  • PaymentStatus  支付状态
  • 其它参数请参考SOAP文档

 

三、 附录

1. 各接口地址

Environment   Authentication   Calling     Endpoint
Live    API Certificate  Name-Value Pair  https://api.paypal.com/nvp
Live    API Signature  Name-Value Pair  https://api-3t.paypal.com/nvp
Live    API Certificate  SOAP    https://api.paypal.com/2.0/
Live    API Signature  SOAP    https://api-3t.paypal.com/2.0/
Sandbox   API Certificate  Name-Value Pair  https://api.sandbox.paypal.com/nvp
Sandbox   API Signature  Name-Value Pair  https://api-3t.sandbox.paypal.com/nvp
Sandbox   API Certificate  SOAP    https://api.sandbox.paypal.com/2.0/
Sandbox   API Signature  SOAP    https://api-3t.sandbox.paypal.com/2.0

Paypal重定向地址
Live  https://www. Paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=
SandBox https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=value

2. 网址

开发者中心 https://developer.paypal.com/
各种源码下载 https://www.paypal.com/IntegrationCenter/ic_downloads.html
API Error https://www.paypal.com/IntegrationCenter/ic_api-errors.html

3. 测试帐号

Developer主帐号
https://developer.paypal.com/
Username gavin2026@hotmail.com
Password  xxxxxx


Seller
Username gavin2_1207532001_biz@hotmail.com
Password  xxxxxx
Buye
Username gavin2_1207532695_per@hotmail.com
Password  xxxxxx


API验证信息
Username gavin2_1207532001_biz_api1.hotmail.com
Password  xxxxxx
Signature   xxxxxx
 

共5页: 1 2 3 4 5