github.com/qiniu/go-sdk/v7@v7.27.0/linking/README.md (about)

     1   # Linking Cloud Server-Side Library for Go
     2  
     3  ## Features
     4  
     5  - 设备管理
     6  	- [x] 添加新的设备: AddDevice(appid string, dev *Device)
     7  	- [x] 查询设备详细信息: QueryDevice(appid, device string)
     8  	- [x] 查询所有设备的列表: ListDevice(appid, prefix, marker string, limit int, online bool)
     9  	- [x] 查询设备的在线记录: ListDeviceHistoryactivity(appid, dev string, start, end int, marker string, limit int)
    10  	- [x] 更新设备配置: UpdateDevice(appid, device string, ops []PatchOperation)
    11  	- [x] 删除指定的设备: DeleteDevice(appid, device string)
    12  
    13  - 设备密钥管理
    14  	- [x] 新增设备密钥: AddDeviceKey(appid, device string)
    15  	- [x] 查询设备密钥: QueryDeviceKey(appid, device string)
    16  	- [x] 删除设备密钥: DeleteDeviceKey(appid, device, dak string)
    17  	- [x] 禁用、启用设备的密钥:UpdateDeviceKeyState(appid, device, dak string, state int)
    18  	- [x] 克隆设备: CloneDeviceKey(appid, fromdevice, todevice string, cleanSelfKeys, deleteDevice bool, deviceAccessKey string)
    19  	- [x] 通过设备 acceskey 查询设备 appid 和 device name: QueryAppidDeviceNameByAccessKey(dak string)
    20  
    21  - Vod
    22  	- [x] 视频片段查询: Segments(appid, device string, start, end int, marker string, limit int)
    23  	- [x] 视频片段进行收藏: Saveas(appid, device string, start, end int, fname, format string)
    24  
    25  - Dtoken
    26  	- [x] 视频回放/缩略图查询/倍速播放/延时直播/视频片段查询 Token 生成: VodToken(appid, device string, deadline int64)
    27  	- [x] 在线记录查询/设备查询 Token 生成: StatusToken(appid, device string, deadline int64)
    28  
    29  ## Contents
    30  
    31  - [Usage](#usage)
    32      - [Configuration](#configuration)
    33  	- [Device](#device)
    34  		- [Add Device](#add-device)
    35  		- [Query Device](#query-device)
    36  		- [List Device](#list-device)
    37  		- [List Device history activity](#list-device-history-activity)
    38  		- [Update Device](#update-device)
    39  		- [Delete Device](#delete-device)
    40  
    41  	- [Device Token](#deviceKey)
    42  		- [Add Device Key](#add-device-key)
    43  		- [Query Deivce Key](#query-deviceKey)
    44  		- [Delete Device Key](#delete-deviceKey)
    45  		- [Update Device Key State](#update-deviceKey))
    46  		- [Clone Device Key](#clone-deviceKey)
    47  		- [Query Appid Device By Device Key](#query-appid-device-by-deviceKey)
    48  	- [Vod](#vod)
    49  		- [Get Segments](#get-segments)
    50  		- [Saveas](#saveas)
    51  
    52  	- [Dtoken](#vod)
    53  		- [Get Vod Token](#get-vod-token)
    54  		- [Get Status Token](#get-status-token)
    55  
    56  ## Usage
    57  
    58  ### Configuration
    59  
    60  ```go
    61  package main
    62  
    63  import (
    64  	// ...
    65  	"github.com/qiniu/go-sdk/v7/auth"
    66  	"github.com/qiniu/go-sdk/v7/linking"
    67  )
    68  
    69  var (
    70  	AccessKey = "<QINIU ACCESS KEY>" // 替换成自己 Qiniu 账号的 AccessKey.
    71  	SecretKey = "<QINIU SECRET KEY>" // 替换成自己 Qiniu 账号的 SecretKey.
    72  	Appid   = "<Appid>"    // App 必须事先创建.
    73  )
    74  
    75  func main() {
    76  	// ...
    77  	mac := auth.New(testAccessKey, testSecretKey)
    78  	manager := linking.NewManager(mac, nil)
    79  	// ...
    80  }
    81  ```
    82  
    83  ### URL
    84  
    85  #### Add Device
    86  
    87  ```go
    88  manager.AddDevice(Appid, dev)
    89  ```
    90  
    91  #### Query Device
    92  
    93  ```go
    94  dev2, err := manager.QueryDevice(Appid, device)
    95  ```
    96  
    97  #### List Device
    98  
    99  ```go
   100  devices, marker, err = manager.ListDevice(Appid, "sdk-testListDevice", "", 1000, false)
   101  ```
   102  
   103  #### List Device history activity
   104  
   105  ```go
   106  segs, marker, err := manager.ListDeviceHistoryactivity(Appid, device, int(start), int(end), "", 1000)
   107  ```
   108  
   109  #### Update Device
   110  
   111  ```go
   112  ops := []PatchOperation{
   113  		PatchOperation{Op: "replace", Key: "segmentExpireDays", Value: 30},
   114  	}
   115  dev3, err := manager.UpdateDevice(Appid, device, ops)
   116  ```
   117  
   118  #### Delete Device
   119  ```go
   120  manager.DeleteDevice(Appid, device)
   121  ```
   122  
   123  ### Device Key
   124  
   125  #### Add Device Key
   126  
   127  ```go
   128  manager.AddDeviceKey(Appid, device)
   129  ```
   130  
   131  #### Query Deivce Key
   132  
   133  ```go
   134  keys, err := manager.QueryDeviceKey(Appid, device)
   135  ```
   136  
   137  #### Delete Device Key
   138  
   139  ```go
   140  err := manager.DeleteDeviceKey(Appid, device, dak)
   141  ```
   142  
   143  #### Update Device Key State
   144  
   145  ```go
   146  err = manager.UpdateDeviceKeyState(Appid, device, dak, 1)
   147  ```
   148  
   149  #### Clone Device Key
   150  
   151  ```go
   152  keys, err := manager.CloneDeviceKey(Appid, device1, device2, false, false, dak1)
   153  ```
   154  
   155  #### Query Appid Device By Device Key
   156  ```go
   157  appid, device, err := manager.QueryAppidDeviceNameByAccessKey(dak)
   158  ```
   159  
   160  ### Vod
   161  
   162  #### Get Segments
   163  
   164  ```go
   165  end := time.Now().Unix()
   166  start := time.Now().Add(-time.Hour).Unix()
   167  segs, marker, err := manager.Segments(Appid, device, int(start), int(end), "", 1000)
   168  ```
   169  
   170  #### Saveas
   171  
   172  ```go
   173  end := time.Now().Unix()
   174  start := time.Now().Add(-time.Hour).Unix()
   175  saveasReply, _ := manager.Saveas(Appid, device, int(start), int(end), "testSaveas.mp4", "mp4")
   176  ```
   177  ### Dtoken
   178  
   179  #### Get Vod Token
   180  ```go
   181  token, err := manager.VodToken(Appid, device, time.Now().Add(time.Hour*5).Unix())
   182  fmt.Println(token)
   183  ```
   184  #### Get Status Token
   185  ```go
   186  time.Sleep(time.Second)
   187  token, err := manager.VodToken(Appid, device, time.Now().Add(time.Hour*5).Unix())
   188  noError(t, err)
   189  fmt.Println(token)
   190  ```
   191  
   192  
   193  视频播放相关 api 编程模型说明:
   194  如用户请求视频相关api(例如:[https://developer.qiniu.com/linking/api/5650/playback](https://developer.qiniu.com/linking/api/5650/playback))时进行业务服务器中转,会造成访问路径比较长, 因此建议服务端只进行dtoken的签算并提供给播放端,播放端直接请求视频播放相关的API,提升播放体验。
   195  具体下token签算参考 [https://developer.qiniu.com/linking/api/5680/the-signature-in-the-url](https://developer.qiniu.com/linking/api/5680/the-signature-in-the-url)
   196  ![WeChatWorkScreenshot_c6c3e265-5ca3-48d9-8cc5-c40343506eeb](https://user-images.githubusercontent.com/34932312/63987548-3d000100-cb0b-11e9-971b-7aea84e07c67.png)