当userENtityGrant过期时,推送过期消息

This commit is contained in:
wenjiarui 2023-03-22 12:00:51 +08:00
parent c5a16eb037
commit 0725963f6a
5 changed files with 93 additions and 65 deletions

View File

@ -1125,9 +1125,9 @@ function syncUserInfoWechatMp(_a, context) {
var _b, _c, _d;
var nickname = _a.nickname, avatarUrl = _a.avatarUrl, encryptedData = _a.encryptedData, iv = _a.iv, signature = _a.signature;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var userId, application, config, _e, _f, sessionKey, user;
return tslib_1.__generator(this, function (_g) {
switch (_g.label) {
var userId, application, config, _e, _f, sessionKey, user, _g, type, config2, _h, appId, appSecret, wechatInstance, result;
return tslib_1.__generator(this, function (_j) {
switch (_j.label) {
case 0:
userId = context.getToken().userId;
application = context.getApplication();
@ -1169,28 +1169,17 @@ function syncUserInfoWechatMp(_a, context) {
dontCollect: true,
})];
case 1:
_e = tslib_1.__read.apply(void 0, [_g.sent(), 1]), _f = _e[0], sessionKey = _f.sessionKey, user = _f.user;
// console.log(avatarUrl);
// const { type, config } = application;
// assert(type === 'wechatMp' || config.type === 'wechatMp');
// const config2 = config as WechatMpConfig;
// const { appId, appSecret } = config2;
// const wechatInstance = WechatSDK.getInstance(appId, 'wechatMp', appSecret);
// const result = wechatInstance.decryptData(sessionKey as string, encryptedData, iv, signature);
_e = tslib_1.__read.apply(void 0, [_j.sent(), 1]), _f = _e[0], sessionKey = _f.sessionKey, user = _f.user;
_g = application, type = _g.type, config2 = _g.config;
(0, assert_1.assert)(type === 'wechatMp' || config2.type === 'wechatMp');
_h = config2, appId = _h.appId, appSecret = _h.appSecret;
wechatInstance = oak_external_sdk_1.WechatSDK.getInstance(appId, 'wechatMp', appSecret);
result = wechatInstance.decryptData(sessionKey, encryptedData, iv, signature);
// 实测发现解密出来的和userInfo完全一致……
// console.log(result);
console.log(result);
return [4 /*yield*/, setUserInfoFromWechat(user, { nickname: nickname, avatar: avatarUrl }, context)];
case 2:
// console.log(avatarUrl);
// const { type, config } = application;
// assert(type === 'wechatMp' || config.type === 'wechatMp');
// const config2 = config as WechatMpConfig;
// const { appId, appSecret } = config2;
// const wechatInstance = WechatSDK.getInstance(appId, 'wechatMp', appSecret);
// const result = wechatInstance.decryptData(sessionKey as string, encryptedData, iv, signature);
// 实测发现解密出来的和userInfo完全一致……
// console.log(result);
_g.sent();
_j.sent();
return [2 /*return*/];
}
});

View File

@ -293,12 +293,21 @@ function setUserSubscribed(openId, eventKey, context) {
time: "".concat(Date.now()),
});
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(url, "'>\u8BF7\u70B9\u51FB\u9886\u53D6</a>");
(0, assert_1.default)(!expired_1); // 如果生成的wechatQrCode没过期userEntityGrant就不可能过期。
wechatInstance.sendServeMessage({
openId: openId,
type: 'text',
content: content,
});
// assert(!expired); // 如果生成的wechatQrCode没过期userEntityGrant就不可能过期。
if (!expired_1) {
wechatInstance.sendServeMessage({
openId: openId,
type: 'text',
content: content,
});
}
else {
wechatInstance.sendServeMessage({
openId: openId,
type: 'text',
content: '您好,您扫描的二维码已经过期,请联系管理员重新获取',
});
}
return [3 /*break*/, 9];
case 7: return [4 /*yield*/, context.select('domain', {
data: {
@ -329,15 +338,24 @@ function setUserSubscribed(openId, eventKey, context) {
scene: sceneStr,
time: "".concat(Date.now()),
});
(0, assert_1.default)(!expired_1); // 如果生成的wechatQrCode没过期userEntityGrant就不可能过期。
wechatInstance.sendServeMessage({
openId: openId,
type: 'news',
url: url,
title: "".concat(name_1, "\u4E3A\u60A8\u521B\u5EFA\u4E86\u4E00\u4E2A\u6388\u6743"),
description: '请接受',
picurl: 'http://img95.699pic.com/element/40018/2473.png_860.png',
});
// assert(!expired); // 如果生成的wechatQrCode没过期userEntityGrant就不可能过期。
if (!expired_1) {
wechatInstance.sendServeMessage({
openId: openId,
type: 'news',
url: url,
title: "".concat(name_1, "\u4E3A\u60A8\u521B\u5EFA\u4E86\u4E00\u4E2A\u6388\u6743"),
description: '请接受',
picurl: 'http://img95.699pic.com/element/40018/2473.png_860.png',
});
}
else {
wechatInstance.sendServeMessage({
openId: openId,
type: 'text',
content: '您好,您扫描的二维码已经过期,请联系管理员重新获取',
});
}
_k.label = 9;
case 9: return [3 /*break*/, 11];
case 10:

View File

@ -25,12 +25,16 @@ function Render(props) {
return [2 /*return*/];
}
});
}); } }, { children: t('common:action.confirm') })) }, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: "\u8BF7\u8F93\u5165\u6635\u79F0", value: nickname, onChange: function (e) { return updateItem({ user: {
id: (0, uuid_1.generateNewId)(),
action: 'update',
data: {
nickname: e.target.value
}
} }, tokenId); } }) }))] })));
}); } }, { children: t('common:action.confirm') })) }, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: "\u8BF7\u8F93\u5165\u6635\u79F0", value: nickname, onChange: function (e) {
return updateItem({
user: {
id: (0, uuid_1.generateNewId)(),
action: 'update',
data: {
nickname: e.target.value,
},
},
}, tokenId);
} }) }))] })));
}
exports.default = Render;

