update kashangwl

master
李光春 2 years ago
parent 816b8d975f
commit 2a046f32ed

@ -1,55 +0,0 @@
package kashangwl
import (
"strconv"
)
// ApiOrderResult 返回参数
type ApiOrderResult struct {
Code string `json:"code"`
Message string `json:"message"`
Data struct {
ID int64 `json:"id"` // 订单号
ProductID int `json:"product_id"` // 商品编号
ProductName string `json:"product_name"` // 商品名称
ProductType int `json:"product_type"` // 商品类型1充值2卡密3卡券4人工
ProductPrice string `json:"product_price"` // 售价
Quantity int `json:"quantity"` // 购买数量
TotalPrice string `json:"total_price"` // 总支付价格
RefundedAmount float64 `json:"refunded_amount"` // 已退款金额
BuyerCustomerID int `json:"buyer_customer_id"` // 买家编号
BuyerCustomerName string `json:"buyer_customer_name"` // 买家名称
SellerCustomerID int `json:"seller_customer_id"` // 卖家编号
SellerCustomerName string `json:"seller_customer_name"` // 卖家名称
State int `json:"state"` // 订单状态100等待发货101正在充值200交易成功500交易失败501未知状态
CreatedAt string `json:"created_at"` // 下单时间
RechargeAccount string `json:"recharge_account"` // 充值账号
ProgressInit int `json:"progress_init"` // 充值进度:初始值
ProgressNow int `json:"progress_now"` // 充值进度:现在值
ProgressTarget int `json:"progress_target"` // 充值进度:目标值
RechargeInfo string `json:"recharge_info"` // 返回信息
RechargeUrl string `json:"recharge_url"` // 卡密充值网址
Cards []struct {
No string `json:"no"`
Password string `json:"password"`
} `json:"cards"` //【卡密类订单】卡密
RechargeParams string `json:"recharge_params"` //【充值类订单】
OuterOrderID string `json:"outer_order_id,omitempty"` // 外部订单号
} `json:"data"`
}
// ApiOrder 获取单个订单信息 http://doc.cqmeihu.cn/sales/OrderInfo.html
func (app *App) ApiOrder(orderId int64) (body []byte, err error) {
// 参数
params := NewParams()
params.Set("order_id", orderId)
// 请求
body, err = app.request("http://www.kashangwl.com/api/order", params)
return body, err
}
// ApiOrderToPrice 价格单位转换
func (app *App) ApiOrderToPrice(price string) (priceFloat64 float64) {
priceFloat64, _ = strconv.ParseFloat(price, 64)
return priceFloat64
}

