Browse Source

增加查询用户积分和红包方法

master v0.7.2
listen 3 years ago
parent
commit
08f8694e32
2 changed files with 131 additions and 0 deletions
  1. +106
    -0
      account.client.go
  2. +25
    -0
      account.client_test.go

+ 106
- 0
account.client.go View File

@ -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
}

+ 25
- 0
account.client_test.go View File

@ -0,0 +1,25 @@
package userrpc
import (
"testing"
)
func Test_GetUserScore(t *testing.T) {
dbname := "shop_v2"
id := "2"
ret, err := GetUserScore(dbname, id)
t.Log(ret)
t.Log(err)
}
func Test_GetUserRedEnvelope(t *testing.T) {
dbname := "shop_v2"
id := "2"
ret, err := GetUserRedEnvelope(dbname, id)
t.Log(ret)
t.Log(err)
}

Loading…
Cancel
Save