commit
e6563804ee
@ -0,0 +1,6 @@
|
|||||||
|
.idea
|
||||||
|
app.dev.ini
|
||||||
|
app.local.ini
|
||||||
|
bin/
|
||||||
|
log/
|
||||||
|
main_test.go
|
@ -0,0 +1,10 @@
|
|||||||
|
package otosaas
|
||||||
|
|
||||||
|
var Api = &api{}
|
||||||
|
|
||||||
|
type api struct {
|
||||||
|
Sku sku
|
||||||
|
Order order
|
||||||
|
Afs afs
|
||||||
|
Push push
|
||||||
|
}
|
@ -0,0 +1,137 @@
|
|||||||
|
package otosaas
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.oa00.com/go/otosaas/config"
|
||||||
|
"log"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if err := config.InitOtoSaas(config.Config{
|
||||||
|
Url: "https://dev-api.otosaas.com/open_api",
|
||||||
|
AppKey: "shama",
|
||||||
|
AppSecret: "7b6cff19a8de4b4dad6480698b4d87b6",
|
||||||
|
HexPrivateKey: "22cc7a92d82f4ade30f63be1a800e700aa9386d422a19ab6e8b43af15a6c8a91",
|
||||||
|
OtoSaasPublicKey: "MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE5QoFDXf57f1tn0UwuTFnnL070fhAE+A9omI9f1LGt5ZQmZUEtEfVSvY2IDhcSo2/JCMysQHyAqwmh5X9Ha4l+Q==",
|
||||||
|
OtoSaasSm4Secret: "8E0BEC651A7D97D0A8B370C074E4E65E",
|
||||||
|
}); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func TestSkuPool(t *testing.T) {
|
||||||
|
result, err := Api.Sku.Pool(0, 100)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, skuCode := range result.SkuCodes {
|
||||||
|
Api.Sku.Detail(skuCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSkuDetail(t *testing.T) {
|
||||||
|
log.Println(Api.Sku.Detail("YD1002902"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSkuImage(t *testing.T) {
|
||||||
|
log.Println(Api.Sku.Image("YD1002902"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSkuStatus(t *testing.T) {
|
||||||
|
log.Println(Api.Sku.Status("YD1002902"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSkuStock(t *testing.T) {
|
||||||
|
log.Println(Api.Sku.Stock("YD1002902"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOrderFreight(t *testing.T) {
|
||||||
|
log.Println(Api.Order.Freight([]SkuFreightItem{
|
||||||
|
{
|
||||||
|
CommodityCode: "YD1002902",
|
||||||
|
CommoditySpecCode: "HL69110000464848",
|
||||||
|
CommodityNum: 1,
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
func TestOrderSubmit(t *testing.T) {
|
||||||
|
log.Println(Api.Order.Submit(OrderSubmit{
|
||||||
|
UserId: "1",
|
||||||
|
UserPhone: "18906611076",
|
||||||
|
TotalPrice: 789,
|
||||||
|
ReceiverName: "杨赟",
|
||||||
|
ReceiverPhone: "15394315510",
|
||||||
|
ReceiverProvince: "浙江省",
|
||||||
|
ReceiverCity: "宁波市",
|
||||||
|
ReceiverRegion: "鄞州区",
|
||||||
|
ReceiverStreetName: "",
|
||||||
|
ReceiverDetailAddress: "浙江省宁波市鄞州区深蓝大厦19楼",
|
||||||
|
CommodityList: []OrderSkuItem{
|
||||||
|
{
|
||||||
|
CommodityCode: "YD1002902",
|
||||||
|
CommoditySpecCode: "HL69110000464848",
|
||||||
|
CommodityNum: 1,
|
||||||
|
CommoditySpecPrice: 789,
|
||||||
|
ShopCode: "hailv",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Remark: "无",
|
||||||
|
FreightAmount: 0,
|
||||||
|
CustomerOrderId: "shama" + time.Now().Format("20060102150405"),
|
||||||
|
CreateTime: time.Now().UnixMilli(),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOrderConfirm(t *testing.T) {
|
||||||
|
log.Println(Api.Order.Confirm("20221213115326352640", "1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOrderDetail(t *testing.T) {
|
||||||
|
log.Println(Api.Order.Detail("20221213115326352640", "1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOrderLogistics(t *testing.T) {
|
||||||
|
log.Println(Api.Order.Logistics("20221213115326352640", "1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOrderReceipt(t *testing.T) {
|
||||||
|
log.Println(Api.Order.Receipt("20221213115326352640", "1", "202212131153263526400101"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAfsApply(t *testing.T) {
|
||||||
|
log.Println(Api.Afs.Apply(AfsApply{
|
||||||
|
UserId: "1",
|
||||||
|
CommodityStatus: 2,
|
||||||
|
OrderId: "20221213115326352640",
|
||||||
|
ItemOrderIds: []string{"202212131153263526400101"},
|
||||||
|
Pics: []string{},
|
||||||
|
ReturnReasonValue: "不想要了",
|
||||||
|
ReturnRemark: "不想要了",
|
||||||
|
Type: 2,
|
||||||
|
ReturnType: 0,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAfsDetail(t *testing.T) {
|
||||||
|
log.Println(Api.Afs.Detail("20221213132903665728", "1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAfsRefund(t *testing.T) {
|
||||||
|
log.Println(Api.Afs.Refund("20221213132903665728", "1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAfsLogisticsAddress(t *testing.T) {
|
||||||
|
log.Println(Api.Afs.LogisticsAddress("20221213132903665728", "1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAfsBackLogisticsBill(t *testing.T) {
|
||||||
|
log.Println(Api.Afs.BackLogisticsBill(BackLogisticsBill{
|
||||||
|
UserId: "1",
|
||||||
|
ReturnOrderId: "20221213132903665728",
|
||||||
|
LogisticsNum: "JDVC16678045614",
|
||||||
|
LogisticsCode: "",
|
||||||
|
LogisticsName: "京东快递",
|
||||||
|
ReturnAddress: "浙江省宁波市深蓝大厦19楼",
|
||||||
|
}))
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"github.com/tjfoc/gmsm/sm2"
|
||||||
|
"github.com/tjfoc/gmsm/x509"
|
||||||
|
)
|
||||||
|
|
||||||
|
var SdkConfig = &Config{}
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Url string // 接口地址
|
||||||
|
AppKey string // appKey
|
||||||
|
AppSecret string // appSecret
|
||||||
|
HexPrivateKey string // 16进制私钥
|
||||||
|
OtoSaasPublicKey string // 酷屏公钥
|
||||||
|
OtoSaasSm4Secret string // 酷屏sm4密钥
|
||||||
|
PrivateKey *sm2.PrivateKey // sm2私钥
|
||||||
|
Sm4Secret []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// InitOtoSaas @Title 初始化酷屏接口
|
||||||
|
func InitOtoSaas(config Config) error {
|
||||||
|
PrivateKey, err := x509.ReadPrivateKeyFromHex(config.HexPrivateKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
config.PrivateKey = PrivateKey
|
||||||
|
|
||||||
|
sm4Secret, err := hex.DecodeString(config.OtoSaasSm4Secret)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
config.Sm4Secret = sm4Secret
|
||||||
|
|
||||||
|
SdkConfig = &config
|
||||||
|
return nil
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
module git.oa00.com/go/otosaas
|
||||||
|
|
||||||
|
go 1.17
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/google/uuid v1.3.0
|
||||||
|
github.com/tjfoc/gmsm v1.4.1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect
|
||||||
|
)
|
@ -0,0 +1,75 @@
|
|||||||
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
|
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||||
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||||
|
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||||
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||||
|
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||||
|
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
|
github.com/tjfoc/gmsm v1.4.1 h1:aMe1GlZb+0bLjn+cKTPEvvn9oUEBlJitaZiiBwsbgho=
|
||||||
|
github.com/tjfoc/gmsm v1.4.1/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee h1:4yd7jl+vXjalO5ztz6Vc1VADv+S/80LGJmyl1ROJ2AI=
|
||||||
|
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
|
||||||
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
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=
|
||||||
|
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||||
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
|
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||||
|
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||||
|
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||||
|
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||||
|
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||||
|
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||||
|
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||||
|
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||||
|
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
@ -0,0 +1,14 @@
|
|||||||
|
package otosaas
|
||||||
|
|
||||||
|
type push struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Success @Title 推送成功
|
||||||
|
func (p *push) Success() string {
|
||||||
|
return `{"code": 0, "message": "推送成功"}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error @Title 推送失败
|
||||||
|
func (p *push) Error() string {
|
||||||
|
return `{"code": 1 "message": "推送失败"}`
|
||||||
|
}
|
@ -0,0 +1,141 @@
|
|||||||
|
package request
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"git.oa00.com/go/otosaas/config"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/tjfoc/gmsm/sm4"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
POST = "POST"
|
||||||
|
GET = "GET"
|
||||||
|
)
|
||||||
|
|
||||||
|
var client = &http.Client{}
|
||||||
|
|
||||||
|
// Request @Title 请求
|
||||||
|
func Request(method, url, data string, headers ...map[string]string) ([]byte, error) {
|
||||||
|
reqest, err := http.NewRequest(method, url, strings.NewReader(data))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(headers) > 0 {
|
||||||
|
for key, value := range headers[0] {
|
||||||
|
reqest.Header.Add(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
response, err := client.Do(reqest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
result, err := io.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encrypt @Title 加密
|
||||||
|
func Encrypt(data string) (string, error) {
|
||||||
|
bytes, err := sm4.Sm4Ecb(config.SdkConfig.Sm4Secret, []byte(data), true)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return hex.EncodeToString(bytes), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decrypt @Title 解密
|
||||||
|
func Decrypt(data string) (string, error) {
|
||||||
|
decodeString, err := hex.DecodeString(data)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
bytes, err := sm4.Sm4Ecb(config.SdkConfig.Sm4Secret, decodeString, false)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(bytes), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sign @Title 签名
|
||||||
|
func Sign(data, timeStamp string) (sign string, err error) {
|
||||||
|
signData, err := config.SdkConfig.PrivateKey.Sign(rand.Reader, []byte(config.SdkConfig.AppSecret+timeStamp+data), nil)
|
||||||
|
if err != nil {
|
||||||
|
return sign, err
|
||||||
|
}
|
||||||
|
return base64.StdEncoding.EncodeToString(signData), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type response struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
BizData string `json:"bizData"`
|
||||||
|
Sign string `json:"sign"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec 调用接口
|
||||||
|
func Exec(action string, data interface{}, resObj interface{}) error {
|
||||||
|
// 加密
|
||||||
|
marshal, _ := json.Marshal(&data)
|
||||||
|
log.Println(string(marshal))
|
||||||
|
encrypt, err := Encrypt(string(marshal))
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// 签名
|
||||||
|
timeStamp := strconv.FormatInt(time.Now().UnixMilli(), 10)
|
||||||
|
sign, err := Sign(encrypt, timeStamp)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes, _ := json.Marshal(map[string]string{
|
||||||
|
"bizData": encrypt,
|
||||||
|
"sign": sign,
|
||||||
|
})
|
||||||
|
|
||||||
|
// 调用接口
|
||||||
|
result, err := Request(POST, config.SdkConfig.Url+action, string(bytes), map[string]string{
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"appKey": config.SdkConfig.AppKey,
|
||||||
|
"timeStamp": timeStamp,
|
||||||
|
"version": "1.0",
|
||||||
|
"requestId": uuid.New().String(),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Println(string(result))
|
||||||
|
resp := response{}
|
||||||
|
if err = json.Unmarshal(result, &resp); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if resp.Code == 0 {
|
||||||
|
decrypt, err := Decrypt(resp.BizData)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Println(decrypt)
|
||||||
|
return json.Unmarshal([]byte(decrypt), &resObj)
|
||||||
|
} else {
|
||||||
|
return errors.New(resp.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,130 @@
|
|||||||
|
package otosaas
|
||||||
|
|
||||||
|
import "git.oa00.com/go/otosaas/request"
|
||||||
|
|
||||||
|
type sku struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
skuPoll = "/mall/v1/commodity/list" // 商品池
|
||||||
|
skuDetail = "/mall/v1/commodity/detail" // 商品详情
|
||||||
|
skuImage = "/mall/v1/commodity/image" // 商品图片
|
||||||
|
skuStatus = "/mall/v1/commodity/status" // 商品状态
|
||||||
|
skuStock = "/mall/v1/commodity/stock" // 商品库存
|
||||||
|
)
|
||||||
|
|
||||||
|
type poolItem struct {
|
||||||
|
TotalCount int `json:"totalCount"`
|
||||||
|
SkuCodes []string `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pool @Title 商品池 最大100条
|
||||||
|
func (s *sku) Pool(page, pageSize uint) (result poolItem, err error) {
|
||||||
|
err = request.Exec(skuPoll, map[string]interface{}{
|
||||||
|
"page": page,
|
||||||
|
"pageSize": pageSize,
|
||||||
|
}, &result)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type SkuDetail struct {
|
||||||
|
ShopCode string `json:"shopCode"`
|
||||||
|
CommodityDetailVos []struct {
|
||||||
|
WordDescription string `json:"wordDescription"` // html详情
|
||||||
|
ImgDescription string `json:"imgDescription"` // 图片详情
|
||||||
|
CommodityDetailType int `json:"commodityDetailType"` // 详情类别 0=文字描述 1=图片描述
|
||||||
|
Id int `json:"id"`
|
||||||
|
CommoditySerial int `json:"commoditySerial"` // 排序
|
||||||
|
} `json:"commodityDetailVos"` // 商品详情
|
||||||
|
CommodityPic string `json:"commodityPic"` // 商品主图
|
||||||
|
CommodityDescription string `json:"commodityDescription"` // 商品描述
|
||||||
|
CommodityCategoryName string `json:"commodityCategoryName"` // 分类名称 一级-二级-三级
|
||||||
|
CommodityCategoryC1 string `json:"commodityCategoryC1"` // 一级分类id
|
||||||
|
CommodityCategoryC2 string `json:"commodityCategoryC2"` // 二级分类id
|
||||||
|
CommodityCategoryC3 string `json:"commodityCategoryC3"` // 三级分类id
|
||||||
|
CommoditySpecifications []struct {
|
||||||
|
CommodityPropGroup string `json:"commodityPropGroup"` // 规格类型id
|
||||||
|
CommodityPropName string `json:"commodityPropName"` // 规格名称
|
||||||
|
SellingPrice float64 `json:"sellingPrice"` // 规格售价
|
||||||
|
SpecificationPic string `json:"specificationPic"` // 规格图
|
||||||
|
OriginalPrice float64 `json:"originalPrice"` // 原价
|
||||||
|
CommodityCode string `json:"commodityCode"` // 商品编号
|
||||||
|
CommodityProp string `json:"commodityProp"` // 规格值id
|
||||||
|
Id int `json:"id"`
|
||||||
|
CommodityPropGroupName string `json:"commodityPropGroupName"` // 规格类型名称
|
||||||
|
SpecificationCode string `json:"specificationCode"` // 商品规格编号
|
||||||
|
Status string `json:"status"` // 商品规格状态 1=上架 2=下架
|
||||||
|
} `json:"commoditySpecifications"` // 规格参数
|
||||||
|
CommodityCode string `json:"commodityCode"` // 商品编码
|
||||||
|
CommodityFreight struct {
|
||||||
|
ShopCode string `json:"shopCode"`
|
||||||
|
ThresholdAmount float64 `json:"thresholdAmount"` // 运费模版
|
||||||
|
FreightTemplateType int `json:"freightTemplateType"`
|
||||||
|
ProvinceName string `json:"provinceName"` // 不配送省份
|
||||||
|
Id string `json:"id"`
|
||||||
|
TransportationType int `json:"transportationType"` // 配送方式 1=快递
|
||||||
|
ProvinceId string `json:"provinceId"` // 不配送省份id
|
||||||
|
ValuationType int `json:"valuationType"` // 计价方式 1=按金额
|
||||||
|
FreightName string `json:"freightName"`
|
||||||
|
ThresholdFee float64 `json:"thresholdFee"` // 运费模版运费
|
||||||
|
DefaultType int `json:"defaultType"`
|
||||||
|
} `json:"commodityFreight"` // 运费详情
|
||||||
|
Id int `json:"id"`
|
||||||
|
CommodityName string `json:"commodityName"` // 商品名称
|
||||||
|
Status string `json:"status"` // 上下架状态 1=上架 2=下架
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detail @Title 商品详情
|
||||||
|
func (s *sku) Detail(skuCode string) (result SkuDetail, err error) {
|
||||||
|
err = request.Exec(skuDetail, map[string]interface{}{
|
||||||
|
"commodityCode": skuCode,
|
||||||
|
}, &result)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type SkuImage struct {
|
||||||
|
CommodityCode string `json:"commodityCode"`
|
||||||
|
CommodityImg []string `json:"commodityImg"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Image @Title 商品图册
|
||||||
|
func (s *sku) Image(skuCode string) (result SkuImage, err error) {
|
||||||
|
err = request.Exec(skuImage, map[string]interface{}{
|
||||||
|
"commodityCode": skuCode,
|
||||||
|
}, &result)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type SkuStatus struct {
|
||||||
|
CommoditySpecifications []struct {
|
||||||
|
SpecificationCode string `json:"specificationCode"` // 规格编码
|
||||||
|
Status string `json:"status"` // 规格状态 1=上架 2=下架
|
||||||
|
} `json:"commoditySpecifications"`
|
||||||
|
CommodityCode string `json:"commodityCode"` // 商品编码
|
||||||
|
Status int `json:"status"` // 商品状态 1=上架 2=下架
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status @Title 商品状态
|
||||||
|
func (s *sku) Status(skuCode string) (result SkuStatus, err error) {
|
||||||
|
err = request.Exec(skuStatus, map[string]interface{}{
|
||||||
|
"commodityCode": skuCode,
|
||||||
|
}, &result)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type SkuStock struct {
|
||||||
|
CommodityTotalStock int `json:"commodityTotalStock"` // 总库存
|
||||||
|
CommoditySpecifications []struct {
|
||||||
|
SpecificationCode string `json:"specificationCode"` // 规格编码
|
||||||
|
Stock int `json:"stock"` // 规格库存
|
||||||
|
} `json:"commoditySpecifications"`
|
||||||
|
CommodityCode string `json:"commodityCode"` // 商品编码
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stock @Title 商品库存
|
||||||
|
func (s *sku) Stock(skuCode string) (result SkuStock, err error) {
|
||||||
|
err = request.Exec(skuStock, map[string]interface{}{
|
||||||
|
"commodityCode": skuCode,
|
||||||
|
}, &result)
|
||||||
|
return
|
||||||
|
}
|
Loading…
Reference in new issue