westcn

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2023 License: MIT Imports: 12 Imported by: 0

README

西数 SDK

West.cn API Request SDK for go 西部数码代理 API SDK,本SDK完成对West.cn部分API的封装,但仅限于开发者使用的部分,其他部分需要使用者自行封装。 内置GBK转UTF8,和Token自动计算,实名认证接口需自行拓展。

安装和简单使用

使用 go get 命令进行安装

go get github.com/virskor/westcn_sdk

创建西部数码 SDK 客户端,直接请求

  client, err := westcn.NewClient(&westcn.ClientOptions{
    BaseApiPath: "https://api.west.cn/api/v2",
    Username: "username",
    ApiPassword: "api_password",
  })
  if err!= nil{
    panic(err)
  }

  // 准备提交的参数
  formData := url.Values{}
  formData.Add("domain", "west")
  formData.Add("suffix", ".com/.net")

  resp, err := client.Request(&westcn.RequestOption{
    Path:     westcn.PATH_DOMAIN_QUERY,
    Method:   "POST",
    FormData: formData,
  })
  if err != nil {
    panic(err)
  }

Documentation

Index

Constants

View Source
const (

	// 获取域名价格
	PATH_INFO_GETPRICE = "/info/?act=getprice"

	// 查询域名
	PATH_DOMAIN_QUERY = "/domain/query/"

	// 获取域名列表
	PATH_DOMAIN_GETDOMAINS = "/domain/?act=getdomains"

	// 域名续费
	PATH_DOMAIN_RENEW = "/domain/?act=renew"

	//  获取域名管理密码
	PATH_DOMAIN_GETPWD = "/domain/?act=getpwd"

	//  修改域名管理密码
	PATH_DOMAIN_MODPWD = "/domain/?act=modpwd"

	// 修改域名DNS
	PATH_DOMAIN_MODDNS = "/domain/?act=moddns"

	// 添加域名解析
	PATH_DOMAIN_ADD_DNS_RECORD = "/domain/?act=adddnsrecord"

	// 修改域名解析
	PATH_DOMAIN_MOD_DNS_RECORD = "/domain/?act=moddnsrecord"

	// 删除域名解析
	PATH_DOMAIN_DEL_DNS_RECORD = "/domain/?act=deldnsrecord"

	// 获取域名解析记录
	PATH_DOMAIN_GET_DNS_RECORD = "/domain/?act=getdnsrecord"

	// 获取域名证书
	PATH_DOMAIN_CERT = "/domain/?act=cert"

	// 设置域名锁定状态
	PATH_DOMAIN_SETLOCK = "/domain/?act=setlock"

	// 获取Whois
	PATH_DOMAIN_WHOIS = "/domain/?act=whois"

	// 获取续费价格
	PATH_DOMAIN_GET_RENEW_PRICE = "/domain/?act=getrenprice"

	// 获取离线记录
	PATH_DOMAIN_GET_OFFLINE = "/domain/?act=offline"

	// 设置注册局安全锁(此功能收费)
	PATH_DOMAIN_BUY_SECURITYLOCK = " /domain/?act=buysecuritylock"

	// 获取注册局安全锁价格
	PATH_DOMAIN_SECURITYLOCK_PRICE = "/domain/?act=securitylockprice"

	// 创建模板
	PATH_AUDIT_SUB = "/audit/?act=auditsub"

	// 修改模板
	PATH_AUDIT_MOD = "/audit/?act=auditmod"

	// 删除模板
	PATH_AUDIT_DEL = "/audit/?act=auditdel"

	// 批量获取模板列表
	PATH_AUDIT_LIST = "/audit/?act=auditlist"

	// 获取模板信息
	PATH_AUDIT_INFO = "/audit/?act=auditinfo"

	// 注册域名
	PATH_AUDIT_REGDOMAIN = "/audit/?act=regdomain"

	// 修改域名信息
	PATH_AUDIT_DOMAIN_MODIFY = "/audit/?act=domainmodisub"

	// 获取域名信息
	PATH_AUDIT_DOMAIN_INFO = "/audit/?act=domaininfo"

	// 获取实名TOKEN
	PATH_AUDIT_UPLOAD_WCF_TOKEN = " /audit/?act=uploadwcftoken"

	// 域名模板过户
	PATH_AUDIT_GHSUB = "/audit/?act=auditghsub"

	// 查询域名过户状态
	PATH_AUDIT_GHLIST = "/audit/?act=ghlist"
)
View Source
const (
	// 默认的API请求地址
	DEFAULT_BASEAPIPATH = "https://api.west.cn/api/v2"
)

Variables

This section is empty.

Functions

func CharsetEncodeMapVal

func CharsetEncodeMapVal(
	maps map[string]interface{},
	converter func(v string) (string, error),
	wantConvKeys ...string) (map[string]interface{}, error)

Convert map[string]interface{}

func GbkToUtf8

func GbkToUtf8(s []byte) ([]byte, error)

GbkToUtf8 returns byte

func IsGBK

func IsGBK(data []byte) bool

IsGBK check data is gbk

func IsUtf8

func IsUtf8(data []byte) bool

IsUtf8 check data is utf-8 or not

func ToGBKString

func ToGBKString(str string) (string, error)

转换为GBK

func ToUnicodeString

func ToUnicodeString(str string) (string, error)

ToUnicodeString from gbkstring

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

Utf8ToGbk

Types

type ClientOptions

type ClientOptions struct {
	// 客户端请求基础地址,默认为 https://api.west.cn/api/v2
	BaseApiPath string `json:"baseApiPath"`

	// 用户名
	Username string `json:"username"`

	// 西部数码ApiPassword
	ApiPassword string `json:"apiPassword"`
}

type RequestOption

type RequestOption struct {
	// 请求的路径
	Path string `json:"path"`

	// 请求的方式,默认为GET
	Method string `json:"method"`

	// 请求的Header,将在请求时同时发送
	Header map[string]interface{} `json:"header"`

	// FormData,传入
	FormData url.Values `json:"body"`

	// Query
	Query map[string]string `json:"query"`
}

发送请求的选项

type RequestToken

type RequestToken struct {
	// 请求的方式,默认为GET
	Value string `json:"value"`

	// token生成的时间
	Time int64 `json:"time"`
}

用于请求的Token

type Response

type Response struct {
	// 可能为空 返回代码 200 成功  其它为失败
	Result int `json:"result,omitempty"`

	// 必须 请求识别码
	ClientID string `json:"clientid"`

	// 可能为空 失败/成功返回的文本信息
	Msg string `json:"msg,omitempty"`

	// 可能为空 错误码(错误码含义详见 附录7.1 错误码说明)
	Errcode int `json:"errcode,omitempty"`

	// 可能为空 响应数据
	Data interface{} `json:"data,omitempty"`
}

西部数码响应结构化数据

type WestClient

type WestClient struct {
	// 客户端选项
	Options *ClientOptions
}

func NewClient

func NewClient(options *ClientOptions) (*WestClient, error)

创建新的客户端

func (*WestClient) Request

func (w *WestClient) Request(option *RequestOption) (*Response, error)

发送请求 注意: Request返回和请求时,数据都被转换为GBK。返回的Response为原始的

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL