uni-open-bridge.md 3.9 KB
Newer Older
d-u-a's avatar
d-u-a 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
# uni-open-bridge

`uni-open-bridge``uni-id` 体系中用于 `开放平台数据` 定时刷新 `access_token``ticket` 的云对象,使用 `uni-open-bridge` 可免维护 `access_token``ticket` 的定时刷新

`uni-open-bridge` 从微信的服务器获取数据,通过 [uni-open-bridge-commmon](https://uniapp.dcloud.net.cn/uniCloud/uni-open-bridge-common) 保存到 `Redis``database`

`uni-open-bridge` 提供了 http 请求的操作方式


## config.json

配置文件需要依赖 `uni-config-center`,在 `uni-config-center` 根目录添加文件夹 `uni-open-bridge`, 新增 `config.json`, 内容如下

```json
{
  "schedule": {
    "__UNI__xxxxxx": { // dcloudAppid,需要在 `uni-config-center` uni-id 中配置
      "enable": true, // 任务全局开关,优先级最高
      "mp-weixin": { // 平台,目前仅支持 微信小程序、微信 H5,详情参见 https://uniapp.dcloud.net.cn/uniCloud/uni-open-bridge#platform
        "enable": true, // 当前平台任务开关
        "tasks": ["accessToken"] // 要执行的任务,微信小程序支持 accessToken
      },
      "h5-weixin": {
        "enable": false,
        "tasks": ["ticket"] // 支持微信 H5 ticket,因 ticker 依赖微信 H5 accessToken,内部自动先获取 accessToken。此处的 accessToken 和微信小程序的 accessToken 不是一个值
      }
    }
  },
  "ipWhitelist": ["0.0.0.0"] // 用于 http 调用的服务器IP白名单,支持配置多个,阿里云暂不支持独立IP,可以先使用腾讯云,如果需要使用阿里云,可以通过http的方式将值保存
}
```

注意:拷贝此文件内容到 `config.json` 时需要移除`注释`


## http 调用

请求类型 `POST`, 需要配置IP白名单字段 `ipWhitelist`,参见 `config.json`

同时需要开启 [URL化](https://uniapp.dcloud.net.cn/uniCloud/http.html),详见 [uniCloud Web](https://unicloud.dcloud.net.cn/) 控制台

### getAccessToken

Url

```
https://xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx.bspapp.com/uni-open-bridge/getAccessToken
```

参数

```json
{
  "dcloudAppid": "__UNI__xxx",
  "platform": "mp-weixin"
}
```

### setAccessToken

Url

```
https://xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx.bspapp.com/uni-open-bridge/setAccessToken
```

```json
{
  "dcloudAppid": "__UNI__xxx",
  "platform": "mp-weixin",
  "value": {
    "access_token": ""
  },
  "expiresIn": 7200
}
```

### removeAccessToken

Url

```
https://xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx.bspapp.com/uni-open-bridge/removeAccessToken
```

参数

```json
{
  "dcloudAppid": "__UNI__xxx",
  "platform": "mp-weixin"
}
```

### getUserKey

Url

```
https://xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx.bspapp.com/uni-open-bridge/getUserKey
```

参数

```json
{
  "dcloudAppid": "__UNI__xxx",
  "platform": "mp-weixin",
  "openid": ""
}
```

### setUserKey

Url

```
https://xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx.bspapp.com/uni-open-bridge/setUserKey
```

参数

```json
{
  "dcloudAppid": "__UNI__xxx",
  "platform": "mp-weixin",
  "openid": "",
  "value": {
    "session_key": ""
  },
  "expiresIn": 7200
}
```

### removeUserKey

Url

```
https://xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx.bspapp.com/uni-open-bridge/removeUserKey
```

参数

```json
{
  "dcloudAppid": "__UNI__xxx",
  "platform": "mp-weixin",
  "openid": ""
}
```

### getTicket

Url

```
https://xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx.bspapp.com/uni-open-bridge/getTicket
```

参数

```json
{
  "dcloudAppid": "__UNI__xxx",
  "platform": "mp-weixin"
}
```


### setTicket

Url

```
https://xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx.bspapp.com/uni-open-bridge/setTicket
```

参数

```json
{
  "dcloudAppid": "__UNI__xxx",
  "platform": "mp-weixin",
  "value": {
    "ticket": ""
  },
  "expiresIn": 7200
}
```

### removeTicket

Url

```
https://xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx.bspapp.com/uni-open-bridge/removeTicket
```

参数

```json
{
  "dcloudAppid": "__UNI__xxx",
  "platform": "mp-weixin"
}
```


注意:部署后将自动开启定时任务,间隔1小时执行