Yao've done

Calm down, and keep on walking!


  • 首页

  • 分类

  • 归档

  • 标签

Ruby安装

发表于 2016-03-10   |   分类于 Linux   |  

ruby安装

root账号执行:

1
yum install ruby

rubyGems安装

1
yum install -y rubygems

nodeJs安装

1
yum install -y nodejs
reference

http://blog.csdn.net/happyteafriends/article/details/8225611

Linux安装Node

发表于 2016-03-10   |   分类于 Linux   |  

Introduction

Node.js的安装方法常见的有源码安装和nvm安装两种,此处为推荐方式:nvm安装

nvm安装

安装nvm

nvm安装可通过crul或wget方式安装,此处以work账户为例,命令为:

1
2
3
4
#curl
curl https://raw.github.com/creationix/nvm/master/install.sh | sh
#wget
wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh

安装完成后,nvm运行环境会自动写入到.bashrc中,但可能未初始化,可通过命令初始化:

1
source /home/work/.bashrc

安装Node.js

直接通过即可完成安装

1
2
3
4
#安装Node.js
nvm install 4
#查看版本
node -v

CentOS7更改hostname

发表于 2016-03-10   |   分类于 Linux   |  

Introduction

  在CentOS或RHEL中,有三种定义的主机名:静态(static)、瞬时(transient)、灵活(pretty)。

static:亦称内核主机名,系统启动时从/etc/hostname中自动读取的。遵从互联网域名字符限制规则
transient:系统运行时临时分配的,如DHCP或mDNS分配的。遵从互联网域名字符限制规则
pretty:作为展示,执行任何形式(包含特殊字符、空白等)的主机名,展示给用户

hostnamectl工具

  在CentOS/RHEL 7中,有个叫hostnamectl的命令行工具,通过该工具可以查看或修改主机名相关配置。

查看主机名相关配置

1
2
#运行命令
hostnamectl status

可得

1
2
3
4
5
6
7
8
9
10
 Static hostname: iZ28xq5zwj6Z
Icon name: computer-vm
Chassis: vm
Machine ID: 45461f76679f48ee96e95da6cc798cc8
Boot ID: 085c24ed9080447eab7cd013d83df490
Virtualization: xen
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-123.9.3.el7.x86_64
Architecture: x86-64

只查看static、transient、pretty主机名,可加上增加参数

1
2
#运行命令
hostnamectl status [--static|--transient|--pretty]

修改主机名

同时修改static、transient、pretty主机名,可通过以下命令:

1
2
3
4
5
6
7
8
9
#root权限运行命令
[root@iZ28xq5zwj6Z ~]# hostnamectl set-hostname "Yao's Server"
#查看
[root@iZ28xq5zwj6Z ~]# hostnamectl status --static
yaosserver
[root@iZ28xq5zwj6Z ~]# hostnamectl status --transient
yaosserver
[root@iZ28xq5zwj6Z ~]# hostnamectl status --pretty
Yao's Server

修改static主机名后,/etc/hostname中的文件会自动更新,但/etc/hosts中的不会,需要手动调整
若要单独修改static、transient、pretty主机名,可通过以下命令:

1
2
#运行命令
hostnamectl [--static|--transient|--pretty] set-hostname <host-name>

Reference

http://ask.xmodulo.com/change-hostname-centos-rhel-7.html

Git别名、颜色配置

发表于 2016-03-10   |   分类于 Git   |  

别名配置

1
2
3
4
5
6
git config --global alias.br branch
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.ps push
git config --global alias.pl pull

高亮配置

1
git config --global color.ui auto
reference

http://www.cnblogs.com/BeginMan/p/3591005.html

Git安装与配置

发表于 2016-03-10   |   分类于 Git   |  

server :CentOS7
client :Window7
referance :http://loading.1976.blog.163.com/blog/static/1278037142011818112249642/

安装Git(Linux)

root账户执行

1
yum install git autoconf gcc bison

安装方式有多种,未比较。

设置Git用户(Linux)

root账户执行

1
2
3
4
5
6
# 新增git用户(会自动生成/home/git目录,若有需要,可通过passwd制定密码)
adduser git
# 切换到git用户
su git
# 进入git目录
cd /home/gitd

Window安装Git

可直接在Git官网下载:http://git-for-windows.github.io/
下载完成后直接安装即可。安装完成后,设置Git账户(在此,Window下推荐使用Cmder,GIt Bash也可):

1
2
git config --global user.name <User Name>
git config --global user.email "name@example.com"

设置ssh认证

参照笔记ssh key登录Linux设置git的ssh key
设置完成后,在有私钥的电脑中(路径:C:\Users\.ssh),可使用一下命令测试登录:

