增加了公众号发跳转小程序认领授权的逻辑
This commit is contained in:
parent
94210abc56
commit
0b6a0b42cb
|
|
@ -9,6 +9,7 @@ var x2js_1 = tslib_1.__importDefault(require("x2js"));
|
||||||
var oak_external_sdk_1 = require("oak-external-sdk");
|
var oak_external_sdk_1 = require("oak-external-sdk");
|
||||||
var uuid_1 = require("oak-domain/lib/utils/uuid");
|
var uuid_1 = require("oak-domain/lib/utils/uuid");
|
||||||
var domain_1 = require("../utils/domain");
|
var domain_1 = require("../utils/domain");
|
||||||
|
var url_2 = require("oak-domain/lib/utils/url");
|
||||||
var X2Js = new x2js_1.default();
|
var X2Js = new x2js_1.default();
|
||||||
function assertFromWeChat(query, config) {
|
function assertFromWeChat(query, config) {
|
||||||
var _a;
|
var _a;
|
||||||
|
|
@ -103,10 +104,10 @@ function setUserUnsubscribed(openId, context) {
|
||||||
}
|
}
|
||||||
function setUserSubscribed(openId, eventKey, context) {
|
function setUserSubscribed(openId, eventKey, context) {
|
||||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||||
var _a, applicationId, applicationType, list, now, data, doUpdate, sceneStr, wcqId, _b, wechatQrCode, application, _c, type, config, _d, appId, appSecret, wechatInstance, expired, entity, entityId, _e, _f, userEntityGrant, _g, id, granter, expired_1, entity2, name_1, _h, domain, url;
|
var _a, applicationId, applicationType, list, now, data, doUpdate, sceneStr, wcqId, _b, wechatQrCode, application, _c, type, config, systemId, _d, appId, appSecret, wechatInstance, expired, entity, entityId, _e, _f, userEntityGrant, _g, id, granter, expired_1, entity2, qrCodeType, name_1, _h, domain, url, _j, appMp, config_1, appId_1, content;
|
||||||
var _this = this;
|
var _this = this;
|
||||||
return tslib_1.__generator(this, function (_j) {
|
return tslib_1.__generator(this, function (_k) {
|
||||||
switch (_j.label) {
|
switch (_k.label) {
|
||||||
case 0:
|
case 0:
|
||||||
_a = context.getApplication(), applicationId = _a.id, applicationType = _a.type;
|
_a = context.getApplication(), applicationId = _a.id, applicationType = _a.type;
|
||||||
return [4 /*yield*/, context.select('wechatUser', {
|
return [4 /*yield*/, context.select('wechatUser', {
|
||||||
|
|
@ -123,7 +124,7 @@ function setUserSubscribed(openId, eventKey, context) {
|
||||||
count: 1,
|
count: 1,
|
||||||
}, { dontCollect: true })];
|
}, { dontCollect: true })];
|
||||||
case 1:
|
case 1:
|
||||||
list = _j.sent();
|
list = _k.sent();
|
||||||
now = Date.now();
|
now = Date.now();
|
||||||
data = {
|
data = {
|
||||||
// activeAt: now,
|
// activeAt: now,
|
||||||
|
|
@ -195,7 +196,7 @@ function setUserSubscribed(openId, eventKey, context) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}); };
|
}); };
|
||||||
if (!eventKey) return [3 /*break*/, 9];
|
if (!eventKey) return [3 /*break*/, 11];
|
||||||
sceneStr = void 0;
|
sceneStr = void 0;
|
||||||
if (eventKey.startsWith('qrscene_')) {
|
if (eventKey.startsWith('qrscene_')) {
|
||||||
sceneStr = eventKey.slice(eventKey.indexOf('qrscene_') + 8);
|
sceneStr = eventKey.slice(eventKey.indexOf('qrscene_') + 8);
|
||||||
|
|
@ -218,10 +219,10 @@ function setUserSubscribed(openId, eventKey, context) {
|
||||||
count: 10,
|
count: 10,
|
||||||
}, { dontCollect: true })];
|
}, { dontCollect: true })];
|
||||||
case 2:
|
case 2:
|
||||||
_b = tslib_1.__read.apply(void 0, [_j.sent(), 1]), wechatQrCode = _b[0];
|
_b = tslib_1.__read.apply(void 0, [_k.sent(), 1]), wechatQrCode = _b[0];
|
||||||
if (!wechatQrCode) return [3 /*break*/, 8];
|
if (!wechatQrCode) return [3 /*break*/, 10];
|
||||||
application = context.getApplication();
|
application = context.getApplication();
|
||||||
_c = application, type = _c.type, config = _c.config;
|
_c = application, type = _c.type, config = _c.config, systemId = _c.systemId;
|
||||||
(0, assert_1.default)(type === 'wechatPublic');
|
(0, assert_1.default)(type === 'wechatPublic');
|
||||||
_d = config, appId = _d.appId, appSecret = _d.appSecret;
|
_d = config, appId = _d.appId, appSecret = _d.appSecret;
|
||||||
wechatInstance = oak_external_sdk_1.WechatSDK.getInstance(appId, 'wechatPublic', appSecret);
|
wechatInstance = oak_external_sdk_1.WechatSDK.getInstance(appId, 'wechatPublic', appSecret);
|
||||||
|
|
@ -241,19 +242,20 @@ function setUserSubscribed(openId, eventKey, context) {
|
||||||
case 'user': return [3 /*break*/, 3];
|
case 'user': return [3 /*break*/, 3];
|
||||||
case 'userEntityGrant': return [3 /*break*/, 4];
|
case 'userEntityGrant': return [3 /*break*/, 4];
|
||||||
}
|
}
|
||||||
return [3 /*break*/, 7];
|
return [3 /*break*/, 9];
|
||||||
case 3:
|
case 3:
|
||||||
{
|
{
|
||||||
// 裂变获得的用户
|
// 裂变获得的用户
|
||||||
if (list[0] && !list[0].userId) {
|
if (list[0] && !list[0].userId) {
|
||||||
Object.assign(data, { userId: entityId });
|
Object.assign(data, { userId: entityId });
|
||||||
}
|
}
|
||||||
return [3 /*break*/, 7];
|
return [3 /*break*/, 9];
|
||||||
}
|
}
|
||||||
_j.label = 4;
|
_k.label = 4;
|
||||||
case 4: return [4 /*yield*/, context.select('userEntityGrant', {
|
case 4: return [4 /*yield*/, context.select('userEntityGrant', {
|
||||||
data: {
|
data: {
|
||||||
id: 1,
|
id: 1,
|
||||||
|
qrCodeType: 1,
|
||||||
granter: {
|
granter: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 1,
|
name: 1,
|
||||||
|
|
@ -267,9 +269,10 @@ function setUserSubscribed(openId, eventKey, context) {
|
||||||
}
|
}
|
||||||
}, { dontCollect: true })];
|
}, { dontCollect: true })];
|
||||||
case 5:
|
case 5:
|
||||||
_f = tslib_1.__read.apply(void 0, [_j.sent(), 1]), userEntityGrant = _f[0];
|
_f = tslib_1.__read.apply(void 0, [_k.sent(), 1]), userEntityGrant = _f[0];
|
||||||
_g = userEntityGrant, id = _g.id, granter = _g.granter, expired_1 = _g.expired, entity2 = _g.entity;
|
_g = userEntityGrant, id = _g.id, granter = _g.granter, expired_1 = _g.expired, entity2 = _g.entity, qrCodeType = _g.qrCodeType;
|
||||||
name_1 = (granter === null || granter === void 0 ? void 0 : granter.name) || (granter === null || granter === void 0 ? void 0 : granter.nickname) || '某用户';
|
name_1 = (granter === null || granter === void 0 ? void 0 : granter.name) || (granter === null || granter === void 0 ? void 0 : granter.nickname) || '某用户';
|
||||||
|
if (!(qrCodeType === 'wechatPublic')) return [3 /*break*/, 7];
|
||||||
return [4 /*yield*/, context.select('domain', {
|
return [4 /*yield*/, context.select('domain', {
|
||||||
data: {
|
data: {
|
||||||
id: 1,
|
id: 1,
|
||||||
|
|
@ -293,7 +296,7 @@ function setUserSubscribed(openId, eventKey, context) {
|
||||||
}
|
}
|
||||||
}, { dontCollect: true })];
|
}, { dontCollect: true })];
|
||||||
case 6:
|
case 6:
|
||||||
_h = tslib_1.__read.apply(void 0, [_j.sent(), 1]), domain = _h[0];
|
_h = tslib_1.__read.apply(void 0, [_k.sent(), 1]), domain = _h[0];
|
||||||
(0, assert_1.default)(domain, "\u5904\u7406userEntityGrant\u65F6\uFF0C\u627E\u4E0D\u5230\u5BF9\u5E94\u7684domain\uFF0CapplicationId\u662F\u300C".concat(applicationId, "\u300D"));
|
(0, assert_1.default)(domain, "\u5904\u7406userEntityGrant\u65F6\uFF0C\u627E\u4E0D\u5230\u5BF9\u5E94\u7684domain\uFF0CapplicationId\u662F\u300C".concat(applicationId, "\u300D"));
|
||||||
url = (0, domain_1.composeDomainUrl)(domain, 'wechatQrCode/scan', {
|
url = (0, domain_1.composeDomainUrl)(domain, 'wechatQrCode/scan', {
|
||||||
scene: sceneStr,
|
scene: sceneStr,
|
||||||
|
|
@ -304,18 +307,46 @@ function setUserSubscribed(openId, eventKey, context) {
|
||||||
openId: openId,
|
openId: openId,
|
||||||
type: 'news',
|
type: 'news',
|
||||||
url: url,
|
url: url,
|
||||||
title: "".concat(name_1, "\u7ED9\u60A8\u521B\u5EFA\u4E86\u4E00\u4E2A\u6388\u6743"),
|
title: "".concat(name_1, "\u4E3A\u60A8\u521B\u5EFA\u4E86\u4E00\u4E2A\u6388\u6743"),
|
||||||
description: '请接受',
|
description: '请接受',
|
||||||
picurl: 'http://img95.699pic.com/element/40018/2473.png_860.png',
|
picurl: 'http://img95.699pic.com/element/40018/2473.png_860.png',
|
||||||
});
|
});
|
||||||
_j.label = 7;
|
return [3 /*break*/, 9];
|
||||||
case 7: return [3 /*break*/, 9];
|
case 7:
|
||||||
|
(0, assert_1.default)(qrCodeType === 'wechatPublicForMp');
|
||||||
|
return [4 /*yield*/, context.select('application', {
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
config: 1,
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
systemId: systemId,
|
||||||
|
type: 'wechatMp',
|
||||||
|
}
|
||||||
|
}, { dontCollect: true })];
|
||||||
case 8:
|
case 8:
|
||||||
console.warn("\u7EBF\u4E0A\u6709\u626B\u63CF\u4E8C\u7EF4\u7801\u573A\u666F\u503C\uFF0C\u4F46\u627E\u4E0D\u5230\u5BF9\u5E94\u7684qrCode\uFF0CeventKey\u662F".concat(eventKey));
|
_j = tslib_1.__read.apply(void 0, [_k.sent(), 1]), appMp = _j[0];
|
||||||
_j.label = 9;
|
(0, assert_1.default)(appMp, '公众号推送小程序码时找不到关联的小程序');
|
||||||
case 9: return [4 /*yield*/, doUpdate()];
|
config_1 = appMp.config;
|
||||||
|
appId_1 = config_1.appId;
|
||||||
|
content = "".concat(name_1, "\u4E3A\u60A8\u521B\u5EFA\u4E86\u4E00\u4E2A\u6388\u6743\uFF0C<a href=\"#\" data-miniprogram-appid=\"").concat(appId_1, "\" data-miniprogram-path=\"").concat((0, url_2.composeUrl)('/pages/wecharQrCode/scan', {
|
||||||
|
oakId: wcqId,
|
||||||
|
time: "".concat(Date.now()),
|
||||||
|
}), "\">\u8BF7\u70B9\u51FB\u9886\u53D6</a>");
|
||||||
|
(0, assert_1.default)(!expired_1); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。
|
||||||
|
wechatInstance.sendServeMessage({
|
||||||
|
openId: openId,
|
||||||
|
type: 'text',
|
||||||
|
content: content,
|
||||||
|
});
|
||||||
|
_k.label = 9;
|
||||||
|
case 9: return [3 /*break*/, 11];
|
||||||
case 10:
|
case 10:
|
||||||
_j.sent();
|
console.warn("\u7EBF\u4E0A\u6709\u626B\u63CF\u4E8C\u7EF4\u7801\u573A\u666F\u503C\uFF0C\u4F46\u627E\u4E0D\u5230\u5BF9\u5E94\u7684qrCode\uFF0CeventKey\u662F".concat(eventKey));
|
||||||
|
_k.label = 11;
|
||||||
|
case 11: return [4 /*yield*/, doUpdate()];
|
||||||
|
case 12:
|
||||||
|
_k.sent();
|
||||||
return [2 /*return*/];
|
return [2 /*return*/];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,7 @@ function render(props) {
|
||||||
!isOwner &&
|
!isOwner &&
|
||||||
number > confirmed && ((0, jsx_runtime_1.jsx)(antd_1.Button, tslib_1.__assign({ size: "large", block: true, type: "primary", onClick: function () {
|
number > confirmed && ((0, jsx_runtime_1.jsx)(antd_1.Button, tslib_1.__assign({ size: "large", block: true, type: "primary", onClick: function () {
|
||||||
handleConfirm();
|
handleConfirm();
|
||||||
}, disabled: oakExecuting }, { children: "\u9886\u53D6" }))), !oakLoading && !expired && (isOwner || hasConfirmed) && ((0, jsx_runtime_1.jsxs)(antd_1.Button, tslib_1.__assign({ size: "large", block: true, type: "primary", onClick: function () {
|
}, disabled: oakExecuting }, { children: "\u9886\u53D6" }))), utils_1.isWeiXin && ((0, jsx_runtime_1.jsx)(antd_1.Button, tslib_1.__assign({ size: "large", block: true, onClick: function () {
|
||||||
redirectPage();
|
|
||||||
}, disabled: oakExecuting }, { children: ["\u9886\u53D6\u6210\u529F", redirectTo ? '(' + redirectCounter + 's)' : ''] }))), utils_1.isWeiXin && ((0, jsx_runtime_1.jsx)(antd_1.Button, tslib_1.__assign({ size: "large", block: true, onClick: function () {
|
|
||||||
WeixinJSBridge.call('closeWindow');
|
WeixinJSBridge.call('closeWindow');
|
||||||
} }, { children: "\u5173\u95ED" })))] }))] })));
|
} }, { children: "\u5173\u95ED" })))] }))] })));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,17 +56,6 @@ exports.default = OakComponent({
|
||||||
var url = pathname.substring(0, 1) === '/'
|
var url = pathname.substring(0, 1) === '/'
|
||||||
? pathname
|
? pathname
|
||||||
: "/".concat(pathname);
|
: "/".concat(pathname);
|
||||||
// if (props) {
|
|
||||||
// for (const param in props) {
|
|
||||||
// const param2 = param as unknown as keyof typeof props;
|
|
||||||
// url += url.includes('?') ? '&' : '?';
|
|
||||||
// url += `${param}=${
|
|
||||||
// typeof props[param2] === 'string'
|
|
||||||
// ? props[param2]
|
|
||||||
// : JSON.stringify(props[param2])
|
|
||||||
// }`;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
this.redirectTo(tslib_1.__assign({ url: url }, props_1), state);
|
this.redirectTo(tslib_1.__assign({ url: url }, props_1), state);
|
||||||
return {
|
return {
|
||||||
loading: false,
|
loading: false,
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,11 @@ import {
|
||||||
} from 'oak-external-sdk';
|
} from 'oak-external-sdk';
|
||||||
import { EntityDict } from '../general-app-domain';
|
import { EntityDict } from '../general-app-domain';
|
||||||
import { BRC } from '../types/RuntimeCxt';
|
import { BRC } from '../types/RuntimeCxt';
|
||||||
import { WechatPublicConfig } from '../entities/Application';
|
import { WechatMpConfig, WechatPublicConfig } from '../entities/Application';
|
||||||
import { WechatPublicEventData } from 'oak-external-sdk';
|
import { WechatPublicEventData } from 'oak-external-sdk';
|
||||||
import { expandUuidTo36Bytes, generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
import { expandUuidTo36Bytes, generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
||||||
import { composeDomainUrl } from '../utils/domain';
|
import { composeDomainUrl } from '../utils/domain';
|
||||||
|
import { composeUrl } from 'oak-domain/lib/utils/url';
|
||||||
|
|
||||||
type VerifyQuery = {
|
type VerifyQuery = {
|
||||||
signature: string,
|
signature: string,
|
||||||
|
|
@ -218,7 +219,7 @@ async function setUserSubscribed(openId: string, eventKey: string, context: BRC)
|
||||||
);
|
);
|
||||||
if (wechatQrCode) {
|
if (wechatQrCode) {
|
||||||
const application = context.getApplication();
|
const application = context.getApplication();
|
||||||
const { type, config } = application!;
|
const { type, config, systemId } = application!;
|
||||||
assert(type === 'wechatPublic');
|
assert(type === 'wechatPublic');
|
||||||
const { appId, appSecret } = config as WechatPublicConfig;
|
const { appId, appSecret } = config as WechatPublicConfig;
|
||||||
|
|
||||||
|
|
@ -254,6 +255,7 @@ async function setUserSubscribed(openId: string, eventKey: string, context: BRC)
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
id: 1,
|
id: 1,
|
||||||
|
qrCodeType: 1,
|
||||||
granter: {
|
granter: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 1,
|
name: 1,
|
||||||
|
|
@ -268,46 +270,80 @@ async function setUserSubscribed(openId: string, eventKey: string, context: BRC)
|
||||||
},
|
},
|
||||||
{ dontCollect: true },
|
{ dontCollect: true },
|
||||||
);
|
);
|
||||||
const { id, granter, expired, entity: entity2 } = userEntityGrant!;
|
const { id, granter, expired, entity: entity2, qrCodeType } = userEntityGrant!;
|
||||||
|
|
||||||
const name = granter?.name || granter?.nickname || '某用户';
|
const name = granter?.name || granter?.nickname || '某用户';
|
||||||
const [domain] = await context.select('domain', {
|
if (qrCodeType === 'wechatPublic') {
|
||||||
data: {
|
// 推domain上的scan/code链接
|
||||||
id: 1,
|
|
||||||
url: 1,
|
const [domain] = await context.select('domain', {
|
||||||
apiPath: 1,
|
data: {
|
||||||
protocol: 1,
|
id: 1,
|
||||||
port: 1,
|
url: 1,
|
||||||
},
|
apiPath: 1,
|
||||||
filter: {
|
protocol: 1,
|
||||||
systemId: {
|
port: 1,
|
||||||
$in: {
|
},
|
||||||
entity: 'application',
|
filter: {
|
||||||
data: {
|
systemId: {
|
||||||
systemId: 1,
|
$in: {
|
||||||
},
|
entity: 'application',
|
||||||
filter: {
|
data: {
|
||||||
id: applicationId,
|
systemId: 1,
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
id: applicationId,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}, { dontCollect: true });
|
||||||
}, { dontCollect: true });
|
assert(domain, `处理userEntityGrant时,找不到对应的domain,applicationId是「${applicationId}」`);
|
||||||
assert(domain, `处理userEntityGrant时,找不到对应的domain,applicationId是「${applicationId}」`);
|
const url = composeDomainUrl(domain as EntityDict['domain']['Schema'], 'wechatQrCode/scan', {
|
||||||
const url = composeDomainUrl(domain as EntityDict['domain']['Schema'], 'wechatQrCode/scan', {
|
scene: sceneStr,
|
||||||
scene: sceneStr,
|
time: `${Date.now()}`,
|
||||||
time: `${Date.now()}`,
|
});
|
||||||
});
|
|
||||||
|
assert(!expired); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。
|
||||||
|
wechatInstance.sendServeMessage({
|
||||||
|
openId,
|
||||||
|
type: 'news',
|
||||||
|
url,
|
||||||
|
title: `${name}为您创建了一个授权`,
|
||||||
|
description: '请接受',
|
||||||
|
picurl: 'http://img95.699pic.com/element/40018/2473.png_860.png',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert(qrCodeType === 'wechatPublicForMp');
|
||||||
|
// 找到相关的小程序
|
||||||
|
const [ appMp ] = await context.select('application', {
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
config: 1,
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
systemId,
|
||||||
|
type: 'wechatMp',
|
||||||
|
}
|
||||||
|
}, { dontCollect: true });
|
||||||
|
assert(appMp, '公众号推送小程序码时找不到关联的小程序');
|
||||||
|
const { config } = appMp;
|
||||||
|
const { appId } = config as WechatMpConfig;
|
||||||
|
|
||||||
assert(!expired); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。
|
// 先试着发文字链接
|
||||||
wechatInstance.sendServeMessage({
|
const content = `${name}为您创建了一个授权,<a href="#" data-miniprogram-appid="${appId}" data-miniprogram-path="${composeUrl('/pages/wecharQrCode/scan', {
|
||||||
openId,
|
oakId: wcqId,
|
||||||
type: 'news',
|
time: `${Date.now()}`,
|
||||||
url,
|
})}">请点击领取</a>`;
|
||||||
title: `${name}给您创建了一个授权`,
|
|
||||||
description: '请接受',
|
assert(!expired); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。
|
||||||
picurl: 'http://img95.699pic.com/element/40018/2473.png_860.png',
|
wechatInstance.sendServeMessage({
|
||||||
});
|
openId,
|
||||||
|
type: 'text',
|
||||||
|
content,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue