Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
6935c641
H
hello_uni-id-pages
项目概览
DCloud
/
hello_uni-id-pages
通知
1054
Star
31
Fork
43
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
2
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello_uni-id-pages
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6935c641
编写于
8月 12, 2022
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
deps: bump uni-open-bridge to pre-release version
上级
7e6fecb6
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
249 addition
and
627 deletion
+249
-627
uni_modules/uni-open-bridge/changelog.md
uni_modules/uni-open-bridge/changelog.md
+2
-0
uni_modules/uni-open-bridge/package.json
uni_modules/uni-open-bridge/package.json
+12
-8
uni_modules/uni-open-bridge/readme.md
uni_modules/uni-open-bridge/readme.md
+2
-574
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/common/uni-open-bridge-common/config.js
...ud/cloudfunctions/common/uni-open-bridge-common/config.js
+1
-9
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/common/uni-open-bridge-common/index.js
...oud/cloudfunctions/common/uni-open-bridge-common/index.js
+36
-13
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/common/uni-open-bridge-common/validator.js
...cloudfunctions/common/uni-open-bridge-common/validator.js
+3
-0
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/uni-open-bridge/bridge.js
...-bridge/uniCloud/cloudfunctions/uni-open-bridge/bridge.js
+126
-0
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/uni-open-bridge/config.js
...-bridge/uniCloud/cloudfunctions/uni-open-bridge/config.js
+4
-4
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/uni-open-bridge/index.obj.js
...idge/uniCloud/cloudfunctions/uni-open-bridge/index.obj.js
+49
-17
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/uni-open-bridge/package.json
...idge/uniCloud/cloudfunctions/uni-open-bridge/package.json
+14
-2
未找到文件。
uni_modules/uni-open-bridge/changelog.md
浏览文件 @
6935c641
## 1.0.0(2022-08-05)
-
首次发布
uni_modules/uni-open-bridge/package.json
浏览文件 @
6935c641
...
...
@@ -2,13 +2,17 @@
"id"
:
"uni-open-bridge"
,
"displayName"
:
"uni-open-bridge"
,
"version"
:
"1.0.0"
,
"description"
:
"uni-open-bridge"
,
"description"
:
"uni-open-bridge
是统一接管微信等三方平台认证的开源库
"
,
"keywords"
:
[
"uni-open-bridge"
"uni-open-bridge-common"
,
"access_token"
,
"session_key"
,
"ticket"
,
"微信"
],
"repository"
:
""
,
"engines"
:
{
"HBuilderX"
:
"^3.
1.0
"
"HBuilderX"
:
"^3.
5.1
"
},
"dcloudext"
:
{
"category"
:
[
...
...
@@ -27,9 +31,9 @@
"qq"
:
""
},
"declaration"
:
{
"ads"
:
""
,
"data"
:
""
,
"permissions"
:
""
"ads"
:
"
无
"
,
"data"
:
"
无
"
,
"permissions"
:
"
无
"
},
"npmurl"
:
""
},
...
...
@@ -38,8 +42,8 @@
"encrypt"
:
[],
"platforms"
:
{
"cloud"
:
{
"tcb"
:
"
u
"
,
"aliyun"
:
"
u
"
"tcb"
:
"
y
"
,
"aliyun"
:
"
y
"
},
"client"
:
{
"Vue"
:
{
...
...
uni_modules/uni-open-bridge/readme.md
浏览文件 @
6935c641
# uni-open-bridge
`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`
文档链接
[
https://uniapp.dcloud.net.cn/uniCloud/uni-open-bridge
](
https://uniapp.dcloud.net.cn/uniCloud/uni-open-bridge
)
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/common/uni-open-bridge-common/config.js
浏览文件 @
6935c641
...
...
@@ -52,15 +52,7 @@ class AppConfig extends ConfigBase {
return
null
}
const
oauthConfig
=
this
.
getOauthConfig
(
appConfig
,
platform
)
if
(
!
oauthConfig
)
{
return
null
}
return
{
appid
:
oauthConfig
.
appid
,
secret
:
oauthConfig
.
secret
}
return
this
.
getOauthConfig
(
appConfig
,
platform
)
}
isSupport
(
platformName
)
{
...
...
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/common/uni-open-bridge-common/index.js
浏览文件 @
6935c641
...
...
@@ -31,7 +31,8 @@ class AccessToken extends Storage {
async
fallback
(
parameters
)
{
const
oauthConfig
=
appConfig
.
get
(
parameters
.
dcloudAppid
,
parameters
.
platform
)
const
methodName
=
(
parameters
.
platform
===
PlatformType
.
MP_WEIXIN
)
?
'
GetMPAccessTokenData
'
:
'
GetH5AccessTokenData
'
const
methodName
=
(
parameters
.
platform
===
PlatformType
.
MP_WEIXIN
)
?
'
GetMPAccessTokenData
'
:
'
GetH5AccessTokenData
'
const
responseData
=
await
WeixinServer
[
methodName
](
oauthConfig
)
const
duration
=
responseData
.
expires_in
...
...
@@ -44,10 +45,17 @@ class AccessToken extends Storage {
}
}
class
User
Key
extends
Storage
{
class
User
AccessToken
extends
Storage
{
constructor
()
{
super
(
'
user-key
'
,
[
'
dcloudAppid
'
,
'
platform
'
,
'
openid
'
])
super
(
'
user-access-token
'
,
[
'
dcloudAppid
'
,
'
platform
'
,
'
openid
'
])
}
}
class
SessionKey
extends
Storage
{
constructor
()
{
super
(
'
session-key
'
,
[
'
dcloudAppid
'
,
'
platform
'
,
'
openid
'
])
}
}
...
...
@@ -70,7 +78,7 @@ class Encryptkey extends Storage {
async
fallback
(
parameters
)
{
const
accessToken
=
await
Factory
.
Get
(
AccessToken
,
parameters
)
const
userSession
=
await
Factory
.
Get
(
User
Key
,
parameters
)
const
userSession
=
await
Factory
.
Get
(
Session
Key
,
parameters
)
const
responseData
=
await
WeixinServer
.
GetUserEncryptKeyData
({
openid
:
parameters
.
openid
,
...
...
@@ -133,16 +141,28 @@ async function removeAccessToken(key) {
await
Factory
.
Remove
(
AccessToken
,
key
)
}
async
function
getUserKey
(
key
,
fallback
)
{
return
await
Factory
.
Get
(
UserKey
,
key
,
fallback
)
async
function
getUserAccessToken
(
key
,
fallback
)
{
return
await
Factory
.
Get
(
UserAccessToken
,
key
,
fallback
)
}
async
function
setUserAccessToken
(
key
,
value
,
expiresIn
)
{
await
Factory
.
Set
(
UserAccessToken
,
key
,
value
,
expiresIn
)
}
async
function
removeUserAccessToken
(
key
)
{
await
Factory
.
Remove
(
UserAccessToken
,
key
)
}
async
function
getSessionKey
(
key
,
fallback
)
{
return
await
Factory
.
Get
(
SessionKey
,
key
,
fallback
)
}
async
function
set
User
Key
(
key
,
value
,
expiresIn
)
{
await
Factory
.
Set
(
User
Key
,
key
,
value
,
expiresIn
)
async
function
set
Session
Key
(
key
,
value
,
expiresIn
)
{
await
Factory
.
Set
(
Session
Key
,
key
,
value
,
expiresIn
)
}
async
function
remove
User
Key
(
key
)
{
await
Factory
.
Remove
(
User
Key
,
key
)
async
function
remove
Session
Key
(
key
)
{
await
Factory
.
Remove
(
Session
Key
,
key
)
}
async
function
getEncryptKey
(
key
,
fallback
)
{
...
...
@@ -173,9 +193,12 @@ module.exports = {
getAccessToken
,
setAccessToken
,
removeAccessToken
,
getUserKey
,
setUserKey
,
removeUserKey
,
getUserAccessToken
,
setUserAccessToken
,
removeUserAccessToken
,
getSessionKey
,
setSessionKey
,
removeSessionKey
,
getEncryptKey
,
setEncryptKey
,
removeEncryptKey
,
...
...
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/common/uni-open-bridge-common/validator.js
浏览文件 @
6935c641
...
...
@@ -16,6 +16,9 @@ const Validator = {
if
(
value
===
undefined
)
{
Validator
.
ThrowNewError
(
'
Invalid Value
'
)
}
if
(
typeof
value
!==
'
object
'
)
{
Validator
.
ThrowNewError
(
'
Invalid Value Type
'
)
}
},
ThrowNewError
(
message
)
{
...
...
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/uni-open-bridge/
index.mp-weixin
.js
→
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/uni-open-bridge/
bridge
.js
浏览文件 @
6935c641
...
...
@@ -4,9 +4,12 @@ const {
getAccessToken
,
setAccessToken
,
removeAccessToken
,
getUserKey
,
setUserKey
,
removeUserKey
,
getUserAccessToken
,
setUserAccessToken
,
removeUserAccessToken
,
getSessionKey
,
setSessionKey
,
removeSessionKey
,
getEncryptKey
,
setEncryptKey
,
removeEncryptKey
,
...
...
@@ -25,12 +28,30 @@ const {
const
openBridgeConfig
=
new
OpenBridgeConfig
()
const
Commands
=
[
'
getAccessToken
'
,
'
setAccessToken
'
,
'
removeAccessToken
'
,
'
getUserAccessToken
'
,
'
setUserAccessToken
'
,
'
removeUserAccessToken
'
,
'
getSessionKey
'
,
'
setSessionKey
'
,
'
removeSessionKey
'
,
'
getEncryptKey
'
,
'
setEncryptKey
'
,
'
removeEncryptKey
'
,
'
getTicket
'
,
'
setTicket
'
,
'
removeTicket
'
]
class
MainFrame
extends
Command
{
constructor
()
{
super
()
MainFrame
.
Commands
.
forEach
((
name
)
=>
{
Commands
.
forEach
((
name
)
=>
{
this
.
register
(
name
,
this
[
name
].
bind
(
this
))
})
}
...
...
@@ -47,16 +68,40 @@ class MainFrame extends Command {
return
await
removeAccessToken
(
parameters
)
}
async
getUserKey
(
parameters
)
{
return
await
getUserKey
(
parameters
,
null
)
async
getUserAccessToken
(
parameters
)
{
return
await
getUserAccessToken
(
parameters
)
}
async
setUserAccessToken
(
parameters
)
{
return
await
setUserAccessToken
(
parameters
,
parameters
.
value
,
parameters
.
expiresIn
)
}
async
removeUserAccessToken
(
parameters
)
{
return
await
removeUserAccessToken
(
parameters
)
}
async
getSessionKey
(
parameters
)
{
return
await
getSessionKey
(
parameters
,
parameters
.
fallback
||
null
)
}
async
set
User
Key
(
parameters
)
{
return
await
set
User
Key
(
parameters
,
parameters
.
value
,
parameters
.
expiresIn
)
async
set
Session
Key
(
parameters
)
{
return
await
set
Session
Key
(
parameters
,
parameters
.
value
,
parameters
.
expiresIn
)
}
async
removeUserKey
(
parameters
)
{
return
await
removeUserKey
(
parameters
)
async
removeSessionKey
(
parameters
)
{
return
await
removeSessionKey
(
parameters
)
}
async
getEncryptKey
(
parameters
)
{
return
await
getEncryptKey
(
parameters
,
null
)
}
async
setEncryptKey
(
parameters
)
{
return
await
setEncryptKey
(
parameters
,
parameters
.
value
,
parameters
.
expiresIn
)
}
async
removeEncryptKey
(
parameters
)
{
return
await
removeEncryptKey
(
parameters
)
}
async
getTicket
(
parameters
)
{
...
...
@@ -72,22 +117,10 @@ class MainFrame extends Command {
}
checkIP
(
ip
)
{
return
openBridgeConfig
.
inWhite
l
ist
(
ip
)
return
openBridgeConfig
.
inWhite
L
ist
(
ip
)
}
}
MainFrame
.
Commands
=
[
'
getAccessToken
'
,
'
setAccessToken
'
,
'
removeAccessToken
'
,
'
getUserKey
'
,
'
setUserKey
'
,
'
removeUserKey
'
,
'
getTicket
'
,
'
setTicket
'
,
'
removeTicket
'
];
const
commands
=
new
MainFrame
();
const
mainFrame
=
new
MainFrame
();
module
.
exports
=
commands
;
module
.
exports
=
mainFrame
;
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/uni-open-bridge/config.js
浏览文件 @
6935c641
...
...
@@ -73,16 +73,16 @@ class ConfigBase {
return
null
}
inWhite
l
ist
(
ip
)
{
return
(
this
.
ipWhite
l
ist
.
indexOf
(
ip
)
>
-
1
)
inWhite
L
ist
(
ip
)
{
return
(
this
.
ipWhite
L
ist
.
indexOf
(
ip
)
>
-
1
)
}
get
openBridge
()
{
return
this
.
_openBridge
}
get
ipWhite
l
ist
()
{
return
this
.
_openBridge
.
ipWhite
l
ist
get
ipWhite
L
ist
()
{
return
this
.
_openBridge
.
ipWhite
L
ist
}
get
ready
()
{
...
...
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/uni-open-bridge/index.obj.js
浏览文件 @
6935c641
'
use strict
'
;
const
{
PlatformType
}
=
require
(
'
./consts.js
'
)
const
runTask
=
require
(
'
./index.task.js
'
)
const
weixinCommand
=
require
(
'
./index.mp-weixin
.js
'
)
const
command
=
require
(
'
./bridge
.js
'
)
async
function
executeCommand
()
{
const
methodName
=
this
.
getMethodName
()
const
parameters
=
JSON
.
parse
(
this
.
getHttpInfo
().
body
)
const
clientInfo
=
this
.
getClientInfo
(
)
if
(
parameters
.
platform
===
PlatformType
.
MP_WEIXIN
)
{
return
await
weixinCommand
.
execute
(
methodName
,
parameters
)
let
parameters
if
(
clientInfo
.
source
===
'
http
'
)
{
const
postData
=
this
.
getHttpInfo
().
body
if
(
!
postData
||
postData
.
length
<
4
)
{
throw
new
Error
(
'
Invalid parameter(s)::
'
+
postData
)
}
parameters
=
JSON
.
parse
(
postData
)
}
else
if
(
clientInfo
.
source
===
'
function
'
)
{
const
args
=
this
.
getParams
()
parameters
=
args
[
0
]
if
(
args
.
length
===
2
)
{
parameters
.
value
=
args
[
1
]
}
if
(
args
.
length
===
3
)
{
parameters
.
expiresIn
=
args
[
2
]
}
}
else
{
throw
new
Error
(
'
Invalid
'
)
}
throw
new
Error
(
'
Invalid Platform
'
)
return
await
command
.
execute
(
methodName
,
parameters
)
}
module
.
exports
=
{
...
...
@@ -25,13 +37,11 @@ module.exports = {
},
async
_before
()
{
const
clientInfo
=
this
.
getClientInfo
()
if
(
!
weixinC
ommand
.
checkIP
(
clientInfo
.
clientIP
))
{
throw
new
Error
(
"
Invalid IP:
"
+
clientInfo
.
clientIP
)
if
(
clientInfo
.
source
===
'
http
'
&&
!
c
ommand
.
checkIP
(
clientInfo
.
clientIP
))
{
throw
new
Error
(
'
Invalid IP::
'
+
clientInfo
.
clientIP
)
}
},
// async runTask() {
// await runTask()
// },
/// AccessToken
async
getAccessToken
()
{
return
await
executeCommand
.
call
(
this
)
},
...
...
@@ -41,15 +51,37 @@ module.exports = {
async
removeAccessToken
()
{
return
await
executeCommand
.
call
(
this
)
},
async
getUserKey
()
{
/// UserAccessToken
async
getUserAccessToken
()
{
return
await
executeCommand
.
call
(
this
)
},
async
setUserAccessToken
()
{
return
await
executeCommand
.
call
(
this
)
},
async
removeUserAccessToken
()
{
return
await
executeCommand
.
call
(
this
)
},
/// SessionKey
async
getSessionKey
()
{
return
await
executeCommand
.
call
(
this
)
},
async
setSessionKey
()
{
return
await
executeCommand
.
call
(
this
)
},
async
removeSessionKey
()
{
return
await
executeCommand
.
call
(
this
)
},
/// EncryptKey
async
getEncryptKey
()
{
return
await
executeCommand
.
call
(
this
)
},
async
set
User
Key
()
{
async
set
Encrypt
Key
()
{
return
await
executeCommand
.
call
(
this
)
},
async
remove
User
Key
()
{
async
remove
Encrypt
Key
()
{
return
await
executeCommand
.
call
(
this
)
},
/// Ticket
async
getTicket
()
{
return
await
executeCommand
.
call
(
this
)
},
...
...
uni_modules/uni-open-bridge/uniCloud/cloudfunctions/uni-open-bridge/package.json
浏览文件 @
6935c641
...
...
@@ -4,7 +4,19 @@
"uni-open-bridge-common"
:
"file:../common/uni-open-bridge-common"
,
"uni-config-center"
:
"file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
},
"cloudfunction-config"
:
{
"memorySize"
:
256
,
"timeout"
:
60
,
"triggers"
:
[{
"name"
:
"uni-open-bridge"
,
"type"
:
"timer"
,
"config"
:
"0 0 * * * * *"
}],
"path"
:
""
,
"runtime"
:
"Nodejs8"
},
"extensions"
:
{
"uni-cloud-jql"
:
{}
"uni-cloud-jql"
:
{},
"uni-cloud-redis"
:
{}
}
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录