-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
453d666
commit e514305
Showing
5 changed files
with
190 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package sdk | ||
|
||
import ( | ||
"github.com/polaris-team/dingtalk-sdk-golang/encrypt" | ||
"github.com/polaris-team/dingtalk-sdk-golang/http" | ||
"github.com/polaris-team/dingtalk-sdk-golang/json" | ||
"strconv" | ||
) | ||
|
||
//内购商品订单处理完成 | ||
//doc:https://ding-doc.dingtalk.com/doc#/serverapi3/lg1nb7/NqyuB | ||
func (client *DingTalkClient) OrderFinish(orderId int64) (*BaseResp, error) { | ||
params := map[string]string{ | ||
"access_token": client.AccessToken, | ||
"biz_order_id": strconv.FormatInt(orderId, 10), | ||
} | ||
body, err := http.Post("https://oapi.dingtalk.com/topapi/appstore/internal/order/finish", params, "") | ||
resp := BaseResp{} | ||
if err != nil { | ||
return nil, err | ||
} | ||
json.FromJson(body, &resp) | ||
return &resp, err | ||
} | ||
|
||
//获取内购商品SKU页面地址 | ||
//doc:https://ding-doc.dingtalk.com/doc#/serverapi3/lg1nb7/Uxjfs | ||
func (client *DingTalkClient) GetSkuPage(goodsCode string, callBackPage string) (GetSkuPageResp, error) { | ||
params := map[string]string{ | ||
"access_token": client.AccessToken, | ||
"goods_code": goodsCode, | ||
} | ||
if callBackPage != "" { | ||
params["callback_page"] = encrypt.URLEncode(callBackPage) | ||
} | ||
body, err := http.Get("https://oapi.dingtalk.com/topapi/appstore/internal/skupage/get", params) | ||
resp := GetSkuPageResp{} | ||
if err != nil { | ||
return resp, err | ||
} | ||
json.FromJson(body, &resp) | ||
return resp, err | ||
} | ||
|
||
//获取内购订单信息 | ||
//doc:https://ding-doc.dingtalk.com/doc#/serverapi3/lg1nb7/MgHqh | ||
func (client *DingTalkClient) GetOrderInfo(orderId int64) (GetOrderInfoResp, error) { | ||
params := map[string]string{ | ||
"access_token": client.AccessToken, | ||
"biz_order_id": strconv.FormatInt(orderId, 10), | ||
} | ||
body, err := http.Get("https://oapi.dingtalk.com/topapi/appstore/internal/order/get", params) | ||
resp := GetOrderInfoResp{} | ||
if err != nil { | ||
return resp, err | ||
} | ||
json.FromJson(body, &resp) | ||
return resp, err | ||
} | ||
|
||
//应用内购商品核销 | ||
//doc:https://ding-doc.dingtalk.com/doc#/serverapi3/lg1nb7/XbiVN | ||
func (client *DingTalkClient) OrderConsume(orderId int64, requestId string, quantity int, userId string) (*BaseResp, error) { | ||
params := map[string]string{ | ||
"access_token": client.AccessToken, | ||
"biz_order_id": strconv.FormatInt(orderId, 10), | ||
"request_id": requestId, | ||
"quantity": strconv.Itoa(quantity), | ||
"userid": userId, | ||
} | ||
body, err := http.Post("https://oapi.dingtalk.com/topapi/appstore/internal/order/consume", params, "") | ||
resp := BaseResp{} | ||
if err != nil { | ||
return nil, err | ||
} | ||
json.FromJson(body, &resp) | ||
return &resp, err | ||
} | ||
|
||
//获取未处理的已支付订单 | ||
//doc:https://ding-doc.dingtalk.com/doc#/serverapi3/lg1nb7/2abS0 | ||
func (client *DingTalkClient) GetUnfinishOrderList(itemCode string, page int64, size int64) (GetUnfinishOrderListResp, error) { | ||
params := map[string]string{ | ||
"access_token": client.AccessToken, | ||
"page": strconv.FormatInt(page, 10), | ||
"page_size": strconv.FormatInt(size, 10), | ||
} | ||
if itemCode != "" { | ||
params["item_code"] = itemCode | ||
} | ||
body, err := http.Get("https://oapi.dingtalk.com/topapi/appstore/internal/unfinishedorder/list", params) | ||
resp := GetUnfinishOrderListResp{} | ||
if err != nil { | ||
return resp, err | ||
} | ||
json.FromJson(body, &resp) | ||
return resp, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package sdk | ||
|
||
import ( | ||
"github.com/polaris-team/dingtalk-sdk-golang/json" | ||
"testing" | ||
) | ||
|
||
func TestDingTalkClient_GetOrderInfo(t *testing.T) { | ||
client := CreateClient() | ||
res, err := client.GetOrderInfo(50010505110088) | ||
t.Log(err) | ||
t.Log(res) | ||
} | ||
|
||
func TestDingTalkClient_GetSkuPage(t *testing.T) { | ||
client := CreateClient() | ||
res, err := client.GetSkuPage("FW_GOODS_1111", "https://apptest.bjx.cloud") | ||
t.Log(err) | ||
t.Log(res) | ||
} | ||
|
||
func TestDingTalkClient_OrderFinish(t *testing.T) { | ||
client := CreateClient() | ||
res, err := client.OrderFinish(50010505110088) | ||
t.Log(err) | ||
t.Log(res) | ||
} | ||
|
||
func TestDingTalkClient_OrderConsume(t *testing.T) { | ||
client := CreateClient() | ||
res, err := client.OrderConsume(50010505110088, "1199291922", 1, "12") | ||
t.Log(err) | ||
t.Log(res) | ||
} | ||
|
||
func TestDingTalkClient_GetUnfinishOrderList(t *testing.T) { | ||
client := CreateClient() | ||
res, err := client.GetUnfinishOrderList("", 1, 10) | ||
t.Log(err) | ||
t.Log(json.ToJson(res)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package sdk | ||
|
||
type GetSkuPageResp struct { | ||
BaseResp | ||
Result string `json:"result"` | ||
} | ||
|
||
type GetOrderInfoResp struct { | ||
BaseResp | ||
Result OrderInfo `json:"result"` | ||
} | ||
|
||
type OrderInfo struct { | ||
CreateTimestamp int64 `json:"create_timestamp"` | ||
StartTimestamp int64 `json:"start_timestamp"` | ||
EndTimestamp int64 `json:"end_timestamp"` | ||
PaidTimestamp int64 `json:"paid_timestamp"` | ||
Quantity int `json:"quantity"` | ||
Status int `json:"status"` | ||
TotalActualPayFee int64 `json:"total_actual_pay_fee"` | ||
GoodsCode string `json:"goods_code"` | ||
ItemCode string `json:"item_code"` | ||
CorpId string `json:"corp_id"` | ||
BizOrderId int64 `json:"biz_order_id"` | ||
} | ||
|
||
type GetUnfinishOrderListResp struct { | ||
BaseResp | ||
Result UnfinishOrderList `json:"result"` | ||
} | ||
|
||
type UnfinishOrderList struct { | ||
Items UnfinishOrderInfo `json:"items"` | ||
} | ||
|
||
type UnfinishOrderInfo struct { | ||
BizOrderId int64 `json:"biz_order_id"` | ||
corpId string `json:"corp_id"` | ||
CreateTimestamp int64 `json:"create_timestamp"` | ||
GoodsCode string `json:"goods_code"` | ||
ItemCode string `json:"item_code"` | ||
PaidTimestamp int64 `json:"paid_timestamp"` | ||
Quantity int `json:"quantity"` | ||
Status int `json:"status"` | ||
TotalActualPayFee int64 `json:"total_actual_pay_fee"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters