wechat判断了wechatQrCode的过期
This commit is contained in:
parent
4ab636890f
commit
0c575966ce
|
|
@ -88,7 +88,7 @@ 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 applicationId, list, now, data, doUpdate, sceneStr, wcqId, _a, weChatQrCode, entity, entityId, _b, _c, userEntityGrant, _d, id, granter, expired, entity2, _e, domain, url, name_1, application, _f, type, config, _g, appId, appSecret, wechatInstance;
|
var applicationId, list, now, data, doUpdate, sceneStr, wcqId, _a, wechatQrCode, application, _b, type, config, _c, appId, appSecret, wechatInstance, expired, entity, entityId, _d, _e, userEntityGrant, _f, id, granter, expired_1, entity2, _g, domain, url;
|
||||||
var _this = this;
|
var _this = this;
|
||||||
return tslib_1.__generator(this, function (_h) {
|
return tslib_1.__generator(this, function (_h) {
|
||||||
switch (_h.label) {
|
switch (_h.label) {
|
||||||
|
|
@ -179,6 +179,7 @@ function setUserSubscribed(openId, eventKey, context) {
|
||||||
id: 1,
|
id: 1,
|
||||||
entity: 1,
|
entity: 1,
|
||||||
entityId: 1,
|
entityId: 1,
|
||||||
|
expired: 1,
|
||||||
},
|
},
|
||||||
filter: {
|
filter: {
|
||||||
id: wcqId,
|
id: wcqId,
|
||||||
|
|
@ -187,11 +188,26 @@ function setUserSubscribed(openId, eventKey, context) {
|
||||||
count: 10,
|
count: 10,
|
||||||
}, { dontCollect: true })];
|
}, { dontCollect: true })];
|
||||||
case 2:
|
case 2:
|
||||||
_a = tslib_1.__read.apply(void 0, [_h.sent(), 1]), weChatQrCode = _a[0];
|
_a = tslib_1.__read.apply(void 0, [_h.sent(), 1]), wechatQrCode = _a[0];
|
||||||
if (!weChatQrCode) return [3 /*break*/, 8];
|
if (!wechatQrCode) return [3 /*break*/, 8];
|
||||||
entity = weChatQrCode.entity, entityId = weChatQrCode.entityId;
|
application = context.getApplication();
|
||||||
_b = entity;
|
_b = application, type = _b.type, config = _b.config;
|
||||||
switch (_b) {
|
(0, assert_1.default)(type === 'wechatPublic');
|
||||||
|
_c = config, appId = _c.appId, appSecret = _c.appSecret;
|
||||||
|
wechatInstance = oak_external_sdk_1.WechatSDK.getInstance(appId, appSecret, 'wechatPublic');
|
||||||
|
expired = wechatQrCode.expired;
|
||||||
|
if (expired) {
|
||||||
|
// 若二维码已经过期,则直接告知用户已经过期
|
||||||
|
wechatInstance.sendServeMessage({
|
||||||
|
openId: openId,
|
||||||
|
type: 'text',
|
||||||
|
content: '此二维码已经过期,请重新获取',
|
||||||
|
});
|
||||||
|
return [2 /*return*/];
|
||||||
|
}
|
||||||
|
entity = wechatQrCode.entity, entityId = wechatQrCode.entityId;
|
||||||
|
_d = entity;
|
||||||
|
switch (_d) {
|
||||||
case 'user': return [3 /*break*/, 3];
|
case 'user': return [3 /*break*/, 3];
|
||||||
case 'userEntityGrant': return [3 /*break*/, 4];
|
case 'userEntityGrant': return [3 /*break*/, 4];
|
||||||
}
|
}
|
||||||
|
|
@ -221,8 +237,8 @@ function setUserSubscribed(openId, eventKey, context) {
|
||||||
}
|
}
|
||||||
}, { dontCollect: true })];
|
}, { dontCollect: true })];
|
||||||
case 5:
|
case 5:
|
||||||
_c = tslib_1.__read.apply(void 0, [_h.sent(), 1]), userEntityGrant = _c[0];
|
_e = tslib_1.__read.apply(void 0, [_h.sent(), 1]), userEntityGrant = _e[0];
|
||||||
_d = userEntityGrant, id = _d.id, granter = _d.granter, expired = _d.expired, entity2 = _d.entity;
|
_f = userEntityGrant, id = _f.id, granter = _f.granter, expired_1 = _f.expired, entity2 = _f.entity;
|
||||||
return [4 /*yield*/, context.select('domain', {
|
return [4 /*yield*/, context.select('domain', {
|
||||||
data: {
|
data: {
|
||||||
id: 1,
|
id: 1,
|
||||||
|
|
@ -246,23 +262,17 @@ function setUserSubscribed(openId, eventKey, context) {
|
||||||
}
|
}
|
||||||
}, { dontCollect: true })];
|
}, { dontCollect: true })];
|
||||||
case 6:
|
case 6:
|
||||||
_e = tslib_1.__read.apply(void 0, [_h.sent(), 1]), domain = _e[0];
|
_g = tslib_1.__read.apply(void 0, [_h.sent(), 1]), domain = _g[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,
|
||||||
});
|
});
|
||||||
(0, assert_1.default)(!expired); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。
|
(0, assert_1.default)(!expired_1); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。
|
||||||
name_1 = granter.name || granter.nickname;
|
|
||||||
application = context.getApplication();
|
|
||||||
_f = application, type = _f.type, config = _f.config;
|
|
||||||
(0, assert_1.default)(type === 'wechatPublic');
|
|
||||||
_g = config, appId = _g.appId, appSecret = _g.appSecret;
|
|
||||||
wechatInstance = oak_external_sdk_1.WechatSDK.getInstance(appId, appSecret, 'wechatPublic');
|
|
||||||
wechatInstance.sendServeMessage({
|
wechatInstance.sendServeMessage({
|
||||||
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, "\u7ED9\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',
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -190,13 +190,14 @@ async function setUserSubscribed(openId: string, eventKey: string, context: BRC)
|
||||||
// sceneStr是id压缩后的字符串
|
// sceneStr是id压缩后的字符串
|
||||||
const wcqId = expandUuidTo36Bytes(sceneStr);
|
const wcqId = expandUuidTo36Bytes(sceneStr);
|
||||||
|
|
||||||
const [weChatQrCode] = await context.select(
|
const [wechatQrCode] = await context.select(
|
||||||
'wechatQrCode',
|
'wechatQrCode',
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
id: 1,
|
id: 1,
|
||||||
entity: 1,
|
entity: 1,
|
||||||
entityId: 1,
|
entityId: 1,
|
||||||
|
expired: 1,
|
||||||
},
|
},
|
||||||
filter: {
|
filter: {
|
||||||
id: wcqId,
|
id: wcqId,
|
||||||
|
|
@ -206,8 +207,29 @@ async function setUserSubscribed(openId: string, eventKey: string, context: BRC)
|
||||||
},
|
},
|
||||||
{ dontCollect: true },
|
{ dontCollect: true },
|
||||||
);
|
);
|
||||||
if (weChatQrCode) {
|
if (wechatQrCode) {
|
||||||
const { entity, entityId } = weChatQrCode;
|
const application = context.getApplication();
|
||||||
|
const { type, config } = application!;
|
||||||
|
assert(type === 'wechatPublic');
|
||||||
|
const { appId, appSecret } = config as WechatPublicConfig;
|
||||||
|
|
||||||
|
const wechatInstance = WechatSDK.getInstance(
|
||||||
|
appId,
|
||||||
|
appSecret,
|
||||||
|
'wechatPublic'
|
||||||
|
) as WechatPublicInstance;
|
||||||
|
|
||||||
|
const { expired } = wechatQrCode;
|
||||||
|
if (expired) {
|
||||||
|
// 若二维码已经过期,则直接告知用户已经过期
|
||||||
|
wechatInstance.sendServeMessage({
|
||||||
|
openId,
|
||||||
|
type: 'text',
|
||||||
|
content: '此二维码已经过期,请重新获取',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { entity, entityId } = wechatQrCode;
|
||||||
switch (entity) {
|
switch (entity) {
|
||||||
case 'user': {
|
case 'user': {
|
||||||
// 裂变获得的用户
|
// 裂变获得的用户
|
||||||
|
|
@ -267,18 +289,6 @@ async function setUserSubscribed(openId: string, eventKey: string, context: BRC)
|
||||||
});
|
});
|
||||||
|
|
||||||
assert(!expired); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。
|
assert(!expired); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。
|
||||||
const name = granter!.name || granter!.nickname;
|
|
||||||
const application = context.getApplication();
|
|
||||||
const { type, config } = application!;
|
|
||||||
assert(type === 'wechatPublic');
|
|
||||||
const { appId, appSecret } = config as WechatPublicConfig;
|
|
||||||
|
|
||||||
const wechatInstance = WechatSDK.getInstance(
|
|
||||||
appId,
|
|
||||||
appSecret,
|
|
||||||
'wechatPublic'
|
|
||||||
) as WechatPublicInstance;
|
|
||||||
|
|
||||||
wechatInstance.sendServeMessage({
|
wechatInstance.sendServeMessage({
|
||||||
openId,
|
openId,
|
||||||
type: 'news',
|
type: 'news',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue