cmiot_v2

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: MIT Imports: 17 Imported by: 0

README

cmiot_v2

中移v2接口sdk go版(非官方)

适用

版本

GitHub version

使用方法

package main

import (
    cmiot "github.com/linxlib/cmiot_v2"
)

const (
	APPID    = "xxxx"
	PASSWORD = "xxxx"
	ECID     = "xxxx"
)

func main()  {
    c := cmiot.NewCMIOTClient(APPID, PASSWORD, ECID)
 	c.SetForwarderId("ip")
 	c.SetDebug(false)
}

  • SetForwarderId 官方后台指定的白名单服务器的ip地址,不需要把程序跑在白名单服务上,也不需要使用代理服务器
  • SetDebug 设为true则在终端输出http请求内容和返回的数据

进度

目前暂只实现了部分单卡查询的接口, 批量查询的尚未实现

注意

  • sdk未经过完全测试
  • 如果开多个协程进行调用, 需要控制请求频率, 否则容易无法返回正常的数据。 可能在多台电脑上开多个程序(手动分布式)运行会比较好。

引用

sdk引用了部分第三方库的代码

  • https://github.com/guonaihong/gout 中的Query Encode代码
  • https://github.com/NETkiddy/cmq-go 中的http请求的部分代码

Documentation

Index

Constants

View Source
const (
	EBID_gprsrealsingle       = "0001000000008" //在线信息实时查询
	EBID_userstatusrealsingle = "0001000000009" //用户状态信息实时查询
	EBID_cardinfo             = "0001000000010" //码号信息查询
	EBID_gprsusedinfosingle   = "0001000000012" //用户当月GPRS查询
	EBID_onandoffrealsingle   = "0001000000025" //开关机状态实时查询
	//EBID_batchsmsusedbydate         = "0001000000026" //短信使用信息批量查询
	//EBID_batchgprsusedbydate = "0001000000027" //流量使用信息批量查询
	EBID_balancerealsingle = "0001000000035" //用户余额信息实时查询
	//EBID_smsusedinfosingle          = "0001000000036" //用户当月短信查询
	//EBID_smsstatusreset             = "0001000000034" // 短信状态重置
	EBID_groupuserinfo = "0001000000039" //集团用户数查询
	//EBID_smsusedbydate              = "0001000000040" //用户短信使用查询
	EBID_gprsrealtimeinfo  = "0001000000083" //套餐内GPRS流量使用情况实时查询
	EBID_arrearageuserinfo = "0001000000328" //欠费停机用户批量查询
	//EBID_querycardprodinfo        = "0001000000264" //物联卡资费套餐查询接口
	EBID_gprsusedinfosinglebydate = "0001000000407" //物联卡单日GPRS使用量查询
	EBID_querycardcount           = "0001000000417" //集团各生命周期物联卡数量查询
	EBID_queryabnormalcardcount   = "0001000000427" //集团异常状态物联卡数据量查询
	//EBID_querygprsonlinecardcount = "0001000000428" //集团GPRS在线物联卡数量查询
	//EBID_querysmsopenstatus         = "0001000000429" //物联卡短信服务开通查询
	//EBID_querygprsopenstatus        = "0001000000430" //物联卡GPRS服务开通查询
	//EBID_queryapnopenstatus         = "0001000000431" //物联卡APN服务开通查询
	EBID_querycardlifecycle = "0001000000432" //物联卡生命周期查询

)
View Source
const (
	APIBASE = "https://api.iot.10086.cn/v2/"
)
View Source
const (
	DEFAULT_HTTP_TIMEOUT = 3000 //ms
)

Variables

View Source
var DefaultTransport = &http.Transport{
	Proxy: http.ProxyFromEnvironment,
	DialContext: (&net.Dialer{
		Timeout:   30 * time.Second,
		KeepAlive: 30 * time.Second,
		DualStack: true,
	}).DialContext,
	MaxIdleConns:          500,
	MaxIdleConnsPerHost:   100,
	IdleConnTimeout:       90 * time.Second,
	TLSHandshakeTimeout:   10 * time.Second,
	ExpectContinueTimeout: 1 * time.Second,
}
View Source
var ErrUnsupported = errors.New("qryEncode:Unsupported type")

ErrUnsupported Unsupported type error returned

Functions

func GetCardStatusPB added in v0.0.7

func GetCardStatusPB(cardStatus string) string

Types

type Adder

type Adder interface {
	// contains filtered or unexported methods
}

Adder interface

type BalanceRealSingle added in v0.0.6

type BalanceRealSingle struct {
	Balance string `json:"balance"`
}

type BalanceRealSingleResp added in v0.0.6

type BalanceRealSingleResp struct {
	*BaseResponse
	Result []*BalanceRealSingle `json:"result"`
}

type BaseQuery

type BaseQuery struct {
	*PublicQuery
	Msisdn string `query:"msisdn"`
}

type BaseQueryNoCardId added in v0.0.6

type BaseQueryNoCardId struct {
	*PublicQuery
}

type BaseQueryWithCardInfo added in v0.1.1

type BaseQueryWithCardInfo struct {
	*PublicQuery
	CardInfo string `query:"card_info"`
	CardType int    `query:"type"`
}

type BaseQueryWithDate added in v0.0.6

type BaseQueryWithDate struct {
	*PublicQuery
	Msisdn    string `query:"msisdn"`
	QueryDate string `query:"query_date"`
}

type BaseQueryWithDate1 added in v0.0.7

type BaseQueryWithDate1 struct {
	*PublicQuery
	Msisdn    string `query:"msisdn"`
	QueryDate string `query:"queryDate"`
}

type BaseResponse

type BaseResponse struct {
	Status  string `json:"status"`
	Message string `json:"message"`
}

type CMIOTClient

type CMIOTClient struct {
	// contains filtered or unexported fields
}

func NewCMIOTClient

func NewCMIOTClient(apiId string, apiPassword string, ecid string) *CMIOTClient

func (*CMIOTClient) GetBalanceRealSingle added in v0.0.6

func (c *CMIOTClient) GetBalanceRealSingle(msidsn string) (*BalanceRealSingle, error)

EBID_balancerealsingle

func (*CMIOTClient) GetGprsRealSingle added in v0.0.6

func (c *CMIOTClient) GetGprsRealSingle(msisdn string) (*GprsRealSingle, error)

EBID_gprsrealsingle 在线信息实时查询

func (*CMIOTClient) GetGprsUsedInfSingle added in v0.0.6

func (c *CMIOTClient) GetGprsUsedInfSingle(Msisdn string) (*GprsUsedInfoSingle, error)

EBID_gprsusedinfosingle

func (*CMIOTClient) GetGprsUsedInfoSingleByDate added in v0.0.6

func (c *CMIOTClient) GetGprsUsedInfoSingleByDate(msidsn string, queryDate string) (*GprsUsedInfoSingleByDate, error)

EBID_gprsusedinfosinglebydate

func (*CMIOTClient) GetGroupUserInfo added in v0.0.6

func (c *CMIOTClient) GetGroupUserInfo(queryDate string) (*GroupUserInfo, error)

EBID_groupuserinfo

func (*CMIOTClient) GetOnOff

func (c *CMIOTClient) GetOnOff(Msisdn string) (bool, error)

EBID_onandoffrealsingle

func (*CMIOTClient) GetSimDataMargin

func (c *CMIOTClient) GetSimDataMargin(Msisdn string) (*Gprs, error)

EBID_gprsrealtimeinfo

func (*CMIOTClient) GetSimStatus

func (c *CMIOTClient) GetSimStatus(Msisdn string) (string, error)

EBID_userstatusrealsingle

func (*CMIOTClient) GetUnnormalCount

func (c *CMIOTClient) GetUnnormalCount() (int64, error)

EBID_queryabnormalcardcount

func (*CMIOTClient) QueryCardCount added in v0.0.6

func (c *CMIOTClient) QueryCardCount() (*QueryCardCount, error)

EBID_querycardcount

func (*CMIOTClient) QueryCardInfo added in v0.1.1

func (c *CMIOTClient) QueryCardInfo(card_info string, card_type int) (*CardInfo, error)

EBID_cardinfo

func (*CMIOTClient) QueryCardLifeCycle

func (c *CMIOTClient) QueryCardLifeCycle(Msisdn string) (bool, error)

EBID_querycardlifecycle

func (*CMIOTClient) SetDebug added in v0.0.5

func (c *CMIOTClient) SetDebug(debug bool)

func (*CMIOTClient) SetForwarderId

func (c *CMIOTClient) SetForwarderId(ip string) bool

type CMIOTHttp

type CMIOTHttp struct {
	// contains filtered or unexported fields
}

func NewCMIOTHttp

func NewCMIOTHttp() *CMIOTHttp

func (*CMIOTHttp) SetTransport

func (this *CMIOTHttp) SetTransport(transport http.RoundTripper)

type CardInfo added in v0.1.1

