mtunion回调
This commit is contained in:
43
platformapi/mtunionapi/callback.go
Normal file
43
platformapi/mtunionapi/callback.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package mtunionapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CallBack struct {
|
||||||
|
Errcode string `json:"errcode"`
|
||||||
|
Errmsg string `json:"errmsg"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CallBackResult struct {
|
||||||
|
Smstitle string `json:"smstitle"`
|
||||||
|
Quantity string `json:"quantity"`
|
||||||
|
Orderid string `json:"orderid"`
|
||||||
|
Dealid string `json:"dealid"`
|
||||||
|
Paytime string `json:"paytime"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Ordertime string `json:"ordertime"`
|
||||||
|
Sid string `json:"sid"`
|
||||||
|
UID string `json:"uid"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Total string `json:"total"`
|
||||||
|
Direct string `json:"direct"`
|
||||||
|
Ratio string `json:"ratio"`
|
||||||
|
Sign string `json:"sign"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) GetCallbackMsg(request *http.Request) (call *CallBackResult, err error) {
|
||||||
|
data, err := ioutil.ReadAll(request.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
values, err := utils.HTTPBody2Values(data, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mapData := utils.URLValues2Map(values)
|
||||||
|
utils.Map2StructByJson(mapData, &call, false)
|
||||||
|
return call, err
|
||||||
|
}
|
||||||
@@ -98,6 +98,36 @@ func (a *API) AccessAPI(action string, isPost bool, bizParams map[string]interfa
|
|||||||
return retVal, err
|
return retVal, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *API) AccessAPI2(action string, isPost bool, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||||
|
params := make(map[string]interface{})
|
||||||
|
params["key"] = a.appKey
|
||||||
|
params = utils.MergeMaps(params, bizParams)
|
||||||
|
signStr := a.signParam(params)
|
||||||
|
params[sigKey] = signStr
|
||||||
|
fullURL := utils.GenerateGetURL(prodURL, action, nil)
|
||||||
|
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||||
|
func() *http.Request {
|
||||||
|
var request *http.Request
|
||||||
|
if !isPost {
|
||||||
|
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(fullURL, "", params), nil)
|
||||||
|
} else {
|
||||||
|
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
|
||||||
|
}
|
||||||
|
return request
|
||||||
|
},
|
||||||
|
a.config,
|
||||||
|
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
|
||||||
|
if jsonResult1 == nil {
|
||||||
|
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
retVal = jsonResult1
|
||||||
|
}
|
||||||
|
return errLevel, err
|
||||||
|
})
|
||||||
|
return retVal, err
|
||||||
|
}
|
||||||
|
|
||||||
func (a *API) AccessStorePage(fullURL string, bizParams map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
|
func (a *API) AccessStorePage(fullURL string, bizParams map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
|
||||||
if a.GetCookieCount() == 0 {
|
if a.GetCookieCount() == 0 {
|
||||||
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
|
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
|
||||||
@@ -143,27 +173,27 @@ func (a *API) MiniCode(actID int, userID string) (url string, err error) {
|
|||||||
"sid": strings.ToLower(userID),
|
"sid": strings.ToLower(userID),
|
||||||
"actId": actID,
|
"actId": actID,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if utils.MustInterface2Int64(result["status"]) != 0 {
|
if utils.MustInterface2Int64(result["status"]) != 0 {
|
||||||
return "",fmt.Errorf(result["des"].(string))
|
return "", fmt.Errorf(result["des"].(string))
|
||||||
}else {
|
} else {
|
||||||
return result["data"].(string),err
|
return result["data"].(string), err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return url, err
|
return url, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) GenerateLink(actID,linkType int, userID string) (url string, err error) {
|
func (a *API) GenerateLink(actID, linkType int, userID string) (url string, err error) {
|
||||||
result, err := a.AccessAPI("generateLink", false, map[string]interface{}{
|
result, err := a.AccessAPI("generateLink", false, map[string]interface{}{
|
||||||
"sid": strings.ToLower(userID),
|
"sid": strings.ToLower(userID),
|
||||||
"actId": actID,
|
"actId": actID,
|
||||||
"linkType": linkType,
|
"linkType": linkType,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if utils.MustInterface2Int64(result["status"]) != 0 {
|
if utils.MustInterface2Int64(result["status"]) != 0 {
|
||||||
return "",fmt.Errorf(result["des"].(string))
|
return "", fmt.Errorf(result["des"].(string))
|
||||||
}else {
|
} else {
|
||||||
return result["data"].(string),err
|
return result["data"].(string), err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return url, err
|
return url, err
|
||||||
|
|||||||
@@ -1,34 +1,80 @@
|
|||||||
package mtunionapi
|
package mtunionapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MtUnionOrderTypeTG=0 //团购订单
|
MtUnionOrderTypeTG = 0 //团购订单
|
||||||
MtUnionOrderTypeJD=2 //酒店订单
|
MtUnionOrderTypeJD = 2 //酒店订单
|
||||||
MtUnionOrderTypeWM=4 //外卖订单
|
MtUnionOrderTypeWM = 4 //外卖订单
|
||||||
MtUnionOrderTypeHF=5 //话费订单
|
MtUnionOrderTypeHF = 5 //话费订单
|
||||||
MtUnionOrderTypeSG=6 //闪购订单
|
MtUnionOrderTypeSG = 6 //闪购订单
|
||||||
|
|
||||||
|
defaultPageSize = 50
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *API) OrderList(orderType int, startTime,endTime int64,page int) (url string, err error) {
|
type OrderListResult struct {
|
||||||
result, err := a.AccessAPI("orderList", false, map[string]interface{}{
|
Total int `json:"total"`
|
||||||
"ts": time.Now().Unix(),
|
DataList []struct {
|
||||||
"type": orderType,
|
Smstitle string `json:"smstitle"`
|
||||||
|
Refundprice string `json:"refundprice"`
|
||||||
|
Refundtime string `json:"refundtime"`
|
||||||
|
Orderid string `json:"orderid"`
|
||||||
|
Refundprofit string `json:"refundprofit"`
|
||||||
|
Paytime string `json:"paytime"`
|
||||||
|
Appkey string `json:"appkey"`
|
||||||
|
Payprice string `json:"payprice"`
|
||||||
|
Profit string `json:"profit"`
|
||||||
|
Sid string `json:"sid"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
} `json:"dataList"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) OrderList(orderType int, startTime, endTime int64, page int) (orderListResult *OrderListResult, err error) {
|
||||||
|
result, err := a.AccessAPI2("api/orderList", false, map[string]interface{}{
|
||||||
|
"ts": time.Now().Unix(),
|
||||||
|
"type": orderType,
|
||||||
"startTime": startTime,
|
"startTime": startTime,
|
||||||
"endTime":endTime,
|
"endTime": endTime,
|
||||||
"page":page,
|
"page": page,
|
||||||
"limit":100,
|
"limit": defaultPageSize,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if utils.MustInterface2Int64(result["status"]) != 0 {
|
utils.Map2StructByJson(result, &orderListResult, false)
|
||||||
return "",fmt.Errorf(result["des"].(string))
|
|
||||||
}else {
|
|
||||||
return result["data"].(string),err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return url, err
|
return orderListResult, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CouponListResult struct {
|
||||||
|
Total int `json:"total"`
|
||||||
|
DataList []struct {
|
||||||
|
AppKey string `json:"appKey"`
|
||||||
|
Sid string `json:"sid"`
|
||||||
|
CouponTime string `json:"couponTime"`
|
||||||
|
Money string `json:"money"`
|
||||||
|
MinUseMoney string `json:"minUseMoney"`
|
||||||
|
CouponName string `json:"couponName"`
|
||||||
|
CouponType string `json:"couponType"`
|
||||||
|
CouponCode string `json:"couponCode"`
|
||||||
|
BeginTime int `json:"beginTime"`
|
||||||
|
EndTime int `json:"endTime"`
|
||||||
|
} `json:"dataList"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) CouponList(orderType int, startTime, endTime int64, page int, sid string) (couponListResult *CouponListResult, err error) {
|
||||||
|
result, err := a.AccessAPI2("api/couponList", false, map[string]interface{}{
|
||||||
|
"ts": time.Now().Unix(),
|
||||||
|
"type": orderType,
|
||||||
|
"startTime": startTime,
|
||||||
|
"endTime": endTime,
|
||||||
|
"page": page,
|
||||||
|
"limit": defaultPageSize,
|
||||||
|
"sid": sid,
|
||||||
|
})
|
||||||
|
if err == nil {
|
||||||
|
utils.Map2StructByJson(result, &couponListResult, false)
|
||||||
|
}
|
||||||
|
return couponListResult, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -1 +1,22 @@
|
|||||||
package mtunionapi
|
package mtunionapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestOrderList(t *testing.T) {
|
||||||
|
result, err := api.OrderList(6, utils.Str2Time("2021-01-01").Unix(), utils.Str2Time("2021-04-01").Unix(), 1)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(utils.Format4Output(result, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCouponList(t *testing.T) {
|
||||||
|
result, err := api.CouponList(4, utils.Str2Time("2021-03-19").Unix(), utils.Str2Time("2021-03-25").Unix(), 1, "000000001")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(utils.Format4Output(result, false))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user