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

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

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