type CardInfo struct {
	IMSI   string
	MSISDN string
	ICCID  string
}

type CardUnusualNum

type CardUnusualNum struct {
	*BaseResponse
	Result []struct {
		CardUnusualNum string `json:"cardUnusualNum"`
	} `json:"result"`
}

type Gprs

type Gprs struct {
	Left       string `json:"left"` //剩余
	ProdId     string `json:"prodid"`
	ProdInstId string `json:"prodinstid"`
	ProdName   string `json:"prodname"`
	Total      string `json:"total"` //总流量
	Used       string `json:"used"`  //已使用
}

type GprsBatch

type GprsBatch struct {
	Status    string `json:"status"`
	Message   string `json:"message"`
	Msisdn    string `json:"msisdn"`
	ProdId    string `json:"prodId"`
	PodInstId string `json:"podInstId"`
	ProdName  string `json:"prodName"`
	GprsTotal string `json:"gprsTotal"`
	GprsUsed  string `json:"gprsUsed"`
	GprsLeft  string `json:"gprsLeft"`
}

type GprsBatchResult

type GprsBatchResult struct {
	*BaseResponse
	Result []GprsBatch `json:"result"`
}

type GprsRealSingle added in v0.0.6

type GprsRealSingle struct {
	APN        string `json:"APN"`
	GPRSSTATUS string `json:"GPRSSTATUS"`
	IP         string `json:"IP"`
	RAT        string `json:"RAT"`
}

type GprsRealSingleResp added in v0.0.6

type GprsRealSingleResp struct {
	*BaseResponse
	Result []*GprsRealSingle `json:"result"`
}

type GprsRealTimeInfo

type GprsRealTimeInfo struct {
	*BaseResponse
	Result []struct {
		Gprs []*Gprs `json:"gprs"`
	} `json:"result"`
}

type GprsUsedInfoSingle added in v0.0.6

type GprsUsedInfoSingle struct {
	TotalGps string `json:"total_gprs"`
}

type GprsUsedInfoSingleByDate added in v0.0.6

type GprsUsedInfoSingleByDate struct {
	Gprs string `json:"gprs"`
}

type GprsUsedInfoSingleByDateResp added in v0.0.6

type GprsUsedInfoSingleByDateResp struct {
	*BaseResponse
	Result []*GprsUsedInfoSingleByDate `json:"result"`
}

type GprsUsedInfoSingleResp added in v0.0.6

type GprsUsedInfoSingleResp struct {
	*BaseResponse
	Result []*GprsUsedInfoSingle `json:"result"`
}

type GroupUserInfo added in v0.0.6

type GroupUserInfo struct {
	Total string `json:"total"`
}

type GroupUserInfoResp added in v0.0.6

type GroupUserInfoResp struct {
	*BaseResponse
	Result []*GroupUserInfo `json:"result"`
}

type PublicQuery

type PublicQuery struct {
	AppID   string `query:"appid"`
	TransID string `query:"transid"`
	EBID    string `query:"ebid"`
	Token   string `query:"token"`
}

type QueryCardCount added in v0.0.6

type QueryCardCount struct {
	NormalNum int `json:"normalnum"`
	OtherNum  int `json:"othernum"`
	SleepNum  int `json:"sleepnum"`
	TestNum   int `json:"testnum"`
}

"normalnum": "28596", "othernum": "3", "sleepnum": "2001", "testnum": "564"

type QueryCardCountResp added in v0.0.6

type QueryCardCountResp struct {
	*BaseResponse
	Result []*QueryCardCount `json:"result"`
}

type QueryCardInfoResp added in v0.1.1

type QueryCardInfoResp struct {
	*BaseResponse
	Result []*CardInfo `json:"result"`
}

type QueryEncode

type QueryEncode struct {
	// contains filtered or unexported fields
}

QueryEncode URL query encoder structure

type UserLifeCyCle

type UserLifeCyCle struct {
	*BaseResponse
	Result []struct {
		LifeCycle string `json:"lifecycle"`
		OpenTime  string `json:"opentime"`
	} `json:"result"`
}

生命周期

type UserOnOffRealSingle

type UserOnOffRealSingle struct {
	*BaseResponse
	Result []struct {
		Status string `json:"status"`
	} `json:"result"`
}

开关机状态

type UserStatusRealSingle

type UserStatusRealSingle struct {
	*BaseResponse
	Result []struct {
		Status string `json:"STATUS"`
	} `json:"result"`
}

卡状态

Jump to

Keyboard shortcuts

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