<!-- TOC -->
- [login <-> game 通信协议](#login<->game通信协议)
    - [错误码ec](#错误码ec)
    - [玩家注册](#玩家注册)
    - [账号登录](#账号登录)
    - [登录验证](#登录验证)
    - [状态报告](#状态报告)
    - [短信登陆](#短信登陆)
<!-- TOC -->

# login<->game通信协议
v0.1
## 错误码ec
    PARAMS_ERROR = -1	//参数错误
	UNKNOW_CMD = -2		//未知cmd
    SUCCESS = 0
	LOGIN_FAILD = 1
	USERNAME_PASSWORD_ERROR = 2
	REGISTER_FAIL = 3
	UPGRADE_FAILD = 4
	UPDATE_PROFILE_FAIL = 5
	VERIFY_TOKEN_FAIL = 6
	SAVE_STATUS_FAIL = 7
	CHANGE_PASSWORD_FAIL = 8
## 首包验证
```json
{
	"cmd":"pk",
	"params":{
                "ts":1570533814000, //毫秒
                "sign":"1a2b3c4d5e6f",//md5结果
	}
}
```
返回
```json
{
	"cmd":"pk",
    "ec":0,
	"result":{
                "sign":byte数组,//公钥
	}
}
```

## 玩家注册
请求
```json
{
	"cmd":"reg",
	"params":{
                "imei":"44:03:2C:F3:18:DF7102601",
                "channel":"123456",
                "ip":"123456",
                "os":"ios",//手机操作系统 android、ios
                "maker":"小米",//手机厂商 
                "promote":123,//推广guid
                "type":123,//推广类型
	}
}
```
返回
```json
{
	"cmd":"reg",
    "ec":0,
	"result":{
                "guid":10000,
                "account":"xxx",
                "password":"md5",
                "token":"abcd1234",
                "expire":360,					
                "uri":"11.22.33.4:3000",//大厅的登陆地址
	}
}
```

## 账号登录
  客户端到登录服务器请求登录
请求
```json
{
	"cmd":"login",
	"params":{
            "account": "xxx",
            "phone":"16866668888"
            "password": "md5",
            "ip": "",	// 适用于服务端无法获取客户端ip 的时候
            "imei":"",
	}
}
```
返回
```json
{
	"cmd":"login",
    "ec":0,
	"result":{
            "guid":10000,
            "token":"fsdf23432",
            "expire":360,	//毫秒 时间戳 存活时长用于客户端缓存，生命周期内可不再访问login					
            "uri":"11.22.33.4:3000",//大厅的登陆地址
	}
}
```

## 登录验证
  玩家连接登录服务器验证成功后，连接 game server 登录游戏，此时游戏服务器会向登录服务器验证玩家合法性

请求
```json 
{
    "cmd":"verify",
	"params":{
            "guid": 10000,
            "token": "adc123",
	}
}
```

返回
```json 
{
	"cmd":"verify",
    "ec":0,
	"result":{
        "guid":10000,
        "account": "",
        "ip": "11.22.33.44",
        "area": "广东",
        "expire":"360",			// token 有效当前时间
        "channel": "",
        "nickname": "dajidali",
        "wx":"123456",			
        "qq": "12223",
        "phone":"1234654645",
        "icon":1,//1:男 2:女
        // ... 					// 其他必要信息
	}
}
```

## 状态报告
  游戏服务器定时(比如 12 s)上报当前状态， 超时不报告或掉线，可认为该 game server 离线。

请求
```json
{
	"cmd":"status",
	"params": {
            "id":1010101,			// 服务ID
            "ip": "11.22.33.53", 	// game server 地址
            "port":11223,
            "capacity":2000,		// 支持连接数
            "active":1000,			// 当前连接数
	}
}
```

返回
```json
{
	"cmd":"status",
    "ec":0,	
}
```

## 升级正式账号

```json
{
	"cmd":"upgrade",
	"params": {
                "guid":10000,		   	        
                "phone":"18688886666",		    
                "password":"123456",			
	}
}
```

返回
```json
{
	"cmd":"upgrade",
    "ec":0,
    "result":{
                "guid":10000,
                "phone":"18688886666",
                "password":"123456",        
	}
}
```

## 修改用户信息
```json
{
	"cmd":"alter",
	"params": {
                "guid":10000,	
                "password":"123456",
                "nickname":"dajidali",	
                "qq":"123456", 
                "wx":"123456",
	}
}
```

返回
```json
{
	"cmd":"alter",
    "ec":0,
    "result":{
                "guid":10000,       
	}
}
```
## 修改用户密码
```json
{
	"cmd":"changp",
	"params": {
                "guid":10000,	
                "password":"123456",
	}
}
```

返回
```json
{
	"cmd":"changp",
    "ec":0,
    "result":{
                "guid":10000,
                "password":"123456",
	}
}
```
## 获取客户端配置
```json
{
	"cmd":"conf",
}
```

返回
```json
{
	"cmd":"conf",
    "ec":0,
    "result":[
            {"*":"*"},
            {"*":"*"},
            {"*":"*"},
            ......
    ]
}
```
## 短信登陆

获取短信验证码:
```json
{
    "cmd":"texts",
    "params":{
        "phone":"16866668888"
    }
}
```
```json
{
    "cmd":"texts",
    "ec":0
}
```

短信登陆:
状态码:

- -1:系统错误
- 1:手机号不存在 未绑定的手机号
- 2:验证码发送频率过高
- 3:发送验证码超时,需重试
- 4:不是13位手机号码
- 5:验证码不一致
- 6:验证码已过期

```json
{
    "cmd":"tlogin",
    "params":{
        "phone":"16866668888",
        "code":"1234",
    }
}
```
```json
{
    "cmd":"tlogin",
    "ec":0,
	"result":{
            "guid":10000,
            "token":"fsdf23432",
            "expire":360,	//毫秒 时间戳 存活时长用于客户端缓存，生命周期内可不再访问login					
            "uri":"11.22.33.4:3000",//大厅的登陆地址
            "password":"asdadads234354asda"
	}
}

```


## 绑定支付

请求
返回

## 绑定银行卡

请求
返回
