Coder Social home page Coder Social logo

blog's People

Stargazers

 avatar

Watchers

 avatar  avatar

blog's Issues

CentOS 7 安装 shadowsocks 客户端

本文分享下我在CentOS7上安装Shadowsocks 客户端的的过程。

1. 安装pip

pip是Python的包管理工具,我们接下来是使用pip安装的Shadowsocks。
这里介绍两种方法:
1. 通过yum管理工具安装:
yum install -y pip
2. 可能你的镜像库没有这个包,那么可以手动安装:

curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py

2.Shadowsocks客户端

安装

pip install --upgrade pip
pip install shadowsocks

配置

新建配置文件/etc/shadowsocks.json

vi /etc/shadowsocks.json

然后填写以下内容:

{
"server":"x.x.x.x",             #你的 ss 服务器 ip
"server_port":0,                #你的 ss 服务器端口
"local_address": "127.0.0.1",   #本地ip
"local_port":0,                 #本地端口
"password":"password",          #连接 ss 密码
"timeout":300,                  #等待超时
"method":"aes-256-cfb",         #加密方式
"workers": 1                    #工作线程数
}

启动

nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1

若需要配置自启动,则再运行:

echo " nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 &" /etc/rc.local

测试

运行 curl --socks5 127.0.0.1:1080 http://httpbin.org/ip , 如下返回你的ss服务器ip,则说明Shadowsocks客户端启动成功。

{
"origin": "x.x.x.x"       #你的 ss 服务器 ip
}

到这里只是安装好了shadowsocks客户端,但是linux系统下的命令行却还不能够走代理,接下来还需要安装Privoxy。

Privoxy

Shadowsocks 是一个 socket5 服务,我们需要使用 Privoxy 把流量转到 http/https 上。

下载并安装Privoxy

没有wget命令的可以使用yum install wget命令安装。

wget http://www.privoxy.org/sf-download-mirror/Sources/3.0.26%20%28stable%29/privoxy-3.0.26-stable-src.tar.gz
tar -zxvf privoxy-3.0.26-stable-src.tar.gz
cd privoxy-3.0.26-stable

建议在下载前去 Privoxy官网下载页 检查一下版本。

新建用户

Privoxy 不建议使用 root 用户运行,所以我们这里新建一个用户:

useradd privoxy 

安装

autoheader && autoconf
./configure
make && make install

如果没有autoconf命令的,同样需要执行yum install autoconf命令安装。

配置

编辑/usr/local/etc/privoxy/config文件

vi /usr/local/etc/privoxy/config

找到以下两句,确保没有注释掉:

listen-address 127.0.0.1:8118   # 8118 是默认端口,不用改,下面会用到
forward-socks5t / 127.0.0.1:0 . # 这里的端口写 shadowsocks 的本地端口(注意最后那个 . 不要漏了)

启动

privoxy --user privoxy /usr/local/etc/privoxy/config

配置 /etc/profile

vi /etc/profile

在上面添加这两句:

export http_proxy=http://127.0.0.1:8118       #这里的端口和上面 privoxy 中的保持一致
export https_proxy=http://127.0.0.1:8118

然后执行source /etc/profile使配置生效。

测试

curl www.google.com

返回一大堆 HTML 则说明你成功了。

最后

如果不能访问,请重启机器,依次打开 shadowsocks 和 privoxy 再测试。

nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 &
privoxy --user privoxy /usr/local/etc/privoxy/config

如果不需要用代理了,记得把/etc/profile里的配置注释掉,不然会一直走代理流量。

oauth2使用password模式获取access_token

oauth2获取access_token的几种方式:

  1. 简化模式(implicit):在redirect_url中传递access_token,oauth客户端运行在浏览器中。
  2. 密码模式(password):将用户名和密码传过去,直接获取access_token。
  3. 客户端模式(client credentials):用户向客户端注册,然后客户端以自己的名义向“服务端”获取资源。
  4. 授权码模式(authorization code):通过客户端的后台服务器,向服务端认证。

这里介绍如何使用密码模式获取access_token:

  1. 拼接授权的client_id和client_secret,并使用base64编码之后作为请求头:
    先拼接:client_id:client_secret 如 : client:secret
    使用任意base64工具编码: Y2xpZW50OnNlY3JldA==
    最后在请求头添加: "Authorization" : "Basic Y2xpZW50OnNlY3JldA=="

  2. 使用post请求:
    url: http://localhost:8020/oauth/token?grant_type=password&username=admin&password=admin
    image

  3. 获取结果:

image

也可直接将client信息直接放在url中,如:

url:http://localhost:8020/oauth/token?grant_type=password&client_id=client&client_secret=secret&username=admin&password=admin

也可将请求数据都放在请求体或者是表单中:

image

react-native开发swift的ios应用,使用callback通信方式回调键值对组

当我们在开发react-native项目时,JS端与原生端的通信是很必要的。但是在iOS开发中我发现很难找到使用RCTResponseSenderBlock方式回调一组数据的方式,找了很多半天,终于找到一种方式,所以记录下来。

1、原生端的代码

@objc func getConfigData(_ callback: RCTResponseSenderBlock){
        let bunderManager:BundleManager? = BundleManager.getBundleManager()
        let appModel:AppModel = (bunderManager?.getAppModel())!
        let token:String = appModel.token!
        let serverUrl:String = appModel.url!
        let loginUrl:String = serverUrl.replacingOccurrences(of: "/mobileCloud/v1/bundle", with: "/oauth/oauth/authorize?response_type=token&state=&client_id=mobile")
        let appVetsionId:String = appModel.id!
        let homeDirectory:String = NSHomeDirectory()+"/Documents"
        //cllback回调键值对组
        callback([
                ["serverUrl":serverUrl,"token":token,"loginUrl":loginUrl,"appVetsionId":appVetsionId,"homeDirectory":homeDirectory]
            ])
    }

注:参数callback前面的下划线是为了接受JS端传过来的参数不用前缀,swift的方法参数在调用时正常时需要加上参数前缀的。如:
bunderManager?.checkBundleConfigUpdate(callback: callback)

2、Object-c对JS端暴露方法

RCT_EXTERN_METHOD(getConfigData:(RCTResponseSenderBlock)callback)

这样,JS端就可以调用到这个方法了。

3、JS端代码

NativeModules.NativeManager.getConfigData((back) => {
       var REQUEST_URL = back.serverUrl + "/getData/"+back.appVetsionId;
        var token = back.token;
   });

JS端就通过这样拿到原生端的数据组了。

使用callback方式调用键值对组数据的方式就是这样。iOS开发中也可以使用promises的方式回调一个数组,但是这样JS端就必须使用async和await的方式调用,比较麻烦,当然也有优势。之后会再发文说明promises的调用方式。
使用过程中有问题的可以再私信我。

springfox-swagger2 创建新的group

springfox-swagger2 创建新的group,只需要实例化一个新的Docket实例,配置groupName,在请求时。使用/v2/api-docs?group=test就可以请求这个group对应的swagger json。

@Bean
    public Docket customImplementation() {
        ApiInfo apiInfo = ApiInfo.DEFAULT;
        apiInfo = new ApiInfo(apiInfo.getTitle(), "my descript", apiInfo.getVersion(),
                apiInfo.getTermsOfServiceUrl(), apiInfo.getContact(), apiInfo.getLicense(), apiInfo.getLicenseUrl());
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("test")
                .apiInfo(apiInfo);
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.