@ -0,0 +1,819 @@ | |||
package userrpc | |||
import ( | |||
"encoding/json" | |||
"errors" | |||
"log" | |||
) | |||
type GetAddReq struct { | |||
Req | |||
UserId string | |||
Value string | |||
Memo string | |||
Source string | |||
SourceId string | |||
} | |||
type GetUpdateReq struct { | |||
Req | |||
UserId string | |||
Value string | |||
UsedValue string | |||
} | |||
type GetLogReq struct { | |||
Req | |||
UserId string | |||
Value string | |||
Before string | |||
After string | |||
Source string | |||
SourceId string | |||
OrderSn string | |||
Target string | |||
TargetId string | |||
ProductThumb string | |||
Memo string | |||
} | |||
type GetUpgradeLogReq struct { | |||
Req | |||
UserId string | |||
Upgrade string | |||
Before string | |||
After string | |||
Source string | |||
Memo string | |||
} | |||
type GetCouponReq struct { | |||
Req | |||
UserId string | |||
CouponId string | |||
ExpireTime string | |||
OrderSn string | |||
Remark string | |||
IsUse string | |||
Usertime string | |||
} | |||
/** | |||
* 获取用户积分 | |||
*/ | |||
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 | |||
} | |||
/** | |||
* 添加积分 | |||
* @2021/09/30 | |||
* @bin | |||
*/ | |||
func AddUserScore(dbname, userId, score, memo string, url ...string) (int64, error) { | |||
if dbname == "" || userId == "" || score == "" { | |||
return 0, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return 0, err | |||
} | |||
defer conn.Close() | |||
data := GetAddReq{} | |||
data.Dbname = dbname | |||
data.UserId = userId | |||
data.Value = score | |||
data.Memo = memo | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
log.Println("AddUserScore crypter error:", err) | |||
return 0, err | |||
} | |||
res := &Response{} | |||
err = conn.AddUserScore(req, res) | |||
if err != nil { | |||
log.Println("userrpc AddUserScore error:", err) | |||
return 0, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return 0, err | |||
} | |||
if res_data_de == "" { | |||
return 0, nil | |||
} | |||
var insertId int64 | |||
err = json.Unmarshal([]byte(res_data_de), &insertId) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return insertId, nil | |||
} | |||
/** | |||
* 更新积分记录 | |||
* @2021/09/30 | |||
* @bin | |||
*/ | |||
func UpdateUserScore(dbname, userId, score, used_score string, url ...string) (bool, error) { | |||
if dbname == "" || userId == "" || score == "" { | |||
return false, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return false, err | |||
} | |||
defer conn.Close() | |||
data := GetUpdateReq{} | |||
data.Dbname = dbname | |||
data.UserId = userId | |||
data.Value = score | |||
data.UsedValue = used_score | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
log.Println("UpdateUserScore crypter error:", err) | |||
return false, err | |||
} | |||
res := &Response{} | |||
err = conn.UpdateUserScore(req, res) | |||
if err != nil { | |||
log.Println("userrpc UpdateUserScore error:", err) | |||
return false, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return false, err | |||
} | |||
if res_data_de == "" { | |||
return false, nil | |||
} | |||
var updateres bool | |||
err = json.Unmarshal([]byte(res_data_de), &updateres) | |||
if err != nil { | |||
return false, err | |||
} | |||
return updateres, nil | |||
} | |||
/** | |||
* 增加积分日志 | |||
* @2021/09/30 | |||
* @bin | |||
*/ | |||
func AddUserScoreLog(dbname, UserId, Score, Before, After, Source, SourceId, OrderSn, Target, TargetId, ProductThumb, Memo string, url ...string) (int64, error) { | |||
if dbname == "" || UserId == "" || Score == "" || After == "" { | |||
return 0, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return 0, err | |||
} | |||
defer conn.Close() | |||
data := GetLogReq{} | |||
data.Dbname = dbname | |||
data.UserId = UserId | |||
data.Value = Score | |||
data.Before = Before | |||
data.After = After | |||
data.Source = Source | |||
data.SourceId = SourceId | |||
data.OrderSn = OrderSn | |||
data.Target = Target | |||
data.TargetId = TargetId | |||
data.ProductThumb = ProductThumb | |||
data.Memo = Memo | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
log.Println("AddUserScoreLog crypter error:", err) | |||
return 0, err | |||
} | |||
res := &Response{} | |||
err = conn.AddUserScoreLog(req, res) | |||
if err != nil { | |||
log.Println("userrpc AddUserScoreLog error:", err) | |||
return 0, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return 0, err | |||
} | |||
if res_data_de == "" { | |||
return 0, nil | |||
} | |||
var insertId int64 | |||
err = json.Unmarshal([]byte(res_data_de), &insertId) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return insertId, nil | |||
} | |||
/** | |||
* 添加成长值 | |||
* @2021/09/30 | |||
* @bin | |||
*/ | |||
func AddUserUpgrade(dbname, userId, upgrade, memo string, url ...string) (int64, error) { | |||
if dbname == "" || userId == "" || upgrade == "" { | |||
return 0, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return 0, err | |||
} | |||
defer conn.Close() | |||
data := GetAddReq{} | |||
data.Dbname = dbname | |||
data.UserId = userId | |||
data.Value = upgrade | |||
data.Memo = memo | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
log.Println("AddUserUpgrade crypter error:", err) | |||
return 0, err | |||
} | |||
res := &Response{} | |||
err = conn.AddUserUpgrade(req, res) | |||
if err != nil { | |||
log.Println("userrpc AddUserUpgrade error:", err) | |||
return 0, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return 0, err | |||
} | |||
if res_data_de == "" { | |||
return 0, nil | |||
} | |||
var insertId int64 | |||
err = json.Unmarshal([]byte(res_data_de), &insertId) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return insertId, nil | |||
} | |||
/** | |||
* 更新成长值记录 | |||
* @2021/09/30 | |||
* @bin | |||
*/ | |||
func UpdateUserUpgrade(dbname, userId, upgrade string, url ...string) (bool, error) { | |||
if dbname == "" || userId == "" || upgrade == "" { | |||
return false, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return false, err | |||
} | |||
defer conn.Close() | |||
data := GetAddReq{} | |||
data.Dbname = dbname | |||
data.UserId = userId | |||
data.Value = upgrade | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
log.Println("UpdateUserUpgrade crypter error:", err) | |||
return false, err | |||
} | |||
res := &Response{} | |||
err = conn.UpdateUserUpgrade(req, res) | |||
if err != nil { | |||
log.Println("userrpc UpdateUserUpgrade error:", err) | |||
return false, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return false, err | |||
} | |||
if res_data_de == "" { | |||
return false, nil | |||
} | |||
var updateres bool | |||
err = json.Unmarshal([]byte(res_data_de), &updateres) | |||
if err != nil { | |||
return false, err | |||
} | |||
return updateres, nil | |||
} | |||
/** | |||
* 增加成长值日志 | |||
* @2021/09/30 | |||
* @bin | |||
*/ | |||
func AddUserUpgradeLog(dbname, UserId, Upgrade, Before, After, Source, Memo string, url ...string) (int64, error) { | |||
if dbname == "" || UserId == "" || Upgrade == "" || After == "" { | |||
return 0, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return 0, err | |||
} | |||
defer conn.Close() | |||
data := GetUpgradeLogReq{} | |||
data.Dbname = dbname | |||
data.UserId = UserId | |||
data.Upgrade = Upgrade | |||
data.Before = Before | |||
data.After = After | |||
data.Source = Source | |||
data.Memo = Memo | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
log.Println("AddUserUpgradeLog crypter error:", err) | |||
return 0, err | |||
} | |||
res := &Response{} | |||
err = conn.AddUserUpgradeLog(req, res) | |||
if err != nil { | |||
log.Println("userrpc AddUserUpgradeLog error:", err) | |||
return 0, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return 0, err | |||
} | |||
if res_data_de == "" { | |||
return 0, nil | |||
} | |||
var insertId int64 | |||
err = json.Unmarshal([]byte(res_data_de), &insertId) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return insertId, nil | |||
} | |||
/** | |||
* 添加红包 | |||
* @2021/09/30 | |||
* @bin | |||
*/ | |||
func AddUserRedEnvelope(dbname, userId, money, memo string, url ...string) (int64, error) { | |||
if dbname == "" || userId == "" || money == "" { | |||
return 0, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return 0, err | |||
} | |||
defer conn.Close() | |||
data := GetAddReq{} | |||
data.Dbname = dbname | |||
data.UserId = userId | |||
data.Value = money | |||
data.Memo = memo | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
log.Println("AddUserRedEnvelope crypter error:", err) | |||
return 0, err | |||
} | |||
res := &Response{} | |||
err = conn.AddUserRedEnvelope(req, res) | |||
if err != nil { | |||
log.Println("userrpc AddUserRedEnvelope error:", err) | |||
return 0, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return 0, err | |||
} | |||
if res_data_de == "" { | |||
return 0, nil | |||
} | |||
var insertId int64 | |||
err = json.Unmarshal([]byte(res_data_de), &insertId) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return insertId, nil | |||
} | |||
/** | |||
* 更新红包记录 | |||
* @2021/09/30 | |||
* @bin | |||
*/ | |||
func UpdateUserRedEnvelope(dbname, userId, money, used_money string, url ...string) (bool, error) { | |||
if dbname == "" || userId == "" || money == "" { | |||
return false, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return false, err | |||
} | |||
defer conn.Close() | |||
data := GetUpdateReq{} | |||
data.Dbname = dbname | |||
data.UserId = userId | |||
data.Value = money | |||
data.UsedValue = used_money | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
log.Println("UpdateUserRedEnvelope crypter error:", err) | |||
return false, err | |||
} | |||
res := &Response{} | |||
err = conn.UpdateUserRedEnvelope(req, res) | |||
if err != nil { | |||
log.Println("userrpc UpdateUserRedEnvelope error:", err) | |||
return false, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return false, err | |||
} | |||
if res_data_de == "" { | |||
return false, nil | |||
} | |||
var updateres bool | |||
err = json.Unmarshal([]byte(res_data_de), &updateres) | |||
if err != nil { | |||
return false, err | |||
} | |||
return updateres, nil | |||
} | |||
/** | |||
* 增加红包日志 | |||
* @2021/09/30 | |||
* @bin | |||
*/ | |||
func AddUserRedEnvelopeLog(dbname, UserId, Money, Before, After, Source, SourceId, OrderSn, Target, TargetId, Memo string, url ...string) (int64, error) { | |||
if dbname == "" || UserId == "" || Money == "" || After == "" { | |||
return 0, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return 0, err | |||
} | |||
defer conn.Close() | |||
data := GetLogReq{} | |||
data.Dbname = dbname | |||
data.UserId = UserId | |||
data.Value = Money | |||
data.Before = Before | |||
data.After = After | |||
data.Source = Source | |||
data.SourceId = SourceId | |||
data.OrderSn = OrderSn | |||
data.Target = Target | |||
data.TargetId = TargetId | |||
data.Memo = Memo | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
log.Println("AddUserRedEnvelopeLog crypter error:", err) | |||
return 0, err | |||
} | |||
res := &Response{} | |||
err = conn.AddUserRedEnvelopeLog(req, res) | |||
if err != nil { | |||
log.Println("userrpc AddUserRedEnvelopeLog error:", err) | |||
return 0, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return 0, err | |||
} | |||
if res_data_de == "" { | |||
return 0, nil | |||
} | |||
var insertId int64 | |||
err = json.Unmarshal([]byte(res_data_de), &insertId) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return insertId, nil | |||
} | |||
/** | |||
* 添加优惠券 | |||
* @2021/09/30 | |||
* @bin | |||
*/ | |||
func AddUserCoupon(dbname, userId, couponId, expireTime, orderSn, remark string, url ...string) (int64, error) { | |||
if dbname == "" || userId == "" || couponId == "" { | |||
return 0, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return 0, err | |||
} | |||
defer conn.Close() | |||
data := GetCouponReq{} | |||
data.Dbname = dbname | |||
data.UserId = userId | |||
data.CouponId = couponId | |||
data.ExpireTime = expireTime | |||
data.OrderSn = orderSn | |||
data.Remark = remark | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
log.Println("AddUserCoupon crypter error:", err) | |||
return 0, err | |||
} | |||
res := &Response{} | |||
err = conn.AddUserCoupon(req, res) | |||
if err != nil { | |||
log.Println("userrpc AddUserCoupon error:", err) | |||
return 0, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return 0, err | |||
} | |||
if res_data_de == "" { | |||
return 0, nil | |||
} | |||
var insertId int64 | |||
err = json.Unmarshal([]byte(res_data_de), &insertId) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return insertId, nil | |||
} | |||
/** | |||
* 更新优惠券记录 | |||
* @2021/09/30 | |||
* @bin | |||
*/ | |||
func UpdateUserCoupon(dbname, userId, couponId, remark, orderSn, isUse, usetime string, url ...string) (bool, error) { | |||
if dbname == "" || userId == "" || couponId == "" { | |||
return false, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return false, err | |||
} | |||
defer conn.Close() | |||
data := GetCouponReq{} | |||
data.Dbname = dbname | |||
data.UserId = userId | |||
data.CouponId = couponId | |||
data.Remark = remark | |||
data.OrderSn = orderSn | |||
data.IsUse = isUse | |||
data.Usertime = usetime | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
log.Println("UpdateUserCoupon crypter error:", err) | |||
return false, err | |||
} | |||
res := &Response{} | |||
err = conn.UpdateUserCoupon(req, res) | |||
if err != nil { | |||
log.Println("userrpc UpdateUserCoupon error:", err) | |||
return false, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return false, err | |||
} | |||
if res_data_de == "" { | |||
return false, nil | |||
} | |||
var updateres bool | |||
err = json.Unmarshal([]byte(res_data_de), &updateres) | |||
if err != nil { | |||
return false, err | |||
} | |||
return updateres, nil | |||
} |
@ -0,0 +1,168 @@ | |||
package userrpc | |||
import ( | |||
"strconv" | |||
"testing" | |||
"time" | |||
) | |||
func Test_GetUserScore(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
id := "2" | |||
ret, err := GetUserScore(dbname, id) | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_GetUserRedEnvelope(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
id := "2" | |||
ret, err := GetUserRedEnvelope(dbname, id) | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_AddUserScore(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
userid := "2" | |||
score := "20" | |||
ret, err := AddUserScore(dbname, userid, score,"") | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_UpdateUserScore(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
userid := "2" | |||
score := "400" | |||
used_score := "300" | |||
ret, err := UpdateUserScore(dbname, userid, score, used_score) | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_AddUserScoreLog(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
userid := "2" | |||
score := "100" | |||
before := "500" | |||
after := "400" | |||
Source := "task" | |||
SourceId := "" | |||
OrderSn := "" | |||
Target := "" | |||
TargetId := "" | |||
ProductThumb := "" | |||
Memo := "" | |||
ret, err := AddUserScoreLog(dbname, userid, score, before, after, Source, SourceId, OrderSn, Target, TargetId, ProductThumb, Memo) | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_AddUserUpgrade(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
userid := "5" | |||
upgrade := "100" | |||
ret, err := AddUserUpgrade(dbname, userid, upgrade,"") | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_UpdateUserUpgrade(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
userid := "5" | |||
upgrade := "100" | |||
ret, err := UpdateUserUpgrade(dbname, userid, upgrade) | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_AddUserUpgradeLog(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
userid := "2" | |||
upgrade := "20" | |||
before := "11" | |||
after := "31" | |||
Source := "task" | |||
Memo := "" | |||
ret, err := AddUserUpgradeLog(dbname, userid, upgrade, before, after, Source, Memo) | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_AddUserRedEnvelope(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
userid := "5" | |||
money := "20" | |||
ret, err := AddUserRedEnvelope(dbname, userid, money,"") | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_UpdateUserRedEnvelope(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
userid := "2" | |||
money := "40" | |||
used_money := "1" | |||
ret, err := UpdateUserRedEnvelope(dbname, userid, money, used_money) | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_AddUserRedEnvelopeLog(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
userid := "2" | |||
money := "-1" | |||
before := "41" | |||
after := "40" | |||
Source := "task" | |||
SourceId := "" | |||
OrderSn := "216304042479173922" | |||
Target := "" | |||
TargetId := "" | |||
ProductThumb := "" | |||
Memo := "" | |||
ret, err := AddUserRedEnvelopeLog(dbname, userid, money, before, after, Source, SourceId, OrderSn, Target, TargetId, ProductThumb, Memo) | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_AddUserCoupon(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
userid := "2" | |||
couponId := "6" | |||
expired_time := "1634684122" | |||
order_sn := "" | |||
remark := "商品券" | |||
ret, err := AddUserCoupon(dbname, userid, couponId, expired_time,order_sn,remark) | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_UpdateUserCoupon(t *testing.T) { | |||
dbname := "shop_v2_org" | |||
userid := "2" | |||
couponId := "6" | |||
remark := "下单使用优惠券" | |||
orderSn := "12345678910" | |||
isUse := "1" | |||
usetime := strconv.Itoa(int(time.Now().Unix())) | |||
ret, err := UpdateUserCoupon(dbname, userid, couponId, remark, orderSn, isUse,usetime) | |||
t.Log(ret) | |||
t.Log(err) | |||
} |
@ -0,0 +1,54 @@ | |||
package userrpc | |||
import ( | |||
"encoding/json" | |||
"errors" | |||
) | |||
func GetAddressInfo(site_id, dbname, address_id string, url ...string) (map[string]string, error) { | |||
if dbname == "" || address_id == "" { | |||
return nil, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
data := GetAddressReq{} | |||
data.SiteId = site_id | |||
data.Dbname = dbname | |||
data.AddressId = address_id | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res := &Response{} | |||
err = conn.GetAddressInfo(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if res_data_de == "" { | |||
return nil, nil | |||
} | |||
var res_arr map[string]string | |||
err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return res_arr, nil | |||
} |
@ -0,0 +1,16 @@ | |||
package userrpc | |||
import ( | |||
"testing" | |||
) | |||
func Test_GetAddressInfo(t *testing.T) { | |||
site_id := "" | |||
dbname := "shop_v2" | |||
id := "2" | |||
ret, err := GetAddressInfo(site_id, dbname, id) | |||
t.Log(ret) | |||
t.Log(err) | |||
} |
@ -0,0 +1,150 @@ | |||
package userrpc | |||
import ( | |||
"encoding/json" | |||
"errors" | |||
"strconv" | |||
"time" | |||
"git.tetele.net/tgo/crypter" | |||
"github.com/golang/protobuf/proto" | |||
) | |||
/** | |||
* 查找商户信息 | |||
* 2021/04/06 | |||
* gz | |||
*/ | |||
func GetBusiness(site_id, dbname, business_id string, url ...string) (*Business, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
data := GetBusinessReq{} | |||
data.SiteId = site_id | |||
data.Dbname = dbname | |||
data.BusinessId = business_id | |||
data_json, err := json.Marshal(data) | |||
if err != nil { | |||
return nil, err | |||
} | |||
encryData := crypter.DesEn(string(data_json), DES_KEY) | |||
now_int64 := time.Now().Unix() | |||
now := strconv.FormatInt(now_int64, 10) | |||
sign := Sign(encryData, now) | |||
req := &Request{ | |||
proto.String(encryData), | |||
proto.String(now), | |||
proto.String(sign), | |||
nil} | |||
res := &Response{} | |||
err = conn.GetBusiness(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return HandleGetBusinessRes(res) | |||
} | |||
/** | |||
* 处理返回结果 | |||
*/ | |||
func HandleGetBusinessRes(res *Response) (*Business, error) { | |||
res_data := res.GetData() | |||
if res_data == "" { | |||
return nil, errors.New("未收到收据") | |||
} | |||
time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64) | |||
if err != nil { | |||
return nil, err | |||
} | |||
now_int64 := time.Now().Unix() | |||
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 { | |||
//时间误差前后10秒,返回 | |||
return nil, errors.New("返回时间错误") | |||
} | |||
check_sign := CheckSign(res.GetSign(), res_data, res.GetTime()) | |||
if !check_sign { | |||
return nil, errors.New("返回数据签名错误") | |||
} | |||
//解密 | |||
res_data_de := crypter.DesDe(res_data, DES_KEY) | |||
var res_arr Business | |||
err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return &res_arr, nil | |||
} | |||
func GetBusinessInfo(site_id, dbname, id string, url ...string) (map[string]string, error) { | |||
if dbname == "" || id == "" { | |||
return nil, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
data := GetBusinessReq{} | |||
data.SiteId = site_id | |||
data.Dbname = dbname | |||
data.BusinessId = id | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res := &Response{} | |||
err = conn.GetBusinessInfo(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if res_data_de == "" { | |||
return nil, nil | |||
} | |||
var res_arr map[string]string | |||
err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return res_arr, nil | |||
} |
@ -0,0 +1,16 @@ | |||
package userrpc | |||
import ( | |||
"testing" | |||
) | |||
func Test_GetBusinessInfo(t *testing.T) { | |||
site_id := "" | |||
dbname := "shop_v2" | |||
id := "5" | |||
ret, err := GetBusinessInfo(site_id, dbname, id) | |||
t.Log(ret) | |||
t.Log(err) | |||
} |
@ -0,0 +1,90 @@ | |||
package userrpc | |||
import ( | |||
"git.tetele.net/tgo/conf" | |||
) | |||
const DES_KEY = "usersrpc" | |||
type Req struct { | |||
SiteId string | |||
Dbname string | |||
} | |||
type Third struct { | |||
Userid string | |||
Platform string | |||
Openid string | |||
Openname string | |||
Unionid string | |||
Avatar string | |||
Mobile string | |||
} | |||
type BindThirdReq struct { | |||
Req | |||
Third | |||
} | |||
type GetThirdReq struct { | |||
Req | |||
Userid string | |||
Platform string | |||
} | |||
type GetBusinessReq struct { | |||
Req | |||
BusinessId string | |||
} | |||
type GetUserReq struct { | |||
Req | |||
UserId string | |||
} | |||
type GetAddressReq struct { | |||
Req | |||
AddressId string | |||
} | |||
type Res struct { | |||
Errcode int | |||
Errmsg string | |||
} | |||
type Business struct { | |||
Type string | |||
BusinessId string | |||
CustomerId string | |||
Name string | |||
CompanyId string | |||
Contact string | |||
Mobile string | |||
HandingFee string | |||
IsOpen string | |||
} | |||
type FansReq struct { | |||
Req | |||
UserId string | |||
BusinessId string | |||
Lock bool | |||
} | |||
func rpc_server_conn(url ...string) (*UserServiceClient, error) { | |||
var rpc_url string | |||
if len(url) > 0 && url[0] != "" { | |||
rpc_url = url[0] | |||
} else if conf.USER_RPC_URL != "" { | |||
rpc_url = conf.USER_RPC_URL | |||
} else { | |||
rpc_url = "127.0.0.1:" + conf.USER_RPC_PORT | |||
} | |||
conn, _, err := DialUserService("tcp", rpc_url) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return conn, nil | |||
} |
@ -0,0 +1,106 @@ | |||
package userrpc | |||
import ( | |||
"encoding/json" | |||
"errors" | |||
"strconv" | |||
"time" | |||
"git.tetele.net/tgo/crypter" | |||
"github.com/golang/protobuf/proto" | |||
) | |||
func SetResData(data interface{}, res *Response) { | |||
res_data_json, err := json.Marshal(data) | |||
if err == nil { | |||
encryData := crypter.DesEn(string(res_data_json), DES_KEY) | |||
now_str := strconv.FormatInt(time.Now().Unix(), 10) | |||
res_sign := Sign(encryData, now_str) | |||
res.Data = proto.String(encryData) | |||
res.Time = proto.String(now_str) | |||
res.Sign = proto.String(res_sign) | |||
} | |||
} | |||
func SetReqData(arg interface{}) (*Request, error) { | |||
data_json, err := json.Marshal(arg) | |||
if err != nil { | |||
return nil, err | |||
} | |||
now_int64 := time.Now().Unix() | |||
encryData := crypter.DesEn(string(data_json), DES_KEY) | |||
now := strconv.FormatInt(now_int64, 10) | |||
sign := Sign(encryData, now) | |||
return &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}, nil | |||
} | |||
func GetReqData(req *Request) (string, error) { | |||
res_data := req.GetData() | |||
if res_data != "" { | |||
time_int64, err := strconv.ParseInt(req.GetTime(), 10, 64) | |||
if err != nil { | |||
return "", err | |||
} | |||
now_int64 := time.Now().Unix() | |||
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 { | |||
//时间误差前后10秒,返回 | |||
return "", errors.New("返回时间错误") | |||
} | |||
check_sign := CheckSign(req.GetSign(), res_data, req.GetTime()) | |||
if !check_sign { | |||
return "", errors.New("返回数据签名错误") | |||
} | |||
//解密 | |||
return crypter.DesDe(res_data, DES_KEY), nil | |||
} | |||
return "", nil | |||
} | |||
func GetResData(res *Response) (string, error) { | |||
res_data := res.GetData() | |||
if res_data != "" { | |||
time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64) | |||
if err != nil { | |||
return "", err | |||
} | |||
now_int64 := time.Now().Unix() | |||
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 { | |||
//时间误差前后10秒,返回 | |||
return "", errors.New("返回时间错误") | |||
} | |||
check_sign := CheckSign(res.GetSign(), res_data, res.GetTime()) | |||
if !check_sign { | |||
return "", errors.New("返回数据签名错误") | |||
} | |||
//解密 | |||
return crypter.DesDe(res_data, DES_KEY), nil | |||
} | |||
return "", nil | |||
} |
@ -0,0 +1,75 @@ | |||
package userrpc | |||
/** | |||
* 绑定粉丝 | |||
* 2021/10/23 | |||
* gz | |||
*/ | |||
func Fans(site_id, dbname, user_id, business_id string, url ...string) error { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return err | |||
} | |||
defer conn.Close() | |||
data := FansReq{} | |||
data.SiteId = site_id | |||
data.Dbname = dbname | |||
data.UserId = user_id | |||
data.BusinessId = business_id | |||
data.Lock = false | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
return err | |||
} | |||
res := &Response{} | |||
err = conn.Fans(req, res) | |||
if err != nil { | |||
return err | |||
} | |||
_, err = GetResData(res) | |||
return nil | |||
} | |||
/** | |||
* 绑定粉丝 | |||
* 2021/10/23 | |||
* gz | |||
*/ | |||
func LockFans(site_id, dbname, user_id, business_id string, url ...string) error { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return err | |||
} | |||
defer conn.Close() | |||
data := FansReq{} | |||
data.SiteId = site_id | |||
data.Dbname = dbname | |||
data.UserId = user_id | |||
data.BusinessId = business_id | |||
data.Lock = true | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
return err | |||
} | |||
res := &Response{} | |||
err = conn.Fans(req, res) | |||
if err != nil { | |||
return err | |||
} | |||
_, err = GetResData(res) | |||
return nil | |||
} |
@ -0,0 +1,16 @@ | |||
package userrpc | |||
import ( | |||
"testing" | |||
) | |||
func Test_Fans(t *testing.T) { | |||
dbname := "shop_v2" | |||
user_id := "6" | |||
business_id := "5" | |||
err := LockFans("", dbname, user_id, business_id) | |||
t.Log(err) | |||
} |
@ -1,8 +1,21 @@ | |||
github.com/chai2010/protorpc v1.0.0 h1:aJ45G9sl1utSKo35EqnBSTs5jqTpdJDJAuZMMYPAtFo= | |||
github.com/chai2010/protorpc v1.0.0/go.mod h1:woR3WwjaQDqFjlzdVsFEKiK5Ur12QL8mYxVPjfr5z54= | |||
git.tetele.net/tgo/conf v0.46.0/go.mod h1:AWVIBEDE5dtotthUgR0SWaR2Qa6/f+O5WQ3s7Tj8q7A= | |||
git.tetele.net/tgo/crypter v0.2.2 h1:YMQJh2Gj5Po4ZfelJUmXBKi01UbmtiSy3bmqRfnYQMo= | |||
git.tetele.net/tgo/crypter v0.2.2/go.mod h1:vfvRLZA8+lHNgNXneOcgvVhDyuv25ZRb+C6xHOmXNx0= | |||
git.tetele.net/yueheng/conf v0.33.1 h1:ZEIv3Vq35RCv5f3T3Uz97s2mkZLl7W5OlmXvzI3/sS8= | |||
git.tetele.net/yueheng/conf v0.33.1/go.mod h1:AWVIBEDE5dtotthUgR0SWaR2Qa6/f+O5WQ3s7Tj8q7A= | |||
git.tetele.net/yueheng/conf v1.2.6/go.mod h1:qRujMTqjMByvdC05qdfscZMFRKM5XA1qbtz4rnFyStY= | |||
github.com/chai2010/protorpc v1.1.3 h1:VJK5hIoZn0XCGol0GmbxZkUG6FbTI5LP2Lam6RVd15w= | |||
github.com/chai2010/protorpc v1.1.3/go.mod h1:/wO0kiyVdu7ug8dCMrA2yDr2vLfyhsLEuzLa9J2HJ+I= | |||
github.com/golang/protobuf v1.0.0 h1:lsek0oXi8iFE9L+EXARyHIjU5rlWIhhTkjDz3vHhWWQ= | |||
github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | |||
github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk= | |||
github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= | |||
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= | |||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= | |||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w= | |||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= | |||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | |||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= | |||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | |||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | |||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | |||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | |||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
@ -0,0 +1,129 @@ | |||
package userrpc | |||
import ( | |||
"crypto/md5" | |||
"encoding/hex" | |||
"encoding/json" | |||
"errors" | |||
"strconv" | |||
"strings" | |||
"time" | |||
"git.tetele.net/tgo/crypter" | |||
) | |||
/** | |||
* 签名 | |||
*/ | |||
func Sign(data string, salt string) string { | |||
var build strings.Builder | |||
build.WriteString(data) | |||
build.WriteString(salt) | |||
build.WriteString("user&rpc") | |||
data_str := build.String() | |||
h := md5.New() | |||
h.Write([]byte(data_str)) // 需要加密的字符串 | |||
return hex.EncodeToString(h.Sum(nil)) // 输出加密结果 | |||
} | |||
/** | |||
* 验证签名 | |||
*/ | |||
func CheckSign(sign_str, data, salt string) bool { | |||
sign := Sign(data, salt) | |||
if strings.Compare(sign_str, sign) > -1 { | |||
return true | |||
} | |||
return false | |||
} | |||
/** | |||
* 处理返回结果 | |||
*/ | |||
func HandleRes(res *Response) (*Res, error) { | |||
res_data := res.GetData() | |||
if res_data == "" { | |||
return nil, errors.New("未收到收据") | |||
} | |||
time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64) | |||
if err != nil { | |||
return nil, err | |||
} | |||
now_int64 := time.Now().Unix() | |||
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 { | |||
//时间误差前后10秒,返回 | |||
return nil, errors.New("返回时间错误") | |||
} | |||
check_sign := CheckSign(res.GetSign(), res_data, res.GetTime()) | |||
if !check_sign { | |||
return nil, errors.New("返回数据签名错误") | |||
} | |||
//解密 | |||
res_data_de := crypter.DesDe(res_data, DES_KEY) | |||
var res_arr Res | |||
err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return &res_arr, nil | |||
} | |||
/** | |||
* 处理返回结果 | |||
*/ | |||
func HandleUserRes(res *Response) (map[string]string, error) { | |||
res_data := res.GetData() | |||
if res_data == "" { | |||
return nil, errors.New("未收到收据") | |||
} | |||
time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64) | |||
if err != nil { | |||
return nil, err | |||
} | |||
now_int64 := time.Now().Unix() | |||
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 { | |||
//时间误差前后10秒,返回 | |||
return nil, errors.New("返回时间错误") | |||
} | |||
check_sign := CheckSign(res.GetSign(), res_data, res.GetTime()) | |||
if !check_sign { | |||
return nil, errors.New("返回数据签名错误") | |||
} | |||
//解密 | |||
res_data_de := crypter.DesDe(res_data, DES_KEY) | |||
var res_arr map[string]string | |||
err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return res_arr, nil | |||
} |
@ -0,0 +1,157 @@ | |||
package userrpc | |||
import ( | |||
"encoding/json" | |||
"errors" | |||
"strconv" | |||
"time" | |||
"git.tetele.net/tgo/crypter" | |||
"github.com/golang/protobuf/proto" | |||
) | |||
/** | |||
* 绑定第三方平台openid | |||
* 2021/04/05 | |||
* gz | |||
*/ | |||
func BindThird(site_id, dbname, platform, user_id, openid, openname, unionid, avatar, mobile string, url ...string) (*Res, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
data := BindThirdReq{} | |||
data.SiteId = site_id | |||
data.Dbname = dbname | |||
data.Openid = openid | |||
data.Openname = openname | |||
data.Platform = platform | |||
data.Unionid = unionid | |||
data.Avatar = avatar | |||
data.Mobile = mobile | |||
data.Userid = user_id | |||
data_json, err := json.Marshal(data) | |||
if err != nil { | |||
return nil, err | |||
} | |||
encryData := crypter.DesEn(string(data_json), DES_KEY) | |||
now_int64 := time.Now().Unix() | |||
now := strconv.FormatInt(now_int64, 10) | |||
sign := Sign(encryData, now) | |||
req := &Request{ | |||
proto.String(encryData), | |||
proto.String(now), | |||
proto.String(sign), | |||
nil} | |||
res := &Response{} | |||
err = conn.BindThird(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return HandleRes(res) | |||
} | |||
/** | |||
* 查找第三方平台openid | |||
* 2021/04/06 | |||
* gz | |||
*/ | |||
func GetThird(site_id, dbname, platform, user_id string, url ...string) (*Third, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
data := GetThirdReq{} | |||
data.SiteId = site_id | |||
data.Dbname = dbname | |||
data.Platform = platform | |||
data.Userid = user_id | |||
data_json, err := json.Marshal(data) | |||
if err != nil { | |||
return nil, err | |||
} | |||
encryData := crypter.DesEn(string(data_json), DES_KEY) | |||
now_int64 := time.Now().Unix() | |||
now := strconv.FormatInt(now_int64, 10) | |||
sign := Sign(encryData, now) | |||
req := &Request{ | |||
proto.String(encryData), | |||
proto.String(now), | |||
proto.String(sign), | |||
nil} | |||
res := &Response{} | |||
err = conn.GetThird(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return HandleGetThirdRes(res) | |||
} | |||
/** | |||
* 处理返回结果 | |||
*/ | |||
func HandleGetThirdRes(res *Response) (*Third, error) { | |||
res_data := res.GetData() | |||
if res_data == "" { | |||
return nil, errors.New("未收到收据") | |||
} | |||
time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64) | |||
if err != nil { | |||
return nil, err | |||
} | |||
now_int64 := time.Now().Unix() | |||
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 { | |||
//时间误差前后10秒,返回 | |||
return nil, errors.New("返回时间错误") | |||
} | |||
check_sign := CheckSign(res.GetSign(), res_data, res.GetTime()) | |||
if !check_sign { | |||
return nil, errors.New("返回数据签名错误") | |||
} | |||
//解密 | |||
res_data_de := crypter.DesDe(res_data, DES_KEY) | |||
var res_arr Third | |||
err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return &res_arr, nil | |||
} |
@ -0,0 +1,28 @@ | |||
package userrpc | |||
import ( | |||
"testing" | |||
"git.tetele.net/tgo/crypter" | |||
) | |||
func Test_BindThird(t *testing.T) { | |||
// dbname := "test1_tetele_com" | |||
// site_id := "1001" | |||
// platform := "deliver_mini" | |||
// user_id := "1" | |||
// openid := "CasfoieFsdfsdfiDiodf_df" | |||
// openname := "测试中" | |||
// avatar := "https://ssss.ttt.ddd/sfsd" | |||
// mobile := "1234456456" | |||
// res, err := BindThird(site_id, dbname, platform, user_id, openid, openname, "", avatar, mobile) | |||
// t.Log(res) | |||
// t.Log(err) | |||
// data := "E5B2642BDEA1FBC85BA958C398E58DEC2E1425E26E25D6A178DBD078AD0DFC6859DF5634B0A01CE01F84E056380981A1F1433044FB197D8965FD8F3322DF2373619AD4ACB158605B45AC3947B200C8B62C2B30256B2D2D7283492F268F609944" | |||
data := "E5B2642BDEA1FBC85BA958C398E58DEC2E1425E26E25D6A178DBD078AD0DFC6859DF5634B0A01CE01F84E056380981A1F1433044FB197D89AF51E05A9E9F5C76BE8F563F2E4D42AB3C3C649B4187A7C48E98988C734CEACD" | |||
org := crypter.DesDe(data, DES_KEY) | |||
t.Log(org) | |||
} |
@ -0,0 +1,56 @@ | |||
package userrpc | |||
import ( | |||
"encoding/json" | |||
) | |||
/** | |||
* 查找第三方平台openid V2版 | |||
* 2021/09/07 | |||
* gz | |||
*/ | |||
func GetUserThird(site_id, dbname, platform, user_id, field string, url ...string) (map[string]string, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
data := map[string]string{ | |||
"site_id": site_id, | |||
"dbname": dbname, | |||
"user_id": user_id, | |||
"platform": platform, | |||
"field": field, | |||
} | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res := &Response{} | |||
err = conn.GetUserThird(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if res_data_de == "" { | |||
return nil, nil | |||
} | |||
var res_arr map[string]string | |||
err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return res_arr, nil | |||
} |
@ -0,0 +1,13 @@ | |||
package userrpc | |||
import ( | |||
"testing" | |||
) | |||
func Test_GetUserThird(t *testing.T) { | |||
org, err := GetUserThird("1", "shop_v2", "miniapp", "2", "id,openid") | |||
t.Log(org) | |||
t.Log(err) | |||
} |