提交 1b09d07f 编写于 作者: JiaRongPing's avatar JiaRongPing
......@@ -91,9 +91,9 @@
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#FFF",
"backgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
/* #ifdef H5 */
"navigationStyle": "custom"
,"navigationStyle": "custom"
/* #endif */
},
"condition": { //模式配置,仅开发期间生效
......
module.exports = {
beforeRegister: function({
userRecord,
clientInfo
} = {}){
console.log(clientInfo);
userRecord.role = ['test-role']
return userRecord
}
}
\ No newline at end of file
// 导入配置
import config from '@/uni_modules/uni-id-pages/config.js'
const passwordLength = config.password.length
const passwordStrength = config.password.strength
let minPasswordLength = 6
let maxPasswordLength = 20
if (passwordLength) {
if (passwordLength[0]) {
minPasswordLength = passwordLength[0]
}
if (passwordLength[1]) {
maxPasswordLength = passwordLength[1]
}
}
// 密码强度表达式
const passwordRules = {
// 密码必须包含大小写字母、数字和特殊符号
super: /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/])[0-9a-zA-Z~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/]{8,16}$/,
// 密码必须包含字母、数字和特殊符号
strong: /^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/])[0-9a-zA-Z~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/]{8,16}$/,
// 密码必须为字母、数字和特殊符号任意两种的组合
medium: /^(?![0-9]+$)(?![a-zA-Z]+$)(?![~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/]+$)[0-9a-zA-Z~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/]{8,16}$/,
// 密码必须包含字母和数字
weak: /^(?=.*[0-9])(?=.*[a-zA-Z])[0-9a-zA-Z~!@#$%^&*_\-+=`|\\(){}[\]:;"'<>,.?/]{6,16}$/
}
const ERROR = {
normal: {
noPwd: '请输入密码',
noRePwd: '再次输入密码',
rePwdErr: '两次输入密码不一致'
},
passwordStrengthError: {
superstrong: '密码必须包含大小写字母、数字和特殊符号',
strong: '密码必须包含字母、数字和特殊符号',
medium: '密码必须为字母、数字和特殊符号任意两种的组合',
weak: '密码必须包含字母'
},
passwordLengthError: {
normal: '密码长度必须在' + minPasswordLength + '-' + maxPasswordLength + '位之间',
minLimit: '密码长度不得少于' + minPasswordLength + '',
maxLimit: '密码长度不得超过' + maxPasswordLength + ''
}
}
function validPwd(password) {
//强度校验
if (passwordStrength && passwordRules[passwordStrength]) {
if (!new RegExp(passwordRules[passwordStrength]).test(password)) {
return ERROR.passwordStrengthError[passwordStrength]
}
}
//长度校验
if (passwordLength) {
if (passwordLength[0] && password.length < passwordLength[0]) {
return ERROR.passwordLengthError.minLimit
}
if (passwordLength[1] && password.length > passwordLength[1]) {
return ERROR.passwordLengthError.maxLimit
}
}
return true
}
function getPwdRules(pwdName = 'password', rePwdName = 'password2') {
const rules = {}
rules[pwdName] = {
rules: [{
required: true,
errorMessage: ERROR.normal.noPwd,
},
{
validateFunction: function(rule, value, data, callback) {
const checkRes = validPwd(value)
if (checkRes !== true) {
callback(checkRes)
}
return true
}
}
]
}
if (rePwdName) {
rules[rePwdName] = {
rules: [{
required: true,
errorMessage: ERROR.normal.noRePwd,
},
{
validateFunction: function(rule, value, data, callback) {
if (value != data.password) {
callback(ERROR.normal.rePwdErr)
}
return true
}
}
]
}
}
return rules
}
export default {
ERROR,
minPasswordLength,
maxPasswordLength,
validPwd,
getPwdRules
}
......@@ -43,26 +43,16 @@
},
agree: {
get() {
return this.uniParentComponent.agree
return this.getParentComponent().agree
},
set(agree) {
console.log('setAgree', agree);
return this.uniParentComponent.agree = agree
return this.getParentComponent().agree = agree
}
}
},
data() {
// #ifndef H5
const uniParentComponent = this.$parent;
// #endif
// #ifdef H5
const uniParentComponent = this.$parent.$parent;
// #endif
return {
//父组件对象
uniParentComponent,
servicesList: [{
"id": "username",
"text": "账号登录",
......@@ -198,10 +188,16 @@
})
//console.log('servicesList', servicesList, this.servicesList);
},
async mounted() {
},
methods: {
getParentComponent(){
// #ifndef H5
return this.$parent;
// #endif
// #ifdef H5
return this.$parent.$parent;
// #endif
},
setUserInfo(e) {
console.log('setUserInfo', e);
},
......@@ -298,7 +294,7 @@
needAgreements
});
if (type != 'univerify' && needAgreements && !this.agree) {
let agreementsRef = this.uniParentComponent.$refs.agreements
let agreementsRef = this.getParentComponent().$refs.agreements
return agreementsRef.popup(() => {
console.log(type, navigateBack);
this.login_before(type, navigateBack)
......
......@@ -40,7 +40,7 @@
if(res.errMsg != "getUserProfile:ok"){
return this.closeMe()
}
let {avatarUrl,nickName} = res.userInfo, cloudPath = userId+'/'+Date.now()+'avatarUrl.jpg';
let {avatarUrl,nickName} = res.userInfo;
let tempFilePath = await new Promise((callBack)=>{
uni.downloadFile({
......@@ -60,6 +60,8 @@
}
});
})
const extName = tempFilePath.split('.').pop() || 'jpg'
const cloudPath = 'user/avatar/'+ userId+'/'+Date.now()+'-avatar.'+extName;
// console.log(tempFilePath);
const result = await uniCloud.uploadFile({
filePath: tempFilePath,
......
......@@ -29,18 +29,30 @@ export default {
"agreements": {
"serviceUrl": "https://xxx", //用户服务协议链接
"privacyUrl": "https://xxx", //隐私政策条款链接
// 哪些场景下显示,1.注册(包括登录并注册,如:微信登录、苹果登录、短信验证码登录)、2.登录(如:用户名密码登录)
"scope": [
'register', 'login'
// 哪些场景下显示,1.注册(包括登录并注册,如:微信登录、苹果登录、短信验证码登录)、2.登录(如:用户名密码登录)
"scope": [
'register', 'login'
]
},
// 提供各类服务接入(如微信登录服务)的应用id
"appid":{
"weixin":{
// 微信公众号的appid,来源:登录微信公众号(https://mp.weixin.qq.com)-> 设置与开发 -> 基本配置 -> 公众号开发信息 -> AppID
"h5":"xxxxxx",
// 微信开放平台的appid,来源:登录微信开放平台(https://open.weixin.qq.com) -> 管理中心 -> 网站应用 -> 选择对应的应用名称,点击查看 -> AppID
"web":"xxxxxx"
}
},
// 提供各类服务接入(如微信登录服务)的应用id
"appid": {
"weixin": {
// 微信公众号的appid,来源:登录微信公众号(https://mp.weixin.qq.com)-> 设置与开发 -> 基本配置 -> 公众号开发信息 -> AppID
"h5": "xxxxxx",
// 微信开放平台的appid,来源:登录微信开放平台(https://open.weixin.qq.com) -> 管理中心 -> 网站应用 -> 选择对应的应用名称,点击查看 -> AppID
"web": "xxxxxx"
}
},
/**
* 密码强度
* superstrong(超强:密码必须包含大小写字母、数字和特殊符号)
* strong(强: 密码必须包含字母、数字和特殊符号)
* medium (中:密码必须为字母、数字和特殊符号任意两种的组合)
* weak(弱:密码必须包含字母)
* 为空或false则不验证密码强度
*/
"password": {
"strength": "strong",
"length": [6, 20] //密码长度,默认在6-20位之间
}
}
}
......@@ -47,7 +47,7 @@
"uni-load-more",
"uni-popup",
"uni-scss",
"uni-transition"
"uni-transition"
],
"encrypt": [],
"platforms": {
......
......@@ -19,7 +19,7 @@
</uni-forms-item>
<uni-forms-item name="password" v-model="formData.password" required>
<uni-easyinput :inputBorder="false" :focus="focusPassword" @blur="focusPassword = false"
class="input-box" maxlength="20" placeholder="请输入6-20位密码" type="password"
class="input-box" maxlength="20" :placeholder="'请输入' + passwordLength[0] + '-' + passwordLength[1] + '位密码'" type="password"
v-model="formData.password" trim="both" />
</uni-forms-item>
<uni-forms-item name="password2" v-model="formData.password2" required>
......@@ -46,6 +46,7 @@
<script>
import rules from './validator.js';
import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js';
import config from '@/uni_modules/uni-id-pages/config.js'
const uniIdCo = uniCloud.importObject("uni-id-co")
export default {
mixins: [mixin],
......@@ -66,6 +67,11 @@
logo: "/static/logo.png"
}
},
computed:{
passwordLength(){
return config.passwordLength
}
},
onReady() {
this.$refs.form.setRules(this.rules)
},
......
import passwordMod from '@/uni_modules/uni-id-pages/common/password.js'
export default {
"username": {
"rules": [{
......@@ -42,45 +43,14 @@ export default {
if (/^\d+$/.test(value)) {
callback('昵称不能为纯数字')
};
if(/[\u4E00-\u9FA5\uF900-\uFA2D]{1,}/.test(value)){
callback('昵称不能包含中文')
}
return true
}
}
],
"label": "昵称"
},
"password": {
"rules": [{
required: true,
errorMessage: '密码长度不少于6位',
},
{
minLength: 6,
maxLength: 20,
errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符',
}
],
"label": "密码"
},
"password2": {
"rules": [{
required: true,
errorMessage: '再次输入密码',
},
{
minLength: 6,
maxLength: 20,
errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符',
},
{
validateFunction: function(rule, value, data, callback) {
// console.log(value);
if (value != data.password) {
callback('两次输入密码不一致')
};
return true
}
}
],
"label": "确认密码"
}
...passwordMod.getPwdRules()
}
......@@ -32,6 +32,7 @@ const USER_STATUS = {
}
const CAPTCHA_SCENE = {
REGISTER: 'register',
LOGIN_BY_PWD: 'login-by-pwd',
LOGIN_BY_SMS: 'login-by-sms',
RESET_PWD_BY_SMS: 'reset-pwd-by-sms',
......
......@@ -54,8 +54,7 @@ const {
} = require('./module/verify/index')
const {
refreshToken,
setPushCid,
getH5WeixinConfig
setPushCid
} = require('./module/utils/index')
const {
getInvitedUser,
......@@ -490,13 +489,5 @@ module.exports = {
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-supported-login-type
* @returns
*/
getSupportedLoginType,
/**
* 获取微信公众号config参数
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-h5-weixin-config
* @param {object} params
* @param {string} params.url 当前页面url不带hash部分
* @returns
*/
getH5WeixinConfig
getSupportedLoginType
}
const path = require('path')
const fs = require('fs')
const {
getWeixinPlatform
} = require('./weixin')
const createConfig = require('uni-config-center')
const requiredConfig = {
'web.h5-weixin': ['appid', 'appsecret'],
......@@ -13,6 +12,11 @@ const requiredConfig = {
'mp-alipay.alipay': ['appid', 'privateKey'],
'app.apple': ['bundleId']
}
const uniIdConfig = createConfig({
pluginId: 'uni-id'
})
class ConfigUtils {
constructor ({
context
......@@ -61,14 +65,17 @@ class ConfigUtils {
getPlatformConfig () {
const appConfig = this.getAppConfig()
if (!appConfig) {
throw new Error(`Config for current app (${this.appId}) was not found, please check your config file or client appId`)
throw new Error(
`Config for current app (${this.appId}) was not found, please check your config file or client appId`)
}
const platform = this.platform
if (
(this.platform === 'app' && appConfig['app-plus']) ||
(this.platform === 'web' && appConfig.h5)
) {
throw new Error(`Client platform is ${this.platform}, but ${this.platform === 'web' ? 'h5' : 'app-plus'} was found in config. Please refer to: https://uniapp.dcloud.net.cn/uniCloud/uni-id-summary?id=m-to-co`)
throw new Error(
`Client platform is ${this.platform}, but ${this.platform === 'web' ? 'h5' : 'app-plus'} was found in config. Please refer to: https://uniapp.dcloud.net.cn/uniCloud/uni-id-summary?id=m-to-co`
)
}
const defaultConfig = {
......@@ -88,7 +95,7 @@ class ConfigUtils {
if (provider === 'weixin' && clientPlatform === 'web') {
const weixinPlatform = getWeixinPlatform.call(this.context)
if (weixinPlatform === 'h5' || weixinPlatform === 'web') {
oatuhProivder = weixinPlatform + '-weixin' // h5-weixin 公众号,web-weixin pc端
oatuhProivder = 'weixin-' + weixinPlatform // weixin-h5 公众号,weixin-web pc端
}
}
return oatuhProivder
......@@ -116,10 +123,10 @@ class ConfigUtils {
}
getHooks () {
const configPath = require.resolve('uni-config-center/uni-id')
const hookPath = path.resolve(configPath, 'hooks/index.js')
if (fs.existsSync(hookPath)) {
return require(hookPath)
if (uniIdConfig.hasFile('hooks/index.js')) {
return require(
uniIdConfig.resolve('hooks/index.js')
)
}
return {}
}
......
......@@ -31,13 +31,13 @@ async function saveQQUserKey ({
const keyObj = {
dcloudAppid: appId,
openid,
platform: qqPlatform + '-weixin'
platform: 'qq-' + qqPlatform
}
switch (qqPlatform) {
case 'mp':
await this.uniOpenBridge.setSessionKey(keyObj, {
session_key: sessionKey
})
}, 30 * 24 * 60 * 60)
break
case 'app':
case 'h5':
......
......@@ -63,13 +63,13 @@ async function saveWeixinUserKey ({
const keyObj = {
dcloudAppid: appId,
openid,
platform: weixinPlatform + '-weixin'
platform: 'weixin-' + weixinPlatform
}
switch (weixinPlatform) {
case 'mp':
await this.uniOpenBridge.setSessionKey(keyObj, {
session_key: sessionKey
})
}, 30 * 24 * 60 * 60)
break
case 'app':
case 'h5':
......
......@@ -106,7 +106,7 @@ module.exports = async function (params = {}) {
openid
})
// eslint-disable-next-line n/no-deprecated-api
const avatarPath = url.parse(avatar).pathname
const avatarPath = url.parse(avatar).pathname
const extName = avatarPath.indexOf('.') > -1 ? url.parse(avatar).pathname.split('.').pop() : 'jpg'
const cloudPath = `user/avatar/${openid.slice(-8) + Date.now()}-avatar.${extName}`
const getAvatarRes = await uniCloud.httpclient.request(avatar)
......
......@@ -5,6 +5,9 @@ const {
const {
verifyCaptcha
} = require('../../lib/utils/captcha')
const {
CAPTCHA_SCENE
} = require('../../common/constants')
/**
* 注册普通用户
......@@ -42,7 +45,7 @@ module.exports = async function (params = {}) {
await verifyCaptcha.call(this, {
captcha,
scene: 'register'
scene: CAPTCHA_SCENE.REGISTER
})
const {
......
const {
getWeixinPlatform
} = require('../../lib/utils/weixin')
const {
getNonceStr
} = require('../../common/utils')
const {
createHash
} = require('crypto')
/**
* 获取微信公众号config参数
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-h5-weixin-config
* @param {object} params
* @param {string} params.url 当前页面url不带hash部分
* @returns
*/
module.exports = async function (params) {
const schema = {
url: 'string'
}
this.middleware.validate(params, schema)
const {
url
} = params
const oauthConfig = this.configUtils.getOauthConfig({
provider: 'weixin'
})
const {
appId
} = this.getClientInfo()
const weixinPlatform = getWeixinPlatform.call(this)
const getTicketRes = await this.uniOpenBridge.getTicket({
dcloudAppid: appId,
platform: weixinPlatform + '-weixin'
})
if (!getTicketRes) {
throw new Error('Wechat official account ticket not found, please referer to: https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#login-by-weixin-h5')
}
const ticket = getTicketRes.ticket
const signContent = {
jsapi_ticket: ticket,
noncestr: getNonceStr(),
timestamp: Math.floor(Date.now() / 1000),
url: url.split('#')[0]
}
const signStr = Object.keys(signContent).sort().reduce(function (str, key) {
return str + key + '=' + signContent[key] + '&'
}, '').replace(/&$/, '')
const signature = createHash('sha1').update(signStr, 'utf8').digest('hex')
return {
errCode: 0,
appId: oauthConfig.appid, // 公众号的唯一标识
timestamp: signContent.timestamp, // 生成签名的时间戳
nonceStr: signContent.noncestr, // 生成签名的随机串
signature // 签名
}
}
module.exports = {
refreshToken: require('./refresh-token'),
setPushCid: require('./set-push-cid'),
getH5WeixinConfig: require('./get-h5-weixin-config')
setPushCid: require('./set-push-cid')
}
{
"name": "uni-id-co",
"version": "1.0.2",
"version": "1.0.8",
"description": "",
"main": "index.js",
"keywords": [],
......
const clientInfo = {
"PLATFORM": "web",
"OS": "ios",
"APPID": "__UNI__ECAF623",
"DEVICEID": "16558192370391366615",
"scene": 1001,
"appId": "__UNI__ECAF623",
"appLanguage": "zh-Hans",
"appName": "uni-id-pages",
"appVersion": "1.0.0",
"appVersionCode": "100",
"browserName": "safari",
"browserVersion": "13.0.3",
"deviceId": "16558192370391366615",
"deviceModel": "iPhone",
"deviceOrientation": "portrait",
"devicePixelRatio": 2.0000000298023224,
"deviceType": "phone",
"hostLanguage": "en-US",
"hostName": "safari",
"hostVersion": "13.0.3",
"osName": "ios",
"osVersion": "13.2.3",
"safeArea": {
"left": 0,
"right": 375,
"top": 0,
"bottom": 667,
"width": 375,
"height": 667
},
"safeAreaInsets": {
"top": 0,
"right": 0,
"bottom": 0,
"left": 0
},
"screenHeight": 667,
"screenWidth": 375,
"statusBarHeight": 0,
"ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1",
"uniCompileVersion": "3.5.4",
"uniPlatform": "web",
"uniRuntimeVersion": "3.5.4",
"windowBottom": 0,
"windowHeight": 667,
"windowTop": 0,
"windowWidth": 375,
"locale": "zh-Hans",
"LOCALE": "zh-Hans"
}
registerUser({
"username": "qqq2",
"nickname": "",
"password": "qqq11122",
"password2": "qqq11122",
"captcha": "3IPP"
})
\ No newline at end of file
## 1.0.0(2022-08-05
## 1.0.0(2022-08-12
- 首次发布
# uni-open-bridge
`uni-open-bridge` 是统一接管微信等三方平台认证的开源库
`uni-open-bridge` 是统一接管微信等三方平台认证凭据(包括但不限于`access_token``session_key``encrypt_key``ticket`)的开源库。
文档链接 [https://uniapp.dcloud.net.cn/uniCloud/uni-open-bridge](https://uniapp.dcloud.net.cn/uniCloud/uni-open-bridge)
'use strict';
const {
PlatformType
} = require('./consts.js')
const configCenter = require('uni-config-center')
const OauthConfig = {
'mp-weixin': ['mp-weixin', 'oauth', 'weixin'],
'h5-weixin': ['web', 'oauth', 'h5-weixin']
'weixin-mp': ['mp-weixin', 'oauth', 'weixin'],
'weixin-h5': ['web', 'oauth', 'weixin-h5']
}
class ConfigBase {
......@@ -83,7 +87,7 @@ class AppConfig extends ConfigBase {
}
}
AppConfig.Support_Platforms = ['mp-weixin', 'h5-weixin']
AppConfig.Support_Platforms = [PlatformType.WEIXIN_MP, PlatformType.WEIXIN_H5]
module.exports = {
......
......@@ -5,12 +5,12 @@ const HTTP_STATUS = {
}
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'
WEIXIN_MP: 'weixin-mp',
WEIXIN_H5: 'weixin-h5',
WEIXIN_APP: 'weixin-app',
WEIXIN_WEB: 'weixin-web',
QQ_MP: 'qq-mp',
QQ_APP: 'qq-app'
}
module.exports = {
......
......@@ -31,7 +31,7 @@ class AccessToken extends Storage {
async fallback(parameters) {
const oauthConfig = appConfig.get(parameters.dcloudAppid, parameters.platform)
const methodName = (parameters.platform === PlatformType.MP_WEIXIN) ? 'GetMPAccessTokenData' :
const methodName = (parameters.platform === PlatformType.WEIXIN_MP) ? 'GetMPAccessTokenData' :
'GetH5AccessTokenData'
const responseData = await WeixinServer[methodName](oauthConfig)
......@@ -111,7 +111,7 @@ class Ticket extends Storage {
async fallback(parameters) {
const accessToken = await Factory.Get(AccessToken, {
dcloudAppid: parameters.dcloudAppid,
platform: PlatformType.H5_WEIXIN
platform: PlatformType.WEIXIN_H5
})
const responseData = await WeixinServer.GetH5TicketData(accessToken)
......@@ -204,5 +204,7 @@ module.exports = {
removeEncryptKey,
getTicket,
setTicket,
removeTicket
removeTicket,
PlatformType,
WeixinServer
}
'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) {
......@@ -141,17 +132,10 @@ class OpenBridgeConfig extends ConfigBase {
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
platform: platformName,
tasks: scheduleTask.tasks
})
}
}
......@@ -159,37 +143,9 @@ class OpenBridgeConfig extends ConfigBase {
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']
OpenBridgeConfig.Support_Platforms = ['weixin-mp', 'weixin-h5']
module.exports = {
......
'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
}
......@@ -9,19 +9,16 @@ const {
} = require('./basic.js')
const {
TaskAccessTokenMP
} = require('./task-mp-weixin.js')
const {
TaskAccessTokenMP,
TaskAccessTokenH5,
TaskTicket
} = require('./task-h5-weixin.js')
} = require('./task-weixin.js')
const TaskMapping = {
'mp-weixin': {
'weixin-mp': {
'accessToken': TaskAccessTokenMP
},
'h5-weixin': {
'weixin-h5': {
'accessToken': TaskAccessTokenH5,
'ticket': TaskTicket
}
......
'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
}
......@@ -2,20 +2,34 @@
const {
getAccessToken,
setAccessToken,
removeAccessToken,
getTicket,
setTicket,
removeTicket
PlatformType
} = 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.WEIXIN_MP
}
const result = await getAccessToken(key)
console.log("setAccessToken...", key, result)
}
}
TaskAccessTokenMP.ID = 'TaskAccessTokenMP'
class TaskAccessTokenH5 extends Task {
......@@ -28,7 +42,7 @@ class TaskAccessTokenH5 extends Task {
async run() {
const key = {
dcloudAppid: this._config.dcloudAppid,
platform: PlatformType.H5_WEIXIN
platform: PlatformType.WEIXIN_H5
}
const result = await getAccessToken(key)
......@@ -36,7 +50,6 @@ class TaskAccessTokenH5 extends Task {
console.log("setAccessToken...", key, result)
}
}
TaskAccessTokenH5.ID = 'TaskAccessTokenH5'
class TaskTicket extends Task {
......@@ -50,7 +63,7 @@ class TaskTicket extends Task {
async run() {
const key = {
dcloudAppid: this._config.dcloudAppid,
platform: PlatformType.H5_WEIXIN
platform: PlatformType.WEIXIN_H5
}
const result = await getTicket(key)
......@@ -58,10 +71,10 @@ class TaskTicket extends Task {
console.log("setTicket...", key, result)
}
}
TaskTicket.ID = 'TaskTicket'
module.exports = {
TaskAccessTokenMP,
TaskAccessTokenH5,
TaskTicket
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册