50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
import { cloneDeep } from 'oak-domain/lib/utils/lodash';
|
|
import { applicationProjection } from '../types/Projection';
|
|
import { assert } from 'oak-domain/lib/utils/assert';
|
|
import WechatSDK from 'oak-external-sdk/lib/WechatSDK';
|
|
export async function wechatMpJump(params, context) {
|
|
const { applicationId, jump_wxa, expireType, expiresAt, expireInterval } = params;
|
|
const envVersionVersionDict = {
|
|
development: 'develop',
|
|
staging: 'trial',
|
|
production: 'release',
|
|
};
|
|
Object.assign(jump_wxa, {
|
|
env_version: envVersionVersionDict[process.env.NODE_ENV],
|
|
});
|
|
assert(applicationId);
|
|
const [application] = await context.select('application', {
|
|
data: cloneDeep(applicationProjection),
|
|
filter: {
|
|
id: applicationId,
|
|
},
|
|
}, {
|
|
dontCollect: true,
|
|
});
|
|
assert(application);
|
|
const { systemId } = application;
|
|
const { type } = application;
|
|
let application2;
|
|
if (type === 'wechatMp') {
|
|
application2 = application;
|
|
}
|
|
else {
|
|
[application2] = await context.select('application', {
|
|
data: cloneDeep(applicationProjection),
|
|
filter: {
|
|
systemId,
|
|
type: 'wechatMp',
|
|
},
|
|
}, {
|
|
dontCollect: true,
|
|
});
|
|
}
|
|
assert(application2);
|
|
const { config } = application2;
|
|
const config2 = config;
|
|
const { appId, appSecret } = config2;
|
|
const wechatInstance = WechatSDK.getInstance(appId, 'wechatMp', appSecret);
|
|
const result = await wechatInstance.getURLScheme({ jump_wxa, expireType, expiresAt, expireInterval });
|
|
return result;
|
|
}
|