Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-interface/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/interface/main/app-interface/dao/pay",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/app-interface/conf:go_default_library",
"//app/interface/main/app-interface/model/pay:go_default_library",
"//library/ecode:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,96 @@
package pay
import (
"context"
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
"time"
"go-common/app/interface/main/app-interface/conf"
"go-common/app/interface/main/app-interface/model/pay"
"go-common/library/ecode"
httpx "go-common/library/net/http/blademaster"
"github.com/pkg/errors"
)
type Dao struct {
c *conf.Config
client *httpx.Client
wallet string
}
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
client: httpx.NewClient(c.HTTPClient),
wallet: c.Host.Pay + "/wallet-int/wallet/getUserWalletInfo",
}
return
}
// UserWalletInfo get user bcoin doc:http://info.bilibili.co/pages/viewpage.action?pageId=7559096
func (d *Dao) UserWalletInfo(c context.Context, mid int64, platform string) (availableBp float64, err error) {
var plat int
if platform == "ios" {
plat = 1
} else if platform == "android" {
plat = 2
} else {
err = fmt.Errorf("platform(%s) error", platform)
return
}
params := url.Values{}
params.Set("customerId", "10006")
params.Set("platformType", strconv.Itoa(plat))
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("traceId", strconv.FormatInt(time.Now().Unix(), 10))
params.Set("timestamp", strconv.FormatInt(time.Now().UnixNano()/1000, 10))
params.Set("signType", "MD5")
params.Set("appkey", d.c.HTTPClient.Key)
type pJSON struct {
CustomerID string `json:"customerId"`
PlatformType int `json:"platformType"`
Mid int64 `json:"mid"`
TraceID string `json:"traceId"`
Timestamp string `json:"timestamp"`
SignType string `json:"signType"`
Appkey string `json:"appkey"`
Sign string `json:"sign"`
}
tmp := params.Encode() + d.c.HTTPClient.Secret
if strings.IndexByte(tmp, '+') > -1 {
tmp = strings.Replace(tmp, "+", "%20", -1)
}
mh := md5.Sum([]byte(tmp))
sign := hex.EncodeToString(mh[:])
p := &pJSON{
CustomerID: "10006",
PlatformType: plat,
Mid: mid,
TraceID: params.Get("traceId"),
Timestamp: params.Get("timestamp"),
SignType: params.Get("signType"),
Appkey: params.Get("appkey"),
Sign: sign,
}
bs, _ := json.Marshal(p)
req, _ := http.NewRequest("POST", d.wallet, strings.NewReader(string(bs)))
req.Header.Set("Content-Type", "application/json")
var wallet *pay.UserWallet
if err = d.client.Do(c, req, &wallet); err != nil {
return
}
if wallet.Code != 0 {
err = errors.Wrap(ecode.Int(wallet.Code), d.wallet+"?"+params.Encode())
return
}
availableBp = wallet.Data.AvailableBp
return
}

View File

@@ -0,0 +1,33 @@
package pay
import (
"reflect"
"testing"
"go-common/app/interface/main/app-interface/conf"
. "github.com/smartystreets/goconvey/convey"
)
func TestNew(t *testing.T) {
Convey("TestNew", t, func() {
})
type args struct {
c *conf.Config
}
tests := []struct {
name string
args args
wantD *Dao
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotD := New(tt.args.c); !reflect.DeepEqual(gotD, tt.wantD) {
t.Errorf("New() = %v, want %v", gotD, tt.wantD)
}
})
}
}