@ -1,7 +1,8 @@
package kashangwl
// ApiBuyResult 返回参数
type ApiBuyResult struct {
import "encoding/json"
type BuyResponse struct {
Code string `json:"code"`
Message string `json:"message"`
Data struct {
@ -21,11 +22,25 @@ type ApiBuyResult struct {
} `json:"data"`
}
// ApiBuy 购买商品 http://doc.cqmeihu.cn/sales/BuyProduct.html
func (app *App) ApiBuy(notMustParams ...Params) (body []byte, err error) {
type BuyResult struct {
Result BuyResponse // 结果
Body []byte // 内容
Err error // 错误
}
func NewBuyResult(result BuyResponse, body []byte, err error) *BuyResult {
return &BuyResult{Result: result, Body: body, Err: err}
}
// Buy 购买商品
// http://doc.cqmeihu.cn/sales/BuyProduct.html
func (app *App) Buy(notMustParams ...Params) *BuyResult {
// 参数
params := app.NewParamsWith(notMustParams...)
// 请求
body, err = app.request("http://www.kashangwl.com/api/buy", params)
return body, err
body, err := app.request("http://www.kashangwl.com/api/buy", params)
// 定义
var response BuyResponse
err = json.Unmarshal(body, &response)
return NewBuyResult(response, body, err)
}

@ -1,43 +1,64 @@
package kashangwl
// OrderResult 返回参数
type OrderResult struct {
import (
"encoding/json"
)
type OrderResponse struct {
Code string `json:"code"`
Message string `json:"message"`
Data struct {
Id int64 `json:"id"`
ProductId int `json:"product_id"`
ProductName string `json:"product_name"`
ProductType int `json:"product_type"`
ProductPrice string `json:"product_price"`
Quantity int `json:"quantity"`
TotalPrice string `json:"total_price"`
RefundedAmount string `json:"refunded_amount"`
BuyerCustomerId int `json:"buyer_customer_id"`
BuyerCustomerName string `json:"buyer_customer_name"`
State int `json:"state"`
CreatedAt string `json:"created_at"`
OuterOrderId string `json:"outer_order_id"`
RechargeAccount string `json:"recharge_account"`
RechargeParams string `json:"recharge_params"`
RechargeInfo string `json:"recharge_info"`
RechargeUrl string `json:"recharge_url"`
Cards []struct {
ID int64 `json:"id"` // 订单号
ProductID int `json:"product_id"` // 商品编号
ProductName string `json:"product_name"` // 商品名称
ProductType int `json:"product_type"` // 商品类型1充值2卡密3卡券4人工
ProductPrice string `json:"product_price"` // 售价
Quantity int `json:"quantity"` // 购买数量
TotalPrice string `json:"total_price"` // 总支付价格
RefundedAmount float64 `json:"refunded_amount"` // 已退款金额
BuyerCustomerID int `json:"buyer_customer_id"` // 买家编号
BuyerCustomerName string `json:"buyer_customer_name"` // 买家名称
SellerCustomerID int `json:"seller_customer_id"` // 卖家编号
SellerCustomerName string `json:"seller_customer_name"` // 卖家名称
State int `json:"state"` // 订单状态100等待发货101正在充值200交易成功500交易失败501未知状态
CreatedAt string `json:"created_at"` // 下单时间
RechargeAccount string `json:"recharge_account"` // 充值账号
ProgressInit int `json:"progress_init"` // 充值进度:初始值
ProgressNow int `json:"progress_now"` // 充值进度:现在值
ProgressTarget int `json:"progress_target"` // 充值进度:目标值
RechargeInfo string `json:"recharge_info"` // 返回信息
RechargeUrl string `json:"recharge_url"` // 卡密充值网址
Cards []struct {
No string `json:"no"`
Password string `json:"password"`
} `json:"cards"`
} `json:"cards"` //【卡密类订单】卡密
RechargeParams string `json:"recharge_params"` //【充值类订单】
OuterOrderID string `json:"outer_order_id,omitempty"` // 外部订单号
} `json:"data"`
}
type OrderResult struct {
Result OrderResponse // 结果
Body []byte // 内容
Err error // 错误
}
func NewOrderResult(result OrderResponse, body []byte, err error) *OrderResult {
return &OrderResult{Result: result, Body: body, Err: err}
}
// Order 获取单个订单信息。
// 仅能获取自己购买的订单。
// http://doc.cqmeihu.cn/sales/OrderInfo.html
func (app App) Order(orderId string) (body []byte, err error) {
func (app App) Order(orderId string) *OrderResult {
// 参数
param := NewParams()
param.Set("order_id", orderId)
params := app.NewParamsWith(param)
// 请求
body, err = app.request("http://www.kashangwl.com/api/order", params)
return body, err
body, err := app.request("http://www.kashangwl.com/api/order", params)
// 定义
var response OrderResponse
err = json.Unmarshal(body, &response)
return NewOrderResult(response, body, err)
}

@ -1,7 +1,8 @@
package kashangwl
// ProductResult 返回参数
type ProductResult struct {
import "encoding/json"
type ProductResponse struct {
Code string `json:"code"`
Message string `json:"message"`
Data struct {
@ -19,38 +20,26 @@ type ProductResult struct {
} `json:"data"`
}
// Product 获取单个商品信息
// http://doc.cqmeihu.cn/sales/product-info.html
func (app App) Product(productId int64) (body []byte, err error) {
// 参数
params := NewParams()
params.Set("product_id", productId)
// 请求
body, err = app.request("http://www.kashangwl.com/api/product", params)
return body, err
type ProductResult struct {
Result ProductResponse // 结果
Body []byte // 内容
Err error // 错误
}
// ProductRechargeParamsResult 返回参数
type ProductRechargeParamsResult struct {
Code string `json:"code"`
Message string `json:"message"`
Data struct {
RechargeAccountLabel string `json:"recharge_account_label"`
RechargeParams []struct {
Name string `json:"name"`
Type string `json:"type"`
Options string `json:"options"`
} `json:"recharge_params"`
} `json:"data"`
func NewProductResult(result ProductResponse, body []byte, err error) *ProductResult {
return &ProductResult{Result: result, Body: body, Err: err}
}
// ProductRechargeParams 接口说明
// 获取商品的充值参数(仅支持充值类商品)
// http://doc.cqmeihu.cn/sales/ProductParams.html
func (app App) ProductRechargeParams(notMustParams ...Params) (body []byte, err error) {
// Product 获取单个商品信息
// http://doc.cqmeihu.cn/sales/product-info.html
func (app App) Product(productId int64) *ProductResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params := NewParams()
params.Set("product_id", productId)
// 请求
body, err = app.request("http://www.kashangwl.com/api/product/recharge-params", params)
return body, err
body, err := app.request("http://www.kashangwl.com/api/product", params)
// 定义
var response ProductResponse
err = json.Unmarshal(body, &response)
return NewProductResult(response, body, err)
}

@ -0,0 +1,40 @@
package kashangwl
import "encoding/json"
type ProductRechargeParamsResponse struct {
Code string `json:"code"`
Message string `json:"message"`
Data struct {
RechargeAccountLabel string `json:"recharge_account_label"`
RechargeParams []struct {
Name string `json:"name"`
Type string `json:"type"`
Options string `json:"options"`
} `json:"recharge_params"`
} `json:"data"`
}
type ProductRechargeParamsResult struct {
Result ProductRechargeParamsResponse // 结果
Body []byte // 内容
Err error // 错误
}
func NewProductRechargeParamsResult(result ProductRechargeParamsResponse, body []byte, err error) *ProductRechargeParamsResult {
return &ProductRechargeParamsResult{Result: result, Body: body, Err: err}
}
// ProductRechargeParams 接口说明
// 获取商品的充值参数(仅支持充值类商品)
// http://doc.cqmeihu.cn/sales/ProductParams.html
func (app App) ProductRechargeParams(notMustParams ...Params) *ProductRechargeParamsResult {
// 参数
params := app.NewParamsWith(notMustParams...)
// 请求
body, err := app.request("http://www.kashangwl.com/api/product/recharge-params", params)
// 定义
var response ProductRechargeParamsResponse
err = json.Unmarshal(body, &response)
return NewProductRechargeParamsResult(response, body, err)
}
Loading…
Cancel
Save