|
@ -0,0 +1,106 @@ |
|
|
|
|
|
package userrpc |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
|
"encoding/json" |
|
|
|
|
|
"errors" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取用户积分 |
|
|
|
|
|
*/ |
|
|
|
|
|
func GetUserScore(dbname,userId string, url ...string) (string, error) { |
|
|
|
|
|
|
|
|
|
|
|
if dbname == "" || userId == "" { |
|
|
|
|
|
return "", errors.New("参数错误") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
conn, err := rpc_server_conn(url...) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", err |
|
|
|
|
|
} |
|
|
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
|
|
|
|
data := GetUserReq{} |
|
|
|
|
|
data.Dbname = dbname |
|
|
|
|
|
data.UserId = userId |
|
|
|
|
|
|
|
|
|
|
|
req, err := SetReqData(data) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res := &Response{} |
|
|
|
|
|
|
|
|
|
|
|
err = conn.GetUserScore(req, res) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res_data_de, err := GetResData(res) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", err |
|
|
|
|
|
} |
|
|
|
|
|
if res_data_de == "" { |
|
|
|
|
|
return "", nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var score string |
|
|
|
|
|
err = json.Unmarshal([]byte(res_data_de),&score) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return score, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取用户红包 |
|
|
|
|
|
*/ |
|
|
|
|
|
func GetUserRedEnvelope(dbname,userId string, url ...string) (string, error) { |
|
|
|
|
|
|
|
|
|
|
|
if dbname == "" || userId == "" { |
|
|
|
|
|
return "", errors.New("参数错误") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
conn, err := rpc_server_conn(url...) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", err |
|
|
|
|
|
} |
|
|
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
|
|
|
|
data := GetUserReq{} |
|
|
|
|
|
data.Dbname = dbname |
|
|
|
|
|
data.UserId = userId |
|
|
|
|
|
|
|
|
|
|
|
req, err := SetReqData(data) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res := &Response{} |
|
|
|
|
|
|
|
|
|
|
|
err = conn.GetUserRedEnvelope(req, res) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res_data_de, err := GetResData(res) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", err |
|
|
|
|
|
} |
|
|
|
|
|
if res_data_de == "" { |
|
|
|
|
|
return "", nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var redEnvelope string |
|
|
|
|
|
err = json.Unmarshal([]byte(res_data_de),&redEnvelope) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return redEnvelope, nil |
|
|
|
|
|
} |