1
ssh git@<server address>

测试成功,为了账户安全,需禁用git用户登录shell,可通过编辑/etc/passwd完成。

1
2
3
4
5
6
# 打开文件
vim /etc/passwd
# 找到git,如
git:x:1001:1001:,,,:/home/git:/bin/bash
# 更改为
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell

如此,git用户便不可登录shell

测试使用

服务器创建仓库

登录git用户,在根目录(~)中:

1
2
3
4
5
6
# 创建目录
mkdir test.git
# 切换工作目录
cd test.git
# 创建仓库
git --bare init

开发机创建仓库并提交

在Window下创建一个测试目录,如:D:\test。
打开Cmder(Git Bash、cmd)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 进入工作目录
cd /d/test
# git初始化
git init
# 生成测试文件(Cmder支持vim),可随意输入文本
vim test.txt
# 将文件加入仓库
git add .
# 进行首次提交(首次提交必须是initial commit)
git commit -m "initial commit"
# 设定远程仓库
git remote add origin git@<server address>:~/test.git/
# 提交到远程仓库
git push origin master

Hexo GitHub Deploy需要输入用户名

发表于 2016-03-10   |   分类于 Blog搭建   |  

Introduction

执行hexo deploy时,需要输入用户名,且已成功配置GitHub的public key,同时通过命令

1
ssh -T git@github.com

可测试成功。
但执行hexo d的时候,提示需要输入用户名和密码,示例如下:

1
2
Username for 'https://github.com': XXX
Password for 'https://damye@github.com':

原因
hexo的_config.yml中配置的是HTTPS方式的GitHub仓库地址,示例:

1
2
3
4
5
deploy:
type: git
repo: https://github.com/username/username.github.io.git
branch: master
message: 'hexo blog deploy'

解决方案
改为ssh方式的Git仓库地址即可

1
2
3
4
5
deploy:
type: git
repo: git@github.com:username/username.github.io.git
branch: master
message: 'hexo blog deploy'

Notice
地址在GitHub仓库Code页上可见

Hexo搭建

发表于 2016-03-10   |   分类于 Blog搭建   |  

Introduction


Hexo是一个快速、简洁且高效的博客框架,使用Markdown渲染文章,生成静态网页。
Hexo

安装Git


Linux上安装参照之前的博客
Window上安装,官网上下载安装即可

安装Node.js


Linux上安装推荐使用nvm安装,具体可参照博客
Window下,Node官网下载安装即可

安装npm


Linux上可源码安装,或使用yum安装(centos)

1
2
3
4
# root账户执行
yum install npm --enablerepo=epel
#同理,nodejs也可类似安装
yum install nodejs --enablerepo=epel

Window下,Node官网下载安装即可

安装Hexo


在blog目录下,输入以下命令:

1
2
3
4
5
npm install -g hexo-cli
npm install hexo --save

#如果命令无法运行,可以尝试更换taobao的npm源
npm install -g cnpm --registry=https://registry.npm.taobao.org

Hexo初始化


创建Hexo文件夹

1
2
3
4
#安装Hexo完成后,执行以下命令,Hexo会在指定文件夹中新建需要的文件
hexo init <folder>
cd <folder>
npm install

Hexo安装完成后,可安装Hexo插件

1
2
3
4
5
6
7
8
9
10
11
12
13
npm install hexo-generator-index --save
npm install hexo-generator-archive --save
npm install hexo-generator-category --save
npm install hexo-generator-tag --save
npm install hexo-server --save
npm install hexo-deployer-git --save
npm install hexo-deployer-heroku --save
npm install hexo-deployer-rsync --save
npm install hexo-deployer-openshift --save
npm install hexo-renderer-marked@0.2 --save
npm install hexo-renderer-stylus@0.2 --save
npm install hexo-generator-feed@1 --save
npm install hexo-generator-sitemap@1 --save

查看效果,执行Hexo

1
hexo server

可打开查看效果

Hexo简写命令

1
2
3
hexo n #生成文章,或者source\_posts手动编辑
hexo s #本地发布预览效果
hexo g #生成public静态文件

多说评论


next默认支持多说和Disqus,本文使用多说评论。具体步骤如下:

创建多说

打开多说,在首页中选择我要安装,然后创建账户,多说域名中填写的即为你的duoshuo_shuotname。
如abc.duoshuo.com中,abc即为duoshuo_shuotname。

配置多说

在站点的_config.yml中(非主题的_config.yml),中添加duoshuo_shortname即可,如下所示:

1
duoshuo_shortname: your-duoshuo-shortname