View File

@ -950,15 +950,15 @@ export async function syncUserInfoWechatMp<ED extends EntityDict, Cxt extends Ba
// console.log(avatarUrl);
// const { type, config } = application;
const { type, config: config2 } = application as Partial<EntityDict['application']['Schema']>;
// assert(type === 'wechatMp' || config.type === 'wechatMp');
assert(type === 'wechatMp' || config2!.type === 'wechatMp');
// const config2 = config as WechatMpConfig;
// const { appId, appSecret } = config2;
// const wechatInstance = WechatSDK.getInstance(appId, 'wechatMp', appSecret);
// const result = wechatInstance.decryptData(sessionKey as string, encryptedData, iv, signature);
const { appId, appSecret } = config2 as WechatMpConfig;
const wechatInstance = WechatSDK.getInstance(appId, 'wechatMp', appSecret);
const result = wechatInstance.decryptData(sessionKey as string, encryptedData, iv, signature);
// 实测发现解密出来的和userInfo完全一致……
// console.log(result);
console.log(result);
await setUserInfoFromWechat<ED, Cxt>(user!, { nickname, avatar: avatarUrl }, context);
}

View File

@ -303,12 +303,21 @@ async function setUserSubscribed(openId: string, eventKey: string, context: BRC)
// 先试着发文字链接
const content = `${name}为您创建了一个授权,<a href='#' data-miniprogram-appid='${appId}' data-miniprogram-path='${url}'>请点击领取</a>`;
assert(!expired); // 如果生成的wechatQrCode没过期userEntityGrant就不可能过期。
wechatInstance.sendServeMessage({
openId,
type: 'text',
content,
});
// assert(!expired); // 如果生成的wechatQrCode没过期userEntityGrant就不可能过期。
if (!expired) {
wechatInstance.sendServeMessage({
openId,
type: 'text',
content,
});
} else {
wechatInstance.sendServeMessage({
openId,
type: 'text',
content: '您好,您扫描的二维码已经过期,请联系管理员重新获取',
});
}
}
else {
// 推domain上的scan/code链接
@ -341,15 +350,23 @@ async function setUserSubscribed(openId: string, eventKey: string, context: BRC)
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',
});
// assert(!expired); // 如果生成的wechatQrCode没过期userEntityGrant就不可能过期。
if (!expired) {
wechatInstance.sendServeMessage({
openId,
type: 'news',
url,
title: `${name}为您创建了一个授权`,
description: '请接受',
picurl: 'http://img95.699pic.com/element/40018/2473.png_860.png',
});
} else {
wechatInstance.sendServeMessage({
openId,
type: 'text',
content: '您好,您扫描的二维码已经过期,请联系管理员重新获取',
});
}
}
}
}