feat: 下单接口
This commit is contained in:
parent
76421e59b9
commit
6482c984fc
|
|
@ -21,5 +21,9 @@ service yl {
|
|||
@doc "卡密同步发放接口"
|
||||
@handler yl
|
||||
post /key/send (Req) returns (Resp)
|
||||
|
||||
@doc "卡密异步发放接口"
|
||||
@handler ylAsync
|
||||
post /key/asyncSend (AsyncReq) returns (AsyncResp)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,4 +28,23 @@ type Resp{
|
|||
}
|
||||
|
||||
|
||||
type AsyncReq {
|
||||
DeliverOrderNo string `json:"deliverOrderNo"` // 平台订单号
|
||||
Price int64 `json:"price"` //结算价格(单位:厘)
|
||||
RequestTime int64 `json:"requestTime"` // 请求时间
|
||||
CreateTime int64 `json:"createTime"` // 订单创建时间,对账时间请用此时间
|
||||
skuId int64 `json:"skuId"` // 平台sku
|
||||
SupplierSkuId int64 `json:"supplierSkuId"` // 供货商sku
|
||||
SupplierId int64 `json:"supplierId"` // 供货商id
|
||||
Account string `json:"thirdSkuId"` // 充值账号
|
||||
ExtendParams string `json:"extendParams"` // 额外参数
|
||||
Count int64 `json:"count"` //数量(此字段只目前支持是金豆,积分等虚拟资产,其他商品不支持)
|
||||
Sign string `json:"sign"`
|
||||
}
|
||||
|
||||
|
||||
type AsyncResp {
|
||||
SupplierOrderNo string `json:"supplierOrderNo"` // 供货商订单号
|
||||
Msg string `json:"msg"` // 返回信息
|
||||
Status int `json:"status"` // 错误码: 0-成功 1-失败
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ type Config struct {
|
|||
Url string
|
||||
Key string
|
||||
}
|
||||
YouleHost string
|
||||
}
|
||||
|
||||
type Rpc struct {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
|
|
@ -15,6 +17,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SignMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
// 卡密异步发放接口
|
||||
Method: http.MethodPost,
|
||||
Path: "/key/asyncSend",
|
||||
Handler: yl.YlAsyncHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 卡密同步发放接口
|
||||
Method: http.MethodPost,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
package yl
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"rs/cmd/api/internal/logic/yl"
|
||||
"rs/cmd/api/internal/svc"
|
||||
"rs/cmd/api/internal/types"
|
||||
)
|
||||
|
||||
// 卡密异步发放接口
|
||||
func YlAsyncHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AsyncReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := yl.NewYlAsyncLogic(r.Context(), svcCtx)
|
||||
resp, err := l.YlAsync(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
package yl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/bytedance/sonic"
|
||||
"rs/cmd/api/internal/logic/vo"
|
||||
"rs/rpc/transfer"
|
||||
"rs/untils/httpclient"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"rs/cmd/api/internal/svc"
|
||||
"rs/cmd/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type YlAsyncLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 卡密异步发放接口
|
||||
func NewYlAsyncLogic(ctx context.Context, svcCtx *svc.ServiceContext) *YlAsyncLogic {
|
||||
return &YlAsyncLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *YlAsyncLogic) YlAsync(req *types.AsyncReq) (resp *types.AsyncResp, err error) {
|
||||
var (
|
||||
reqData transfer.MarketKeySendReq
|
||||
extendParam types.KeySendExtendParam
|
||||
)
|
||||
err = sonic.Unmarshal([]byte(req.ExtendParams), &extendParam)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("extendParam 格式错误")
|
||||
}
|
||||
|
||||
reqData = transfer.MarketKeySendReq{
|
||||
AppId: extendParam.AppId,
|
||||
ReqCode: "voucher.create",
|
||||
MemId: fmt.Sprintf("%d", req.SupplierId),
|
||||
ReqSerialNo: req.DeliverOrderNo,
|
||||
Timestamp: time.Unix(req.CreateTime, 0).Format("20060102150405"),
|
||||
PosId: extendParam.PosId,
|
||||
VoucherId: strconv.Itoa(int(req.SupplierSkuId)),
|
||||
VoucherNum: extendParam.Num,
|
||||
MobileNo: extendParam.MobileNo,
|
||||
SendMsg: extendParam.SendMsg,
|
||||
}
|
||||
if reqData.SendMsg == "" {
|
||||
reqData.SendMsg = "2"
|
||||
}
|
||||
reqData.Sign = l.svcCtx.Config.Sys.PrimaryKey
|
||||
result, err := l.svcCtx.TransferRpc.MarketKeySend(l.ctx, &reqData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("rpc请求失败:%v", err.Error())
|
||||
}
|
||||
|
||||
var status = 1
|
||||
if result.ErrCode != vo.RES_SUCCESS {
|
||||
return nil, fmt.Errorf("请求失败:%v", result.Msg)
|
||||
}
|
||||
|
||||
if result.Data == nil {
|
||||
return nil, fmt.Errorf("请求失败:%v", result.Msg)
|
||||
}
|
||||
return &types.AsyncResp{
|
||||
Msg: "",
|
||||
Status: status,
|
||||
SupplierOrderNo: result.Data.VoucherCode,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (l *YlAsyncLogic) getExchangeUrl(voucherCode string) string {
|
||||
if strings.Contains(voucherCode, "http") {
|
||||
return voucherCode
|
||||
}
|
||||
return fmt.Sprintf("%s%s", l.svcCtx.Config.Sys.Url, voucherCode)
|
||||
}
|
||||
|
||||
// 往营销系统下单,返回数据,通知下游系统
|
||||
func (l *YlAsyncLogic) asyncSendMarket(req *types.NotifyReq) (result *types.NotifyResp, err error) {
|
||||
targetUrl := l.svcCtx.Config.YouleHost + "/supplier/order/sendResultNotify"
|
||||
var header = map[string]string{"Content-Type": "application/json;charset=UTF-8"}
|
||||
|
||||
body, err := sonic.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求失败:%v", err.Error())
|
||||
}
|
||||
resp, err := httpclient.FastHttpPost(targetUrl, header, body, 0)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求失败:%v", err.Error())
|
||||
}
|
||||
|
||||
result = &types.NotifyResp{}
|
||||
// todo 解析返回数据
|
||||
err = sonic.Unmarshal(resp, result)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
@ -1,6 +1,28 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.2
|
||||
|
||||
package types
|
||||
|
||||
type AsyncReq struct {
|
||||
DeliverOrderNo string `json:"deliverOrderNo"` // 平台订单号
|
||||
Price int64 `json:"price"` //结算价格(单位:厘)
|
||||
RequestTime int64 `json:"requestTime"` // 请求时间
|
||||
CreateTime int64 `json:"createTime"` // 订单创建时间,对账时间请用此时间
|
||||
SkuId int64 `json:"skuId"` // 平台sku
|
||||
SupplierSkuId int64 `json:"supplierSkuId"` // 供货商sku
|
||||
SupplierId int64 `json:"supplierId"` // 供货商id
|
||||
Account string `json:"thirdSkuId"` // 充值账号
|
||||
ExtendParams string `json:"extendParams"` // 额外参数
|
||||
Count int64 `json:"count"` //数量(此字段只目前支持是金豆,积分等虚拟资产,其他商品不支持)
|
||||
Sign string `json:"sign"`
|
||||
}
|
||||
|
||||
type AsyncResp struct {
|
||||
SupplierOrderNo string `json:"supplierOrderNo"` // 供货商订单号
|
||||
Msg string `json:"msg"` // 返回信息
|
||||
Status int `json:"status"` // 错误码: 0-成功 1-失败
|
||||
}
|
||||
|
||||
type Empty struct {
|
||||
}
|
||||
|
||||
|
|
@ -23,3 +45,25 @@ type Resp struct {
|
|||
StartTime string `json:"startTime"`
|
||||
EndTime string `json:"endTime"`
|
||||
}
|
||||
|
||||
type NotifyReq struct {
|
||||
DeliverOrderNo string `json:"deliverOrderNo"` // 平台订单号
|
||||
SupplierOrderNo string `json:"supplierOrderNo"` // 供货商订单号
|
||||
SupplierSkuId int64 `json:"supplierSkuId"` // 供货商sku
|
||||
RequestTime int64 `json:"requestTime"` // 请求时间
|
||||
Account string `json:"thirdSkuId"` // 充值账号
|
||||
Status int `json:"status"` //错误码: 1-发货成功 2-发货失败
|
||||
Msg string `json:"msg"` // 错误信息
|
||||
Price int64 `json:"price"` //结算价格(单位:厘)
|
||||
SupplierId int64 `json:"supplierId"` // 供货商id
|
||||
CardNo string `json:"cardNo"` // 卡号,可为空字符串
|
||||
CardKey string `json:"cardKey"` // 卡密,可为空字符串
|
||||
CardExpireTime string `json:"cardExpireTime"` // 卡密过期时间,可为空字符串
|
||||
CardExchangeUrl string `json:"cardExchangeUrl"` // 卡密兑换地址,可为空字符串
|
||||
Sign string `json:"sign"`
|
||||
}
|
||||
|
||||
type NotifyResp struct {
|
||||
Status int `json:"status"` // 错误码: 0-成功 1-失败
|
||||
Msg string `json:"msg"` // 返回信息
|
||||
}
|
||||
|
|
|
|||
14
go.mod
14
go.mod
|
|
@ -13,6 +13,7 @@ require (
|
|||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 // indirect
|
||||
github.com/andybalholm/brotli v1.1.1 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/buger/jsonparser v1.1.1 // indirect
|
||||
github.com/bytedance/sonic v1.11.9 // indirect
|
||||
|
|
@ -45,6 +46,7 @@ require (
|
|||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
|
|
@ -65,6 +67,8 @@ require (
|
|||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
github.com/spf13/cast v1.6.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.57.0 // indirect
|
||||
go.etcd.io/etcd/api/v3 v3.5.13 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.13 // indirect
|
||||
go.etcd.io/etcd/client/v3 v3.5.13 // indirect
|
||||
|
|
@ -84,12 +88,12 @@ require (
|
|||
go.uber.org/multierr v1.9.0 // indirect
|
||||
go.uber.org/zap v1.24.0 // indirect
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/net v0.30.0 // indirect
|
||||
golang.org/x/oauth2 v0.17.0 // indirect
|
||||
golang.org/x/sync v0.6.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/term v0.19.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
golang.org/x/term v0.25.0 // indirect
|
||||
golang.org/x/text v0.19.0 // indirect
|
||||
golang.org/x/time v0.5.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
|
||||
|
|
|
|||
37
go.sum
37
go.sum
|
|
@ -755,6 +755,8 @@ github.com/alicebob/miniredis/v2 v2.32.1/go.mod h1:AqkLNAfUm0K07J28hnAyyQKf/x0Yk
|
|||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 h1:PpfENOj/vPfhhy9N2OFRjpue0hjM5XqAp2thFmkXXIk=
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704/go.mod h1:RcDobYh8k5VP6TNybz9m++gL3ijVI5wueVr0EM10VsU=
|
||||
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
|
||||
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
|
||||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||
github.com/apache/arrow/go/v10 v10.0.1/go.mod h1:YvhnlEePVnBS4+0z3fhPfUy7W1Ikj0Ih0vcRo/gZ1M0=
|
||||
github.com/apache/arrow/go/v11 v11.0.0/go.mod h1:Eg5OsL5H+e299f7u5ssuXsuHQVEGC4xei5aX110hRiI=
|
||||
|
|
@ -867,6 +869,8 @@ github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4Nij
|
|||
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
|
||||
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
|
||||
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/fullstorydev/grpcurl v1.8.7/go.mod h1:pVtM4qe3CMoLaIzYS8uvTuDj2jVYmXqMUkZeijnXp/E=
|
||||
|
|
@ -1095,7 +1099,6 @@ github.com/jhump/goprotoc v0.5.0/go.mod h1:VrbvcYrQOrTi3i0Vf+m+oqQWk9l72mjkJCYo7
|
|||
github.com/jhump/protoreflect v1.11.0/go.mod h1:U7aMIjN0NWq9swDP7xDdoMfRHb35uiuTd3Z9nFXJf5E=
|
||||
github.com/jhump/protoreflect v1.12.0/go.mod h1:JytZfP5d0r8pVNLZvai7U/MCuTWITgrI4tTg7puQFKI=
|
||||
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
|
||||
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
|
||||
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
|
||||
|
|
@ -1125,6 +1128,8 @@ github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47e
|
|||
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
|
||||
github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
|
||||
github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4=
|
||||
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
||||
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||
|
|
@ -1339,6 +1344,10 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8
|
|||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/urfave/cli/v2 v2.11.0/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.57.0 h1:Xw8SjWGEP/+wAAgyy5XTvgrWlOD1+TxbbvNADYCm1Tg=
|
||||
github.com/valyala/fasthttp v1.57.0/go.mod h1:h6ZBaPRlzpZ6O3H5t2gEk1Qi33+TmLvfwgLLp0t9CpE=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
|
||||
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
|
||||
|
|
@ -1346,6 +1355,8 @@ github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgk
|
|||
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
|
||||
github.com/xhit/go-str2duration v1.2.0/go.mod h1:3cPSlfZlUHVlneIVfePFWcJZsuwf+P1v2SRTV4cUmp4=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
|
|
@ -1589,8 +1600,8 @@ golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
|||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
|
||||
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
|
||||
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
|
||||
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
|
||||
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
|
||||
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
|
|
@ -1644,8 +1655,8 @@ golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJ
|
|||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
|
|
@ -1748,8 +1759,8 @@ golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
|
|
@ -1763,8 +1774,8 @@ golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
|
|||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo=
|
||||
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
|
||||
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
|
||||
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
|
||||
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
|
||||
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
|
@ -1783,8 +1794,8 @@ golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
|||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
||||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
|
|
@ -1865,8 +1876,8 @@ golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
|
|||
golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
|
||||
golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
|
||||
golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM=
|
||||
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
|
||||
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
|
|
|||
|
|
@ -0,0 +1,97 @@
|
|||
package httpclient
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
"time"
|
||||
)
|
||||
|
||||
func FastHttpPost(url string, header map[string]string, body []byte, timeout int) ([]byte, error) {
|
||||
req := fasthttp.AcquireRequest()
|
||||
defer fasthttp.ReleaseRequest(req) // 用完需要释放资源
|
||||
// 默认是application/x-www-form-urlencoded
|
||||
req.Header.SetMethod("POST")
|
||||
for k, v := range header {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
req.SetRequestURI(url)
|
||||
req.SetBody(body)
|
||||
resp := fasthttp.AcquireResponse()
|
||||
defer fasthttp.ReleaseResponse(resp) // 用完需要释放资源
|
||||
var err error
|
||||
if timeout <= 0 {
|
||||
if err = fasthttp.Do(req, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err = fasthttp.DoTimeout(req, resp, time.Duration(timeout)*time.Second); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
b := resp.Body()
|
||||
//fmt.Println(string(b),"http请求")
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func FastHttpPostForm(url string, header map[string]string, body map[string]string, timeout int) ([]byte, error) {
|
||||
req := fasthttp.AcquireRequest()
|
||||
defer fasthttp.ReleaseRequest(req) // 用完需要释放资源
|
||||
// 默认是application/x-www-form-urlencoded
|
||||
req.Header.SetMethod("POST")
|
||||
for k, v := range header {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
req.SetRequestURI(url)
|
||||
args := &fasthttp.Args{}
|
||||
for k, v := range body {
|
||||
args.Add(k, v)
|
||||
}
|
||||
req.SetBody(args.QueryString())
|
||||
resp := fasthttp.AcquireResponse()
|
||||
defer fasthttp.ReleaseResponse(resp) // 用完需要释放资源
|
||||
var err error
|
||||
if timeout == 0 {
|
||||
if err = fasthttp.Do(req, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err := fasthttp.DoTimeout(req, resp, time.Duration(timeout)*time.Second); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
b := resp.Body()
|
||||
return b, nil
|
||||
}
|
||||
func FastHttpGet(url string, header map[string]string, body map[string]string, timeout int) ([]byte, error) {
|
||||
req := fasthttp.AcquireRequest()
|
||||
defer fasthttp.ReleaseRequest(req) // 用完需要释放资源
|
||||
// 默认是application/x-www-form-urlencoded
|
||||
req.Header.SetMethod("GET")
|
||||
for k, v := range header {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
if len(body) > 0 {
|
||||
url += "?"
|
||||
for k, v := range body {
|
||||
url += k + "=" + v + "&"
|
||||
}
|
||||
url = url[0 : len(url)-1]
|
||||
}
|
||||
fmt.Println(url)
|
||||
req.SetRequestURI(url)
|
||||
resp := fasthttp.AcquireResponse()
|
||||
defer fasthttp.ReleaseResponse(resp) // 用完需要释放资源
|
||||
var err error
|
||||
if timeout == 0 {
|
||||
if err = fasthttp.Do(req, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err := fasthttp.DoTimeout(req, resp, time.Duration(timeout)*time.Second); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
b := resp.Body()
|
||||
return b, nil
|
||||
}
|
||||
Loading…
Reference in New Issue