参考

使用GitHub和Hexo搭建免费静态Blog
使用GitHub Page建立个人站点
Hexo文档
不如_hexo你的博客

微信支付(简要示例)

发表于 2016-03-10   |   分类于 微信开发   |  

Generral

微信支付需要微信公众号申请,申请微信支付,申请成功后,支付Server端需要:

1、微信公众号唯一标识(APPID)
2、商户号(MMCHID)
3、商户支付密钥(KEY)
4、公众账号secert(APPSECERT)
5、证书(仅退款、撤销订单时需要)

通常,H5支付和APP支付需要申请两个以上信息,分别处理,Server端需要根据来源,读取不同的配置文件。

JSAPI支付

该类别主要用于H5,只能在微信浏览器中操作。

页面地址重定向,获取微信code,以得到openid,参考代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//获取微信openid
$code = '';
if(!empty($_GET['code']))
$code = $_GET['code'];
if(empty($code)){
$this->wxRedirect();
if(!empty($_GET['code']))
$code = $_GET['code'];
}
$data = Cm_WxAuth::getOauthToken($code);
var_dump($data);
//重定向
private function wxRedirect() {
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$redirectUrl = Cm_WxAuth::getCode($url);
$this->redirect($redirectUrl);
}
//获取重定向URL
public static function getCode($redirect) {
//加载微信支付配置
$wxConf = Cm_Conf::getCmConf('wxpay', true);
$wxConf = $wxConf['mp'];
$query = array(
'appid' => $wxConf['APPID'],
'redirect_uri' => $redirect,
'response_type' => 'code',
'scope' => 'snsapi_base',
);
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?" . http_build_query($query) . "#wechat_redirect";
return $url;
}
public static function getOauthToken($code) {
//加载微信支付配置
$wxConf = Cm_Conf::getCmConf('wxpay', true);
$wxConf = $wxConf['mp'];
$query = array(
'appid' => $wxConf['APPID'],
'secret' => $wxConf['APPSECRET'],
'code' => $code,
'grant_type' => 'authorization_code',
);
$url = self::API_OAUTH_TOKEN . "?" . http_build_query($query);
$strJson = Cm_Http::get($url);
$res = json_decode($strJson, true);
return $res;
}

微信JSSDK

发表于 2016-03-10   |   分类于 微信开发   |  

说明

此为基本文档,仅仅有微信发送给朋友和分享到朋友圈两个功能,其余类似。
参照https://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html

JSSDK使用步骤

绑定域名

登录微信公众平台->“公众号设置”,填写”JS接口安全域名”。
备注:登录后可在“开发者中心”查看对应的接口权限。

引入JS文件

在需要调用JS接口的页面引入如下JS文件,(支持https):http://res.wx.qq.com/open/js/jweixin-1.0.0.js
请注意,如果你的页面启用了https,务必引入 https://res.wx.qq.com/open/js/jweixin-1.0.0.js ,否则将无法在iOS9.0以上系统中成功使用JSSDK
如需使用摇一摇周边功能,请引入 jweixin-1.1.0.js
备注:支持使用 AMD/CMD 标准模块加载方法加载

通过config接口注入权限验证配置

所有需要使用JS-SDK的页面必须先注入配置信息,否则将无法调用(同一个url仅需调用一次,对于变化url的SPA的web app可在每次url变化时进行调用,目前Android微信客户端不支持pushState的H5新特性,所以使用pushState来实现web app的页面会导致签名失败,此问题会在Android6.2中修复)。
该步骤需要Server端配合处理。

1
2
3
4
5
6
7
8
9
10
wx.config({
debug: true,
appId: '<?php echo $signPackage["appId"];?>',
timestamp: <?php echo $signPackage["timestamp"];?>,
nonceStr: '<?php echo $signPackage["nonceStr"];?>',
signature: '<?php echo $signPackage["signature"];?>',
jsApiList: [
// 所有要调用的 API 都要加到这个列表中
]
});

ready接口处理成功验证

1
2
3
4
wx.ready(function(){

// config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
});

通过error接口处理失败验证

1
2
3
wx.error(function(res){
// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
});

基础接口参照官方URL


心得

1、调试引入js可在PC端调试配置(config),但域名需要加入JS安全域名;
2、微信端调试时,可把debug模式打开;
3、config里面的URL必须是JS所在页面的URL,否则会报”invalid signature”.

123
dam叶

dam叶

Lazy boy write lazy blog

29 日志
15 分类
31 标签
RSS
github weibo zhihu
© 2016 dam叶
由 Hexo 强力驱动
主题 - NexT.Muse