首次完整推送,

V:1.20240808.006
This commit is contained in:
fm453
2024-08-13 18:32:37 +08:00
parent 15be3e9373
commit c62d15b288
939 changed files with 111777 additions and 0 deletions

View File

View File

@ -0,0 +1,84 @@
{
"id": "uni-open-bridge",
"displayName": "uni-open-bridge",
"version": "1.0.0",
"description": "uni-open-bridge",
"keywords": [
"uni-open-bridge"
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"category": [
"uniCloud",
"云函数模板"
],
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-vue": "u",
"app-nvue": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

View File

@ -0,0 +1,577 @@
# uni-open-bridge
`uni-open-bridge`
## config.json
```json
{
"schedule": {
"__UNI__xxxxxx": {
"enable": true,
"mp-weixin": {
"enable": true,
"tasks": ["accessToken"]
},
"h5-weixin": {
"enable": false,
"tasks": ["ticket"]
}
}
},
"ipWhitelist": ["0.0.0.0"]
}
```
## http 调用
请求类型 `POST`, 需要配置IP白名单字段 `ipWhitelist`,参见 `config.json`
### 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"
}
```
# uni-open-bridge-common
`uni-open-bridge-common``uni-id` 体系中用于 `开放平台数据` 管理的公共模块。
> `云函数公共模块`是不同云函数共享代码的一种方式。如果你不了解什么是`云函数公共模块`,请另读文档[公共模块](https://uniapp.dcloud.io/uniCloud/cf-common)
`uni-open-bridge-common` 提供了 `access_token``session_key``encrypt_key``ticket` 的读取、写入、删除操作。
`uni-open-bridge-common` 支持多层 读取 / 写入 机制,`redis -> database -> fallback`,优先级如下:
如果用户没有开通 `redis` 或者操作失败,透传到 `database``database` 失败后,如果用户配置了 `fallback`,继续调用 `fallback` 方法,否则抛出 `Error`
`database` 对应的表为: `opendb-open-data`
## access_token
`access_token` 是微信小程序全局唯一后台接口调用凭据,调用绝大多数后台接口时都需使用。开发者可以通过 getAccessToken 接口获取并进行妥善保存。[详情](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/backend-api.html#access_token)
### getAccessToken(key: Object)
读取 access_token
### setAccessToken(key: Object, value: Object, expiresIn: Number)
写入 access_token
### removeAccessToken(key: Object)
删除 access_token
### key 属性
|参数 |类型 |必填 |描述 |
|:-: |:-: |:-: |:-: |
|dcloudAppid|String |是 |DCloud应用appid。[详情](https://ask.dcloud.net.cn/article/35907) |
|platform |String |是 |[详情](#platform) |
|fallback |Function |否 |[详情](#fallback) |
### value 属性
|参数 |类型 |描述 |
|:-: |:-: |:-: |
|access_token |String | |
### expiresIn
有效时间(秒)
### 示例代码
```js
'use strict';
const {
getAccessToken,
setAccessToken,
removeAccessToken
} = require('uni-open-bridge-common')
exports.main = async (event, context) => {
const key = {
dcloudAppid: '',
platform: ''
}
const value = {
access_token: ''
}
const expiresIn = 7200
// 写入 (redis / 数据库)
await setAccessToken(key, value, expiresIn)
// 读取 (redis / 数据库)
let result1 = await getAccessToken(key)
// 删除
await removeAccessToken(key)
// 删除后读取, 返回 null
let result2 = await getAccessToken(key)
console.log(result2) // null
return null
};
```
## user_key
平台对应的值
|平台 |值 |描述 |
|:-: |:-: |:-: |
|微信小程序 |session_key|微信小程序会话密钥。[详情](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/code2Session.html) |
### getUserKey(key: Object)
读取 user_key
### setUserKey(key: Object, value: Object, expiresIn: Number)
写入 user_key
### removeUserKey(key: Object)
删除 user_key
### key 属性
|参数 |类型 |必填 |描述 |
|:-: |:-: |:-: |:-: |
|dcloudAppid|String |是 |DCloud应用appid。[详情](https://ask.dcloud.net.cn/article/35907) |
|platform |String |是 |[详情](#platform) |
|openid |String |是 | |
|fallback |Function |否 |[详情](#fallback) |
### value 属性
|参数 |类型 |描述 |
|:-: |:-: |:-: |
|session_key|String |微信小程序会话密钥 |
### expiresIn
有效时间(秒)
### 示例代码
```js
'use strict';
const {
getUserKey,
setUserKey,
removeUserKey,
} = require('uni-open-bridge-common')
exports.main = async (event, context) => {
const key = {
dcloudAppid: '',
platform: '',
openid: ''
}
const value = {
'session_key': ''
}
const expiresIn = 7200
// 写入 (redis / 数据库)
await setUserKey(key, value, expiresIn)
// 读取 (redis / 数据库)
let result1 = await getUserKey(key)
// 删除
await removeUserKey(key)
// 删除后读取, 返回 null
let result2 = await getUserKey(key)
console.log(result2) // null
return null
};
```
## encrypt_key
为了避免小程序与开发者后台通信时数据被截取和篡改微信侧维护了一个用户维度的可靠key用于小程序和后台通信时进行加密和签名。[详情](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/user-encryptkey.html)
开发者可以分别通过小程序前端和微信后台提供的接口,获取用户的加密 key。
### getEncryptKey(key: Object)
读取 encrypt_key
### setEncryptKey(key: Object, value: Object, expiresIn: Number)
写入 encrypt_key
### removeEncryptKey(key: Object)
删除 encrypt_key
### key 属性
|参数 |类型 |必填 |描述 |
|:-: |:-: |:-: |:-: |
|dcloudAppid|String |是 |DCloud应用appid。[详情](https://ask.dcloud.net.cn/article/35907) |
|platform |String |是 |[详情](#platform) |
|openid |String |是 | |
|version |Number |是 |版本 |
|fallback |Function |否 |[详情](#fallback) |
### value 属性
|参数 |类型 |描述 |
|:-: |:-: |:-: |
|encrypt_key|String |加密 key |
|iv |String |加密 iv |
### expiresIn
有效时间(秒)
### 示例代码
```js
'use strict';
const {
getEncryptKey,
setEncryptKey,
removeEncryptKey
} = require('uni-open-bridge-common')
exports.main = async (event, context) => {
const key = {
dcloudAppid: '',
platform: '',
openid: '',
version: 1
}
const value = {
encrypt_key: '',
iv: ''
}
const expiresIn = 7200
// 写入 (redis / 数据库)
await setEncryptKey(key, value, expiresIn)
// 读取 (redis / 数据库)
let result1 = await getEncryptKey(key)
// 删除
await removeEncryptKey(key)
// 删除后读取, 返回 null
let result2 = await getEncryptKey(key)
console.log(result2) // null
return null
};
```
## ticket
`ticket` 是公众号用于调用微信 JS 接口的临时票据。[详情](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#62)
### getTicket(key: Object)
读取 ticket
### setTicket(key: Object, value: Object, expiresIn: Number)
写入 ticket
### removeTicket(key: Object)
删除 ticket
### key 属性
|参数 |类型 |必填 |描述 |
|:-: |:-: |:-: |:-: |
|dcloudAppid|String |是 |DCloud应用appid。[详情](https://ask.dcloud.net.cn/article/35907) |
|platform |String |是 |[详情](#platform) |
|fallback |Function |否 |[详情](#fallback) |
### value 属性
|参数 |类型 |描述 |
|:-: |:-: |:-: |
|ticket |String | |
### expiresIn
有效时间(秒)
### 示例代码
```js
'use strict';
const {
getTicket,
setTicket,
removeTicket
} = require('uni-open-bridge-common')
exports.main = async (event, context) => {
const key = {
dcloudAppid: '',
platform: ''
}
const value = {
ticket: ''
}
const expiresIn = 7200
// 写入 (redis / 数据库)
await setTicket(key, value, expiresIn)
// 读取 (redis / 数据库)
let result1 = await getTicket(key)
// 删除
await removeTicket(key)
// 删除后读取, 返回 null
let result2 = await getTicket(key)
console.log(result2) // null
return null
};
```
## Platform@platform
平台对应的值
|值 |描述 |
|:-: |:-: |
|mp-weixin |微信小程序 |
|app-weixin |微信 App |
|h5-weixin |微信公众号 |
|web-weixin |微信pc网页 |
|mp-qq |QQ 小程序 |
|app-qq |QQ App |
## fallback@fallback
可选 `async function fallback()`,当 `reids -> database` 都找不到对应 `key` 时,调用此方法,需要返回数据格式如下
```json
{
value: null,
duration: 1
}
```
注意事项
- 所有方法类型为 `async`,需要使用 `await`
- 所有方法校验 `key` 属性是否有效,无效则 `throw new Error()`,对 `value` 仅校验是否为 `undefined`

View File

@ -0,0 +1,131 @@
'use strict';
class Command {
constructor() {
this._registered = {}
}
async execute(name, args) {
if (this._registered[name]) {
return await this._registered[name].execute(args)
}
}
canExecute(name, args) {
if (this._registered[name] && this._registered[name].canExecute) {
this._registered[name].canExecute(args)
}
return false
}
register(name, execute, canExecute) {
this._registered[name] = {
execute,
canExecute
}
}
}
class Task {
constructor(id) {
this._id = id || this._newTaskId()
this._state = Task.TASK_STATE.WAITING
}
async run() {}
async cancel() {}
async taskAction() {}
_newTaskId() {
let guid = ''
const format = 'xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx'
for (let i = 0; i < format.length; i++) {
if (format[i] === 'x') {
guid += (Math.random() * 16 | 0).toString(16)
} else {
guid += format[i]
}
}
return guid.toUpperCase()
}
get id() {
return this._id
}
set id(value) {
this._id = value
}
get state() {
return this._state
}
set state(value) {
this._state = value
}
}
Task.TASK_STATE = {
WAITING: "WAITING",
RESOLVING: "RESOLVING",
RESOLVED: "RESOLVED",
EXECUTING: "EXECUTING",
ERROR: "ERROR",
COMPLETED: "COMPLETED",
CANCELLING: "CANCELLING",
CANCELLED: "CANCELLED"
}
class TaskManager {
constructor() {
this._tasks = []
}
get tasks() {
return this._tasks
}
clear() {
this._tasks.length = 0
}
getTask(id) {
return this._tasks.find((item) => {
return (item.id == id)
})
}
addTask(task) {
this._tasks.push(task)
}
deleteTask(id) {
const index = this.findIndex(id)
if (index < 0) {
return
}
this._tasks[index].cancel()
if (index > -1) {
this._tasks.splice(index, 1)
}
}
findIndex(id) {
return this._tasks.findIndex((item) => {
return (item.id == id)
})
}
}
module.exports = {
Command,
Task,
TaskManager
};

View File

@ -0,0 +1,197 @@
'use strict';
const {
PlatformType
} = require('./consts.js')
const configCenter = require('uni-config-center')
const OauthConfig = {
'mp-weixin': ['oauth', 'weixin'],
'h5-weixin': ['oauth', 'weixin']
}
class TaskConfig {
constructor(options) {
this._dcloudAppid = options.dcloudAppid
this._appid = options.appid
this._secret = options.secret
this._platform = options.platform
this._tasks = options.tasks
this._timeout = 1000 * 10
}
get dcloudAppid() {
return this._dcloudAppid
}
get appid() {
return this._appid
}
get secret() {
return this._secret
}
get platform() {
return this._platform
}
get tasks() {
return this._tasks
}
}
class ConfigBase {
constructor() {
const uniIdConfig = configCenter({
pluginId: 'uni-id'
})
const openBridgeConfig = configCenter({
pluginId: 'uni-open-bridge'
})
this._uniId = uniIdConfig.config()
this._openBridge = openBridgeConfig.config()
this._ready = true
}
getAppConfig(appid) {
if (Array.isArray(this._uniId)) {
return this._uniId.find((item) => {
return (item.dcloudAppid === appid)
})
}
if (this._uniId.dcloudAppid === appid) {
return this._uniId
}
return null
}
inWhitelist(ip) {
return (this.ipWhitelist.indexOf(ip) > -1)
}
get openBridge() {
return this._openBridge
}
get ipWhitelist() {
return this._openBridge.ipWhitelist
}
get ready() {
return this._ready
}
}
class OpenBridgeConfig extends ConfigBase {
constructor() {
super()
this._tasks = []
this.resolve()
}
get tasks() {
return this._tasks
}
resolve() {
this._tasks.length = 0
const appids = Object.keys(this.openBridge.schedule)
for (let i = 0; i < appids.length; i++) {
const appid = appids[i]
let appConfig = this.getAppConfig(appid)
if (appConfig != null) {
const schedule = this.openBridge.schedule[appid]
if (schedule) {
this.resolveSchedule(appid, appConfig, schedule)
}
}
}
}
resolveSchedule(dcloudAppid, appConfig, schedule) {
if (schedule.enable !== true) {
return
}
const schedulePlatforms = Object.keys(schedule)
for (let i = 0; i < schedulePlatforms.length; i++) {
const platformName = schedulePlatforms[i]
const scheduleTask = schedule[platformName]
if (!scheduleTask.enable) {
continue
}
if (!this.isSupport(platformName)) {
continue
}
const oauthConfig = this.getOauthConfig(appConfig, platformName)
if (!oauthConfig) {
continue
}
this._tasks.push({
platform: platformName,
tasks: scheduleTask.tasks,
dcloudAppid: dcloudAppid,
appid: oauthConfig.appid,
secret: oauthConfig.secret
})
}
}
isSupport(platformName) {
return (OpenBridgeConfig.Support_Platforms.indexOf(platformName) >= 0)
}
getOauthConfig(appConfig, platformName) {
const platformConfig = appConfig[platformName]
if (!platformConfig) {
return null
}
let tree = OauthConfig[platformName]
let node = platformConfig
for (let i = 0; i < tree.length; i++) {
let nodeName = tree[i]
if (node[nodeName]) {
node = node[nodeName]
} else {
node = null
break
}
}
if (node && node.appid && node.appsecret) {
return {
appid: node.appid,
secret: node.appsecret
}
}
return null
}
}
OpenBridgeConfig.Support_Platforms = ['mp-weixin', 'h5-weixin']
module.exports = {
OpenBridgeConfig
};

View File

@ -0,0 +1,19 @@
'use strict';
const HTTP_STATUS = {
SUCCESS: 200
}
const PlatformType = {
MP_WEIXIN: 'mp-weixin',
H5_WEIXIN: 'h5-weixin',
APP_WEIXIN: 'app-weixin',
WEB_WEIXIN: 'web-weixin',
MP_QQ: 'mp-qq',
APP_QQ: 'app-qq'
}
module.exports = {
HTTP_STATUS,
PlatformType
}

View File

@ -0,0 +1,93 @@
'use strict';
const {
getAccessToken,
setAccessToken,
removeAccessToken,
getUserKey,
setUserKey,
removeUserKey,
getEncryptKey,
setEncryptKey,
removeEncryptKey,
getTicket,
setTicket,
removeTicket
} = require('uni-open-bridge-common')
const {
Command
} = require('./basic.js');
const {
OpenBridgeConfig
} = require('./config.js')
const openBridgeConfig = new OpenBridgeConfig()
class MainFrame extends Command {
constructor() {
super()
MainFrame.Commands.forEach((name) => {
this.register(name, this[name].bind(this))
})
}
async getAccessToken(parameters) {
return await getAccessToken(parameters)
}
async setAccessToken(parameters) {
return await setAccessToken(parameters, parameters.value, parameters.expiresIn)
}
async removeAccessToken(parameters) {
return await removeAccessToken(parameters)
}
async getUserKey(parameters) {
return await getUserKey(parameters, null)
}
async setUserKey(parameters) {
return await setUserKey(parameters, parameters.value, parameters.expiresIn)
}
async removeUserKey(parameters) {
return await removeUserKey(parameters)
}
async getTicket(parameters) {
return await getTicket(parameters, null)
}
async setTicket(parameters) {
return await setTicket(parameters, parameters.value, parameters.expiresIn)
}
async removeTicket(parameters) {
return await removeTicket(parameters)
}
checkIP(ip) {
return openBridgeConfig.inWhitelist(ip)
}
}
MainFrame.Commands = [
'getAccessToken',
'setAccessToken',
'removeAccessToken',
'getUserKey',
'setUserKey',
'removeUserKey',
'getTicket',
'setTicket',
'removeTicket'
];
const commands = new MainFrame();
module.exports = commands;

View File

@ -0,0 +1,62 @@
'use strict';
const {
PlatformType
} = require('./consts.js')
const runTask = require('./index.task.js')
const weixinCommand = require('./index.mp-weixin.js')
async function executeCommand() {
const methodName = this.getMethodName()
const parameters = JSON.parse(this.getHttpInfo().body)
if (parameters.platform === PlatformType.MP_WEIXIN) {
return await weixinCommand.execute(methodName, parameters)
}
throw new Error('Invalid Platform')
}
module.exports = {
async _timing() {
console.log('triggered by timing')
await runTask()
},
async _before() {
const clientInfo = this.getClientInfo()
if (!weixinCommand.checkIP(clientInfo.clientIP)) {
throw new Error("Invalid IP:" + clientInfo.clientIP)
}
},
// async runTask() {
// await runTask()
// },
async getAccessToken() {
return await executeCommand.call(this)
},
async setAccessToken() {
return await executeCommand.call(this)
},
async removeAccessToken() {
return await executeCommand.call(this)
},
async getUserKey() {
return await executeCommand.call(this)
},
async setUserKey() {
return await executeCommand.call(this)
},
async removeUserKey() {
return await executeCommand.call(this)
},
async getTicket() {
return await executeCommand.call(this)
},
async setTicket() {
return await executeCommand.call(this)
},
async removeTicket() {
return await executeCommand.call(this)
}
}

View File

@ -0,0 +1,86 @@
'use strict';
const {
OpenBridgeConfig
} = require('./config.js')
const {
TaskManager
} = require('./basic.js')
const {
TaskAccessTokenMP
} = require('./task-mp-weixin.js')
const {
TaskAccessTokenH5,
TaskTicket
} = require('./task-h5-weixin.js')
const TaskMapping = {
'mp-weixin': {
'accessToken': TaskAccessTokenMP
},
'h5-weixin': {
'accessToken': TaskAccessTokenH5,
'ticket': TaskTicket
}
}
class ScheduleManager extends TaskManager {
constructor() {
super()
}
async runAll() {
for (let i = 0; i < this.tasks.length; i++) {
const task = this.tasks[i]
try {
await task.run()
} catch (e) {
console.log("task.run::", e)
}
}
}
newTask(T, config) {
const newTask = new T(config)
super.addTask(newTask)
return newTask
}
}
ScheduleManager.instance = function() {
if (!ScheduleManager._instance) {
ScheduleManager._instance = new ScheduleManager()
}
return ScheduleManager._instance
}
async function main() {
const openBridgeConfig = new OpenBridgeConfig()
ScheduleManager.instance().clear()
for (let taskConfig of openBridgeConfig.tasks) {
let {
platform,
tasks
} = taskConfig
for (let taskName of tasks) {
const platformTask = TaskMapping[platform]
if (platformTask) {
ScheduleManager.instance().newTask(platformTask[taskName], taskConfig)
}
}
}
await ScheduleManager.instance().runAll()
}
module.exports = main;

View File

@ -0,0 +1,10 @@
{
"name": "uni-open-bridge",
"dependencies": {
"uni-open-bridge-common": "file:../common/uni-open-bridge-common",
"uni-config-center": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
},
"extensions": {
"uni-cloud-jql": {}
}
}

View File

@ -0,0 +1,67 @@
'use strict';
const {
getAccessToken,
setAccessToken,
removeAccessToken,
getTicket,
setTicket,
removeTicket
} = require('uni-open-bridge-common')
const {
Task
} = require('./basic.js')
const {
PlatformType
} = require('./consts.js')
class TaskAccessTokenH5 extends Task {
constructor(config) {
super()
this._config = config || null
}
async run() {
const key = {
dcloudAppid: this._config.dcloudAppid,
platform: PlatformType.H5_WEIXIN
}
const result = await getAccessToken(key)
console.log("setAccessToken...", key, result)
}
}
TaskAccessTokenH5.ID = 'TaskAccessTokenH5'
class TaskTicket extends Task {
constructor(config) {
super()
this._config = config || null
}
async run() {
const key = {
dcloudAppid: this._config.dcloudAppid,
platform: PlatformType.H5_WEIXIN
}
const result = await getTicket(key)
console.log("setTicket...", key, result)
}
}
TaskTicket.ID = 'TaskTicket'
module.exports = {
TaskAccessTokenH5,
TaskTicket
}

View File

@ -0,0 +1,41 @@
'use strict';
const {
getAccessToken,
setAccessToken,
removeAccessToken
} = require('uni-open-bridge-common')
const {
Task
} = require('./basic.js')
const {
PlatformType
} = require('./consts.js')
class TaskAccessTokenMP extends Task {
constructor(config) {
super()
this._config = config || null
}
async run() {
const key = {
dcloudAppid: this._config.dcloudAppid,
platform: PlatformType.MP_WEIXIN
}
const result = await getAccessToken(key)
console.log("setAccessToken...", key, result)
}
}
TaskAccessTokenMP.ID = 'TaskAccessTokenMP'
module.exports = {
TaskAccessTokenMP
}