parent
a3a184da64
commit
8893bde638
@ -1,8 +0,0 @@
|
||||
package service
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrTypeIsNil = errors.New("类型为Nil")
|
||||
ErrTypeUnknown = errors.New("未处理到的数据类型")
|
||||
)
|
@ -1,186 +0,0 @@
|
||||
package ddk
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/bitly/go-simplejson"
|
||||
"github.com/dtapps/go-library/service"
|
||||
"github.com/nilorg/sdk/convert"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
// ClientId 应用Key
|
||||
ClientId string
|
||||
// ClientSecret 秘密
|
||||
ClientSecret string
|
||||
// Router 环境请求地址
|
||||
Router = "https://gw-api.pinduoduo.com/api/router"
|
||||
// Timeout ...
|
||||
Timeout time.Duration
|
||||
)
|
||||
|
||||
// Parameter 参数
|
||||
type Parameter map[string]interface{}
|
||||
|
||||
// ParameterJsonEncode 参数
|
||||
type ParameterJsonEncode []string
|
||||
|
||||
// copyParameter 复制参数
|
||||
func copyParameter(srcParams Parameter) Parameter {
|
||||
newParams := make(Parameter)
|
||||
for key, value := range srcParams {
|
||||
newParams[key] = value
|
||||
}
|
||||
return newParams
|
||||
}
|
||||
|
||||
// execute 执行API接口
|
||||
func execute(param Parameter) (bytes []byte, err error) {
|
||||
err = checkConfig()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var req *http.Request
|
||||
req, err = http.NewRequest("POST", Router, strings.NewReader(param.getRequestData()))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
|
||||
httpClient := &http.Client{}
|
||||
httpClient.Timeout = Timeout
|
||||
var response *http.Response
|
||||
response, err = httpClient.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if response.StatusCode != 200 {
|
||||
err = fmt.Errorf("请求错误:%d", response.StatusCode)
|
||||
return
|
||||
}
|
||||
defer response.Body.Close()
|
||||
bytes, err = ioutil.ReadAll(response.Body)
|
||||
return
|
||||
}
|
||||
|
||||
// Execute 执行API接口
|
||||
func Execute(method string, param Parameter) (res *simplejson.Json, err error) {
|
||||
param["type"] = method
|
||||
param.setRequestData()
|
||||
|
||||
var bodyBytes []byte
|
||||
bodyBytes, err = execute(param)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return bytesToResult(bodyBytes)
|
||||
}
|
||||
|
||||
func bytesToResult(bytes []byte) (res *simplejson.Json, err error) {
|
||||
res, err = simplejson.NewJson(bytes)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if responseError, ok := res.CheckGet("error_response"); ok {
|
||||
if subMsg, subOk := responseError.CheckGet("sub_msg"); subOk {
|
||||
err = errors.New(subMsg.MustString())
|
||||
} else {
|
||||
err = errors.New(responseError.Get("msg").MustString())
|
||||
}
|
||||
res = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 检查配置
|
||||
func checkConfig() error {
|
||||
if ClientId == "" {
|
||||
return errors.New("ClientId 不能为空")
|
||||
}
|
||||
if ClientSecret == "" {
|
||||
return errors.New("ClientSecret 不能为空")
|
||||
}
|
||||
if Router == "" {
|
||||
return errors.New("Router 不能为空")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p Parameter) setRequestData() {
|
||||
hh, _ := time.ParseDuration("8h")
|
||||
loc := time.Now().UTC().Add(hh)
|
||||
p["timestamp"] = strconv.FormatInt(loc.Unix(), 10)
|
||||
p["client_id"] = ClientId
|
||||
p["data_type"] = "JSON"
|
||||
p["version"] = "v1"
|
||||
// 设置签名
|
||||
p["sign"] = getSign(p)
|
||||
}
|
||||
|
||||
// 获取请求数据
|
||||
func (p Parameter) getRequestData() string {
|
||||
// 公共参数
|
||||
args := url.Values{}
|
||||
// 请求参数
|
||||
for key, val := range p {
|
||||
args.Set(key, interfaceToString(val))
|
||||
}
|
||||
return args.Encode()
|
||||
}
|
||||
|
||||
// 获取签名
|
||||
func getSign(params Parameter) string {
|
||||
// 获取Key
|
||||
var keys []string
|
||||
for k := range params {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
// 排序asc
|
||||
sort.Strings(keys)
|
||||
// 把所有参数名和参数值串在一起
|
||||
query := bytes.NewBufferString(ClientSecret)
|
||||
for _, k := range keys {
|
||||
query.WriteString(k)
|
||||
query.WriteString(interfaceToString(params[k]))
|
||||
}
|
||||
query.WriteString(ClientSecret)
|
||||
// 使用MD5加密
|
||||
h := md5.New()
|
||||
io.Copy(h, query)
|
||||
// 把二进制转化为大写的十六进制
|
||||
return strings.ToUpper(hex.EncodeToString(h.Sum(nil)))
|
||||
}
|
||||
|
||||
func interfaceToString(src interface{}) string {
|
||||
if src == nil {
|
||||
panic(service.ErrTypeIsNil)
|
||||
}
|
||||
switch src.(type) {
|
||||
case string:
|
||||
return src.(string)
|
||||
case int, int8, int32, int64:
|
||||
case uint8, uint16, uint32, uint64:
|
||||
case float32, float64:
|
||||
return convert.ToString(src)
|
||||
}
|
||||
data, err := json.Marshal(src)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(data)
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package eastiot
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/gohttp"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
AppID string
|
||||
ApiKey string
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) ([]byte, error) {
|
||||
// 公共参数
|
||||
params["appId"] = app.AppID
|
||||
params["timeStamp"] = time.Now().Unix()
|
||||
// 签名
|
||||
params["sign"] = app.getSign(app.ApiKey, params)
|
||||
// 请求
|
||||
if method == http.MethodGet {
|
||||
get, err := gohttp.Get(url, params)
|
||||
return get.Body, err
|
||||
} else {
|
||||
postJson, err := gohttp.PostForm(url, params)
|
||||
return postJson.Body, err
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package eastiot
|
||||
|
||||
// Params 请求参数
|
||||
type Params map[string]interface{}
|
||||
|
||||
func NewParams() Params {
|
||||
p := make(Params)
|
||||
return p
|
||||
}
|
||||
|
||||
func (app *App) NewParamsWith(params ...Params) Params {
|
||||
p := make(Params)
|
||||
for _, v := range params {
|
||||
p.SetParams(v)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p Params) Set(key string, value interface{}) {
|
||||
p[key] = value
|
||||
}
|
||||
|
||||
func (p Params) SetParams(params Params) {
|
||||
for key, value := range params {
|
||||
p[key] = value
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package eastiot
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/dtapps/go-library/utils/gomd5"
|
||||
"sort"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (app *App) getSign(ApiKey string, p map[string]interface{}) string {
|
||||
var keys []string
|
||||
for k := range p {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
signStr := ""
|
||||
for _, key := range keys {
|
||||
signStr += fmt.Sprintf("%s=%s&", key, app.getString(p[key]))
|
||||
}
|
||||
signStr += fmt.Sprintf("apiKey=%s", ApiKey)
|
||||
return gomd5.ToUpper(signStr)
|
||||
}
|
||||
|
||||
func (app *App) getString(i interface{}) string {
|
||||
switch v := i.(type) {
|
||||
case string:
|
||||
return v
|
||||
case int:
|
||||
return strconv.Itoa(v)
|
||||
case bool:
|
||||
return strconv.FormatBool(v)
|
||||
default:
|
||||
bytes, _ := json.Marshal(v)
|
||||
return string(bytes)
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package ejiaofei
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dtapps/go-library/utils/gohttp"
|
||||
"github.com/dtapps/go-library/utils/gomd5"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
UserID string
|
||||
Pwd string
|
||||
Key string
|
||||
signStr string
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) ([]byte, error) {
|
||||
// 公共参数
|
||||
params["userid"] = app.UserID
|
||||
params["pwd"] = app.Pwd
|
||||
// 签名
|
||||
params["userkey"] = gomd5.ToUpper(fmt.Sprintf("%s%s", app.signStr, app.Key))
|
||||
// 请求
|
||||
if method == http.MethodGet {
|
||||
get, err := gohttp.Get(url, params)
|
||||
return get.Body, err
|
||||
} else {
|
||||
postJson, err := gohttp.PostForm(url, params)
|
||||
return postJson.Body, err
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package ejiaofei
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type CheckCostResult struct {
|
||||
XMLName xml.Name `xml:"response"`
|
||||
UserID string `xml:"userid"` // 用户账号
|
||||
OrderID string `xml:"orderid"` // 用户提交订单号
|
||||
Face float64 `xml:"face"` // 官方价格
|
||||
Price float64 `xml:"price"` // 用户成本价
|
||||
Error int `xml:"error"` // 错误提示
|
||||
}
|
||||
|
||||
// CheckCost 会员订单成本价查询接口
|
||||
func (app *App) CheckCost(orderID string) (body []byte, err error) {
|
||||
// 参数
|
||||
param := NewParams()
|
||||
param.Set("orderid", orderID)
|
||||
params := app.NewParamsWith(param)
|
||||
// 签名
|
||||
app.signStr = fmt.Sprintf("userid%vpwd%vorderid%v", app.UserID, app.Pwd, orderID)
|
||||
// 请求
|
||||
body, err = app.request("http://api.ejiaofei.net:11140/checkCost.do", params, http.MethodGet)
|
||||
return body, err
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package ejiaofei
|
||||
|
||||
// Params 请求参数
|
||||
type Params map[string]interface{}
|
||||
|
||||
func NewParams() Params {
|
||||
p := make(Params)
|
||||
return p
|
||||
}
|
||||
|
||||
func (app *App) NewParamsWith(params ...Params) Params {
|
||||
p := make(Params)
|
||||
for _, v := range params {
|
||||
p.SetParams(v)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p Params) Set(key string, value interface{}) {
|
||||
p[key] = value
|
||||
}
|
||||
|
||||
func (p Params) SetParams(params Params) {
|
||||
for key, value := range params {
|
||||
p[key] = value
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package ejiaofei
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type QueryTxProductResult struct {
|
||||
XMLName xml.Name `xml:"response"`
|
||||
Error string `xml:"error"` // 错误提示
|
||||
}
|
||||
|
||||
// QueryTxProduct 可充值腾讯产品查询
|
||||
func (app *App) QueryTxProduct() (body []byte, err error) {
|
||||
// 签名
|
||||
app.signStr = fmt.Sprintf("userid%vpwd%v", app.UserID, app.Pwd)
|
||||
// 请求
|
||||
body, err = app.request("http://api.ejiaofei.net:11140/queryTXproduct.do", map[string]interface{}{}, http.MethodGet)
|
||||
return body, err
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/dtapps/go-library/utils/gohttp"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
AppKey string // 应用Key
|
||||
SecretKey string // 密钥
|
||||
}
|
||||
|
||||
type ErrResp struct {
|
||||
Code string `json:"code"`
|
||||
ErrorMessage string `json:"errorMessage"`
|
||||
ErrorSolution string `json:"errorSolution"`
|
||||
}
|
||||
|
||||
func (app *App) request(params map[string]interface{}) (resp []byte, err error) {
|
||||
// 签名
|
||||
app.Sign(params)
|
||||
// 发送请求
|
||||
httpGet, err := gohttp.PostForm("https://api.jd.com/routerjson", params)
|
||||
// 检查错误
|
||||
var errResp ErrResp
|
||||
_ = json.Unmarshal(httpGet.Body, &errResp)
|
||||
return httpGet.Body, err
|
||||
}
|
||||
|
||||
// GoodsPriceToInt64 商品券后价
|
||||
func (app *App) GoodsPriceToInt64(LowestCouponPrice float64) int64 {
|
||||
return int64(LowestCouponPrice * 100)
|
||||
}
|
||||
|
||||
// GoodsOriginalPriceToInt64 商品原价
|
||||
func (app *App) GoodsOriginalPriceToInt64(Price float64) int64 {
|
||||
return int64(Price * 100)
|
||||
}
|
||||
|
||||
// CouponProportionToInt64 佣金比率
|
||||
func (app *App) CouponProportionToInt64(CommissionShare float64) int64 {
|
||||
return int64(CommissionShare * 10)
|
||||
}
|
||||
|
||||
// CouponAmountToInt64 优惠券金额
|
||||
func (app *App) CouponAmountToInt64(Commission float64) int64 {
|
||||
return int64(Commission * 100)
|
||||
}
|
||||
|
||||
// CommissionIntegralToInt64 佣金积分
|
||||
func (app *App) CommissionIntegralToInt64(GoodsPrice, CouponProportion int64) int64 {
|
||||
return (GoodsPrice * CouponProportion) / 1000
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 签名
|
||||
func createSign(signStr string) string {
|
||||
h := md5.New()
|
||||
h.Write([]byte(signStr))
|
||||
cipherStr := h.Sum(nil)
|
||||
return strings.ToUpper(hex.EncodeToString(cipherStr))
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Params 请求参数
|
||||
type Params map[string]interface{}
|
||||
|
||||
func NewParams() Params {
|
||||
p := make(Params)
|
||||
return p
|
||||
}
|
||||
|
||||
func NewParamsWithType(_method string, params ...Params) Params {
|
||||
p := make(Params)
|
||||
p["method"] = _method
|
||||
hh, _ := time.ParseDuration("8h")
|
||||
loc := time.Now().UTC().Add(hh)
|
||||
p["timestamp"] = loc.Format("2006-01-02 15:04:05")
|
||||
p["format"] = "json"
|
||||
p["v"] = "1.0"
|
||||
p["sign_method"] = "md5"
|
||||
for _, v := range params {
|
||||
p.SetParams(v)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (app *App) Sign(p Params) {
|
||||
p["app_key"] = app.AppKey
|
||||
// 排序所有的 key
|
||||
var keys []string
|
||||
for key := range p {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
signStr := app.SecretKey
|
||||
for _, key := range keys {
|
||||
signStr += key + getString(p[key])
|
||||
}
|
||||
signStr += app.SecretKey
|
||||
p["sign"] = createSign(signStr)
|
||||
}
|
||||
|
||||
func (p Params) Set(key string, value interface{}) {
|
||||
p[key] = value
|
||||
}
|
||||
|
||||
func (p Params) SetParams(params Params) {
|
||||
for key, value := range params {
|
||||
p[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
func (p Params) SetCustomParameters(uid string, sid string) {
|
||||
p["custom_parameters"] = map[string]interface{}{
|
||||
"uid": uid,
|
||||
"sid": sid,
|
||||
}
|
||||
}
|
||||
|
||||
func (p Params) GetQuery() string {
|
||||
u := url.Values{}
|
||||
for k, v := range p {
|
||||
u.Set(k, getString(v))
|
||||
}
|
||||
return u.Encode()
|
||||
}
|
||||
|
||||
func getString(i interface{}) string {
|
||||
switch v := i.(type) {
|
||||
case string:
|
||||
return v
|
||||
case []byte:
|
||||
return string(v)
|
||||
case int:
|
||||
return strconv.Itoa(v)
|
||||
case bool:
|
||||
return strconv.FormatBool(v)
|
||||
default:
|
||||
bytes, _ := json.Marshal(v)
|
||||
return string(bytes)
|
||||
}
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
package jdk
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/bitly/go-simplejson"
|
||||
"github.com/dtapps/go-library/service"
|
||||
"github.com/nilorg/sdk/convert"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
// AppKey 应用Key
|
||||
AppKey string
|
||||
// SecretKey 秘密
|
||||
SecretKey string
|
||||
// Router 环境请求地址
|
||||
Router = "https://api.jd.com/routerjson"
|
||||
// Timeout ...
|
||||
Timeout time.Duration
|
||||
)
|
||||
|
||||
// Parameter 参数
|
||||
type Parameter map[string]interface{}
|
||||
|
||||
// copyParameter 复制参数
|
||||
func copyParameter(srcParams Parameter) Parameter {
|
||||
newParams := make(Parameter)
|
||||
for key, value := range srcParams {
|
||||
newParams[key] = value
|
||||
}
|
||||
return newParams
|
||||
}
|
||||
|
||||
// execute 执行API接口
|
||||
func execute(param Parameter) (bytes []byte, err error) {
|
||||
err = checkConfig()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var req *http.Request
|
||||
req, err = http.NewRequest("POST", Router, strings.NewReader(param.getRequestData()))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
|
||||
httpClient := &http.Client{}
|
||||
httpClient.Timeout = Timeout
|
||||
var response *http.Response
|
||||
response, err = httpClient.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if response.StatusCode != 200 {
|
||||
err = fmt.Errorf("请求错误:%d", response.StatusCode)
|
||||
return
|
||||
}
|
||||
defer response.Body.Close()
|
||||
bytes, err = ioutil.ReadAll(response.Body)
|
||||
return
|
||||
}
|
||||
|
||||
// Execute 执行API接口
|
||||
func Execute(method string, param Parameter) (res *simplejson.Json, err error) {
|
||||
param["method"] = method
|
||||
param.setRequestData()
|
||||
|
||||
var bodyBytes []byte
|
||||
bodyBytes, err = execute(param)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return bytesToResult(bodyBytes)
|
||||
}
|
||||
|
||||
func bytesToResult(bytes []byte) (res *simplejson.Json, err error) {
|
||||
res, err = simplejson.NewJson(bytes)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if responseError, ok := res.CheckGet("error_response"); ok {
|
||||
if subMsg, subOk := responseError.CheckGet("sub_msg"); subOk {
|
||||
err = errors.New(subMsg.MustString())
|
||||
} else {
|
||||
err = errors.New(responseError.Get("msg").MustString())
|
||||
}
|
||||
res = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 检查配置
|
||||
func checkConfig() error {
|
||||
if AppKey == "" {
|
||||
return errors.New("AppKey 不能为空")
|
||||
}
|
||||
if SecretKey == "" {
|
||||
return errors.New("SecretKey 不能为空")
|
||||
}
|
||||
if Router == "" {
|
||||
return errors.New("Router 不能为空")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p Parameter) setRequestData() {
|
||||
hh, _ := time.ParseDuration("8h")
|
||||
loc := time.Now().UTC().Add(hh)
|
||||
p["app_key"] = AppKey
|
||||
p["timestamp"] = loc.Format("2006-01-02 15:04:05")
|
||||
p["format"] = "json"
|
||||
p["v"] = "1.0"
|
||||
p["sign_method"] = "md5"
|
||||
// 设置签名
|
||||
p["sign"] = getSign(p)
|
||||
}
|
||||
|
||||
// 获取请求数据
|
||||
func (p Parameter) getRequestData() string {
|
||||
// 公共参数
|
||||
args := url.Values{}
|
||||
// 请求参数
|
||||
for key, val := range p {
|
||||
args.Set(key, interfaceToString(val))
|
||||
}
|
||||
return args.Encode()
|
||||
}
|
||||
|
||||
// 获取签名
|
||||
func getSign(params Parameter) string {
|
||||
// 获取Key
|
||||
keys := []string{}
|
||||
for k := range params {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
// 排序asc
|
||||
sort.Strings(keys)
|
||||
// 把所有参数名和参数值串在一起
|
||||
query := bytes.NewBufferString(SecretKey)
|
||||
for _, k := range keys {
|
||||
query.WriteString(k)
|
||||
query.WriteString(interfaceToString(params[k]))
|
||||
}
|
||||
query.WriteString(SecretKey)
|
||||
// 使用MD5加密
|
||||
h := md5.New()
|
||||
io.Copy(h, query)
|
||||
// 把二进制转化为大写的十六进制
|
||||
return strings.ToUpper(hex.EncodeToString(h.Sum(nil)))
|
||||
}
|
||||
|
||||
func interfaceToString(src interface{}) string {
|
||||
if src == nil {
|
||||
panic(service.ErrTypeIsNil)
|
||||
}
|
||||
switch src.(type) {
|
||||
case string:
|
||||
return src.(string)
|
||||
case int, int8, int32, int64:
|
||||
case uint8, uint16, uint32, uint64:
|
||||
case float32, float64:
|
||||
return convert.ToString(src)
|
||||
}
|
||||
data, err := json.Marshal(src)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(data)
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package meituan
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/dtapps/go-library/utils/gohttp"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// App 美团联盟
|
||||
type App struct {
|
||||
Secret string // 秘钥
|
||||
AppKey string // 渠道标记
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) (resp []byte, err error) {
|
||||
|
||||
// GET方式
|
||||
if method == http.MethodGet {
|
||||
get, err := gohttp.Get(url, params)
|
||||
return get.Body, err
|
||||
} else {
|
||||
// 请求参数
|
||||
paramsStr, err := json.Marshal(params)
|
||||
postJson, err := gohttp.PostJson(url, paramsStr)
|
||||
return postJson.Body, err
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
package meituan
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type OpenapiPoiCategoryResult struct {
|
||||
Code int `json:"code"`
|
||||
Data []struct {
|
||||
Name string `json:"name"`
|
||||
Subcate []struct {
|
||||
Name string `json:"name"` // 品类名称
|
||||
ID int `json:"id"` // 品类id
|
||||
} `json:"subcate"`
|
||||
ID int `json:"id"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
// OpenapiPoiCategory 基础数据 - 品类接口 https://openapi.meituan.com/#api-0.%E5%9F%BA%E7%A1%80%E6%95%B0%E6%8D%AE-GetHttpsOpenapiMeituanComPoiDistrictCityid1
|
||||
func (app *App) OpenapiPoiCategory(cityID int) (result OpenapiPoiCategoryResult, err error) {
|
||||
|
||||
param := NewParams()
|
||||
param.Set("cityid", cityID)
|
||||
|
||||
// 参数
|
||||
params := app.NewParamsWith(param)
|
||||
|
||||
// 请求
|
||||
body, err := app.request("https://openapi.meituan.com/poi/category", params, "GET")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(body, &result); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type OpenapiPoiAreaResult struct {
|
||||
Code int `json:"code"`
|
||||
Data []struct {
|
||||
Area []struct {
|
||||
Name string `json:"name"` // 商圈名称
|
||||
ID int `json:"id"` // 商圈id
|
||||
} `json:"area"`
|
||||
Name string `json:"name"` // 行政区名称
|
||||
ID int `json:"id"` // 行政区id
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
// OpenapiPoiArea 基础数据 - 商圈接口 https://openapi.meituan.com/#api-0.%E5%9F%BA%E7%A1%80%E6%95%B0%E6%8D%AE-GetHttpsOpenapiMeituanComPoiAreaCityid1
|
||||
func (app *App) OpenapiPoiArea(cityID int) (result OpenapiPoiAreaResult, err error) {
|
||||
|
||||
param := NewParams()
|
||||
param.Set("cityid", cityID)
|
||||
|
||||
// 参数
|
||||
params := app.NewParamsWith(param)
|
||||
|
||||
// 请求
|
||||
body, err := app.request("https://openapi.meituan.com/poi/area", params, "GET")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(body, &result); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type OpenapiPoiDistrictResult struct {
|
||||
Code int `json:"code"` // 状态码 0表示请求正常
|
||||
Data []struct {
|
||||
Name string `json:"name"` // 行政区名称
|
||||
ID int `json:"id"` // 行政区id
|
||||
} `json:"data"` // 返回行政区列表
|
||||
}
|
||||
|
||||
// OpenapiPoiDistrict 基础数据 - 城市的行政区接口 https://openapi.meituan.com/#api-0.%E5%9F%BA%E7%A1%80%E6%95%B0%E6%8D%AE-GetHttpsOpenapiMeituanComPoiDistrictCityid1
|
||||
func (app *App) OpenapiPoiDistrict(cityID int) (result OpenapiPoiDistrictResult, err error) {
|
||||
|
||||
param := NewParams()
|
||||
param.Set("cityid", cityID)
|
||||
|
||||
// 参数
|
||||
params := app.NewParamsWith(param)
|
||||
|
||||
// 请求
|
||||
body, err := app.request("https://openapi.meituan.com/poi/district", params, "GET")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(body, &result); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type OpenapiPoiCityResult struct {
|
||||
Code int `json:"code"` // 状态码 0表示请求正常
|
||||
Data []struct {
|
||||
Pinyin string `json:"pinyin"` // 城市拼音
|
||||
Name string `json:"name"` // 城市名称
|
||||
ID int `json:"id"` // 城市id
|
||||
} `json:"data"` // 返回城市列表
|
||||
}
|
||||
|
||||
// OpenapiPoiCity 基础数据 - 开放城市接口 https://openapi.meituan.com/#api-0.%E5%9F%BA%E7%A1%80%E6%95%B0%E6%8D%AE-GetHttpsOpenapiMeituanComPoiCity
|
||||
func (app *App) OpenapiPoiCity() (result OpenapiPoiCityResult, err error) {
|
||||
|
||||
// 请求
|
||||
body, err := app.request("https://openapi.meituan.com/poi/city", map[string]interface{}{}, "GET")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(body, &result); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package meituan
|
||||
|
||||
// Params 请求参数
|
||||
type Params map[string]interface{}
|
||||
|
||||
func NewParams() Params {
|
||||
p := make(Params)
|
||||
return p
|
||||
}
|
||||
|
||||
func (app *App) NewParamsWith(params ...Params) Params {
|
||||
p := make(Params)
|
||||
for _, v := range params {
|
||||
p.SetParams(v)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p Params) Set(key string, value interface{}) {
|
||||
p[key] = value
|
||||
}
|
||||
|
||||
func (p Params) SetParams(params Params) {
|
||||
for key, value := range params {
|
||||
p[key] = value
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package meituan
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
|
||||
"io"
|
||||
"sort"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (app *App) getSign(Secret string, params map[string]interface{}) string {
|
||||
// 参数按照参数名的字典升序排列
|
||||
var keys []string
|
||||
for k := range params {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
signStr := bytes.NewBufferString(Secret)
|
||||
for _, k := range keys {
|
||||
signStr.WriteString(k)
|
||||
signStr.WriteString(app.getString(params[k]))
|
||||
}
|
||||
signStr.WriteString(Secret)
|
||||
// md5加密
|
||||
has := md5.New()
|
||||
io.Copy(has, signStr)
|
||||
return hex.EncodeToString(has.Sum(nil))
|
||||
}
|
||||
|
||||
func (app *App) getString(i interface{}) string {
|
||||
switch v := i.(type) {
|
||||
case string:
|
||||
return v
|
||||
case int:
|
||||
return strconv.Itoa(v)
|
||||
case bool:
|
||||
return strconv.FormatBool(v)
|
||||
default:
|
||||
marshal, _ := json.Marshal(v)
|
||||
return string(marshal)
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package pintoto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type ApiUserInfoResult struct {
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
Data struct {
|
||||
Nickname string `json:"nickname"` // 用户昵称
|
||||
Mobile int64 `json:"mobile"` // 注册号码
|
||||
Balance float64 `json:"balance"` // 账户余额
|
||||
FreezeAmount float64 `json:"freeze_amount"` // 冻结金额
|
||||
} `json:"data"`
|
||||
Code int `json:"code"`
|
||||
}
|
||||
|
||||
// ApiUserInfo 账号信息查询 https://www.showdoc.com.cn/1154868044931571/6269224958928211
|
||||
func (app *App) ApiUserInfo() (result ApiUserInfoResult, err error) {
|
||||
body, err := app.request("https://movieapi2.pintoto.cn/api/user/info", map[string]interface{}{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(body, &result); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package pintoto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// App 电影票服务
|
||||
type App struct {
|
||||
AppKey string
|
||||
AppSecret string
|
||||
}
|
||||
|
||||
type ErrResp struct {
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
Code int `json:"code"`
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}) ([]byte, error) {
|
||||
// 公共参数
|
||||
params["time"] = time.Now().Unix()
|
||||
params["appKey"] = app.AppKey
|
||||
// 签名
|
||||
params["sign"] = app.getSign(app.AppSecret, params)
|
||||
var req *http.Request
|
||||
req, err := http.NewRequest("POST", url, strings.NewReader(app.getRequestData(params)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
httpClient := &http.Client{}
|
||||
var response *http.Response
|
||||
response, err = httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 请求错误
|
||||
if response.StatusCode != 200 {
|
||||
return nil, errors.New(fmt.Sprintf("请求错误:%d", response.StatusCode))
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
body, err := ioutil.ReadAll(response.Body)
|
||||
|
||||
// 检查错误
|
||||
apiErr := ErrResp{}
|
||||
if err := json.Unmarshal(body, &apiErr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 接口状态错误
|
||||
if apiErr.Code != 200 {
|
||||
return nil, errors.New(apiErr.Message)
|
||||
}
|
||||
return body, nil
|
||||
}
|
||||
|
||||
func (app *App) GradeToFloat64(i interface{}) float64 {
|
||||
switch v := i.(type) {
|
||||
case string:
|
||||
float, _ := strconv.ParseFloat(v, 64)
|
||||
return float
|
||||
case float64:
|
||||
return v
|
||||
case int64:
|
||||
return float64(v) / math.Pow10(0)
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package pintoto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type GetCityArea struct {
|
||||
CityId int `json:"cityId"` // 城市id
|
||||
}
|
||||
|
||||
type GetCityAreaResult struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data struct {
|
||||
List []struct {
|
||||
AreaId int `json:"areaId"` // 区域id
|
||||
AreaName string `json:"areaName"` // 区域名
|
||||
} `json:"list"`
|
||||
} `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
// GetCityArea 城市下区域 https://www.showdoc.com.cn/1154868044931571/6243539682553126
|
||||
func (app *App) GetCityArea(param GetCityArea) (result GetCityAreaResult, err error) {
|
||||
// api params
|
||||
params := map[string]interface{}{}
|
||||
b, _ := json.Marshal(¶m)
|
||||
var m map[string]interface{}
|
||||
_ = json.Unmarshal(b, &m)
|
||||
for k, v := range m {
|
||||
params[k] = v
|
||||
}
|
||||
body, err := app.request("https://movieapi2.pintoto.cn/movieapi/movie-info/get-city-area", params)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(body, &result); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package pintoto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type GetCityListResult struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data struct {
|
||||
List []struct {
|
||||
PinYin string `json:"pinYin"` // 城市首字母
|
||||
RegionName string `json:"regionName"` // 城市名
|
||||
CityId int `json:"cityId"` // 城市id
|
||||
} `json:"list"`
|
||||
} `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
// GetCityList 城市列表 https://www.showdoc.com.cn/1154868044931571/5865562425538244
|
||||
func (app *App) GetCityList() (result GetCityListResult, err error) {
|
||||
body, err := app.request("https://movieapi2.pintoto.cn/movieapi/movie-info/get-city-list", map[string]interface{}{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(body, &result); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package pintoto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type GetVersionResult struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data string `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
// GetVersion 获取同步版本号 https://www.showdoc.com.cn/1154868044931571/6566701084841699
|
||||
func (app *App) GetVersion() (result GetVersionResult, err error) {
|
||||
body, err := app.request("https://movieapi2.pintoto.cn/movieapi/movie-info/get-version", map[string]interface{}{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(body, &result); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package pintoto
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (app *App) getSign(appSecret string, p map[string]interface{}) string {
|
||||
var keys []string
|
||||
for k := range p {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
signStr := ""
|
||||
for _, key := range keys {
|
||||
signStr += fmt.Sprintf("%s=%s&", key, app.getString(p[key]))
|
||||
}
|
||||
signStr += fmt.Sprintf("appSecret=%s", appSecret)
|
||||
// md5加密
|
||||
data := []byte(signStr)
|
||||
has := md5.Sum(data)
|
||||
return fmt.Sprintf("%x", has)
|
||||
}
|
||||
|
||||
func (app *App) getString(i interface{}) string {
|
||||
switch v := i.(type) {
|
||||
case string:
|
||||
return v
|
||||
case int:
|
||||
return strconv.Itoa(v)
|
||||
case bool:
|
||||
return strconv.FormatBool(v)
|
||||
default:
|
||||
bytes, _ := json.Marshal(v)
|
||||
return string(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取请求数据
|
||||
func (app *App) getRequestData(params map[string]interface{}) string {
|
||||
// 公共参数
|
||||
args := url.Values{}
|
||||
// 请求参数
|
||||
for key, val := range params {
|
||||
args.Set(key, app.getString(val))
|
||||
}
|
||||
return args.Encode()
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
package config
|
||||
|
||||
const Api = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send"
|
@ -1,10 +0,0 @@
|
||||
package message
|
||||
|
||||
type MsgType_ string
|
||||
|
||||
const (
|
||||
TextStr MsgType_ = "text"
|
||||
NewsStr MsgType_ = "news"
|
||||
MarkdownStr MsgType_ = "markdown"
|
||||
fileStr MsgType_ = "file"
|
||||
)
|
@ -1,45 +0,0 @@
|
||||
package qywechat
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/dtapps/go-library/service/qywechat/config"
|
||||
"github.com/dtapps/go-library/service/qywechat/message"
|
||||
"github.com/dtapps/go-library/utils/gojson"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type QyBot struct {
|
||||
Key string
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Errcode int64 `json:"errcode"`
|
||||
Errmsg string `json:"errmsg"`
|
||||
Type string `json:"type"`
|
||||
MediaId string `json:"media_id"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
func (bot *QyBot) Send(msg message.Message) (Response, error) {
|
||||
var response Response
|
||||
qyUrl := fmt.Sprintf("%s?key=%s", config.Api, bot.Key)
|
||||
toString, err := gojson.MarshalToString(msg)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
resp, e := http.Post(qyUrl, "application/json", strings.NewReader(toString))
|
||||
if e != nil {
|
||||
return response, e
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
e = json.Unmarshal(body, &response)
|
||||
if e != nil {
|
||||
return response, e
|
||||
}
|
||||
return response, nil
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package taobao
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/dtapps/go-library/utils/gohttp"
|
||||
"github.com/dtapps/go-library/utils/gostring"
|
||||
"regexp"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// App 公共请求参数
|
||||
type App struct {
|
||||
AppKey string // 应用Key
|
||||
AppSecret string // 密钥
|
||||
}
|
||||
type ErrResp struct {
|
||||
ErrorResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
SubCode string `json:"sub_code"`
|
||||
SubMsg string `json:"sub_msg"`
|
||||
RequestId string `json:"request_id"`
|
||||
} `json:"error_response"`
|
||||
}
|
||||
|
||||
func (app *App) request(params map[string]interface{}) (resp []byte, err error) {
|
||||
// 签名
|
||||
app.Sign(params)
|
||||
// 发送请求
|
||||
httpGet, err := gohttp.Get("https://eco.taobao.com/router/rest", params)
|
||||
// 检查错误
|
||||
var errResp ErrResp
|
||||
_ = json.Unmarshal(httpGet.Body, &errResp)
|
||||
return httpGet.Body, err
|
||||
}
|
||||
|
||||
func (app *App) ZkFinalPriceParseInt64(ZkFinalPrice string) int64 {
|
||||
parseInt, err := strconv.ParseInt(ZkFinalPrice, 10, 64)
|
||||
if err != nil {
|
||||
re := regexp.MustCompile("[0-9]+")
|
||||
SalesTipMap := re.FindAllString(ZkFinalPrice, -1)
|
||||
if len(SalesTipMap) == 2 {
|
||||
return gostring.ToInt64(fmt.Sprintf("%s%s", SalesTipMap[0], SalesTipMap[1])) * 10
|
||||
} else {
|
||||
return gostring.ToInt64(SalesTipMap[0]) * 100
|
||||
}
|
||||
} else {
|
||||
return parseInt * 100
|
||||
}
|
||||
}
|
||||
|
||||
func (app *App) CommissionRateParseInt64(CommissionRate string) int64 {
|
||||
parseInt, err := strconv.ParseInt(CommissionRate, 10, 64)
|
||||
if err != nil {
|
||||
re := regexp.MustCompile("[0-9]+")
|
||||
SalesTipMap := re.FindAllString(CommissionRate, -1)
|
||||
if len(SalesTipMap) == 2 {
|
||||
return gostring.ToInt64(fmt.Sprintf("%s%s", SalesTipMap[0], SalesTipMap[1]))
|
||||
} else {
|
||||
return gostring.ToInt64(SalesTipMap[0])
|
||||
}
|
||||
} else {
|
||||
return parseInt
|
||||
}
|
||||
}
|
||||
|
||||
func (app *App) CouponAmountToInt64(CouponAmount int64) int64 {
|
||||
return CouponAmount * 100
|
||||
}
|
||||
|
||||
func (app *App) CommissionIntegralToInt64(GoodsPrice, CouponProportion int64) int64 {
|
||||
return (GoodsPrice * CouponProportion) / 100
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package taobao
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 签名
|
||||
func createSign(signStr string) string {
|
||||
h := md5.New()
|
||||
h.Write([]byte(signStr))
|
||||
cipherStr := h.Sum(nil)
|
||||
return strings.ToUpper(hex.EncodeToString(cipherStr))
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package taobao
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Params 请求参数
|
||||
type Params map[string]interface{}
|
||||
|
||||
func NewParams() Params {
|
||||
p := make(Params)
|
||||
return p
|
||||
}
|
||||
|
||||
func NewParamsWithType(_method string, params ...Params) Params {
|
||||
p := make(Params)
|
||||
p["method"] = _method
|
||||
hh, _ := time.ParseDuration("8h")
|
||||
loc := time.Now().UTC().Add(hh)
|
||||
p["timestamp"] = strconv.FormatInt(loc.Unix(), 10)
|
||||
p["format"] = "json"
|
||||
p["v"] = "2.0"
|
||||
p["sign_method"] = "md5"
|
||||
p["partner_id"] = "Nilorg"
|
||||
for _, v := range params {
|
||||
p.SetParams(v)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (app *App) Sign(p Params) {
|
||||
p["app_key"] = app.AppKey
|
||||
// 排序所有的 key
|
||||
var keys []string
|
||||
for key := range p {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
signStr := app.AppSecret
|
||||
for _, key := range keys {
|
||||
signStr += key + getString(p[key])
|
||||
}
|
||||
signStr += app.AppSecret
|
||||
p["sign"] = createSign(signStr)
|
||||
}
|
||||
|
||||
func (p Params) Set(key string, value interface{}) {
|
||||
p[key] = value
|
||||
}
|
||||
|
||||
func (p Params) SetParams(params Params) {
|
||||
for key, value := range params {
|
||||
p[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
func (p Params) GetQuery() string {
|
||||
u := url.Values{}
|
||||
for k, v := range p {
|
||||
u.Set(k, getString(v))
|
||||
}
|
||||
return u.Encode()
|
||||
}
|
||||
|
||||
func getString(i interface{}) string {
|
||||
switch v := i.(type) {
|
||||
case string:
|
||||
return v
|
||||
case []byte:
|
||||
return string(v)
|
||||
case int:
|
||||
return strconv.Itoa(v)
|
||||
case bool:
|
||||
return strconv.FormatBool(v)
|
||||
default:
|
||||
bytes, _ := json.Marshal(v)
|
||||
return string(bytes)
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package taobao
|
||||
|
||||
type TbkActivityInfoGetResult struct {
|
||||
TbkActivityInfoGetResponse struct {
|
||||
Data struct {
|
||||
WxQrcodeUrl string `json:"wx_qrcode_url"`
|
||||
ClickUrl string `json:"click_url"`
|
||||
ShortClickUrl string `json:"short_click_url"`
|
||||
TerminalType string `json:"terminal_type"`
|
||||
MaterialOssUrl string `json:"material_oss_url"`
|
||||
PageName string `json:"page_name"`
|
||||
PageStartTime string `json:"page_start_time"`
|
||||
PageEndTime string `json:"page_end_time"`
|
||||
WxMiniprogramPath string `json:"wx_miniprogram_path"`
|
||||
} `json:"data"`
|
||||
} `json:"tbk_activity_info_get_response"`
|
||||
}
|
||||
|
||||
// TbkActivityInfoGet 淘宝客-推广者-官方活动转链 https://open.taobao.com/api.htm?spm=a219a.7386797.0.0.5a83669a7rURsF&source=search&docId=48340&docType=2
|
||||
func (app *App) TbkActivityInfoGet(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := NewParamsWithType("taobao.tbk.activity.info.get", notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request(params)
|
||||
return
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package taobao
|
||||
|
||||
type TbkDgMaterialOptionalResult struct {
|
||||
TbkDgMaterialOptionalResponse struct {
|
||||
ResultList struct {
|
||||
MapData []struct {
|
||||
CategoryId int `json:"category_id"`
|
||||
CategoryName string `json:"category_name"`
|
||||
CommissionRate string `json:"commission_rate"`
|
||||
CommissionType string `json:"commission_type"`
|
||||
CouponId string `json:"coupon_id"`
|
||||
CouponInfo string `json:"coupon_info"`
|
||||
CouponRemainCount int `json:"coupon_remain_count"`
|
||||
CouponCount int `json:"coupon__count"`
|
||||
CpaRewardType string `json:"cpa_reward_type"`
|
||||
IncludeDxjh string `json:"include_dxjh"`
|
||||
IncludeMkt string `json:"include_mkt"`
|
||||
InfoDxjh string `json:"info_dxjh"`
|
||||
ItemDescription string `json:"item_description"`
|
||||
ItemId int64 `json:"item_id"`
|
||||
ItemUrl string `json:"item_url"`
|
||||
LevelOneCategoryId int64 `json:"level_one_category_id"`
|
||||
LevelOneCategoryName string `json:"level_one_category_name"`
|
||||
Nick string `json:"nick"`
|
||||
NumIid int64 `json:"num_iid"`
|
||||
PictUrl string `json:"pict_url"`
|
||||
Presale int `json:"presale"`
|
||||
PresaleDiscountFeeText string `json:"presale_discount_fee_text"`
|
||||
PresaleEndTime int64 `json:"presale_end_time"`
|
||||
PresaleStartTime int64 `json:"presale_start_time"`
|
||||
PresaleTailEndTime int64 `json:"presale_tail_end_time"`
|
||||
PresaleTailStartTime int64 `json:"presale_tail_start_time"`
|
||||
Provcity string `json:"provcity"`
|
||||
RealPostFe int `json:"real_post_fe"`
|
||||
ReservePrice string `json:"reserve_price"`
|
||||
SellerId int64 `json:"seller_id"`
|
||||
ShopDsr int `json:"shop_dsr"`
|
||||
ShopTitle string `json:"shop_title"`
|
||||
ShortTitle string `json:"short_title"`
|
||||
SmallImages struct {
|
||||
String []string `json:"string"`
|
||||
} `json:"small_images"`
|
||||
SuperiorBrand string `json:"superior_brand"`
|
||||
Title string `json:"title"`
|
||||
TkTotalCommi string `json:"tk_total_commi"`
|
||||
TkTotalSales string `json:"tk_total_sales"`
|
||||
Url string `json:"url"`
|
||||
UserType int `json:"user_type"`
|
||||
Volume int64 `json:"volume"`
|
||||
WhiteImage string `json:"white_image"`
|
||||
XId string `json:"x_id"`
|
||||
ZkFinalPrice string `json:"zk_final_price"`
|
||||
CouponShareUrl string `json:"coupon_share_url"`
|
||||
CouponAmount string `json:"coupon_amount"`
|
||||
} `json:"map_data"`
|
||||
} `json:"result_list"`
|
||||
TotalResults int `json:"total_results"`
|
||||
RequestId string `json:"request_id"`
|
||||
} `json:"tbk_dg_material_optional_response"`
|
||||
}
|
||||
|
||||
// TbkDgMaterialOptional 淘宝客-推广者-物料搜索 https://open.taobao.com/api.htm?docId=35896&docType=2&source=search
|
||||
func (app *App) TbkDgMaterialOptional(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := NewParamsWithType("taobao.tbk.dg.material.optional", notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request(params)
|
||||
return
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package taobao
|
||||
|
||||
type TbkDgOptimusMaterialResult struct {
|
||||
TbkDgOptimusMaterialResponse struct {
|
||||
IsDefault string `json:"is_default"`
|
||||
ResultList struct {
|
||||
MapData []struct {
|
||||
CategoryId int `json:"category_id"`
|
||||
ClickUrl string `json:"click_url"`
|
||||
CommissionRate string `json:"commission_rate"`
|
||||
CouponAmount int64 `json:"coupon_amount"`
|
||||
CouponClickUrl string `json:"coupon_click_url"`
|
||||
CouponEndTime string `json:"coupon_end_time"`
|
||||
CouponRemainCount int `json:"coupon_remain_count"`
|
||||
CouponShareUrl string `json:"coupon_share_url"`
|
||||
CouponStartFee string `json:"coupon_start_fee"`
|
||||
CouponStartTime string `json:"coupon_start_time"`
|
||||
CouponTotalCount int `json:"coupon_total_count"`
|
||||
CpaRewardType string `json:"cpa_reward_type"`
|
||||
ItemDescription string `json:"item_description"`
|
||||
ItemId int64 `json:"item_id"`
|
||||
JhsPriceUspList string `json:"jhs_price_usp_list"`
|
||||
LevelOneCategoryId int64 `json:"level_one_category_id"`
|
||||
LevelOneCategoryName string `json:"level_one_category_name"`
|
||||
Nick string `json:"nick"`
|
||||
PictUrl string `json:"pict_url"`
|
||||
ReservePrice string `json:"reserve_price"`
|
||||
SellerId int64 `json:"seller_id"`
|
||||
ShopTitle string `json:"shop_title"`
|
||||
ShortTitle string `json:"short_title"`
|
||||
SmallImages struct {
|
||||
String []string `json:"string"`
|
||||
} `json:"small_images"`
|
||||
SubTitle string `json:"sub_title"`
|
||||
Title string `json:"title"`
|
||||
UserType int `json:"user_type"`
|
||||
Volume int64 `json:"volume"`
|
||||
WhiteImage string `json:"white_image"`
|
||||
ZkFinalPrice string `json:"zk_final_price"`
|
||||
} `json:"map_data"`
|
||||
} `json:"result_list"`
|
||||
RequestId string `json:"request_id"`
|
||||
} `json:"tbk_dg_optimus_material_response"`
|
||||
}
|
||||
|
||||
// TbkDgOptimusMaterial 淘宝客-推广者-物料精选 https://open.taobao.com/api.htm?spm=a219a.7386797.0.0.5d67669aIeQeVI&source=search&docId=33947&docType=2
|
||||
func (app *App) TbkDgOptimusMaterial(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := NewParamsWithType("taobao.tbk.dg.optimus.material", notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request(params)
|
||||
return
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package taobao
|
||||
|
||||
type TbkItemInfoGetResult struct {
|
||||
TbkItemInfoGetResponse struct {
|
||||
Results struct {
|
||||
NTbkItem []struct {
|
||||
CatLeafName string `json:"cat_leaf_name"`
|
||||
CatName string `json:"cat_name"`
|
||||
FreeShipment bool `json:"free_shipment"`
|
||||
HotFlag string `json:"hot_flag"`
|
||||
ItemUrl string `json:"item_url"`
|
||||
JuOnlineEnd string `json:"ju_online_end"`
|
||||
JuOnlineStartTime string `json:"ju_online_start_time"`
|
||||
JuPreShowEndTime string `json:"ju_pre_show_end_time"`
|
||||
JuPreShowStartTime string `json:"ju_pre_show_start_time"`
|
||||
MaterialLibType string `json:"material_lib_type"`
|
||||
Nick string `json:"nick"`
|
||||
NumIid int64 `json:"num_iid"`
|
||||
PictUrl string `json:"pict_url"`
|
||||
PresaleDeposit string `json:"presale_deposit"`
|
||||
PresaleEndTime int `json:"presale_end_time"`
|
||||
PresaleStartTime int `json:"presale_start_time"`
|
||||
PresaleTailEndTime int `json:"presale_tail_end_time"`
|
||||
PresaleTailStartTime int `json:"presale_tail_start_time"`
|
||||
Provcity string `json:"provcity"`
|
||||
ReservePrice string `json:"reserve_price"`
|
||||
SellerId int64 `json:"seller_id"`
|
||||
SmallImages struct {
|
||||
String []string `json:"string"`
|
||||
} `json:"small_images"`
|
||||
SuperiorBrand string `json:"superior_brand"`
|
||||
Title string `json:"title"`
|
||||
TmallPllPlayActivityStartTime int `json:"tmall_pll_play_activity_start_time"`
|
||||
UserType int `json:"user_type"`
|
||||
Volume int64 `json:"volume"`
|
||||
ZkFinalPrice string `json:"zk_final_price"`
|
||||
} `json:"n_tbk_item"`
|
||||
} `json:"results"`
|
||||
RequestId string `json:"request_id"`
|
||||
} `json:"tbk_item_info_get_response"`
|
||||
}
|
||||
|
||||
// TbkItemInfoGet 淘宝客-公用-淘宝客商品详情查询(简版) https://open.taobao.com/api.htm?docId=24518&docType=2&source=search
|
||||
func (app *App) TbkItemInfoGet(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := NewParamsWithType("taobao.tbk.item.info.get", notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request(params)
|
||||
return
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package taobao
|
||||
|
||||
type TbkSpreadGetResult struct {
|
||||
TbkSpreadGetResponse struct {
|
||||
Results struct {
|
||||
TbkSpread []struct {
|
||||
Content string `json:"content"`
|
||||
ErrMsg string `json:"err_msg"`
|
||||
} `json:"tbk_spread"`
|
||||
} `json:"results"`
|
||||
TotalResults int `json:"total_results"`
|
||||
RequestId string `json:"request_id"`
|
||||
} `json:"tbk_spread_get_response"`
|
||||
}
|
||||
|
||||
// TbkSpreadGet 淘宝客-公用-长链转短链 https://open.taobao.com/api.htm?docId=27832&docType=2&source=search
|
||||
func (app *App) TbkSpreadGet(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := NewParamsWithType("taobao.tbk.spread.get", notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request(params)
|
||||
return
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package taobao
|
||||
|
||||
type TbkTPwdCreateResult struct {
|
||||
TbkTpwdCreateResponse struct {
|
||||
Data struct {
|
||||
Model string `json:"model"`
|
||||
PasswordSimple string `json:"password_simple"`
|
||||
} `json:"data"`
|
||||
RequestId string `json:"request_id"`
|
||||
} `json:"tbk_tpwd_create_response"`
|
||||
}
|
||||
|
||||
// TbkTPwdCreate 淘宝客-公用-淘口令生成 https://open.taobao.com/api.htm?docId=31127&docType=2&source=search
|
||||
func (app *App) TbkTPwdCreate(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := NewParamsWithType("taobao.tbk.tpwd.create", notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request(params)
|
||||
return
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package tianyancha
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/dtapps/go-library/utils/gohttp"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type App struct{}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) (resp []byte, err error) {
|
||||
// 请求
|
||||
if method == http.MethodGet {
|
||||
get, err := gohttp.Get(url, params)
|
||||
return get.Body, err
|
||||
} else {
|
||||
paramsStr, err := json.Marshal(params)
|
||||
postJson, err := gohttp.PostJson(url, paramsStr)
|
||||
return postJson.Body, err
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package tianyancha
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type EquityHumanIndexNodeResult struct {
|
||||
IsLogin int `json:"isLogin"`
|
||||
Message string `json:"message"`
|
||||
Special string `json:"special"`
|
||||
State string `json:"state"`
|
||||
VipMessage string `json:"vipMessage"`
|
||||
}
|
||||
|
||||
func (app *App) EquityHumanIndexNode(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := app.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request("https://capi.tianyancha.com/cloud-equity-provider/v4/equity/humanIndexnode.json", params, http.MethodGet)
|
||||
return body, err
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package tianyancha
|
||||
|
||||
// Params 请求参数
|
||||
type Params map[string]interface{}
|
||||
|
||||
func NewParams() Params {
|
||||
p := make(Params)
|
||||
return p
|
||||
}
|
||||
|
||||
func (app *App) NewParamsWith(params ...Params) Params {
|
||||
p := make(Params)
|
||||
for _, v := range params {
|
||||
p.SetParams(v)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p Params) Set(key string, value interface{}) {
|
||||
p[key] = value
|
||||
}
|
||||
|
||||
func (p Params) SetParams(params Params) {
|
||||
for key, value := range params {
|
||||
p[key] = value
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package tianyancha
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SearchHumanSuggestResult struct {
|
||||
Data struct {
|
||||
Id int `json:"id"`
|
||||
HumanName interface{} `json:"humanName"`
|
||||
DistinctNum int `json:"distinctNum"`
|
||||
ViewNum int `json:"viewNum"`
|
||||
ResultCount int `json:"resultCount"`
|
||||
ResultList []struct {
|
||||
Name string `json:"name"`
|
||||
Hid int64 `json:"hid"`
|
||||
HeadUrl interface{} `json:"headUrl"`
|
||||
Introduction interface{} `json:"introduction"`
|
||||
Event interface{} `json:"event"`
|
||||
BossCertificate int `json:"bossCertificate"`
|
||||
CompanyNum int `json:"companyNum"`
|
||||
Office []interface{} `json:"office"`
|
||||
Companys interface{} `json:"companys"`
|
||||
PartnerNum int `json:"partnerNum"`
|
||||
CoopCount int `json:"coopCount"`
|
||||
Partners interface{} `json:"partners"`
|
||||
Cid int64 `json:"cid"`
|
||||
TypeJoin interface{} `json:"typeJoin"`
|
||||
Alias interface{} `json:"alias"`
|
||||
ServiceType int `json:"serviceType"`
|
||||
ServiceCount int `json:"serviceCount"`
|
||||
OfficeV1 []interface{} `json:"officeV1"`
|
||||
Pid interface{} `json:"pid"`
|
||||
Role interface{} `json:"role"`
|
||||
} `json:"resultList"`
|
||||
TotalPage int `json:"totalPage"`
|
||||
CurrentPage int `json:"currentPage"`
|
||||
RealName interface{} `json:"realName"`
|
||||
AdviceQuery interface{} `json:"adviceQuery"`
|
||||
} `json:"data"`
|
||||
VipMessage string `json:"vipMessage"`
|
||||
Special string `json:"special"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
func (app *App) SearchHumanSuggest(key string) (body []byte, err error) {
|
||||
body, err = app.request(fmt.Sprintf("https://www.tianyancha.com/search/humanSuggest.json?key=%s", key), map[string]interface{}{}, http.MethodGet)
|
||||
return body, err
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package wechatqy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/dtapps/go-library/utils/gohttp"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
Key string
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}) (body []byte, err error) {
|
||||
// 请求参数
|
||||
paramsStr, err := json.Marshal(params)
|
||||
// 请求
|
||||
postJson, err := gohttp.PostJson(url, paramsStr)
|
||||
return postJson.Body, err
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package wechatqy
|
||||
|
||||
// Params 请求参数
|
||||
type Params map[string]interface{}
|
||||
|
||||
func NewParams() Params {
|
||||
p := make(Params)
|
||||
return p
|
||||
}
|
||||
|
||||
func (app *App) NewParamsWith(params ...Params) Params {
|
||||
p := make(Params)
|
||||
for _, v := range params {
|
||||
p.SetParams(v)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p Params) Set(key string, value interface{}) {
|
||||
p[key] = value
|
||||
}
|
||||
|
||||
func (p Params) SetParams(params Params) {
|
||||
for key, value := range params {
|
||||
p[key] = value
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package wechatunion
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/dtapps/go-library/utils/gohttp"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
AppId string // 小程序唯一凭证,即 AppID
|
||||
AppSecret string // 小程序唯一凭证密钥,即 AppSecret
|
||||
AccessToken string // 接口调用凭证
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) (resp []byte, err error) {
|
||||
if method == http.MethodGet {
|
||||
get, err := gohttp.Get(url, params)
|
||||
return get.Body, err
|
||||
} else {
|
||||
// 请求参数
|
||||
paramsStr, err := json.Marshal(params)
|
||||
postJson, err := gohttp.PostJson(url, paramsStr)
|
||||
return postJson.Body, err
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package wechatunion
|
||||
|
||||
// Params 请求参数
|
||||
type Params map[string]interface{}
|
||||
|
||||
func NewParams() Params {
|
||||
p := make(Params)
|
||||
return p
|
||||
}
|
||||
|
||||
func (app *App) NewParamsWith(params ...Params) Params {
|
||||
p := make(Params)
|
||||
for _, v := range params {
|
||||
p.SetParams(v)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p Params) Set(key string, value interface{}) {
|
||||
p[key] = value
|
||||
}
|
||||
|
||||
func (p Params) SetParams(params Params) {
|
||||
for key, value := range params {
|
||||
p[key] = value
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
package wechatunion
|
@ -0,0 +1 @@
|
||||
package wechatunion
|
@ -0,0 +1,7 @@
|
||||
package wechatunion
|
||||
|
||||
const (
|
||||
commissionStatus_SettlementPending = "SETTLEMENT_PENDING" // 待结算
|
||||
commissionStatus_SettlementSuccess = "SETTLEMENT_SUCCESS" // 已结算
|
||||
commissionStatus_SettlementCanceled = "SETTLEMENT_CANCELED" // 取消结算
|
||||
)
|
@ -0,0 +1,22 @@
|
||||
package wikeyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dtapps/go-library/utils/gohttp"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
StoreID int
|
||||
AppKey int
|
||||
AppSecret string
|
||||
ClientIP string
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}) (resp []byte, err error) {
|
||||
// 签名
|
||||
sign := app.sign(params)
|
||||
// 请求
|
||||
requestUrl := fmt.Sprintf("%s?app_key=%d×tamp=%s&client=%s&format=%s&v=%s&sign=%s", url, app.AppKey, sign.Timestamp, sign.Client, sign.Format, sign.V, sign.Sign)
|
||||
postForm, err := gohttp.PostForm(requestUrl, params)
|
||||
return postForm.Body, err
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package wikeyun
|
||||
|
||||
// OilCardAdd 添加充值卡
|
||||
func (app *App) OilCardAdd(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := app.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request("https://router.wikeyun.cn/rest/Oil/addCard", params)
|
||||
return body, err
|
||||
}
|
||||
|
||||
// OilCardEdit 编辑充值卡
|
||||
func (app *App) OilCardEdit(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := app.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request("https://router.wikeyun.cn/rest/Oil/editCard", params)
|
||||
return body, err
|
||||
}
|
||||
|
||||
// OilCardDel 油卡删除
|
||||
func (app *App) OilCardDel(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := app.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request("https://router.wikeyun.cn/rest/Oil/delCard", params)
|
||||
return body, err
|
||||
}
|
||||
|
||||
// OilCardInfo 油卡详情
|
||||
func (app *App) OilCardInfo(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := app.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request("https://router.wikeyun.cn/rest/Oil/cardInfo", params)
|
||||
return body, err
|
||||
}
|
||||
|
||||
// OilOrderPush 充值下单
|
||||
func (app *App) OilOrderPush(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := app.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request("https://router.wikeyun.cn/rest/Oil/pushOrder", params)
|
||||
return body, err
|
||||
}
|
||||
|
||||
// OilOrderQuery 订单查询
|
||||
func (app *App) OilOrderQuery(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := app.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request("https://router.wikeyun.cn/rest/Oil/query", params)
|
||||
return body, err
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package wikeyun
|
||||
|
||||
// Params 请求参数
|
||||
type Params map[string]interface{}
|
||||
|
||||
func NewParams() Params {
|
||||
p := make(Params)
|
||||
return p
|
||||
}
|
||||
|
||||
func (app *App) NewParamsWith(params ...Params) Params {
|
||||
p := make(Params)
|
||||
for _, v := range params {
|
||||
p.SetParams(v)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p Params) Set(key string, value interface{}) {
|
||||
p[key] = value
|
||||
}
|
||||
|
||||
func (p Params) SetParams(params Params) {
|
||||
for key, value := range params {
|
||||
p[key] = value
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
package wikeyun
|
@ -0,0 +1,35 @@
|
||||
package wikeyun
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// RechargeQueryResponse 返回参数
|
||||
type RechargeQueryResponse struct {
|
||||
Code string `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data struct {
|
||||
OrderNumber string `json:"order_number"`
|
||||
Status int `json:"status"`
|
||||
Mobile string `json:"mobile"`
|
||||
Amount int `json:"amount"`
|
||||
OrderNo string `json:"order_no"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
// RechargeQuery 查询接口
|
||||
func (app *App) RechargeQuery(orderNumber string) (result RechargeQueryResponse, err error) {
|
||||
// 请求
|
||||
body, err := app.request("https://router.wikeyun.cn/rest/Recharge/query", map[string]interface{}{
|
||||
"order_number": orderNumber, // 官方订单号
|
||||
})
|
||||
if err != nil {
|
||||
return result, errors.New(err.Error())
|
||||
}
|
||||
err = json.Unmarshal(body, &result)
|
||||
if err != nil {
|
||||
return result, errors.New(err.Error())
|
||||
}
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package wikeyun
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// UserQueryResponse 返回参数
|
||||
type UserQueryResponse struct {
|
||||
Code string `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data struct {
|
||||
Money string `json:"money"`
|
||||
ID int `json:"id"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
// UserQuery 查询余额接口
|
||||
func (app *App) UserQuery() (result UserQueryResponse, err error) {
|
||||
// 请求
|
||||
body, err := app.request("https://router.wikeyun.cn/rest/User/query", map[string]interface{}{})
|
||||
if err != nil {
|
||||
return result, errors.New(err.Error())
|
||||
}
|
||||
err = json.Unmarshal(body, &result)
|
||||
if err != nil {
|
||||
return result, errors.New(err.Error())
|
||||
}
|
||||
return result, nil
|
||||
}
|
Loading…
Reference in new issue